Skip to content

Commit

Permalink
move fee payment to fees component
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanoroshiba committed Nov 20, 2024
1 parent d0169bc commit 6aecbcd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 38 deletions.
30 changes: 3 additions & 27 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ pub(crate) use self::{
},
};
use crate::{
accounts::{
component::AccountsComponent,
StateWriteExt as _,
},
accounts::component::AccountsComponent,
address::StateWriteExt as _,
assets::StateWriteExt as _,
authority::{
Expand All @@ -112,10 +109,7 @@ use crate::{
Component as _,
PrepareStateInfo,
},
fees::{
component::FeesComponent,
StateReadExt as _,
},
fees::component::FeesComponent,
grpc::StateWriteExt as _,
ibc::component::IbcComponent,
mempool::{
Expand Down Expand Up @@ -737,15 +731,8 @@ impl App {
.get_chain_id()
.await
.wrap_err("failed to get chain ID from state")?;
let sudo_address = self
.state
.get_sudo_address()
.await
.wrap_err("failed to get sudo address from state")?;

let (validator_updates, events) = self
.component_post_execution_state_updates(&sudo_address)
.await?;
let (validator_updates, events) = self.component_post_execution_state_updates().await?;

// get deposits for this block from state's ephemeral cache and put them to storage.
let mut state_tx = StateDelta::new(self.state.clone());
Expand Down Expand Up @@ -1029,7 +1016,6 @@ impl App {
#[instrument(name = "App::component_post_execution_state_updates", skip_all)]
async fn component_post_execution_state_updates(
&mut self,
fee_recipient: &[u8; 20],
) -> Result<(Vec<tendermint::validator::Update>, Vec<Event>)> {
let state_tx = StateDelta::new(self.state.clone());
let mut arc_state_tx = Arc::new(state_tx);
Expand Down Expand Up @@ -1061,16 +1047,6 @@ impl App {
// clear validator updates
state_tx.clear_validator_updates();

// gather block fees and transfer them to the block proposer
let fees = self.state.get_block_fees();

for fee in fees {
state_tx
.increase_balance(fee_recipient, fee.asset(), fee.amount())
.await
.wrap_err("failed to increase fee recipient balance")?;
}

let events = self.apply(state_tx);
Ok((
validator_updates
Expand Down
7 changes: 2 additions & 5 deletions crates/astria-sequencer/src/app/tests_app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ async fn app_handle_post_tx_execution_validator_updates() {
];

let mut app = initialize_app(None, initial_validator_set).await;
let proposer_address = [0u8; 20];

let validator_updates = vec![
ValidatorUpdate {
Expand All @@ -885,10 +884,8 @@ async fn app_handle_post_tx_execution_validator_updates() {
.unwrap();
app.apply(state_tx);

let (returned_validator_updates, _) = app
.component_post_execution_state_updates(&proposer_address)
.await
.unwrap();
let (returned_validator_updates, _) =
app.component_post_execution_state_updates().await.unwrap();
// we only assert length here as the ordering of the updates is not guaranteed
// and validator::Update does not implement Ord
assert_eq!(returned_validator_updates.len(), validator_updates.len());
Expand Down
6 changes: 1 addition & 5 deletions crates/astria-sequencer/src/app/tests_breaking_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use crate::{
initialize_app,
},
},
authority::StateReadExt as _,
benchmark_and_test_utils::{
astria_address,
astria_address_from_hex_string,
Expand Down Expand Up @@ -345,10 +344,7 @@ async fn app_execute_transaction_with_every_action_snapshot() {
let signed_tx = Arc::new(tx_bridge.sign(&bridge));
app.execute_transaction(signed_tx).await.unwrap();

let sudo_address = app.state.get_sudo_address().await.unwrap();
app.component_post_execution_state_updates(&sudo_address)
.await
.unwrap();
app.component_post_execution_state_updates().await.unwrap();

app.prepare_commit(storage.clone()).await.unwrap();
app.commit(storage.clone()).await;
Expand Down
22 changes: 21 additions & 1 deletion crates/astria-sequencer/src/fees/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ use std::sync::Arc;

use astria_core::protocol::genesis::v1::GenesisAppState;
use astria_eyre::eyre::{
OptionExt as _,
Result,
WrapErr as _,
};
use tracing::instrument;

use super::StateReadExt as _;
use crate::{
accounts::StateWriteExt as _,
authority::StateReadExt,
component::{
Component,
PrepareStateInfo,
Expand Down Expand Up @@ -142,8 +146,24 @@ impl Component for FeesComponent {

#[instrument(name = "FeesComponent::handle_post_tx_execution", skip_all)]
async fn handle_post_tx_execution<S: fees::StateWriteExt + 'static>(
_state: &mut Arc<S>,
state: &mut Arc<S>,
) -> Result<()> {
// gather block fees and transfer them to sudo
let fees = state.get_block_fees();
let sudo_address = state
.get_sudo_address()
.await
.wrap_err("failed to get sudo address for fee payment")?;

let state_tx = Arc::get_mut(state)
.ok_or_eyre("must only have one reference to the state; this is a bug")?;
for fee in fees {
state_tx
.increase_balance(&sudo_address, fee.asset(), fee.amount())
.await
.wrap_err("failed to increase fee recipient balance")?;
}

Ok(())
}
}

0 comments on commit 6aecbcd

Please sign in to comment.