mirror of
https://github.com/akula-bft/akula.git
synced 2026-04-19 03:00:13 -04:00
Interhashes fixes, tests, workarounds
This commit is contained in:
@@ -631,7 +631,7 @@ impl TableDecode for AccountChange {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct StorageChangeKey {
|
||||
pub block_number: BlockNumber,
|
||||
pub address: Address,
|
||||
|
||||
@@ -17,7 +17,7 @@ use rlp::{Decodable, Encodable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{iter::Step, mem::size_of, ops::Add};
|
||||
|
||||
pub use ethereum_types::{Address, Bloom, H160, H256, H512, H64, U512, U64};
|
||||
pub use ethereum_types::{Address, Bloom, H128, H160, H256, H512, H64, U512, U64};
|
||||
pub use ethnum::*;
|
||||
|
||||
pub const KECCAK_LENGTH: usize = H256::len_bytes();
|
||||
|
||||
@@ -7,14 +7,14 @@ use crate::{
|
||||
stages::*,
|
||||
},
|
||||
stages::stage_util::should_do_clean_promotion,
|
||||
trie::{increment_intermediate_hashes, regenerate_intermediate_hashes},
|
||||
trie::regenerate_intermediate_hashes,
|
||||
StageId,
|
||||
};
|
||||
use anyhow::{format_err, Context};
|
||||
use async_trait::async_trait;
|
||||
use std::{cmp, sync::Arc};
|
||||
use tempfile::TempDir;
|
||||
use tracing::info;
|
||||
use tracing::*;
|
||||
|
||||
/// Generation of intermediate hashes for efficient computation of the state trie root
|
||||
#[derive(Debug)]
|
||||
@@ -77,18 +77,24 @@ where
|
||||
)
|
||||
.await?
|
||||
{
|
||||
debug!("Regenerating intermediate hashes");
|
||||
regenerate_intermediate_hashes(tx, self.temp_dir.as_ref(), Some(block_state_root))
|
||||
.await
|
||||
.with_context(|| "Failed to generate interhashes")?
|
||||
} else {
|
||||
increment_intermediate_hashes(
|
||||
tx,
|
||||
self.temp_dir.as_ref(),
|
||||
past_progress,
|
||||
Some(block_state_root),
|
||||
)
|
||||
.await
|
||||
.with_context(|| "Failed to update interhashes")?
|
||||
debug!("Incrementing intermediate hashes");
|
||||
regenerate_intermediate_hashes(tx, self.temp_dir.as_ref(), Some(block_state_root))
|
||||
.await
|
||||
.with_context(|| "Failed to generate interhashes")?
|
||||
// TODO: fix increment
|
||||
// increment_intermediate_hashes(
|
||||
// tx,
|
||||
// self.temp_dir.as_ref(),
|
||||
// past_progress,
|
||||
// Some(block_state_root),
|
||||
// )
|
||||
// .await
|
||||
// .with_context(|| "Failed to update interhashes")?
|
||||
};
|
||||
|
||||
info!("Block #{} state root OK: {:?}", max_block, trie_root)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
use crate::{models::KECCAK_LENGTH, trie::util::assert_subset};
|
||||
use ethereum_types::H256;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct Node {
|
||||
state_mask: u16,
|
||||
tree_mask: u16,
|
||||
@@ -117,3 +117,27 @@ pub(crate) fn unmarshal_node(v: &[u8]) -> Option<Node> {
|
||||
state_mask, tree_mask, hash_mask, hashes, root_hash,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use hex_literal::hex;
|
||||
|
||||
#[test]
|
||||
fn node_marshalling() {
|
||||
let n = Node::new(
|
||||
0xf607,
|
||||
0x0005,
|
||||
0x4004,
|
||||
vec![
|
||||
hex!("90d53cd810cc5d4243766cd4451e7b9d14b736a1148b26b3baac7617f617d321").into(),
|
||||
hex!("cc35c964dda53ba6c0b87798073a9628dbc9cd26b5cce88eb69655a9c609caf1").into(),
|
||||
],
|
||||
Some(hex!("aaaabbbb0006767767776fffffeee44444000005567645600000000eeddddddd").into()),
|
||||
);
|
||||
|
||||
// REQUIRE(std::bitset<16>(n.hash_mask()).count() == n.hashes().size());
|
||||
|
||||
assert_eq!(unmarshal_node(&marshal_node(&n)).unwrap(), n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,3 +57,33 @@ impl PrefixSet {
|
||||
self.sorted = false;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn prefix_set() {
|
||||
let mut ps = PrefixSet::new();
|
||||
assert!(!ps.contains(b""));
|
||||
assert!(!ps.contains(b"a"));
|
||||
|
||||
ps.insert(b"abc");
|
||||
ps.insert(b"fg");
|
||||
ps.insert(b"abc"); // duplicate
|
||||
ps.insert(b"ab");
|
||||
|
||||
assert!(ps.contains(b""));
|
||||
assert!(ps.contains(b"a"));
|
||||
assert!(!ps.contains(b"aac"));
|
||||
assert!(ps.contains(b"ab"));
|
||||
assert!(ps.contains(b"abc"));
|
||||
assert!(!ps.contains(b"abcd"));
|
||||
assert!(!ps.contains(b"b"));
|
||||
assert!(ps.contains(b"f"));
|
||||
assert!(ps.contains(b"fg"));
|
||||
assert!(!ps.contains(b"fgk"));
|
||||
assert!(!ps.contains(b"fy"));
|
||||
assert!(!ps.contains(b"yyz"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::cmp;
|
||||
|
||||
pub(crate) fn has_prefix(s: &[u8], prefix: &[u8]) -> bool {
|
||||
&s[0..prefix.len()] == prefix
|
||||
s.starts_with(prefix)
|
||||
}
|
||||
|
||||
pub(crate) fn assert_subset(sub: u16, sup: u16) {
|
||||
|
||||
Reference in New Issue
Block a user