Skip to content

Commit

Permalink
worker: checkpoint on some fixed interval
Browse files Browse the repository at this point in the history
  • Loading branch information
prajwolrg committed Aug 8, 2024
1 parent 2fd09eb commit ffad95b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions crates/consensus-logic/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ fn handle_sync_event<D: Database, E: ExecEngineCtl>(
// Make sure that the new state index is set as expected.
assert_eq!(state.state_tracker.cur_state_idx(), ev_idx);

// Write the state checkpoint.
// TODO Don't do this on every update.
let css = state.database.client_state_store();
css.write_client_state_checkpoint(ev_idx, new_state.as_ref().clone())?;
// Write the state checkpoint on interval.
if ev_idx % state.params.run.client_checkpoint_interval as u64 == 0 {
let css = state.database.client_state_store();
css.write_client_state_checkpoint(ev_idx, new_state.as_ref().clone())?;
}

Check warning on line 223 in crates/consensus-logic/src/worker.rs

View check run for this annotation

Codecov / codecov/patch

crates/consensus-logic/src/worker.rs#L220-L223

Added lines #L220 - L223 were not covered by tests

// Broadcast the update to all the different things listening (which should
// be consolidated).
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct RollupParams {
pub struct RunParams {
/// Number of blocks that we follow the L1 from.
pub l1_follow_distance: u64,
/// Number of events after which we checkpoint the client
pub client_checkpoint_interval: u32,
}

/// Combined set of parameters across all the consensus logic.
Expand Down
1 change: 1 addition & 0 deletions crates/test-utils/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub fn gen_params() -> Params {
},
run: RunParams {
l1_follow_distance: 3,
client_checkpoint_interval: 10,
},
}
}
Expand Down
5 changes: 4 additions & 1 deletion sequencer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct SyncParams {
pub l1_follow_distance: u64,
pub max_reorg_depth: u32,
pub client_poll_dur_ms: u32,
pub client_checkpoint_interval: u32,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -47,7 +48,7 @@ pub struct Config {
}

impl Config {
pub fn new() -> Config {
pub fn default() -> Config {

Check warning on line 51 in sequencer/src/config.rs

View check run for this annotation

Codecov / codecov/patch

sequencer/src/config.rs#L51

Added line #L51 was not covered by tests
Self {
bitcoind_rpc: BitcoindParams {
rpc_url: String::new(),
Expand All @@ -64,6 +65,7 @@ impl Config {
l1_follow_distance: 6,
max_reorg_depth: 4,
client_poll_dur_ms: 200,
client_checkpoint_interval: 10,

Check warning on line 68 in sequencer/src/config.rs

View check run for this annotation

Codecov / codecov/patch

sequencer/src/config.rs#L68

Added line #L68 was not covered by tests
},
exec: ExecParams {
reth: RethELParams {
Expand Down Expand Up @@ -123,6 +125,7 @@ mod test {
l1_follow_distance = 6
max_reorg_depth = 4
client_poll_dur_ms = 200
client_checkpoint_interval = 10
[exec.reth]
rpc_url = "http://localhost:8551"
Expand Down
3 changes: 2 additions & 1 deletion sequencer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
// initialize the full configuration
let mut config = match args.config.as_ref() {
Some(config_path) => load_configuration(config_path)?,
None => Config::new(),
None => Config::default(),

Check warning on line 84 in sequencer/src/main.rs

View check run for this annotation

Codecov / codecov/patch

sequencer/src/main.rs#L84

Added line #L84 was not covered by tests
};

// Values passed over arguments get the precedence over the configuration files
Expand Down Expand Up @@ -111,6 +111,7 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
},
run: RunParams {
l1_follow_distance: config.sync.l1_follow_distance,
client_checkpoint_interval: config.sync.client_checkpoint_interval,

Check warning on line 114 in sequencer/src/main.rs

View check run for this annotation

Codecov / codecov/patch

sequencer/src/main.rs#L114

Added line #L114 was not covered by tests
},
};

Expand Down

0 comments on commit ffad95b

Please sign in to comment.