Allow reverting the last tx with no flow data update. (#51)

* Allow reverting the last tx with no flow data update.

* Add details for panic.
This commit is contained in:
peilun-conflux 2024-04-15 10:44:18 +08:00 committed by GitHub
parent 8cff5dabe7
commit f5a71375be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View File

@ -188,7 +188,10 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
self.layers[0][index] = leaf;
self.recompute_after_fill_leaves(index, index + 1);
} else if self.layers[0][index] != leaf {
panic!("Fill with invalid leaf")
panic!(
"Fill with invalid leaf, index={} was={:?} get={:?}",
index, self.layers[0][index], leaf
);
}
}

View File

@ -535,12 +535,19 @@ impl LogManager {
+ previous_tx.num_entries() as u64)
/ PORA_CHUNK_SIZE as u64)
as usize;
assert!(current_len > expected_len);
while let Some((subtree_depth, _)) = initial_data.subtree_list.pop() {
current_len -= 1 << (subtree_depth - 1);
if current_len == expected_len {
break;
if current_len > expected_len {
while let Some((subtree_depth, _)) = initial_data.subtree_list.pop()
{
current_len -= 1 << (subtree_depth - 1);
if current_len == expected_len {
break;
}
}
} else {
warn!(
"revert last tx with no-op: {} {}",
current_len, expected_len
);
}
assert_eq!(current_len, expected_len);
while let Some((index, h)) = initial_data.known_leaves.pop() {