From 6ca53b4212c9d5e7fe5bd20d1f01c3d4ff078afc Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Thu, 24 Oct 2024 15:43:18 +0200 Subject: [PATCH] fix breaking changes --- prdoc/pr_5741.prdoc | 2 -- .../rpc-spec-v2/src/chain_head/chain_head.rs | 17 ++++++++++++++++- .../src/chain_head/chain_head_storage.rs | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_5741.prdoc b/prdoc/pr_5741.prdoc index 5eafbc90ee85..14161e3e0dca 100644 --- a/prdoc/pr_5741.prdoc +++ b/prdoc/pr_5741.prdoc @@ -21,5 +21,3 @@ crates: bump: major - name: sc-rpc-server bump: patch - - name: sc-service - bump: major diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs index 279a7594fef9..8e9391896b4d 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs @@ -73,6 +73,9 @@ pub struct ChainHeadConfig { /// Stop all subscriptions if the distance between the leaves and the current finalized /// block is larger than this value. pub max_lagging_distance: usize, + /// The maximum number of items reported by the `chainHead_storage` before + /// pagination is required. + pub operation_max_storage_items: usize, /// The maximum number of `chainHead_follow` subscriptions per connection. pub max_follow_subscriptions_per_connection: usize, } @@ -99,6 +102,10 @@ const MAX_LAGGING_DISTANCE: usize = 128; /// The maximum number of `chainHead_follow` subscriptions per connection. const MAX_FOLLOW_SUBSCRIPTIONS_PER_CONNECTION: usize = 4; +/// The maximum number of items the `chainHead_storage` can return +/// before paginations is required. +const MAX_STORAGE_ITER_ITEMS: usize = 5; + impl Default for ChainHeadConfig { fn default() -> Self { ChainHeadConfig { @@ -107,6 +114,7 @@ impl Default for ChainHeadConfig { subscription_max_ongoing_operations: MAX_ONGOING_OPERATIONS, max_lagging_distance: MAX_LAGGING_DISTANCE, max_follow_subscriptions_per_connection: MAX_FOLLOW_SUBSCRIPTIONS_PER_CONNECTION, + operation_max_storage_items: MAX_STORAGE_ITER_ITEMS, } } } @@ -124,6 +132,9 @@ pub struct ChainHead, Block: BlockT, Client> { /// Stop all subscriptions if the distance between the leaves and the current finalized /// block is larger than this value. max_lagging_distance: usize, + /// The maximum number of items reported by the `chainHead_storage` before + /// pagination is required. + operation_max_storage_items: usize, /// Phantom member to pin the block type. _phantom: PhantomData, } @@ -148,6 +159,7 @@ impl, Block: BlockT, Client> ChainHead { backend, ), max_lagging_distance: config.max_lagging_distance, + operation_max_storage_items: config.operation_max_storage_items, _phantom: PhantomData, } } @@ -423,7 +435,10 @@ where Err(_) => return ResponsePayload::error(ChainHeadRpcError::InvalidBlock), }; - let mut storage_client = ChainHeadStorage::::new(self.client.clone()); + let mut storage_client = ChainHeadStorage::::new( + self.client.clone(), + self.operation_max_storage_items + ); let (rp, rp_fut) = method_started_response(block_guard.operation().operation_id()); diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs index 936117e66f98..19541cc9f152 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs @@ -44,7 +44,7 @@ impl Clone for ChainHeadStorage { impl ChainHeadStorage { /// Constructs a new [`ChainHeadStorage`]. - pub fn new(client: Arc) -> Self { + pub fn new(client: Arc, _operation_max_storage_items: usize) -> Self { Self { client: Storage::new(client), _phandom: PhantomData } } }