Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport/stable2412: chainHead: Always report discarded items for storage operations #6842

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions prdoc/pr_6760.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: 'chainHead: Always report discarded items for storage operations'
doc:
- audience: [Node Dev, Node Operator]
description: |-
This PR ensures that substrate always reports discarded items as zero.
This is needed to align with the rpc-v2 spec
crates:
- name: sc-rpc-spec-v2
bump: patch
10 changes: 6 additions & 4 deletions substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ where
}),
};

let (rp, rp_fut) = method_started_response(operation_id);
let (rp, rp_fut) = method_started_response(operation_id, None);
let fut = async move {
// Wait for the server to send out the response and if it produces an error no event
// should be generated.
Expand Down Expand Up @@ -432,7 +432,8 @@ where

let mut storage_client = ChainHeadStorage::<Client, Block, BE>::new(self.client.clone());

let (rp, rp_fut) = method_started_response(block_guard.operation().operation_id());
// Storage items are never discarded.
let (rp, rp_fut) = method_started_response(block_guard.operation().operation_id(), Some(0));

let fut = async move {
// Wait for the server to send out the response and if it produces an error no event
Expand Down Expand Up @@ -507,7 +508,7 @@ where
let operation_id = block_guard.operation().operation_id();
let client = self.client.clone();

let (rp, rp_fut) = method_started_response(operation_id.clone());
let (rp, rp_fut) = method_started_response(operation_id.clone(), None);
let fut = async move {
// Wait for the server to send out the response and if it produces an error no event
// should be generated.
Expand Down Expand Up @@ -630,8 +631,9 @@ where

fn method_started_response(
operation_id: String,
discarded_items: Option<usize>,
) -> (ResponsePayload<'static, MethodResponse>, MethodResponseFuture) {
let rp = MethodResponse::Started(MethodResponseStarted { operation_id, discarded_items: None });
let rp = MethodResponse::Started(MethodResponseStarted { operation_id, discarded_items });
ResponsePayload::success(rp).notify_on_completion()
}

Expand Down
7 changes: 5 additions & 2 deletions substrate/client/rpc-spec-v2/src/chain_head/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ async fn ensure_operation_limits_works() {
let operation_id = match response {
MethodResponse::Started(started) => {
// Check discarded items.
assert!(started.discarded_items.is_none());
assert_eq!(started.discarded_items, Some(0));
started.operation_id
},
MethodResponse::LimitReached => panic!("Expected started response"),
Expand Down Expand Up @@ -3228,7 +3228,10 @@ async fn storage_closest_merkle_value() {
.await
.unwrap();
let operation_id = match response {
MethodResponse::Started(started) => started.operation_id,
MethodResponse::Started(started) => {
assert_eq!(started.discarded_items, Some(0));
started.operation_id
},
MethodResponse::LimitReached => panic!("Expected started response"),
};

Expand Down
Loading