Skip to content

Commit

Permalink
Process L1 blocks in a different task. (#1163)
Browse files Browse the repository at this point in the history
* Process L1 blocks in a different task.

This introduces handler for L1 blocks which is spawned as a separate task

* Add DA block handler

* Happy clippy

* Move all L1 processing into L1BlockHandler

* Remove uninformative log

* Keep logic for retrying L1 blocks if L2 range is missing

* Happy Clippy: 2

* Process L2 blocks in order

* add some logs

* Process blocks immediately and queue if failed

* Import info

* Fix logs

* Process all L2 blocks in pending

* more logs

---------

Co-authored-by: eyusufatik <[email protected]>
  • Loading branch information
rakanalh and eyusufatik authored Sep 12, 2024
1 parent cfaa0a0 commit 7386e22
Show file tree
Hide file tree
Showing 7 changed files with 642 additions and 466 deletions.
98 changes: 58 additions & 40 deletions bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sov_rollup_interface::fork::ForkManager;
use sov_state::storage::NativeStorage;
use sov_stf_runner::{FullNodeConfig, InitVariant, ProverConfig};
use tokio::sync::broadcast;
use tracing::instrument;
use tracing::{info, instrument};

mod bitcoin;
mod mock;
Expand Down Expand Up @@ -75,19 +75,25 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {

let genesis_root = prover_storage.get_root_hash(1);

let prev_data = match ledger_db.get_head_soft_confirmation()? {
Some((number, soft_confirmation)) => Some((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
)),
None => None,
};
let init_variant = match prev_data {
Some((root_hash, batch_hash)) => InitVariant::Initialized((root_hash, batch_hash)),
None => match genesis_root {
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
_ => InitVariant::Genesis(genesis_config),
},
let init_variant = match ledger_db.get_head_soft_confirmation()? {
// At least one soft confirmation was processed
Some((number, soft_confirmation)) => {
info!("Initialize sequencer at batch number {:?}. State root: {:?}. Last soft confirmation hash: {:?}.", number, prover_storage.get_root_hash(number.0 + 1)?.as_ref(), soft_confirmation.hash);

InitVariant::Initialized((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
))
}
None => {
info!("Initialize sequencer at genesis.");
match genesis_root {
// Chain was initialized but no soft confirmations was processed
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
// Not even initialized
_ => InitVariant::Genesis(genesis_config),
}
}
};

let current_l2_height = ledger_db
Expand Down Expand Up @@ -170,19 +176,25 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {

let genesis_root = prover_storage.get_root_hash(1);

let prev_data = match ledger_db.get_head_soft_confirmation()? {
Some((number, soft_confirmation)) => Some((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
)),
None => None,
};
let init_variant = match prev_data {
Some((root_hash, batch_hash)) => InitVariant::Initialized((root_hash, batch_hash)),
None => match genesis_root {
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
_ => InitVariant::Genesis(genesis_config),
},
let init_variant = match ledger_db.get_head_soft_confirmation()? {
// At least one soft confirmation was processed
Some((number, soft_confirmation)) => {
info!("Initialize node at batch number {:?}. State root: {:?}. Last soft confirmation hash: {:?}.", number, prover_storage.get_root_hash(number.0 + 1)?.as_ref(), soft_confirmation.hash);

InitVariant::Initialized((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
))
}
None => {
info!("Initialize node at genesis.");
match genesis_root {
// Chain was initialized but no soft confirmations was processed
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
// Not even initialized
_ => InitVariant::Genesis(genesis_config),
}
}
};

let code_commitments_by_spec = self.get_code_commitments_by_spec();
Expand Down Expand Up @@ -277,19 +289,25 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {

let genesis_root = prover_storage.get_root_hash(1);

let prev_data = match ledger_db.get_head_soft_confirmation()? {
Some((number, soft_confirmation)) => Some((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
)),
None => None,
};
let init_variant = match prev_data {
Some((root_hash, batch_hash)) => InitVariant::Initialized((root_hash, batch_hash)),
None => match genesis_root {
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
_ => InitVariant::Genesis(genesis_config),
},
let init_variant = match ledger_db.get_head_soft_confirmation()? {
// At least one soft confirmation was processed
Some((number, soft_confirmation)) => {
info!("Initialize prover at batch number {:?}. State root: {:?}. Last soft confirmation hash: {:?}.", number, prover_storage.get_root_hash(number.0 + 1)?.as_ref(), soft_confirmation.hash);

InitVariant::Initialized((
prover_storage.get_root_hash(number.0 + 1)?,
soft_confirmation.hash,
))
}
None => {
info!("Initialize prover at genesis.");
match genesis_root {
// Chain was initialized but no soft confirmations was processed
Ok(root_hash) => InitVariant::Initialized((root_hash, [0; 32])),
// Not even initialized
_ => InitVariant::Genesis(genesis_config),
}
}
};

let code_commitments_by_spec = self.get_code_commitments_by_spec();
Expand Down
Loading

0 comments on commit 7386e22

Please sign in to comment.