-
Notifications
You must be signed in to change notification settings - Fork 2.7k
rpc: Use the blocks pinning API for chainHead methods #13233
Changes from 8 commits
a72b8a8
d672047
c9a0d7e
3536c94
bdfdb7d
43d6825
6bc2e87
9015061
09773d3
4a38133
e509399
3c2cc6c
c6bfb6f
09fe732
b7dcacd
d67c6ed
fa5323f
852c302
cdd1428
ad9e921
866bb87
b2e08ce
b63f102
c46d7d4
7da0406
5561e56
d36f748
ff3c9d5
9781584
cc31043
efb14c4
10b61d5
c5266cc
f5a911f
7bf9da0
6c054ba
6a3f9e5
d287533
6073ae2
871dcb8
083e3c3
1bb4b00
04a167c
cc24ad1
b3ca736
3b1764f
9cd53f1
8b0eaff
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,15 +60,15 @@ use sp_runtime::{ | |
| use std::{marker::PhantomData, sync::Arc}; | ||
|
|
||
| /// An API for chain head RPC calls. | ||
| pub struct ChainHead<BE, Block: BlockT, Client> { | ||
| pub struct ChainHead<BE: Backend<Block> + 'static, Block: BlockT, Client> { | ||
|
||
| /// Substrate client. | ||
| client: Arc<Client>, | ||
| /// Backend of the chain. | ||
| backend: Arc<BE>, | ||
| /// Executor to spawn subscriptions. | ||
| executor: SubscriptionTaskExecutor, | ||
| /// Keep track of the pinned blocks for each subscription. | ||
| subscriptions: Arc<SubscriptionManagement<Block>>, | ||
| subscriptions: Arc<SubscriptionManagement<Block, BE>>, | ||
| /// The hexadecimal encoded hash of the genesis block. | ||
| genesis_hash: String, | ||
| /// The maximum number of pinned blocks allowed per connection. | ||
|
|
@@ -77,7 +77,7 @@ pub struct ChainHead<BE, Block: BlockT, Client> { | |
| _phantom: PhantomData<Block>, | ||
| } | ||
|
|
||
| impl<BE, Block: BlockT, Client> ChainHead<BE, Block, Client> { | ||
| impl<BE: Backend<Block> + 'static, Block: BlockT, Client> ChainHead<BE, Block, Client> { | ||
| /// Create a new [`ChainHead`]. | ||
| pub fn new<GenesisHash: AsRef<[u8]>>( | ||
| client: Arc<Client>, | ||
|
|
@@ -129,7 +129,7 @@ impl<BE, Block: BlockT, Client> ChainHead<BE, Block, Client> { | |
| fn generate_initial_events<Block, BE, Client>( | ||
| client: &Arc<Client>, | ||
| backend: &Arc<BE>, | ||
| handle: &SubscriptionHandle<Block>, | ||
| handle: &SubscriptionHandle<Block, BE>, | ||
| runtime_updates: bool, | ||
| ) -> Result<Vec<FollowEvent<Block::Hash>>, SubscriptionManagementError> | ||
| where | ||
|
|
@@ -314,13 +314,14 @@ async fn submit_events<EventStream, T>( | |
|
|
||
| /// Generate the "NewBlock" event and potentially the "BestBlockChanged" event for | ||
| /// every notification. | ||
| fn handle_import_blocks<Client, Block>( | ||
| fn handle_import_blocks<BE, Client, Block>( | ||
| client: &Arc<Client>, | ||
| handle: &SubscriptionHandle<Block>, | ||
| handle: &SubscriptionHandle<Block, BE>, | ||
| runtime_updates: bool, | ||
| notification: BlockImportNotification<Block>, | ||
| ) -> Result<(FollowEvent<Block::Hash>, Option<FollowEvent<Block::Hash>>), SubscriptionManagementError> | ||
| where | ||
| BE: Backend<Block> + 'static, | ||
| Block: BlockT + 'static, | ||
| Client: CallApiAt<Block> + 'static, | ||
| { | ||
|
|
@@ -370,12 +371,13 @@ where | |
|
|
||
| /// Generate the "Finalized" event and potentially the "BestBlockChanged" for | ||
| /// every notification. | ||
| fn handle_finalized_blocks<Client, Block>( | ||
| fn handle_finalized_blocks<BE, Client, Block>( | ||
| client: &Arc<Client>, | ||
| handle: &SubscriptionHandle<Block>, | ||
| handle: &SubscriptionHandle<Block, BE>, | ||
| notification: FinalityNotification<Block>, | ||
| ) -> Result<(FollowEvent<Block::Hash>, Option<FollowEvent<Block::Hash>>), SubscriptionManagementError> | ||
| where | ||
| BE: Backend<Block> + 'static, | ||
| Block: BlockT + 'static, | ||
| Client: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static, | ||
| { | ||
|
|
@@ -474,9 +476,8 @@ where | |
| return Err(err) | ||
| }, | ||
| }; | ||
|
|
||
| // Keep track of the subscription. | ||
| let Some((rx_stop, sub_handle)) = self.subscriptions.insert_subscription(sub_id.clone(), runtime_updates, self.max_pinned_blocks) else { | ||
| let Some((rx_stop, sub_handle)) = self.subscriptions.insert_subscription(sub_id.clone(), runtime_updates, self.max_pinned_blocks, self.backend.clone()) else { | ||
| // Inserting the subscription can only fail if the JsonRPSee | ||
| // generated a duplicate subscription ID. | ||
| debug!(target: "rpc-spec-v2", "[follow][id={:?}] Subscription already accepted", sub_id); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.