Skip to content

Commit

Permalink
turbohash
Browse files Browse the repository at this point in the history
  • Loading branch information
suurkivi committed Dec 18, 2024
1 parent f26ba24 commit 22bb674
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 125 deletions.
2 changes: 1 addition & 1 deletion src/perf/trie_only_perftest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Args {

pub fn run() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let turbohash = 0;
let turbohash = 1;

let host = ("127.0.0.1", cadence::DEFAULT_PORT);
let socket = net::UdpSocket::bind("0.0.0.0:0").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/proto/sync_trie.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ message DbTrieNode {
bytes key = 1;
repeated uint32 childChars = 2;
uint32 items = 3;
bytes hash = 4;
map<uint32, bytes> childHashes = 4;
}

10 changes: 8 additions & 2 deletions src/storage/trie/merkle_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ impl MerkleTrie {

if let Some(root) = self.root.as_mut() {
let mut txn = RocksDbTransactionBatch::new();
let results = root.insert(ctx, db, &mut txn, keys, 0)?;
// root_stub_map: the hash of a node is stored/cached in the parent of that node (in a hashmap)
// the root doesn't have a parent, but still needs a hashmap here to satisfy the API. Note also
// that the root's hash will NOT be populated anywhere in this map. Use root.hash() for that.
let mut root_stub_map = HashMap::new();
let results = root.insert(ctx, &mut root_stub_map, db, &mut txn, keys, 0)?;

txn_batch.merge(txn);
Ok(results)
Expand Down Expand Up @@ -185,7 +189,9 @@ impl MerkleTrie {

if let Some(root) = self.root.as_mut() {
let mut txn = RocksDbTransactionBatch::new();
let results = root.delete(ctx, db, &mut txn, keys, 0)?;
// root_stub_map: see comment in insert()
let root_stub_map = &mut HashMap::new();
let results = root.delete(ctx, root_stub_map, db, &mut txn, keys, 0)?;

txn_batch.merge(txn);
Ok(results)
Expand Down
Loading

0 comments on commit 22bb674

Please sign in to comment.