Skip to content

Commit

Permalink
grandpa: Ensure WarpProof stays in its limits (#6963)
Browse files Browse the repository at this point in the history
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: #6957

---------

Co-authored-by: command-bot <>
  • Loading branch information
bkchr authored Dec 20, 2024
1 parent 97d3b86 commit d0c8a07
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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

0 comments on commit d0c8a07

Please sign in to comment.