Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion crates/astria-sequencer/src/accounts/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use astria_core::protocol::genesis::v1::GenesisAppState;
use astria_eyre::eyre::{
OptionExt as _,
Result,
WrapErr as _,
};
Expand Down Expand Up @@ -33,7 +34,11 @@ impl Component for AccountsComponent {
let native_asset = state
.get_native_asset()
.await
.wrap_err("failed to read native asset from state")?;
.wrap_err("failed to read native asset from state")?
.ok_or_eyre(
"native asset does not exist in state but is required to set genesis account \
balances",
)?;
for account in app_state.accounts() {
state
.put_account_balance(&account.address, &native_asset, account.balance)
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/accounts/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ mod tests {
// native account should work with ibc too
state.put_native_asset(nria()).unwrap();

let asset_0 = state.get_native_asset().await.unwrap();
let asset_0 = state.get_native_asset().await.unwrap().unwrap();
let asset_1 = asset_1();
let asset_2 = asset_2();

Expand Down
7 changes: 0 additions & 7 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ use crate::{
component::FeesComponent,
construct_tx_fee_event,
StateReadExt as _,
StateWriteExt as _,
},
grpc::StateWriteExt as _,
ibc::component::IbcComponent,
Expand Down Expand Up @@ -305,12 +304,6 @@ impl App {
.put_block_height(0)
.wrap_err("failed to write block height to state")?;

for fee_asset in genesis_state.allowed_fee_assets() {
state_tx
.put_allowed_fee_asset(fee_asset)
.wrap_err("failed to write allowed fee asset to state")?;
}

// call init_chain on all components
FeesComponent::init_chain(&mut state_tx, &genesis_state)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/app/tests_app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn app_genesis_and_init_chain() {

assert_eq!(
app.state.get_native_asset().await.unwrap(),
"nria".parse::<TracePrefixed>().unwrap()
Some("nria".parse::<TracePrefixed>().unwrap()),
);
}

Expand Down
18 changes: 9 additions & 9 deletions crates/astria-sequencer/src/assets/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use astria_core::primitive::v1::asset;
use astria_eyre::{
anyhow_to_eyre,
eyre::{
bail,
Result,
WrapErr as _,
},
Expand All @@ -27,20 +26,21 @@ use crate::storage::StoredValue;
#[async_trait]
pub(crate) trait StateReadExt: StateRead {
#[instrument(skip_all)]
async fn get_native_asset(&self) -> Result<asset::TracePrefixed> {
async fn get_native_asset(&self) -> Result<Option<asset::TracePrefixed>> {
let Some(bytes) = self
.get_raw(keys::NATIVE_ASSET)
.await
.map_err(anyhow_to_eyre)
.wrap_err("failed to read raw native asset from state")?
else {
bail!("native asset denom not found in state");
return Ok(None);
};
StoredValue::deserialize(&bytes)
.and_then(|value| {
storage::TracePrefixedDenom::try_from(value).map(asset::TracePrefixed::from)
})
.wrap_err("invalid native asset bytes")
.map(Option::Some)
}

#[instrument(skip_all)]
Expand Down Expand Up @@ -129,16 +129,16 @@ mod tests {
let mut state = StateDelta::new(snapshot);

// doesn't exist at first
let _ = state
.get_native_asset()
.await
.expect_err("no native asset denom should exist at first");
assert!(
state.get_native_asset().await.unwrap().is_none(),
"no native asset denom should exist at first"
);

// can write
let denom_orig: asset::TracePrefixed = "denom_orig".parse().unwrap();
state.put_native_asset(denom_orig.clone()).unwrap();
assert_eq!(
state.get_native_asset().await.expect(
state.get_native_asset().await.unwrap().expect(
"a native asset denomination was written and must exist inside the database"
),
denom_orig,
Expand All @@ -149,7 +149,7 @@ mod tests {
let denom_update: asset::TracePrefixed = "denom_update".parse().unwrap();
state.put_native_asset(denom_update.clone()).unwrap();
assert_eq!(
state.get_native_asset().await.expect(
state.get_native_asset().await.unwrap().expect(
"a native asset denomination update was written and must exist inside the database"
),
denom_update,
Expand Down
6 changes: 6 additions & 0 deletions crates/astria-sequencer/src/fees/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ impl Component for FeesComponent {
where
S: fees::StateWriteExt + fees::StateReadExt,
{
for fee_asset in app_state.allowed_fee_assets() {
state
.put_allowed_fee_asset(fee_asset)
.wrap_err("failed to write allowed fee asset to state")?;
}

let transfer_fees = app_state.fees().transfer;
if let Some(transfer_fees) = transfer_fees {
state
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/mempool/mempool_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod tests {
// native account should work with ibc too
state.put_native_asset(nria()).unwrap();

let asset_0 = state.get_native_asset().await.unwrap();
let asset_0 = state.get_native_asset().await.unwrap().unwrap();
let asset_1: Denom = "asset_0".parse().unwrap();
let asset_2: Denom = "asset_1".parse().unwrap();

Expand Down