Skip to content

Commit

Permalink
Merge branch 'main' into ENG-106/migrate_to_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanoroshiba committed Aug 2, 2024
2 parents d92a373 + be139d5 commit f086ab5
Show file tree
Hide file tree
Showing 58 changed files with 2,125 additions and 1,855 deletions.
316 changes: 209 additions & 107 deletions crates/astria-core/src/protocol/transaction/v1alpha1/action.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
asset,
ADDRESS_LEN,
},
Protobuf as _,
};

pub mod action;
Expand Down
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
37 changes: 21 additions & 16 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ use astria_core::{
use tracing::instrument;

use crate::{
accounts::state_ext::{
StateReadExt,
StateWriteExt,
},
bridge::state_ext::StateReadExt as _,
state_ext::{
accounts::{
self,
StateReadExt as _,
StateWriteExt as _,
},
address,
assets,
bridge::StateReadExt as _,
transaction::action_handler::ActionHandler,
};

pub(crate) async fn transfer_check_stateful<S: StateReadExt + 'static>(
pub(crate) async fn transfer_check_stateful<S>(
action: &TransferAction,
state: &S,
from: Address,
) -> Result<()> {
) -> Result<()>
where
S: accounts::StateReadExt + assets::StateReadExt + 'static,
{
ensure!(
state
.is_allowed_fee_asset(&action.fee_asset)
Expand Down Expand Up @@ -83,15 +84,16 @@ pub(crate) async fn transfer_check_stateful<S: StateReadExt + 'static>(
#[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: 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 All @@ -107,7 +109,10 @@ impl ActionHandler for TransferAction {
}

#[instrument(skip_all)]
async fn execute<S: StateWriteExt>(&self, state: &mut S, from: Address) -> Result<()> {
async fn execute<S>(&self, state: &mut S, from: Address) -> Result<()>
where
S: accounts::StateWriteExt + assets::StateWriteExt,
{
let fee = state
.get_transfer_base_fee()
.await
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::{
asset::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
7 changes: 6 additions & 1 deletion crates/astria-sequencer/src/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
pub(crate) mod action;
pub(crate) mod component;
pub(crate) mod query;
pub(crate) mod state_ext;
mod state_ext;

pub(crate) use state_ext::{
StateReadExt,
StateWriteExt,
};
Loading

0 comments on commit f086ab5

Please sign in to comment.