MPT insert into leaf, overlapping keys case

This commit is contained in:
Daniel Lubarov 2022-10-10 10:42:02 -07:00
parent 8776cee48b
commit 50002df8e4
2 changed files with 36 additions and 4 deletions

View File

@ -21,7 +21,7 @@
// branch[17] = insert_value
//
// if common_len > 0:
// return Extension[common_key, branch]
// return Extension[common_len, common_key, branch]
// else:
// return branch
@ -104,7 +104,19 @@ finished_processing_insert_value:
extension_for_common_key:
// stack: branch_ptr, common_len, common_key, node_len, node_key, insert_len, insert_key, node_value_ptr, insert_value_ptr, retdest
PANIC // TODO
// return Extension[common_len, common_key, branch]
%get_trie_data_size
// stack: extension_ptr, branch_ptr, common_len, common_key, ...
PUSH @MPT_NODE_EXTENSION %append_to_trie_data
SWAP2 %append_to_trie_data // Append common_len to our node
SWAP2 %append_to_trie_data // Append common_key to our node
SWAP1 %append_to_trie_data // Append branch_ptr to our node
// stack: extension_ptr, node_len, node_key, insert_len, insert_key, node_value_ptr, insert_value_ptr, retdest
SWAP6
%pop6
// stack: extension_ptr, retdest
SWAP1
JUMP
node_key_continues:
// stack: branch_ptr, common_len, common_key, node_len, node_key, insert_len, insert_key, node_value_ptr, insert_value_ptr, retdest

View File

@ -23,7 +23,7 @@ fn mpt_insert_empty() -> Result<()> {
}
#[test]
fn mpt_insert_leaf_same_key() -> Result<()> {
fn mpt_insert_leaf_identical_keys() -> Result<()> {
let key = Nibbles {
count: 3,
packed: 0xABC.into(),
@ -41,7 +41,7 @@ fn mpt_insert_leaf_same_key() -> Result<()> {
}
#[test]
fn mpt_insert_leaf_nonoverlapping_key() -> Result<()> {
fn mpt_insert_leaf_nonoverlapping_keys() -> Result<()> {
let state_trie = PartialTrie::Leaf {
nibbles: Nibbles {
count: 3,
@ -60,6 +60,26 @@ fn mpt_insert_leaf_nonoverlapping_key() -> Result<()> {
test_state_trie(state_trie, insert)
}
#[test]
fn mpt_insert_leaf_overlapping_keys() -> Result<()> {
let state_trie = PartialTrie::Leaf {
nibbles: Nibbles {
count: 3,
packed: 0xABC.into(),
},
value: test_account_1_rlp(),
};
let insert = InsertEntry {
nibbles: Nibbles {
count: 3,
packed: 0xADE.into(),
},
v: test_account_2_rlp(),
};
test_state_trie(state_trie, insert)
}
#[test]
fn mpt_insert_branch_replacing_empty_child() -> Result<()> {
let children = std::array::from_fn(|_| Box::new(PartialTrie::Empty));