Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

rpc: Implement chainHead RPC API #12544

Merged
merged 80 commits into from
Dec 19, 2022
Merged

rpc: Implement chainHead RPC API #12544

merged 80 commits into from
Dec 19, 2022

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Oct 21, 2022

This PR implements the chainHead methods.

The chainHead methods include:

This 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.

chainHead_unstable_follow

Event: Ok(Object({"event": String("initialized"), "finalizedBlockHash": String("0xb83c6a7c4666843f38293b85d8191fdbd4c054fa1ee49650bcdf2ac2867121e2"), "finalizedBlockRuntime": Object({"spec": Object({"apis": Array([Array([String("0xdf6acb689907609b"), Number(4)]), Array([String("0x37e397fc7c91f5e4"), Number(1)]), Array([String("0x40fe3ad401f8959a"), Number(6)]), Array([String("0xd2bc9897eed08f15"), Number(3)]), Array([String("0xf78b278be53f454c"), Number(2)]), Array([String("0xed99c5acb25eedf5"), Number(3)]), Array([String("0x17a6bc0d0062aeb3"), Number(1)]), Array([String("0xcbca25e39f142387"), Number(2)]), Array([String("0x687ad44ad37f03c2"), Number(1)]), Array([String("0xbc9d89904f5b923f"), Number(1)]), Array([String("0x68b66ba122c93fa7"), Number(1)]), Array([String("0x37c8bb1350a9a2a8"), Number(2)]), Array([String("0xf3ff14d5ab527059"), Number(2)]), Array([String("0x91d5df18b0d2cf58"), Number(1)]), Array([String("0xab3c0572291feb8b"), Number(1)])]), "authoringVersion": Number(10), "implName": String("substrate-node"), "implVersion": Number(0), "specName": String("node"), "specVersion": Number(268), "stateVersion": Number(1), "transactionVersion": Number(2)}), "type": String("valid")})}))
Event: Ok(Object({"blockHash": String("0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c"), "event": String("newBlock"), "newRuntime": Null, "parentBlockHash": String("0xb83c6a7c4666843f38293b85d8191fdbd4c054fa1ee49650bcdf2ac2867121e2")}))
Event: Ok(Object({"blockHash": String("0x653b74aab0b8767ea86e4a4d91792203a1ec230e5499ec4c6dcd16bf1929570e"), "event": String("newBlock"), "newRuntime": Null, "parentBlockHash": String("0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c")}))
Event: Ok(Object({"bestBlockHash": String("0x653b74aab0b8767ea86e4a4d91792203a1ec230e5499ec4c6dcd16bf1929570e"), "event": String("bestBlockChanged")}))
Event: Ok(Object({"blockHash": String("0x3cb58c4a14615bed81d007460f4825e6b49ef5f1ed7b2272ac5dcde250919a43"), "event": String("newBlock"), "newRuntime": Null, "parentBlockHash": String("0x653b74aab0b8767ea86e4a4d91792203a1ec230e5499ec4c6dcd16bf1929570e")}))
Event: Ok(Object({"bestBlockHash": String("0x3cb58c4a14615bed81d007460f4825e6b49ef5f1ed7b2272ac5dcde250919a43"), "event": String("bestBlockChanged")}))
Event: Ok(Object({"event": String("finalized"), "finalizedBlockHashes": Array([String("0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c")]), "prunedBlockHashes": Array([])}))
  Block is finalized hash="0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c"
  [OLD::chain_getBlock] hash="0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c"
         Result=Object({"block": Object({"extrinsics": Array([String("0x280403000b8952a1858401")]), "header": Object({"digest": Object({"logs": Array([String("0x0642414245b5010100000000776427210000000034d2c861ee7b8a2976744790de52081141238aee7a468ff6fadefb45c7789522572085cb94adeed7d33da3abf978d628af6149bc55f93224e0451e03b616cb01693fd1a503a4a257238fc368e8e8f05d517ae62e26b160f63bc318caa5229e0b"), String("0x054241424501017291330f162229c740ef277948fd64c39347e0cd8dd6d1faa59254d6b3bd83176d9dd9866dc0e1d2afead08066c184ad54acaf21e96ecfdae5501403cd76898b")])}), "extrinsicsRoot": String("0xdfd8970b4bb466a3021d64eea94325b6feb8b85c2a6f90c016d5efde4a82ccaf"), "number": String("0x4"), "parentHash": String("0xb83c6a7c4666843f38293b85d8191fdbd4c054fa1ee49650bcdf2ac2867121e2"), "stateRoot": String("0x0f038ffc5a2a139b5f2a7b4715d23f1827c57ef2de3f7e2019ea7c3e4263b622")})}), "justifications": Null})
  [OLD::state_getStorage] hash="0x9039ce8530314f50325408dff4a82fabaa05a54269be90b2ca0bfc98bd8bc77c"
         Result=String("0x0040fa7f398074858a02000000000000")

  [chainHead_unstable_body] result=Some(Ok(Object({"event": String("done"), "result": String("0x04280403000b8952a1858401")})))
  [chainHead_unstable_storage] result=Some(Ok(Object({"event": String("done"), "result": String("0x0040fa7f398074858a02000000000000")})))
  [chainHead_unstable_call] result=Some(Ok(Object({"event": String("done"), "result": String("0x00000000")})))

Unit Tests

./src/chain_head/subscription.rs

Integration Tests

./src/chain_head/tests.rs

CC: @paritytech/tools-team.

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv added B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Oct 21, 2022
@lexnv lexnv self-assigned this Oct 21, 2022
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Oct 21, 2022
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Contributor

@skunert skunert left a 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 👍

