Skip to content

Commit

Permalink
set app hash properly when initializing app
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Apr 30, 2024
1 parent 5e0487c commit f2fb39a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
24 changes: 17 additions & 7 deletions crates/astria-sequencer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,30 @@ pub(crate) struct App {
}

impl App {
pub(crate) fn new(snapshot: Snapshot) -> Self {
pub(crate) async fn new(snapshot: Snapshot) -> anyhow::Result<Self> {
tracing::debug!("initializing App instance");

let app_hash: AppHash = snapshot
.root_hash()
.await
.context("failed to get current root hash")?
.0
.to_vec()
.try_into()
.expect("root hash conversion must succeed; should be 32 bytes");

// We perform the `Arc` wrapping of `State` here to ensure
// there should be no unexpected copies elsewhere.
let state = Arc::new(StateDelta::new(snapshot));

Self {
Ok(Self {
state,
validator_address: None,
executed_proposal_hash: Hash::default(),
execution_results: None,
write_batch: None,
app_hash: AppHash::default(),
}
app_hash,
})
}

#[instrument(name = "App:init_chain", skip_all)]
Expand Down Expand Up @@ -767,12 +776,13 @@ impl App {
.prepare_commit(state)
.await
.context("failed to prepare commit")?;
let app_hash = write_batch
let app_hash: AppHash = write_batch
.root_hash()
.0
.to_vec()
.try_into()
.context("failed to convert app hash")?;
info!(app_hash = %telemetry::display::hex(app_hash.as_bytes()), "prepared commit");
self.write_batch = Some(write_batch);
Ok(app_hash)
}
Expand Down Expand Up @@ -927,7 +937,7 @@ impl App {
))
.expect("must be able to successfully commit to storage");
tracing::debug!(
app_hash = %telemetry::display::base64(&app_hash),
app_hash = %telemetry::display::hex(&app_hash),
"finished committing state",
);
self.app_hash = app_hash
Expand Down Expand Up @@ -1114,7 +1124,7 @@ mod test {
.await
.expect("failed to create temp storage backing chain state");
let snapshot = storage.latest_snapshot();
let mut app = App::new(snapshot);
let mut app = App::new(snapshot).await.unwrap();

let genesis_state = genesis_state.unwrap_or_else(|| GenesisState {
accounts: default_genesis_accounts(),
Expand Down
4 changes: 3 additions & 1 deletion crates/astria-sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ impl Sequencer {
crate::asset::initialize_native_asset(&native_asset);
}

let app = App::new(snapshot);
let app = App::new(snapshot)
.await
.context("failed to initialize app")?;

let consensus_service = tower::ServiceBuilder::new()
.layer(request_span::layer(|req: &ConsensusRequest| {
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/service/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ mod test {

let storage = cnidarium::TempStorage::new().await.unwrap();
let snapshot = storage.latest_snapshot();
let mut app = App::new(snapshot);
let mut app = App::new(snapshot).await.unwrap();
app.init_chain(storage.clone(), genesis_state, vec![], "test".to_string())
.await
.unwrap();
Expand Down

0 comments on commit f2fb39a

Please sign in to comment.