diff --git a/core/node/consensus/src/en.rs b/core/node/consensus/src/en.rs index 5e9aadc8f37..a7acc5e82b2 100644 --- a/core/node/consensus/src/en.rs +++ b/core/node/consensus/src/en.rs @@ -149,11 +149,17 @@ impl EN { s.spawn_bg(async { Ok(runner.run(ctx).await?) }); let attestation = Arc::new(attestation::Controller::new(attester)); - s.spawn_bg(self.run_attestation_controller( - ctx, - global_config.clone(), - attestation.clone(), - )); + s.spawn_bg({ + let attestation = attestation.clone(); + let global_config = global_config.clone(); + async { + // Hardcoded panic on failure. + self.run_attestation_controller(ctx, global_config, attestation) + .await + .unwrap(); + Ok(()) + } + }); let executor = executor::Executor { config: config::executor(&cfg, &secrets, &global_config, build_version)?, @@ -214,9 +220,15 @@ impl EN { async fn run_attestation_controller( &self, ctx: &ctx::Ctx, - cfg: consensus_dal::GlobalConfig, + mut cfg: consensus_dal::GlobalConfig, attestation: Arc, ) -> ctx::Result<()> { + // Hardcoded registry address. + cfg.registry_address = Some( + "0xd35b99bdad58baa6b912022c77d1f409001442a4" + .parse() + .unwrap(), + ); const POLL_INTERVAL: time::Duration = time::Duration::seconds(5); let registry = registry::Registry::new(cfg.genesis.clone(), self.pool.clone()).await; let mut next = attester::BatchNumber(0); @@ -228,7 +240,16 @@ impl EN { .wrap("fetch_attestation_status()") { Err(err) => tracing::warn!("{err:#}"), - Ok(status) => { + Ok(mut status) => { + // Hardcoded batch selection. + status.next_batch_to_attest = self + .pool + .connection(ctx) + .await + .wrap("connection()")? + .batch_to_attest(ctx) + .await + .wrap("batch_to_attest()")?; if status.genesis != cfg.genesis.hash() { return Err(anyhow::format_err!("genesis mismatch").into()); } diff --git a/core/node/consensus/src/storage/connection.rs b/core/node/consensus/src/storage/connection.rs index 6ec5794e968..37f76a6f42e 100644 --- a/core/node/consensus/src/storage/connection.rs +++ b/core/node/consensus/src/storage/connection.rs @@ -247,6 +247,17 @@ impl<'a> Connection<'a> { .await??) } + pub(crate) async fn batch_to_attest( + &mut self, + ctx: &ctx::Ctx, + ) -> ctx::Result { + let n = self.next_block(ctx).await?; + Ok(ctx + .wait(self.0.consensus_dal().batch_of_block(n)) + .await?? + .context("unknown batch")?) + } + /// (Re)initializes consensus genesis to start at the last L2 block in storage. /// Noop if `spec` matches the current genesis. pub(crate) async fn adjust_global_config(