client/rpc-spec-v2/Cargo.toml Outdated Show resolved Hide resolved
client/rpc-spec-v2/src/chain_head/chain_head.rs Outdated Show resolved Hide resolved
client/rpc-spec-v2/src/chain_head/chain_head.rs Outdated Show resolved Hide resolved
client/rpc-spec-v2/src/chain_head/chain_head.rs Outdated Show resolved Hide resolved
lexnv and others added 2 commits November 24, 2022 10:50
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Contributor

@skunert skunert left a 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(),
Copy link
Member

@niklasad1 niklasad1 Dec 12, 2022

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.

Copy link
Contributor Author

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

Copy link
Member

@niklasad1 niklasad1 left a 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 <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv merged commit e118df5 into master Dec 19, 2022
@lexnv lexnv deleted the lexnv/rpc_chainhead branch December 19, 2022 15:38
@lexnv lexnv mentioned this pull request Dec 19, 2022
4 tasks
@Polkadot-Forum
Copy link

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

ltfschoen pushed a commit to ltfschoen/substrate that referenced this pull request Feb 22, 2023
* rpc/chain_head: Add event structure for serialization

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add tests for events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add API trait for `chainHead`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add RPC errors

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Manage subscription ID tracking for pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add tests for subscription management

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Constructor for the API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Placeholders for API implementation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Accept RPC subscription sink

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate the runtime API event

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `body` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `header` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `call` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `unpin` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update `Cargo.lock`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement `getGenesis` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Parse params from hex string

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Constuct API with genesis hash

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add the finalized block to reported tree route

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Export the API and events for better ergonomics

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Add test module with helper functions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test block events from the `follow` pubsub

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `genesisHash` getter

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `header` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `body` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test calling into the runtime API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test runtime for the `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Add runtime code changes for `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Remove space from rustdoc

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use the `child_key` for storage queries

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Test `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Test child trie query for `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Event serialization typo

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Remove subscription aliases

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add `NetworkConfig` parameter

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Named parameters as camelCase if present

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement From<ApiError> for RuntimeEvents

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Handle pruning of the best block in finalization window

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate initial block events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify that initial in-memory blocks are reported

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify the finalized event with forks and pruned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Separate logic for generating initial events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Handle stopping a subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Submit events until the "Stop" event is triggered

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Separate logic for handling new and finalized blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Extend subscription logic with subId handle

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Adjust to the new subscription mngmt API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Refuse RuntimeAPI calls without the runtime flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify RuntimeAPI calls without runtime flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add best block per subscription

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Check storage keys for prefixes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Check storage queries with invalid prefixes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Allow maximum number of pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test the maximum number of pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Adjust to origin/master and apply clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/service: Enable the `chainHead` API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Stop subscription on client disconnect and add debug logs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix sending `Stop` on subscription exit

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Check best block is descendent of latest finalized

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Report events before pruning the best block

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Nonrecursive initial block generation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate initial events on subscription executor

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Reduce dev-dependencies for tokio

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply suggestions from code review

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* rpc/chain_head: Accept empty parameters

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use debug of `HexDisplay` for full format

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Enable subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use jsonrpsee 16.2 camelCase feature for paramaters

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use `NonZeroUsize` for `NetworkConfig` param

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Rename `runtime_updates` to `has_runtime_updates`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* rpc/chain_head: Add event structure for serialization

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add tests for events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add API trait for `chainHead`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add RPC errors

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Manage subscription ID tracking for pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add tests for subscription management

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Constructor for the API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Placeholders for API implementation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Accept RPC subscription sink

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate the runtime API event

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `body` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `header` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `call` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement the `unpin` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update `Cargo.lock`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement `getGenesis` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Parse params from hex string

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Constuct API with genesis hash

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add the finalized block to reported tree route

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Export the API and events for better ergonomics

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Add test module with helper functions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test block events from the `follow` pubsub

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `genesisHash` getter

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `header` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test `body` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test calling into the runtime API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test runtime for the `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Add runtime code changes for `follow` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Remove space from rustdoc

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use the `child_key` for storage queries

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Test `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Test child trie query for `storage` method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Event serialization typo

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Remove subscription aliases

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add `NetworkConfig` parameter

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Named parameters as camelCase if present

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Implement From<ApiError> for RuntimeEvents

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Handle pruning of the best block in finalization window

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate initial block events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify that initial in-memory blocks are reported

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify the finalized event with forks and pruned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Separate logic for generating initial events

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Handle stopping a subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Submit events until the "Stop" event is triggered

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Separate logic for handling new and finalized blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Extend subscription logic with subId handle

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Adjust to the new subscription mngmt API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Refuse RuntimeAPI calls without the runtime flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Verify RuntimeAPI calls without runtime flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Add best block per subscription

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Check storage keys for prefixes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Check storage queries with invalid prefixes

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Allow maximum number of pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Test the maximum number of pinned blocks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Adjust to origin/master and apply clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* client/service: Enable the `chainHead` API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Stop subscription on client disconnect and add debug logs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Fix sending `Stop` on subscription exit

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Check best block is descendent of latest finalized

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* chain_head/tests: Report events before pruning the best block

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Nonrecursive initial block generation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Generate initial events on subscription executor

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Reduce dev-dependencies for tokio

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Apply suggestions from code review

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>

* rpc/chain_head: Accept empty parameters

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use debug of `HexDisplay` for full format

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Enable subscription ID

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use jsonrpsee 16.2 camelCase feature for paramaters

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Use `NonZeroUsize` for `NetworkConfig` param

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc/chain_head: Rename `runtime_updates` to `has_runtime_updates`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants