-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add API for block pinning #12475
Comments
// CC @bkchr @skunert @jsdw @niklasad1 Is there anything special that we should do for storage and runtime calls at a pinned block, other than what was done in #12476 ? |
Just to summarize from what @bkchr suggested in #12476:
API pinning / unpinningSubstrate Client needs to expose an API for pinning / unpinning blocks. A block that is pinned with this API has the following guarantees:
The substrate client is pinning the blocks before they are reported here When the last notification BlockImportNotification or FinalityNotification is dropped, the block in unpinned. ImplicationsLeaking Blocks in DBIf the substrate node crashes or is terminated, the block's entries from
This would imply extending the meta_keys with a new key On node start-up, the
This option is more simplistic in nature but has the downside that the node needs to keep the information Option 1 I believe is a promising approach for the long term, as the block's body could exponentially Enforced Substrate LimitsThis DB feature does not enforce any limit on the number of blocks kept around. @arkpar raised this in the following #12497:
To err on the safe side, Option 1 seems like a good path forward. We enforce a limit big enough in AlternativesBuild upon the #12497 "delayed-pruning" PR and expose a new notification stream: The RPC layer can subscribe to This has the benefit of avoiding the previous limitations, plus not needing to hold references to the notifications, but the // CC @tomaka @bkchr @arkpar @skunert @jsdw @niklasad1 Would love to hear your thoughts on this 🙏 |
Another aspect is that we need to report the node's blocks from memory after the From RPC V2 Spec:
This is achieved at the moment without subscribing to BlockImportNotification or FinalityNotification. |
Just relinking here my comment about smoldot's API: #12476 (comment) |
First, thank you for creating this good write-up @lexnv!
Sounds like a good idea to me. If we need db support for this, we could still implement this later.
For sure we need a limit! I think we should go this way. In the node we should "trust" all logic to not pin blocks indefinitely and that everything has some reasonable upper bound. For now I would not try to put this upper bound into the pinning and more rely on the fact that every component on its own ensures that it doesn't keep all blocks pinned. For the RPC layer/RPC server sitting in Substrate we should ensure that we have some kind of upper bound of pinned blocks per node and in total. These upper bounds should also be part of the spec or somehow be query able by applications to follow these upper bounds. |
There are two kinds of blocks/states that may be pinned.
|
The block pinning is a feature required by the RPC Spec V2.
The block pinning feature should be called for subscribers of the
chainHead_unstable_follow
method.Each block produced by the
chainHead_unstable_follow
(new block, best block, finalized block) subscription shouldbe pinned to offer data access for:
chain_getBlock
RPC)chain_getHeader
RPC)The substrate has pin and unpin functionality but it is only preserving the state of the block.
Extend the database and client to offer support for
pin_block
andunpin_block
to reference countthe desired block and prevent it from pruning.
The text was updated successfully, but these errors were encountered: