Skip to content

Commit

Permalink
grandpa: Ensure WarpProof stays in its limits
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.
  • Loading branch information
bkchr committed Dec 18, 2024
1 parent ef88865 commit 1c759d1
Showing 1 changed file with 13 additions and 3 deletions.
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 1c759d1

Please sign in to comment.