From 6aecbcd5839f592ce2a7a3131af97a7083735540 Mon Sep 17 00:00:00 2001 From: ethanoroshiba Date: Wed, 20 Nov 2024 10:51:31 -0600 Subject: [PATCH] move fee payment to fees component --- crates/astria-sequencer/src/app/mod.rs | 30 ++----------------- .../astria-sequencer/src/app/tests_app/mod.rs | 7 ++--- .../src/app/tests_breaking_changes.rs | 6 +--- crates/astria-sequencer/src/fees/component.rs | 22 +++++++++++++- 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/crates/astria-sequencer/src/app/mod.rs b/crates/astria-sequencer/src/app/mod.rs index 6d81219f33..dc6bfba8f2 100644 --- a/crates/astria-sequencer/src/app/mod.rs +++ b/crates/astria-sequencer/src/app/mod.rs @@ -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::{ @@ -112,10 +109,7 @@ use crate::{ Component as _, PrepareStateInfo, }, - fees::{ - component::FeesComponent, - StateReadExt as _, - }, + fees::component::FeesComponent, grpc::StateWriteExt as _, ibc::component::IbcComponent, mempool::{ @@ -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()); @@ -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, Vec)> { let state_tx = StateDelta::new(self.state.clone()); let mut arc_state_tx = Arc::new(state_tx); @@ -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 diff --git a/crates/astria-sequencer/src/app/tests_app/mod.rs b/crates/astria-sequencer/src/app/tests_app/mod.rs index ce9b9bf371..5e37a29117 100644 --- a/crates/astria-sequencer/src/app/tests_app/mod.rs +++ b/crates/astria-sequencer/src/app/tests_app/mod.rs @@ -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 { @@ -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()); diff --git a/crates/astria-sequencer/src/app/tests_breaking_changes.rs b/crates/astria-sequencer/src/app/tests_breaking_changes.rs index ec15fd9d56..e300b076f9 100644 --- a/crates/astria-sequencer/src/app/tests_breaking_changes.rs +++ b/crates/astria-sequencer/src/app/tests_breaking_changes.rs @@ -64,7 +64,6 @@ use crate::{ initialize_app, }, }, - authority::StateReadExt as _, benchmark_and_test_utils::{ astria_address, astria_address_from_hex_string, @@ -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; diff --git a/crates/astria-sequencer/src/fees/component.rs b/crates/astria-sequencer/src/fees/component.rs index d9f28df705..019fe3bc34 100644 --- a/crates/astria-sequencer/src/fees/component.rs +++ b/crates/astria-sequencer/src/fees/component.rs @@ -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, @@ -142,8 +146,24 @@ impl Component for FeesComponent { #[instrument(name = "FeesComponent::handle_post_tx_execution", skip_all)] async fn handle_post_tx_execution( - _state: &mut Arc, + state: &mut Arc, ) -> 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(()) } }