-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
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.
Just minor nits, logic looks good to me 👍
Signed-off-by: Alexandru Vasile <[email protected]>
Co-authored-by: Sebastian Kunert <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
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.
LGTM
|
||
// Get the string representation for the subscription. | ||
let sub_id = match sub_id { | ||
SubscriptionId::Num(num) => num.to_string(), |
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.
Return value: String containing an opaque value representing the subscription.
It's technically possible to provide a custom SubscriptionId
such number but perhaps we could enforce substrate to only accept something that serializes to a String.
I think it's better to reject the subscription if the subscription ID is a number feels like bug if someone tries to use another custom subscription ID generator but it's converted to a String under the hood.
This is a edge-case and we could deal with it in another PR.
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 change the logic to reject subscription IDs represented by numbers.
I'd like to tackle that in another PR, it seems that chain_head/tests infrastructure is providing by default numbers.
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.
nice work, LGTM
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-37/1736/1 |
* rpc/chain_head: Add event structure for serialization Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add tests for events Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add API trait for `chainHead` Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add RPC errors Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Manage subscription ID tracking for pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add tests for subscription management Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Constructor for the API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Placeholders for API implementation Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Accept RPC subscription sink Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate the runtime API event Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `body` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `header` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `call` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `unpin` method Signed-off-by: Alexandru Vasile <[email protected]> * Update `Cargo.lock` Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement `getGenesis` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Parse params from hex string Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Constuct API with genesis hash Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add the finalized block to reported tree route Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Export the API and events for better ergonomics Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Add test module with helper functions Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test block events from the `follow` pubsub Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `genesisHash` getter Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `header` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `body` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test calling into the runtime API Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test runtime for the `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Add runtime code changes for `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Remove space from rustdoc Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use the `child_key` for storage queries Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Test `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Test child trie query for `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Event serialization typo Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Remove subscription aliases Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add `NetworkConfig` parameter Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Named parameters as camelCase if present Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement From<ApiError> for RuntimeEvents Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Handle pruning of the best block in finalization window Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate initial block events Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify that initial in-memory blocks are reported Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify the finalized event with forks and pruned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Separate logic for generating initial events Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Handle stopping a subscription ID Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Submit events until the "Stop" event is triggered Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Separate logic for handling new and finalized blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Extend subscription logic with subId handle Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Adjust to the new subscription mngmt API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Refuse RuntimeAPI calls without the runtime flag Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify RuntimeAPI calls without runtime flag Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add best block per subscription Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Check storage keys for prefixes Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Check storage queries with invalid prefixes Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Allow maximum number of pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test the maximum number of pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Adjust to origin/master and apply clippy Signed-off-by: Alexandru Vasile <[email protected]> * client/service: Enable the `chainHead` API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Stop subscription on client disconnect and add debug logs Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix sending `Stop` on subscription exit Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Check best block is descendent of latest finalized Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Report events before pruning the best block Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Nonrecursive initial block generation Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate initial events on subscription executor Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Reduce dev-dependencies for tokio Signed-off-by: Alexandru Vasile <[email protected]> * Apply suggestions from code review Co-authored-by: Sebastian Kunert <[email protected]> * rpc/chain_head: Accept empty parameters Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use debug of `HexDisplay` for full format Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Enable subscription ID Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use jsonrpsee 16.2 camelCase feature for paramaters Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use `NonZeroUsize` for `NetworkConfig` param Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Rename `runtime_updates` to `has_runtime_updates` Signed-off-by: Alexandru Vasile <[email protected]> Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Sebastian Kunert <[email protected]>
* rpc/chain_head: Add event structure for serialization Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add tests for events Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add API trait for `chainHead` Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add RPC errors Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Manage subscription ID tracking for pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add tests for subscription management Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Constructor for the API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Placeholders for API implementation Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Accept RPC subscription sink Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate the runtime API event Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `body` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `header` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `call` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement the `unpin` method Signed-off-by: Alexandru Vasile <[email protected]> * Update `Cargo.lock` Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement `getGenesis` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Parse params from hex string Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Constuct API with genesis hash Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add the finalized block to reported tree route Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Export the API and events for better ergonomics Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Add test module with helper functions Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test block events from the `follow` pubsub Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `genesisHash` getter Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `header` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test `body` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test calling into the runtime API Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test runtime for the `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Add runtime code changes for `follow` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Remove space from rustdoc Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use the `child_key` for storage queries Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Test `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Test child trie query for `storage` method Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Event serialization typo Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Remove subscription aliases Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add `NetworkConfig` parameter Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Named parameters as camelCase if present Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Implement From<ApiError> for RuntimeEvents Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Handle pruning of the best block in finalization window Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate initial block events Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify that initial in-memory blocks are reported Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify the finalized event with forks and pruned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Separate logic for generating initial events Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Handle stopping a subscription ID Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Submit events until the "Stop" event is triggered Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Separate logic for handling new and finalized blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Extend subscription logic with subId handle Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Adjust to the new subscription mngmt API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Refuse RuntimeAPI calls without the runtime flag Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Verify RuntimeAPI calls without runtime flag Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Add best block per subscription Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Check storage keys for prefixes Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Check storage queries with invalid prefixes Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Allow maximum number of pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Test the maximum number of pinned blocks Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Adjust to origin/master and apply clippy Signed-off-by: Alexandru Vasile <[email protected]> * client/service: Enable the `chainHead` API Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Stop subscription on client disconnect and add debug logs Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Fix sending `Stop` on subscription exit Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Check best block is descendent of latest finalized Signed-off-by: Alexandru Vasile <[email protected]> * chain_head/tests: Report events before pruning the best block Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Nonrecursive initial block generation Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Generate initial events on subscription executor Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Reduce dev-dependencies for tokio Signed-off-by: Alexandru Vasile <[email protected]> * Apply suggestions from code review Co-authored-by: Sebastian Kunert <[email protected]> * rpc/chain_head: Accept empty parameters Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use debug of `HexDisplay` for full format Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Enable subscription ID Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use jsonrpsee 16.2 camelCase feature for paramaters Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Use `NonZeroUsize` for `NetworkConfig` param Signed-off-by: Alexandru Vasile <[email protected]> * rpc/chain_head: Rename `runtime_updates` to `has_runtime_updates` Signed-off-by: Alexandru Vasile <[email protected]> Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Sebastian Kunert <[email protected]>
This PR implements the chainHead methods.
The
chainHead
methods include:follow
methodThis PR also includes the unsubscribe methods.
This PR relies on, but not blocked by the delayed pruning from #12497.
The PR should follow after a new jsonrpsee release and merge into substrate for
exposing the
subscription_id
API.Part of: #12071.
Testing Done
Manual Testing
Created an app using jsonrpsee to subscribe to block production and compare the results
with the OLD API V1.
Unit Tests
./src/chain_head/subscription.rs
Integration Tests
./src/chain_head/tests.rs
CC: @paritytech/tools-team.