diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index ae982708c8cb..b47ceae95a03 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -55,6 +55,11 @@ pub use disputes::{ // For a 16-ary Merkle Prefix Trie, we can expect at most 16 32-byte hashes per node. const MERKLE_NODE_MAX_SIZE: usize = 512; // 16-ary Merkle Prefix Trie for 32-bit ValidatorIndex has depth at most 8. +// Merkle Prefix Tries use the key in order to determine Proof structure. +// To that effect, at every depth we require 4-bit nibbles from the key in +// order to determine the Trie node of that key. +// In this case, the key is a 32-bit validator index, and 32/4 = 8, the max +// proof depth. const MERKLE_PROOF_MAX_DEPTH: usize = 8; /// The bomb limit for decompressing code blobs. @@ -305,7 +310,7 @@ impl Proof { } #[derive(thiserror::Error, Debug)] -/// +/// This is a convenience error type to adequately handle erronious Merkle Proofs pub enum MerkleProofError { #[error("Merkle max proof depth exceeded {0} > {} .", MERKLE_PROOF_MAX_DEPTH)] /// This error signifies that the Proof length exceeds the trie's max depth @@ -330,7 +335,7 @@ impl TryFrom>> for Proof { .map_err(|_| Self::Error::MerkleProofNodeSizeExceeded(length))?; out.push(data); } - Ok(Proof(BoundedVec::from_vec(out).expect("Buffer size is deterined above. qed"))) + Ok(Proof(BoundedVec::from_vec(out).expect("Buffer size is determined above. qed"))) } }