diff --git a/test-support/reference-trie/src/substrate_like.rs b/test-support/reference-trie/src/substrate_like.rs index e9b67489..53f78a5c 100644 --- a/test-support/reference-trie/src/substrate_like.rs +++ b/test-support/reference-trie/src/substrate_like.rs @@ -15,7 +15,7 @@ //! Codec and layout configuration similar to upstream default substrate one. use super::{CodecError as Error, NodeCodec as NodeCodecT, *}; -use trie_db::node::Value; +use trie_db::{nibble_ops, node::Value}; /// No extension trie with no hashed value. pub struct HashedValueNoExt; @@ -45,7 +45,6 @@ impl TrieLayout for HashedValueNoExtThreshold { /// Constants specific to encoding with external value node support. pub mod trie_constants { const FIRST_PREFIX: u8 = 0b_00 << 6; - pub const NIBBLE_SIZE_BOUND: usize = u16::max_value() as usize; pub const LEAF_PREFIX_MASK: u8 = 0b_01 << 6; pub const BRANCH_WITHOUT_MASK: u8 = 0b_10 << 6; pub const BRANCH_WITH_MASK: u8 = 0b_11 << 6; @@ -263,8 +262,6 @@ fn partial_from_iterator_encode>( nibble_count: usize, node_kind: NodeKind, ) -> Vec { - let nibble_count = std::cmp::min(trie_constants::NIBBLE_SIZE_BOUND, nibble_count); - let mut output = Vec::with_capacity(4 + (nibble_count / nibble_ops::NIBBLE_PER_BYTE)); match node_kind { NodeKind::Leaf => NodeHeader::Leaf(nibble_count).encode_to(&mut output), @@ -378,8 +375,6 @@ pub(crate) fn size_and_prefix_iterator( prefix: u8, prefix_mask: usize, ) -> impl Iterator { - let size = std::cmp::min(trie_constants::NIBBLE_SIZE_BOUND, size); - let max_value = 255u8 >> prefix_mask; let l1 = std::cmp::min(max_value as usize - 1, size); let (first_byte, mut rem) = if size == l1 { @@ -422,14 +417,13 @@ fn decode_size(first: u8, input: &mut impl Input, prefix_mask: usize) -> Result< return Ok(result) } result -= 1; - while result <= trie_constants::NIBBLE_SIZE_BOUND { + loop { let n = input.read_byte()? as usize; if n < 255 { return Ok(result + n + 1) } result += 255; } - Ok(trie_constants::NIBBLE_SIZE_BOUND) } /// Reference implementation of a `TrieStream` without extension. @@ -441,7 +435,7 @@ pub struct ReferenceTrieStreamNoExt { /// Create a leaf/branch node, encoding a number of nibbles. fn fuse_nibbles_node<'a>(nibbles: &'a [u8], kind: NodeKind) -> impl Iterator + 'a { - let size = std::cmp::min(trie_constants::NIBBLE_SIZE_BOUND, nibbles.len()); + let size = nibbles.len(); let iter_start = match kind { NodeKind::Leaf => size_and_prefix_iterator(size, trie_constants::LEAF_PREFIX_MASK, 2),