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

grandpa: Ensure WarpProof stays in its limits #6963

Merged
merged 2 commits into from
Dec 20, 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
10 changes: 10 additions & 0 deletions prdoc/pr_6963.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'grandpa: Ensure `WarpProof` stays in its limits'
doc:
- audience: Node Dev
description: |-
There was the chance that a `WarpProof` was bigger than the maximum warp sync proof size. This could have happened when inserting the last justification, which then may pushed the total proof size above the maximum. The solution is simply to ensure that the last justfication also fits into the limits.

Close: https://github.com/paritytech/polkadot-sdk/issues/6957
crates:
- name: sc-consensus-grandpa
bump: patch
16 changes: 13 additions & 3 deletions substrate/client/consensus/grandpa/src/warp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,20 @@ impl<Block: BlockT> WarpSyncProof<Block> {
let header = blockchain.header(latest_justification.target().1)?
.expect("header hash corresponds to a justification in db; must exist in db as well; qed.");

proofs.push(WarpSyncFragment { header, justification: latest_justification })
let proof = WarpSyncFragment { header, justification: latest_justification };

// Check for the limit. We remove some bytes from the maximum size, because we're
// only counting the size of the `WarpSyncFragment`s. The extra margin is here
// to leave room for rest of the data (the size of the `Vec` and the boolean).
if proofs_encoded_len + proof.encoded_size() >= MAX_WARP_SYNC_PROOF_SIZE - 50 {
false
} else {
proofs.push(proof);
true
}
} else {
true
}

true
};

let final_outcome = WarpSyncProof { proofs, is_finished };
Expand Down
Loading