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: Implement chainHead RPC API
#12544
Merged
Merged
Changes from 75 commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
717ee38
rpc/chain_head: Add event structure for serialization
lexnv 3716594
rpc/chain_head: Add tests for events
lexnv c3ac4b8
rpc/chain_head: Add API trait for `chainHead`
lexnv 4f88981
rpc/chain_head: Add RPC errors
lexnv ab1bc81
rpc/chain_head: Manage subscription ID tracking for pinned blocks
lexnv 2e2237f
rpc/chain_head: Add tests for subscription management
lexnv 798acd2
rpc/chain_head: Constructor for the API
lexnv 373887c
rpc/chain_head: Placeholders for API implementation
lexnv aa1d21b
rpc/chain_head: Accept RPC subscription sink
lexnv d8e60f7
rpc/chain_head: Generate the runtime API event
lexnv 8dbdaf8
rpc/chain_head: Implement the `follow` method
lexnv 3ed5c79
rpc/chain_head: Implement the `body` method
lexnv 27d9a5c
rpc/chain_head: Implement the `header` method
lexnv 9ec6b36
rpc/chain_head: Implement the `storage` method
lexnv 70fd229
rpc/chain_head: Implement the `call` method
lexnv d93161a
rpc/chain_head: Implement the `unpin` method
lexnv 2bec344
Update `Cargo.lock`
lexnv 7e4326a
rpc/chain_head: Implement `getGenesis` method
lexnv 0f32685
rpc/chain_head: Fix clippy
lexnv 4ba5d77
rpc/chain_head: Parse params from hex string
lexnv 542d360
rpc/chain_head: Constuct API with genesis hash
lexnv e1f5796
rpc/chain_head: Add the finalized block to reported tree route
lexnv cf3530c
rpc/chain_head: Export the API and events for better ergonomics
lexnv 7ae67fa
chain_head/tests: Add test module with helper functions
lexnv 80b8776
chain_head/tests: Test block events from the `follow` pubsub
lexnv 83e926c
chain_head/tests: Test `genesisHash` getter
lexnv f047db9
chain_head/tests: Test `header` method
lexnv 05d6219
chain_head/tests: Test `body` method
lexnv f9c004b
chain_head/tests: Test calling into the runtime API
lexnv e0ab77c
chain_head/tests: Test runtime for the `follow` method
lexnv 04574cc
chain_head/tests: Add runtime code changes for `follow` method
lexnv b64a9c9
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv 2de8d6c
rpc/chain_head: Remove space from rustdoc
lexnv d78e04d
rpc/chain_head: Use the `child_key` for storage queries
lexnv ba8a257
rpc/chain_head: Test `storage` method
lexnv 745c795
rpc/chain_head: Test child trie query for `storage` method
lexnv c80a428
rpc/chain_head: Event serialization typo
lexnv cce8e42
rpc/chain_head: Remove subscription aliases
lexnv a5678c4
rpc/chain_head: Add `NetworkConfig` parameter
lexnv e6f7df0
rpc/chain_head: Named parameters as camelCase if present
lexnv 80ddec8
rpc/chain_head: Implement From<ApiError> for RuntimeEvents
lexnv 08fe794
rpc/chain_head: Handle pruning of the best block in finalization window
lexnv 76c0d2c
rpc/chain_head: Generate initial block events
lexnv cad484e
chain_head/tests: Verify that initial in-memory blocks are reported
lexnv 351154f
chain_head/tests: Verify the finalized event with forks and pruned bl…
lexnv f185e7c
rpc/chain_head: Fix clippy
lexnv 4742b7c
rpc/chain_head: Separate logic for generating initial events
lexnv 06ac897
rpc/chain_head: Handle stopping a subscription ID
lexnv 06797df
rpc/chain_head: Submit events until the "Stop" event is triggered
lexnv 2a1b79f
rpc/chain_head: Separate logic for handling new and finalized blocks
lexnv e5fac2c
rpc/chain_head: Extend subscription logic with subId handle
lexnv 6b84dd4
rpc/chain_head: Adjust to the new subscription mngmt API
lexnv 091cd90
rpc/chain_head: Refuse RuntimeAPI calls without the runtime flag
lexnv f5514b8
chain_head/tests: Verify RuntimeAPI calls without runtime flag
lexnv a060fb8
rpc/chain_head: Add best block per subscription
lexnv d782cc2
rpc/chain_head: Check storage keys for prefixes
lexnv 4ce5fe5
chain_head/tests: Check storage queries with invalid prefixes
lexnv 60a46ab
rpc/chain_head: Allow maximum number of pinned blocks
lexnv 239013c
chain_head/tests: Test the maximum number of pinned blocks
lexnv 1edc4a7
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv 7804896
rpc/chain_head: Adjust to origin/master and apply clippy
lexnv 42035bf
client/service: Enable the `chainHead` API
lexnv ed720a1
rpc/chain_head: Stop subscription on client disconnect and add debug …
lexnv 3820d4f
rpc/chain_head: Fix sending `Stop` on subscription exit
lexnv e95fa3f
rpc/chain_head: Check best block is descendent of latest finalized
lexnv 4372c4a
chain_head/tests: Report events before pruning the best block
lexnv eab917f
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv 9d25bea
rpc/chain_head: Nonrecursive initial block generation
lexnv 1065eaf
rpc/chain_head: Generate initial events on subscription executor
lexnv 6dbd383
rpc/chain_head: Reduce dev-dependencies for tokio
lexnv 54b7395
Apply suggestions from code review
lexnv 331e1bb
rpc/chain_head: Accept empty parameters
lexnv 6da3073
rpc/chain_head: Use debug of `HexDisplay` for full format
lexnv cafd5ef
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv cc4d1a5
rpc/chain_head: Enable subscription ID
lexnv 9a3f5f7
rpc/chain_head: Use jsonrpsee 16.2 camelCase feature for paramaters
lexnv 7e7afed
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv 22bd9fa
Merge remote-tracking branch 'origin/master' into lexnv/rpc_chainhead
lexnv 0111353
rpc/chain_head: Use `NonZeroUsize` for `NetworkConfig` param
lexnv 41aee3e
rpc/chain_head: Rename `runtime_updates` to `has_runtime_updates`
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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| #![allow(non_snake_case)] | ||
|
|
||
| //! API trait of the chain head. | ||
| use crate::chain_head::event::{ChainHeadEvent, FollowEvent, NetworkConfig}; | ||
| use jsonrpsee::{core::RpcResult, proc_macros::rpc}; | ||
|
|
||
| #[rpc(client, server)] | ||
| pub trait ChainHeadApi<Hash> { | ||
| /// Track the state of the head of the chain: the finalized, non-finalized, and best blocks. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[subscription( | ||
| name = "chainHead_unstable_follow", | ||
| unsubscribe = "chainHead_unstable_unfollow", | ||
| item = FollowEvent<Hash>, | ||
| )] | ||
| fn chain_head_unstable_follow(&self, runtimeUpdates: bool); | ||
|
|
||
| /// Retrieves the body (list of transactions) of a pinned block. | ||
| /// | ||
| /// This method should be seen as a complement to `chainHead_unstable_follow`, | ||
| /// allowing the JSON-RPC client to retrieve more information about a block | ||
| /// that has been reported. | ||
| /// | ||
| /// Use `archive_unstable_body` if instead you want to retrieve the body of an arbitrary block. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[subscription( | ||
| name = "chainHead_unstable_body", | ||
| unsubscribe = "chainHead_unstable_stopBody", | ||
| item = ChainHeadEvent<String>, | ||
| )] | ||
| fn chain_head_unstable_body( | ||
| &self, | ||
| followSubscription: String, | ||
| hash: Hash, | ||
| networkConfig: Option<NetworkConfig>, | ||
| ); | ||
|
|
||
| /// Retrieves the header of a pinned block. | ||
| /// | ||
| /// This method should be seen as a complement to `chainHead_unstable_follow`, | ||
| /// allowing the JSON-RPC client to retrieve more information about a block | ||
| /// that has been reported. | ||
| /// | ||
| /// Use `archive_unstable_header` if instead you want to retrieve the header of an arbitrary | ||
| /// block. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[method(name = "chainHead_unstable_header", blocking)] | ||
| fn chain_head_unstable_header( | ||
| &self, | ||
| followSubscription: String, | ||
| hash: Hash, | ||
| ) -> RpcResult<Option<String>>; | ||
|
|
||
| /// Get the chain's genesis hash. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[method(name = "chainHead_unstable_genesisHash", blocking)] | ||
| fn chain_head_unstable_genesis_hash(&self) -> RpcResult<String>; | ||
|
|
||
| /// Return a storage entry at a specific block's state. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[subscription( | ||
| name = "chainHead_unstable_storage", | ||
| unsubscribe = "chainHead_unstable_stopStorage", | ||
| item = ChainHeadEvent<String>, | ||
| )] | ||
| fn chain_head_unstable_storage( | ||
| &self, | ||
| followSubscription: String, | ||
| hash: Hash, | ||
| key: String, | ||
| childKey: Option<String>, | ||
| networkConfig: Option<NetworkConfig>, | ||
| ); | ||
|
|
||
| /// Call into the Runtime API at a specified block's state. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[subscription( | ||
| name = "chainHead_unstable_call", | ||
| unsubscribe = "chainHead_unstable_stopCall", | ||
| item = ChainHeadEvent<String>, | ||
| )] | ||
| fn chain_head_unstable_call( | ||
| &self, | ||
| followSubscription: String, | ||
| hash: Hash, | ||
| function: String, | ||
| callParameters: String, | ||
| networkConfig: Option<NetworkConfig>, | ||
| ); | ||
|
|
||
| /// Unpin a block reported by the `follow` method. | ||
| /// | ||
| /// Ongoing operations that require the provided block | ||
| /// will continue normally. | ||
| /// | ||
| /// # Unstable | ||
| /// | ||
| /// This method is unstable and subject to change in the future. | ||
| #[method(name = "chainHead_unstable_unpin", blocking)] | ||
| fn chain_head_unstable_unpin(&self, followSubscription: String, hash: Hash) -> RpcResult<()>; | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.