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

refactor(sequencer): remove global state #1317

Merged
merged 6 commits into from
Aug 1, 2024
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
13 changes: 8 additions & 5 deletions crates/astria-core/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
pub use penumbra_ibc::params::IBCParameters;

use crate::primitive::v1::{
asset,
asset::{
self,
TracePrefixed,
},
Address,
};

Expand All @@ -26,7 +29,7 @@ pub struct GenesisState {
authority_sudo_address: Address,
ibc_sudo_address: Address,
ibc_relayer_addresses: Vec<Address>,
native_asset_base_denomination: String,
native_asset_base_denomination: TracePrefixed,
ibc_params: IBCParameters,
allowed_fee_assets: Vec<asset::Denom>,
fees: Fees,
Expand Down Expand Up @@ -59,7 +62,7 @@ impl GenesisState {
}

#[must_use]
pub fn native_asset_base_denomination(&self) -> &str {
pub fn native_asset_base_denomination(&self) -> &TracePrefixed {
&self.native_asset_base_denomination
}

Expand Down Expand Up @@ -140,7 +143,7 @@ pub struct UncheckedGenesisState {
pub authority_sudo_address: Address,
pub ibc_sudo_address: Address,
pub ibc_relayer_addresses: Vec<Address>,
pub native_asset_base_denomination: String,
pub native_asset_base_denomination: TracePrefixed,
pub ibc_params: IBCParameters,
pub allowed_fee_assets: Vec<asset::Denom>,
pub fees: Fees,
Expand Down Expand Up @@ -295,7 +298,7 @@ mod tests {
authority_sudo_address: alice(),
ibc_sudo_address: alice(),
ibc_relayer_addresses: vec![alice(), bob()],
native_asset_base_denomination: "nria".to_string(),
native_asset_base_denomination: "nria".parse().unwrap(),
ibc_params: IBCParameters {
ibc_enabled: true,
inbound_ics20_transfers_enabled: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer-utils/src/genesis_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn genesis_state() -> GenesisState {
authority_sudo_address: alice(),
ibc_sudo_address: alice(),
ibc_relayer_addresses: vec![alice(), bob()],
native_asset_base_denomination: "nria".to_string(),
native_asset_base_denomination: "nria".parse().unwrap(),
ibc_params: IBCParameters {
ibc_enabled: true,
inbound_ics20_transfers_enabled: true,
Expand Down
20 changes: 12 additions & 8 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ use astria_core::{
use tracing::instrument;

use crate::{
accounts,
accounts::StateReadExt as _,
accounts::{
self,
StateReadExt as _,
},
address,
assets,
bridge::StateReadExt as _,
transaction::action_handler::ActionHandler,
Expand Down Expand Up @@ -81,15 +84,16 @@ where
#[async_trait::async_trait]
impl ActionHandler for TransferAction {
async fn check_stateless(&self) -> Result<()> {
crate::address::ensure_base_prefix(&self.to).context("destination address is invalid")?;
Ok(())
}

async fn check_stateful<S: accounts::StateReadExt + 'static>(
&self,
state: &S,
from: Address,
) -> Result<()> {
async fn check_stateful<S>(&self, state: &S, from: Address) -> Result<()>
where
S: accounts::StateReadExt + address::StateReadExt + 'static,
{
state.ensure_base_prefix(&self.to).await.context(
"failed ensuring that the destination address matches the permitted base prefix",
)?;
ensure!(
state
.get_bridge_account_rollup_id(&from)
Expand Down
20 changes: 13 additions & 7 deletions crates/astria-sequencer/src/accounts/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use tendermint::abci::request::{
};
use tracing::instrument;

use super::state_ext::StateWriteExt;
use crate::{
assets::get_native_asset,
accounts,
assets,
component::Component,
};

Expand All @@ -24,11 +24,17 @@ impl Component for AccountsComponent {
type AppState = astria_core::sequencer::GenesisState;

#[instrument(name = "AccountsComponent::init_chain", skip_all)]
async fn init_chain<S: StateWriteExt>(mut state: S, app_state: &Self::AppState) -> Result<()> {
let native_asset = get_native_asset();
async fn init_chain<S>(mut state: S, app_state: &Self::AppState) -> Result<()>
where
S: accounts::StateWriteExt + assets::StateReadExt,
{
let native_asset = state
.get_native_asset()
.await
.context("failed to read native asset from state")?;
for account in app_state.accounts() {
state
.put_account_balance(account.address, native_asset, account.balance)
.put_account_balance(account.address, &native_asset, account.balance)
.context("failed writing account balance to state")?;
}

Expand All @@ -39,15 +45,15 @@ impl Component for AccountsComponent {
}

#[instrument(name = "AccountsComponent::begin_block", skip_all)]
async fn begin_block<S: StateWriteExt + 'static>(
async fn begin_block<S: accounts::StateWriteExt + 'static>(
_state: &mut Arc<S>,
_begin_block: &BeginBlock,
) -> Result<()> {
Ok(())
}

#[instrument(name = "AccountsComponent::end_block", skip_all)]
async fn end_block<S: StateWriteExt + 'static>(
async fn end_block<S: accounts::StateWriteExt + 'static>(
_state: &mut Arc<S>,
_end_block: &EndBlock,
) -> Result<()> {
Expand Down
Loading
Loading