This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
rpc: Use the blocks pinning API for chainHead methods #13233
Merged
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
a72b8a8
rpc/chain_head: Add backend to subscription management
lexnv d672047
rpc/chain_head: Pin blocks internally and adjust testing
lexnv c9a0d7e
client/in_mem: Reference for the number of pinned blocks
lexnv 3536c94
rpc/tests: Check in-memory references to pinned blocks
lexnv bdfdb7d
rpc/chain_head: Fix clippy
lexnv 43d6825
rpc/chain_head: Remove unused comment
lexnv 6bc2e87
rpc/chain_head: Place subscription handle under `Arc` and unpin block…
lexnv 9015061
rpc/tests: Check all pinned blocks are unpinned on drop
lexnv 09773d3
Apply suggestions from code review
lexnv 4a38133
Update client/rpc-spec-v2/src/chain_head/subscription.rs
lexnv e509399
rpc/tests: Retry fetching the pinned references for CI correctness
lexnv 3c2cc6c
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv c6bfb6f
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
09fe732
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
b7dcacd
client/service: Use 512 as maximum number of pinned blocks
lexnv d67c6ed
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv fa5323f
chain_head: Fix merging conflicts
lexnv 852c302
rpc/chain_head: Adjust subscriptions to use pinning API
lexnv cdd1428
rpc/chain_head/tests: Test subscription management
lexnv ad9e921
rpc/chain_head: Adjust chain_head follow to the new API
lexnv 866bb87
rpc/chain_head: Adjust chain_head.rs to the new API
lexnv b2e08ce
rpc/chain_head/tests: Adjust test.rs to the new API
lexnv b63f102
client/builder: Use new chainHead API
lexnv c46d7d4
rpc/chain_head: Fix documentation
lexnv 7da0406
rpc/chain_head: Fix clippy
lexnv 5561e56
client/in_mem: ChainHead no longer uses `in_mem::children`
lexnv d36f748
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv ff3c9d5
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv 9781584
Update client/rpc-spec-v2/src/chain_head/subscription.rs
lexnv cc31043
Update client/rpc-spec-v2/src/chain_head/subscription.rs
lexnv efb14c4
Update client/rpc-spec-v2/src/chain_head/subscription.rs
lexnv 10b61d5
Update client/rpc-spec-v2/src/chain_head/subscription.rs
lexnv c5266cc
chain_head: Add block state machine
lexnv f5a911f
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv 7bf9da0
Address feedback
lexnv 6c054ba
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv 6a3f9e5
Use new_native_or_wasm_executor
lexnv d287533
chain_head: Remove 'static on Backend
lexnv 6073ae2
chain_head: Add documentation
lexnv 871dcb8
chain_head: Lock blocks before async blocks
lexnv 083e3c3
chain_head_follower: Remove static on backend
lexnv 1bb4b00
Update client/service/src/builder.rs
lexnv 04a167c
Update client/service/src/builder.rs
lexnv cc24ad1
chain_head: Add BlockHeaderAbsent to the PartialEq impl
lexnv b3ca736
client: Add better documentation around pinning constants
lexnv 3b1764f
chain_head: Move subscription to dedicated module
lexnv 9cd53f1
Merge remote-tracking branch 'origin/master' into lexnv/chainhead_pin…
lexnv 8b0eaff
subscription: Rename global pin / unpin functions
lexnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apply suggestions from code review
Co-authored-by: Bastian Köcher <[email protected]>
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a logic error? If we try to pin the same block twice, the first
unpinwill unpin it in the backend (assuming it is only pinned by this subscription). Is this documented in the spec that when you receive the same block as best and some seconds later as finalized (without having called unpin in between), you only need to call unpin once?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I couldn't find something super specific in the RPC spec regarding this, tho I was expecting users to call
unpinonly once (when they are no longer interested in using the block).From the spec:
I was also thinking along the lines: the newBlock event is where the block is declared and pinned; and bestBlockChanged and finalized are updates about what happens with that block.
I think we could update the spec documentation for the
unpinmethod to state that only block hashes reported by thenewBlockevent are supposed to be unpinned.What do you think about it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds reasonable to me that:
newBlockevent,best/finalisedevents emitted re that block (and no pinning happens at this point),newBlock, whenever a user would like to unpin that block hash they will call "unpin" once against the hash to unpin it.But, if a
newBlockis unpinned quickly and then a best/finalized event is emitted for it.. should it need unpinning again? I think offhand I'd go with "it's been unpinned so it stays unpinned, and those events are just notifications about the block you've already declared you don't care about any more".But that would make it annoying for people to ignore all but best/finalized blocks! Because the simplest logic to do so would be to call "unpin" on all "newBlock" events and not on any best/finalized block events.
"unpin" could potentially take both a block hash and a type (new/best/finalized) so that you can opt-out of all block events you don't care about but still keep pinned the ones you do?
Or, a best/finalized notificiation could pin the block again, and "unpin" just takes the hash, but that runs the risk of race conditions (I "unpin" a newBlock but by the time the unpin request hits the node ,a bestBlock for that hash is emitted).
So two options then are:
Maybe there's a simpler way around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should pin on the first event we see (a client can only see bestBlock/finalized without newblock by having connected after the block was imported) and then unpin should be called when they are not interested anymore. We should update the spec to mention this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we could update the spec to reflect something along the lines:
"Any block hash reported by chainHead's events is guaranteed to be pinned in memory and it requires a single
chainHead_unstable_unpincall to unpin the block."The spec states currently:
Yep, that's along the lines of how we pin internally for this
chainheadsubscription.Before using the subscriptions (best block and finalized) we are:
newBlockevent for each children of the finalized recursively (and pin the block)I might be wrong, but I think its entirely possible that we can miss blocks (warp sync etc) and such we always
pinthe block on the first event that we get from the subscriptions.In case of errors or jumps, the chainHead should produce the
Stopevents.Let me know if that is correct, I ll take an action to create a PR to clarify a bit the spec, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way would be to allow users to call
unpinonly for hashes reported by theFinalizedevent: paritytech/json-rpc-interface-spec#32. Let me know if this makes a bit more sense, thanks!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if they call
unpinafter receiving eg anewBlock, and then the server sends afinalizedwith the same hash? I assume that the block is still unpinned even though the client has been told about it again.If I was only interested in finalized blocks, and did not want to have any non-finalized blocks pinned any longer than necessary, what would I do?
I gather from chatting with Alex that that what I'd do is hold off on calling "unpin" on anything until I see a
finalizednotification (which also lists all blocks that are "pruned"), and then I could use that list tounpinall blocks that are listed as "pruned" now that I know they aren't important any more. (This relies on that list of pruned blocks really just being a list of all blocks not in the finalized chain, since if they are pinned they wouldn't be pruned). Does that make sense?I think github is being slow; this message popped up after I wrote mine :) Also seems like a very valid approach so long as the finalized event def lists all of the blocks produced since the last finalized event that aren't on the finalized chain (so we know what we can safely unpin now). A nice thing about this is that the client is never sent a hash to a block that's already been unpinned (since they can't unpin until they won't hear any more about the block anyway!).