Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove substrate like codec limit #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions test-support/reference-trie/src/substrate_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -263,8 +262,6 @@ fn partial_from_iterator_encode<I: Iterator<Item = u8>>(
nibble_count: usize,
node_kind: NodeKind,
) -> Vec<u8> {
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),
Expand Down Expand Up @@ -378,8 +375,6 @@ pub(crate) fn size_and_prefix_iterator(
prefix: u8,
prefix_mask: usize,
) -> impl Iterator<Item = u8> {
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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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<Item = u8> + '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),
Expand Down