Skip to content

Commit

Permalink
misc: I think I fixed the root of the state overwrite issue now
Browse files Browse the repository at this point in the history
  • Loading branch information
delbonis committed Jan 3, 2025
1 parent 1685a50 commit ac7b766
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/chaintsn/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub fn process_block(
epoch::process_epoch(state, &epoch_data, params)?;
}

// TODO remove
let final_epoch = state.state().cur_epoch();
debug!("epoch now is {final_epoch}");

Ok(())
}

Expand Down
13 changes: 10 additions & 3 deletions crates/state/src/state_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,22 @@ pub fn apply_write_batch_to_chainstate(
mut chainstate: Chainstate,
batch: &WriteBatch,
) -> Chainstate {
for op in &batch.ops {
apply_op_to_chainstate(op, &mut chainstate);
}
// This overwrites the whole toplevel state. This probably makes you think
// it doesn't make sense to take the chainstate arg at all. But this will
// probably make more sense in the future when we make the state structure
// more sophisticated, splitting apart the epoch state from the per-slot
// state more.
chainstate = batch.new_toplevel_chain_state.clone();

// Don't want to forget about this either.
if let Some(es) = batch.new_toplevel_epoch_state.clone() {
chainstate.epoch_state = es;
}

for op in &batch.ops {
apply_op_to_chainstate(op, &mut chainstate);
}

chainstate
}

Expand Down
4 changes: 2 additions & 2 deletions functional-tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ def wait_until_with_value(

def wait_until_next_epoch(seqrpc, timeout: int = 5, step: float = 2):
"""Waits until the current checkpoint index increases."""
init_epoch = seqrpc.strata_syncStatus()["tip_epoch"]
init_epoch = seqrpc.strata_syncStatus()["cur_epoch"]

def _f():
status = seqrpc.strata_syncStatus()
print("waiting for epoch, sync status", status)
cur_epoch = status["tip_epoch"]
cur_epoch = status["cur_epoch"]
return cur_epoch > init_epoch

wait_until(_f, "Epoch never advanced", timeout, step)
Expand Down

0 comments on commit ac7b766

Please sign in to comment.