Skip to content

Commit d0c8a07

Browse files
authored
grandpa: Ensure WarpProof stays in its limits (#6963)
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 <>
1 parent 97d3b86 commit d0c8a07

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

prdoc/pr_6963.prdoc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: 'grandpa: Ensure `WarpProof` stays in its limits'
2+
doc:
3+
- audience: Node Dev
4+
description: |-
5+
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.
6+
7+
Close: https://github.com/paritytech/polkadot-sdk/issues/6957
8+
crates:
9+
- name: sc-consensus-grandpa
10+
bump: patch

substrate/client/consensus/grandpa/src/warp_proof.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,20 @@ impl<Block: BlockT> WarpSyncProof<Block> {
174174
let header = blockchain.header(latest_justification.target().1)?
175175
.expect("header hash corresponds to a justification in db; must exist in db as well; qed.");
176176

177-
proofs.push(WarpSyncFragment { header, justification: latest_justification })
177+
let proof = WarpSyncFragment { header, justification: latest_justification };
178+
179+
// Check for the limit. We remove some bytes from the maximum size, because we're
180+
// only counting the size of the `WarpSyncFragment`s. The extra margin is here
181+
// to leave room for rest of the data (the size of the `Vec` and the boolean).
182+
if proofs_encoded_len + proof.encoded_size() >= MAX_WARP_SYNC_PROOF_SIZE - 50 {
183+
false
184+
} else {
185+
proofs.push(proof);
186+
true
187+
}
188+
} else {
189+
true
178190
}
179-
180-
true
181191
};
182192

183193
let final_outcome = WarpSyncProof { proofs, is_finished };

0 commit comments

Comments
 (0)