Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Jun 22, 2024
1 parent 29fb8c3 commit e19ac6e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions storage/aptosdb/src/state_store/state_merkle_batch_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@

use crate::{
metrics::{LATEST_SNAPSHOT_VERSION, OTHER_TIMERS_SECONDS},
schema::jellyfish_merkle_node::JellyfishMerkleNodeSchema,
state_merkle_db::Node,
state_store::{buffered_state::CommitMessage, StateDb},
};
use anyhow::{anyhow, ensure, Result};
use aptos_crypto::HashValue;
use aptos_jellyfish_merkle::node_type::NodeKey;
use aptos_logger::{info, trace};
use aptos_metrics_core::TimerHelper;
use aptos_scratchpad::SmtAncestors;
use aptos_storage_interface::state_delta::StateDelta;
use aptos_types::state_store::state_value::StateValue;
use aptos_types::state_store::{state_key::StateKey, state_value::StateValue};
use std::sync::{mpsc::Receiver, Arc};
use aptos_jellyfish_merkle::node_type::{Children, NodeKey};
use aptos_types::state_store::state_key::StateKey;
use crate::schema::jellyfish_merkle_node::JellyfishMerkleNodeSchema;
use crate::state_merkle_db::Node;

pub struct StateMerkleBatch {
// pub top_levels_batch: SchemaBatch,
Expand Down Expand Up @@ -66,8 +65,7 @@ impl StateMerkleBatchCommitter {
.with_label_values(&["commit_jellyfish_merkle_nodes"])
.start_timer();

self
.state_db
self.state_db
.state_merkle_db
.metadata_db()
.put::<JellyfishMerkleNodeSchema>(
Expand All @@ -76,8 +74,9 @@ impl StateMerkleBatchCommitter {
root_hash,
root_hash,
(StateKey::raw(b"root"), current_version),
)
).unwrap();
),
)
.unwrap();

/*
// commit jellyfish merkle nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};
use aptos_logger::trace;
use aptos_scratchpad::SmtAncestors;
use aptos_storage_interface::{state_delta::StateDelta};
use aptos_storage_interface::state_delta::StateDelta;
use aptos_types::state_store::state_value::StateValue;
use static_assertions::const_assert;
use std::{
Expand Down
51 changes: 32 additions & 19 deletions storage/scratchpad/src/sparse_merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ use aptos_types::{
nibble::nibble_path::NibblePath, proof::SparseMerkleLeafNode,
state_store::state_storage_usage::StateStorageUsage,
};
use fastcrypto::hash::MultisetHash;
use fastcrypto::hash::{EllipticCurveMultisetHash, MultisetHash};
use rayon::prelude::*;
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
Expand Down Expand Up @@ -422,6 +423,36 @@ where
return Ok(self.clone());
}

let inc_hash_diff = updates
.par_iter()
.fold(
EllipticCurveMultisetHash::default,
|mut inc_hash, (key, val_opt)| {
if let Some(old_val) = proof_reader.get_proof(key.0) {
let old_hash = SparseMerkleLeafNode::new(key.0, old_val)
.hash()
.into_inner();
inc_hash.remove(old_hash);
}
if let Some(Some(new_val)) = val_opt {
let new_hash = SparseMerkleLeafNode::new(key.0, new_val.hash())
.hash()
.into_inner();
inc_hash.insert(new_hash);
}
inc_hash
},
)
.reduce(
EllipticCurveMultisetHash::default,
|mut inc_hash, other_inc_hash| {
inc_hash.union(&other_inc_hash);
inc_hash
},
);
let mut inc_hash = self.smt.inner.root().inc_hash.clone();
inc_hash.union(&inc_hash_diff);

let content = self
.smt
.inner
Expand All @@ -430,24 +461,6 @@ where
.view_layers_since(&self.base_smt.inner.root().content)
.new_layer(&updates[..]);

let hashes_to_remove = updates.iter().filter_map(|(k, _)| {
proof_reader.get_proof(k.0).map(|value_hash| {
SparseMerkleLeafNode::new(k.0, value_hash)
.hash()
.into_inner()
})
});
let hashes_to_insert = updates.iter().filter_map(|(k, v)| {
v.as_ref().and_then(|val| {
val.as_ref()
.map(|v| SparseMerkleLeafNode::new(k.0, v.hash()).hash().into_inner())
})
});

let mut inc_hash = self.smt.inner.root().inc_hash.clone();
inc_hash.remove_all(hashes_to_remove);
inc_hash.insert_all(hashes_to_insert);

let root = Root::new(inc_hash, content);

Ok(self.spawn(root, usage))
Expand Down
2 changes: 1 addition & 1 deletion storage/storage-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ aptos-types = { workspace = true }
aptos-vm = { workspace = true }
bcs = { workspace = true }
crossbeam-channel = { workspace = true }
dashmap = { workspace = true }
dashmap = { workspace = true, features = ["rayon"] }
once_cell = { workspace = true }
parking_lot = { workspace = true }
proptest = { workspace = true }
Expand Down
19 changes: 9 additions & 10 deletions storage/storage-interface/src/cached_state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
};
use aptos_crypto::{hash::CryptoHash, HashValue};
use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER;
use aptos_logger::info;
use aptos_scratchpad::{FrozenSparseMerkleTree, SparseMerkleTree, StateStoreStatus};
use aptos_types::{
state_store::{
Expand All @@ -25,7 +26,6 @@ use std::{
fmt::{Debug, Formatter},
sync::Arc,
};
use aptos_logger::info;

static IO_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
rayon::ThreadPoolBuilder::new()
Expand Down Expand Up @@ -168,10 +168,7 @@ impl CachedStateView {
let snapshot = reader
.get_state_snapshot_before(next_version)
.map_err(Into::<StateviewError>::into)?;
info!(
snapshot = snapshot,
"alden alden alden."
);
info!(snapshot = snapshot, "alden alden alden.");

Ok(Self::new_impl(id, snapshot, speculative_state, reader))
}
Expand Down Expand Up @@ -212,15 +209,17 @@ impl CachedStateView {
}

pub fn into_state_cache(self) -> StateCache {
// FIXME(aldenhu): make faster
let proofs = self
.sharded_state_cache
.par_iter()
.map(|shard| {
shard.iter().map(|dashmap_ref| {
let (key, (_val_ver_opt, val_opt)) = dashmap_ref.pair();
(key.hash(), val_opt.as_ref().map(CryptoHash::hash))
})
shard
.par_iter()
.map(|dashmap_ref| {
let (key, (_val_ver_opt, val_opt)) = dashmap_ref.pair();
(key.hash(), val_opt.as_ref().map(CryptoHash::hash))
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>()
.into_iter()
Expand Down

0 comments on commit e19ac6e

Please sign in to comment.