Skip to content

Commit

Permalink
fixup(bootstrap): Tweak child received action
Browse files Browse the repository at this point in the history
  • Loading branch information
tizoc committed Mar 22, 2024
1 parent 2aa788f commit df11465
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Expand Up @@ -95,8 +95,7 @@ pub enum TransitionFrontierSyncLedgerSnarkedAction {
ChildHashesAccepted {
address: LedgerAddress,
hashes: (LedgerHash, LedgerHash),
left_hash_stale: bool,
right_hash_stale: bool,
previous_hashes: (LedgerHash, LedgerHash),
},
ChildHashesRejected {
address: LedgerAddress,
Expand Down
Expand Up @@ -334,20 +334,16 @@ impl TransitionFrontierSyncLedgerSnarkedAction {
}

// TODO: for async ledger this needs an intermediary action
let (current_left_hash, current_right_hash) = store
let (previous_left_hash, previous_right_hash) = store
.service()
.child_hashes_get(snarked_ledger_hash, address)
.unwrap();

let left_hash_stale = current_left_hash != *left_hash;
let right_hash_stale = current_right_hash != *right_hash;

store.dispatch(
TransitionFrontierSyncLedgerSnarkedAction::ChildHashesAccepted {
address: address.clone(),
hashes: (left_hash.clone(), right_hash.clone()),
left_hash_stale,
right_hash_stale,
previous_hashes: (previous_left_hash, previous_right_hash),
},
);
}
Expand Down
@@ -1,5 +1,5 @@
use crate::{
ledger::{tree_height_for_num_accounts, LEDGER_DEPTH},
ledger::{ledger_empty_hash_at_depth, tree_height_for_num_accounts, LEDGER_DEPTH},
transition_frontier::sync::ledger::snarked::{
LedgerNumAccountsQueryPending, LedgerQueryQueued,
},
Expand Down Expand Up @@ -238,8 +238,7 @@ impl TransitionFrontierSyncLedgerSnarkedState {
TransitionFrontierSyncLedgerSnarkedAction::ChildHashesAccepted {
address,
hashes,
left_hash_stale,
right_hash_stale,
previous_hashes,
} => {
let Self::Pending {
queue,
Expand All @@ -254,21 +253,25 @@ impl TransitionFrontierSyncLedgerSnarkedState {
// Once hashes are accepted, we can consider this query fulfilled
pending.remove(address);

let (left, right) = hashes;
let (previous_left, previous_right) = previous_hashes;

// TODO(tizoc): for non-stale hashes, we can consider the full subtree
// as accepted. Given the value of `num_accounts` and the position
// in the tree we could estimate how many accounts and hashes
// from that subtree will be skipped and add them to the count.
*num_hashes_accepted += 2;

let (left, right) = hashes;
// Empty node hashes are not counted in the stats.
let empty = ledger_empty_hash_at_depth(address.length() + 1);
*num_hashes_accepted += (*left != empty) as u64 + (*right != empty) as u64;

if *left_hash_stale {
if left != previous_left {
queue.push_back(LedgerQueryQueued::Address {
address: address.child_left(),
expected_hash: left.clone(),
});
}
if *right_hash_stale {
if right != previous_right {
queue.push_back(LedgerQueryQueued::Address {
address: address.child_right(),
expected_hash: right.clone(),
Expand Down

0 comments on commit df11465

Please sign in to comment.