ChainSafe / ChainSafe/gossamer
Clean Up Old Runtimes on Canonical Chain
- Dominant language
- Go
- Stars
- 454
- Forks
- 144
- PR merge metrics
- No merged PRs in 30d
Description
(EDIT by Quentin on 2023-01-16)
Currently, Gossamer maintains running instances of all runtimes that were included in the canonical chain. This leads to a build up in memory usage for each runtime upgrade, since the previous instance (and all its associated wasmer/cgo resources) are kept running (see #1973).
So far, all calls need the best block runtime except:
- [`dot/core`'s `handleBlock`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/core/service.go#L215) needs the parent block runtime
- [`dot/core`'s `handleBlock`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/core/service.go#L227) needs the (upgraded or not) current block runtime to detect if we should substitute it
- RPC calls [`get_Metadata`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/core/service.go#L547), [`get_RuntimeVersion`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/core/service.go#L488) and [`payment_Queryinfo`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/rpc/modules/payment.go#L48) can get the runtime for any block hash given
- [`dot/sync`'s `handleBlock`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/dot/sync/chain_processor.go#L256) needs the parent block runtime
- [`lib/babe`'s `handleSlot`](https://github.com/ChainSafe/gossamer/blob/c326612ea1a80b837b318bc10c510d182fbb1054/lib/babe/babe.go#L506) needs the slot parent block runtime
Changes to be made:
Runtimes to keep instantiated:
- Best block runtime
- Finalised block runtime
- Unfinalised runtimes
Note each of these runtimes might be the same runtime pointer in most cases.
- Keep the best block runtime instantiated
- Keep the finalised block runtime instantiated (might be the same pointer as best block)
- Keep a mapping from runtime-upgrade block hash <-> runtime location (hash, db key etc.)
- When needed, find the ancestor runtime-upgrade block OR finalised block (whichever is found first) for a given block hash, then find the corresponding runtime and instantiate it from disk
- Remove mapping block hash <-> runtime pointer
Unanswered questions:
1. Can an upgrade happen on some but not all of the unfinalised forks? -> Yes
2. Do we need the runtime substitution feature?
Contributor guide
Assessment
This issue has not been assessed yet.