Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(trusted-sync): start #380

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions examples/trusted-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ async fn sync(cli: cli::Cli) -> Result<()> {

let mut start =
cli.start_l2_block.filter(|n| *n >= cfg.genesis.l2.number).unwrap_or(cfg.genesis.l2.number);
debug!(target: LOG_TARGET, "Genesis L2 block number: {}", cfg.genesis.l2.number);

// If the start block from tip cli flag is specified, find the latest l2 block number
// and subtract the specified number of blocks to get the start block number.
if let Some(blocks) = cli.start_blocks_from_tip {
start = l2_provider.latest_block_number().await?.saturating_sub(blocks);
info!(target: LOG_TARGET, "Starting {} blocks from tip at L2 block number: {}", blocks, start);
let latest = l2_provider.latest_block_number().await?;
debug!(target: LOG_TARGET, "Fetched latest block number: {}", latest);
start = if latest < cfg.genesis.l2.number {
warn!(target: LOG_TARGET, "latest l2 block number prior to genesis. Reverting to genesis. ({} < {})", latest, cfg.genesis.l2.number);
cfg.genesis.l2.number
} else {
let sub_tip = latest.saturating_sub(blocks);
info!(target: LOG_TARGET, "Starting {} blocks from tip at L2 block number: {}", blocks, sub_tip);
sub_tip
};
}
metrics::START_L2_BLOCK.inc_by(start);
println!("Starting from L2 block number: {}", metrics::START_L2_BLOCK.get());
Expand Down
Loading