-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(sequencer): consolidate all action handling to one module (#1759)
## Summary Moved all action and transaction handling to single module. ## Background Previously, all implementations of `ActionHandler` were done separately in components which corresponded to their given actions (or groups of actions, such as in `bridge`). While this may make sense from an action-centered point of view, it is confusing to an outsider to have to look many different places to find where stateless/stateful checks and execution occur. This PR consolidates all of the implementations as well as their testing. ## Changes - Created new `action_handler` module and moved the corresponding `ActionHandler` trait as well as all of its `impl`s into this module. - Renamed some moved tests for clarity. - Categorized tests by action in submodule `tests`. - Categorized impls by action in submodule `impls`. ## Testing Passing all tests. ## Changelogs Changelogs updated ## Related Issues closes #1657
- Loading branch information
1 parent
ab87d35
commit d5b9a3d
Showing
34 changed files
with
861 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub(crate) mod action; | ||
pub(crate) mod component; | ||
pub(crate) mod query; | ||
mod state_ext; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
crates/astria-sequencer/src/action_handler/impls/fee_asset_change.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use astria_core::protocol::transaction::v1::action::FeeAssetChange; | ||
use astria_eyre::eyre::{ | ||
self, | ||
ensure, | ||
WrapErr as _, | ||
}; | ||
use async_trait::async_trait; | ||
use cnidarium::StateWrite; | ||
use futures::StreamExt as _; | ||
use tokio::pin; | ||
|
||
use crate::{ | ||
action_handler::ActionHandler, | ||
authority::StateReadExt as _, | ||
fees::{ | ||
StateReadExt as _, | ||
StateWriteExt as _, | ||
}, | ||
transaction::StateReadExt as _, | ||
}; | ||
|
||
#[async_trait] | ||
impl ActionHandler for FeeAssetChange { | ||
async fn check_stateless(&self) -> eyre::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> eyre::Result<()> { | ||
let from = state | ||
.get_transaction_context() | ||
.expect("transaction source must be present in state when executing an action") | ||
.address_bytes(); | ||
let authority_sudo_address = state | ||
.get_sudo_address() | ||
.await | ||
.wrap_err("failed to get authority sudo address")?; | ||
ensure!( | ||
authority_sudo_address == from, | ||
"unauthorized address for fee asset change" | ||
); | ||
match self { | ||
FeeAssetChange::Addition(asset) => { | ||
state | ||
.put_allowed_fee_asset(asset) | ||
.context("failed to write allowed fee asset to state")?; | ||
} | ||
FeeAssetChange::Removal(asset) => { | ||
state.delete_allowed_fee_asset(asset); | ||
|
||
pin!( | ||
let assets = state.allowed_fee_assets(); | ||
); | ||
ensure!( | ||
assets | ||
.filter_map(|item| std::future::ready(item.ok())) | ||
.next() | ||
.await | ||
.is_some(), | ||
"cannot remove last allowed fee asset", | ||
); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.