diff --git a/crates/astria-sequencer/src/accounts/action.rs b/crates/astria-sequencer/src/accounts/action.rs index fea06788d..f59c54833 100644 --- a/crates/astria-sequencer/src/accounts/action.rs +++ b/crates/astria-sequencer/src/accounts/action.rs @@ -12,6 +12,10 @@ use cnidarium::{ StateRead, StateWrite, }; +use tracing::{ + instrument, + Level, +}; use super::AddressBytes; use crate::{ @@ -31,10 +35,12 @@ use crate::{ #[async_trait::async_trait] impl ActionHandler for TransferAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, state: S) -> Result<()> { let from = state .get_transaction_context() @@ -57,6 +63,11 @@ impl ActionHandler for TransferAction { } } +#[instrument(skip_all, + fields(from = %from.display_address(), + to = %action.to.display_address(), + amount = %action.amount), + err(level = Level::WARN))] pub(crate) async fn execute_transfer( action: &TransferAction, from: TAddress, @@ -115,6 +126,11 @@ where Ok(()) } +#[instrument(skip_all, + fields(from = %from.display_address(), + to = %action.to.display_address(), + amount = %action.amount), + err(level = Level::WARN))] pub(crate) async fn check_transfer( action: &TransferAction, from: TAddress, diff --git a/crates/astria-sequencer/src/accounts/component.rs b/crates/astria-sequencer/src/accounts/component.rs index e197a1911..8d4bb27bb 100644 --- a/crates/astria-sequencer/src/accounts/component.rs +++ b/crates/astria-sequencer/src/accounts/component.rs @@ -24,7 +24,7 @@ pub(crate) struct AccountsComponent; impl Component for AccountsComponent { type AppState = GenesisAppState; - #[instrument(name = "AccountsComponent::init_chain", skip_all)] + #[instrument(name = "AccountsComponent::init_chain", skip_all, err)] async fn init_chain(mut state: S, app_state: &Self::AppState) -> Result<()> where S: accounts::StateWriteExt + assets::StateReadExt, @@ -45,7 +45,7 @@ impl Component for AccountsComponent { Ok(()) } - #[instrument(name = "AccountsComponent::begin_block", skip_all)] + #[instrument(name = "AccountsComponent::begin_block", skip_all, err)] async fn begin_block( _state: &mut Arc, _begin_block: &BeginBlock, @@ -53,7 +53,7 @@ impl Component for AccountsComponent { Ok(()) } - #[instrument(name = "AccountsComponent::end_block", skip_all)] + #[instrument(name = "AccountsComponent::end_block", skip_all, err)] async fn end_block( _state: &mut Arc, _end_block: &EndBlock, diff --git a/crates/astria-sequencer/src/accounts/query.rs b/crates/astria-sequencer/src/accounts/query.rs index 1aaa5f641..5431dd587 100644 --- a/crates/astria-sequencer/src/accounts/query.rs +++ b/crates/astria-sequencer/src/accounts/query.rs @@ -36,6 +36,7 @@ use crate::{ state_ext::StateReadExt as _, }; +#[instrument(skip_all, fields(%asset), err)] async fn ibc_to_trace( state: S, asset: asset::IbcPrefixed, @@ -77,6 +78,7 @@ async fn get_trace_prefixed_account_balances( stream.try_collect::>().await } +#[instrument(skip_all)] pub(crate) async fn balance_request( storage: Storage, request: request::Query, @@ -116,6 +118,7 @@ pub(crate) async fn balance_request( } } +#[instrument(skip_all)] pub(crate) async fn nonce_request( storage: Storage, request: request::Query, @@ -154,6 +157,7 @@ pub(crate) async fn nonce_request( } } +#[instrument(skip_all, fields(%height), err)] async fn get_snapshot_and_height(storage: &Storage, height: Height) -> Result<(Snapshot, Height)> { let snapshot = match height.value() { 0 => storage.latest_snapshot(), @@ -177,6 +181,7 @@ async fn get_snapshot_and_height(storage: &Storage, height: Height) -> Result<(S Ok((snapshot, height)) } +#[instrument(skip_all)] async fn preprocess_request( storage: &Storage, request: &request::Query, diff --git a/crates/astria-sequencer/src/accounts/state_ext.rs b/crates/astria-sequencer/src/accounts/state_ext.rs index 268798bfa..ba3311cf8 100644 --- a/crates/astria-sequencer/src/accounts/state_ext.rs +++ b/crates/astria-sequencer/src/accounts/state_ext.rs @@ -164,7 +164,7 @@ fn extract_asset_from_key(s: &str) -> Result { #[async_trait] pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt { - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()))] fn account_asset_keys( &self, address: impl AddressBytes, @@ -175,7 +175,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt { } } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()))] fn account_asset_balances( &self, address: impl AddressBytes, @@ -208,7 +208,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt { Ok(balance) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()), err)] async fn get_account_nonce(&self, address: T) -> Result { let bytes = self .get_raw(&nonce_storage_key(address)) @@ -224,7 +224,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt { Ok(nonce) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_transfer_base_fee(&self) -> Result { let bytes = self .get_raw(TRANSFER_BASE_FEE_STORAGE_KEY) @@ -260,7 +260,7 @@ pub(crate) trait StateWriteExt: StateWrite { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address(), nonce), err)] fn put_account_nonce(&mut self, address: T, nonce: u32) -> Result<()> { let bytes = borsh::to_vec(&Nonce(nonce)).wrap_err("failed to serialize nonce")?; self.put_raw(nonce_storage_key(address), bytes); @@ -321,7 +321,7 @@ pub(crate) trait StateWriteExt: StateWrite { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(fee), err)] fn put_transfer_base_fee(&mut self, fee: u128) -> Result<()> { let bytes = borsh::to_vec(&Fee(fee)).wrap_err("failed to serialize fee")?; self.put_raw(TRANSFER_BASE_FEE_STORAGE_KEY.to_string(), bytes); diff --git a/crates/astria-sequencer/src/address/state_ext.rs b/crates/astria-sequencer/src/address/state_ext.rs index df4d0d33d..18cf48fa3 100644 --- a/crates/astria-sequencer/src/address/state_ext.rs +++ b/crates/astria-sequencer/src/address/state_ext.rs @@ -28,6 +28,7 @@ fn ibc_compat_prefix_key() -> &'static str { #[async_trait] pub(crate) trait StateReadExt: StateRead { + #[instrument(skip_all, fields(%address), err)] async fn ensure_base_prefix(&self, address: &Address) -> Result<()> { let prefix = self .get_base_prefix() @@ -41,6 +42,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(()) } + #[instrument(skip_all, err)] async fn try_base_prefixed(&self, slice: &[u8]) -> Result
{ let prefix = self .get_base_prefix() diff --git a/crates/astria-sequencer/src/api_state_ext.rs b/crates/astria-sequencer/src/api_state_ext.rs index f0a5d5f70..8d021be5f 100644 --- a/crates/astria-sequencer/src/api_state_ext.rs +++ b/crates/astria-sequencer/src/api_state_ext.rs @@ -135,7 +135,7 @@ impl From for RollupIdSer { #[async_trait] pub(crate) trait StateReadExt: StateRead { - #[instrument(skip_all)] + #[instrument(skip_all, fields(%height), err)] async fn get_block_hash_by_height(&self, height: u64) -> Result<[u8; 32]> { let key = block_hash_by_height_key(height); let Some(hash) = self @@ -153,7 +153,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(hash) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(hash = %hex::encode(hash)), err)] async fn get_sequencer_block_header_by_hash( &self, hash: &[u8], @@ -175,7 +175,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(header) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(hash = %hex::encode(hash)), err)] async fn get_rollup_ids_by_block_hash(&self, hash: &[u8]) -> Result> { let key = rollup_ids_by_hash_key(hash); let Some(rollup_ids_bytes) = self @@ -192,7 +192,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(rollup_ids) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(hash = %hex::encode(hash)), err)] async fn get_sequencer_block_by_hash(&self, hash: &[u8]) -> Result { let Some(header_bytes) = self .nonverifiable_get_raw(&sequencer_block_header_by_hash_key(hash)) @@ -266,7 +266,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(block) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%height), err)] async fn get_sequencer_block_by_height(&self, height: u64) -> Result { let hash = self .get_block_hash_by_height(height) @@ -277,7 +277,7 @@ pub(crate) trait StateReadExt: StateRead { .wrap_err("failed to get sequencer block by hash") } - #[instrument(skip_all)] + #[instrument(skip_all, fields(hash = %hex::encode(hash), %rollup_id), err)] async fn get_rollup_data( &self, hash: &[u8], @@ -301,7 +301,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(rollup_transactions) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(hash = %hex::encode(hash)), err)] async fn get_block_proofs_by_block_hash( &self, hash: &[u8], @@ -338,7 +338,7 @@ pub(crate) trait StateReadExt: StateRead { impl StateReadExt for T {} pub(crate) trait StateWriteExt: StateWrite { - #[instrument(skip_all)] + #[instrument(skip_all, fields(height = %block.height()), err)] fn put_sequencer_block(&mut self, block: SequencerBlock) -> Result<()> { // split up and write the sequencer block to state in the following order: // 1. height to block hash diff --git a/crates/astria-sequencer/src/app/mod.rs b/crates/astria-sequencer/src/app/mod.rs index 921f0fe9a..f0daf0622 100644 --- a/crates/astria-sequencer/src/app/mod.rs +++ b/crates/astria-sequencer/src/app/mod.rs @@ -72,6 +72,7 @@ use tracing::{ debug, info, instrument, + Level, }; use crate::{ @@ -184,6 +185,7 @@ pub(crate) struct App { } impl App { + #[instrument(skip_all, err)] pub(crate) async fn new( snapshot: Snapshot, mempool: Mempool, @@ -218,7 +220,7 @@ impl App { }) } - #[instrument(name = "App:init_chain", skip_all)] + #[instrument(name = "App:init_chain", skip_all, err)] pub(crate) async fn init_chain( &mut self, storage: Storage, @@ -301,7 +303,7 @@ impl App { /// It puts this special "commitment" as the first transaction in a block. /// When other validators receive the block, they know the first transaction is /// supposed to be the commitment, and verifies that is it correct. - #[instrument(name = "App::prepare_proposal", skip_all)] + #[instrument(name = "App::prepare_proposal", skip_all, err)] pub(crate) async fn prepare_proposal( &mut self, prepare_proposal: abci::request::PrepareProposal, @@ -351,7 +353,7 @@ impl App { /// Generates a commitment to the `sequence::Actions` in the block's transactions /// and ensures it matches the commitment created by the proposer, which /// should be the first transaction in the block. - #[instrument(name = "App::process_proposal", skip_all)] + #[instrument(name = "App::process_proposal", skip_all, err(level = Level::WARN))] pub(crate) async fn process_proposal( &mut self, process_proposal: abci::request::ProcessProposal, @@ -482,7 +484,7 @@ impl App { /// /// As a result, all transactions in a sequencer block are guaranteed to execute /// successfully. - #[instrument(name = "App::execute_transactions_prepare_proposal", skip_all)] + #[instrument(name = "App::execute_transactions_prepare_proposal", skip_all, err)] async fn execute_transactions_prepare_proposal( &mut self, block_size_constraints: &mut BlockSizeConstraints, @@ -633,7 +635,7 @@ impl App { /// /// As a result, all transactions in a sequencer block are guaranteed to execute /// successfully. - #[instrument(name = "App::execute_transactions_process_proposal", skip_all)] + #[instrument(name = "App::execute_transactions_process_proposal", skip_all, err(level = Level::WARN))] async fn execute_transactions_process_proposal( &mut self, txs: Vec, @@ -765,7 +767,7 @@ impl App { /// /// This is called by cometbft after the block has already been /// committed by the network's consensus. - #[instrument(name = "App::finalize_block", skip_all)] + #[instrument(name = "App::finalize_block", skip_all, err)] pub(crate) async fn finalize_block( &mut self, finalize_block: abci::request::FinalizeBlock, @@ -836,7 +838,7 @@ impl App { }), Err(e) => { // this is actually a protocol error, as only valid txs should be finalized - tracing::error!( + tracing::warn!( error = AsRef::::as_ref(&e), "failed to finalize transaction; ignoring it", ); @@ -953,8 +955,8 @@ impl App { Ok(app_hash) } - #[instrument(name = "App::begin_block", skip_all)] - async fn begin_block( + #[instrument(name = "App::begin_block", skip_all, err)] + pub(crate) async fn begin_block( &mut self, begin_block: &abci::request::BeginBlock, ) -> Result> { @@ -1020,8 +1022,8 @@ impl App { Ok(state_tx.apply().1) } - #[instrument(name = "App::end_block", skip_all)] - async fn end_block( + #[instrument(name = "App::end_block", skip_all, err)] + pub(crate) async fn end_block( &mut self, height: u64, fee_recipient: [u8; 20], @@ -1141,6 +1143,7 @@ impl App { // NOTE: this function locks the mempool until all accounts have been cleaned. // this could potentially stall consensus from moving to the next round if // the mempool is large, especially if recosting transactions. +#[instrument(skip_all)] async fn update_mempool_after_finalization( mempool: &mut Mempool, state: &S, diff --git a/crates/astria-sequencer/src/assets/query.rs b/crates/astria-sequencer/src/assets/query.rs index b6b3f1c9e..d6737ea16 100644 --- a/crates/astria-sequencer/src/assets/query.rs +++ b/crates/astria-sequencer/src/assets/query.rs @@ -14,6 +14,7 @@ use tendermint::abci::{ response, Code, }; +use tracing::instrument; use crate::{ assets::StateReadExt as _, @@ -24,6 +25,7 @@ use crate::{ // // Example: // `abci-cli query --path=asset/denom/` +#[instrument(skip_all)] pub(crate) async fn denom_request( storage: Storage, request: request::Query, @@ -110,6 +112,7 @@ fn preprocess_request(params: &[(String, String)]) -> Result( #[async_trait] pub(crate) trait StateReadExt: StateRead { - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_native_asset(&self) -> Result { let Some(bytes) = self .get_raw(NATIVE_ASSET_KEY) @@ -86,7 +86,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(asset) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%asset), err)] async fn has_ibc_asset(&self, asset: TAsset) -> Result where TAsset: Into + std::fmt::Display + Send, @@ -121,7 +121,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(Some(denom)) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_block_fees(&self) -> Result> { let mut fees = Vec::new(); @@ -149,7 +149,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(fees) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%asset), err)] async fn is_allowed_fee_asset(&self, asset: TAsset) -> Result where TAsset: Into + std::fmt::Display + Send, @@ -162,7 +162,7 @@ pub(crate) trait StateReadExt: StateRead { .is_some()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_allowed_fee_assets(&self) -> Result> { let mut assets = Vec::new(); @@ -194,7 +194,7 @@ pub(crate) trait StateWriteExt: StateWrite { self.put_raw(NATIVE_ASSET_KEY.to_string(), asset.to_string().into_bytes()); } - #[instrument(skip_all)] + #[instrument(skip_all, err)] fn put_ibc_asset(&mut self, asset: &asset::TracePrefixed) -> Result<()> { let bytes = borsh::to_vec(&DenominationTrace(asset.to_string())) .wrap_err("failed to serialize asset")?; @@ -203,7 +203,7 @@ pub(crate) trait StateWriteExt: StateWrite { } /// Adds `amount` to the block fees for `asset`. - #[instrument(skip_all)] + #[instrument(skip_all, fields(%asset, %amount), err)] async fn get_and_increase_block_fees( &mut self, asset: TAsset, diff --git a/crates/astria-sequencer/src/authority/action.rs b/crates/astria-sequencer/src/authority/action.rs index 130b87624..6e36906c7 100644 --- a/crates/astria-sequencer/src/authority/action.rs +++ b/crates/astria-sequencer/src/authority/action.rs @@ -12,6 +12,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::StateWriteExt as _, @@ -29,10 +33,12 @@ use crate::{ #[async_trait::async_trait] impl ActionHandler for ValidatorUpdate { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() @@ -78,12 +84,14 @@ impl ActionHandler for ValidatorUpdate { #[async_trait::async_trait] impl ActionHandler for SudoAddressChangeAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } /// check that the signer of the transaction is the current sudo address, /// as only that address can change the sudo address + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() @@ -108,12 +116,14 @@ impl ActionHandler for SudoAddressChangeAction { #[async_trait::async_trait] impl ActionHandler for FeeChangeAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } /// check that the signer of the transaction is the current sudo address, /// as only that address can change the fee + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/authority/component.rs b/crates/astria-sequencer/src/authority/component.rs index 1ab9f1a32..160b36785 100644 --- a/crates/astria-sequencer/src/authority/component.rs +++ b/crates/astria-sequencer/src/authority/component.rs @@ -35,7 +35,7 @@ pub(crate) struct AuthorityComponentAppState { impl Component for AuthorityComponent { type AppState = AuthorityComponentAppState; - #[instrument(name = "AuthorityComponent::init_chain", skip_all)] + #[instrument(name = "AuthorityComponent::init_chain", skip_all, err)] async fn init_chain(mut state: S, app_state: &Self::AppState) -> Result<()> { // set sudo key and initial validator set state @@ -48,7 +48,7 @@ impl Component for AuthorityComponent { Ok(()) } - #[instrument(name = "AuthorityComponent::begin_block", skip_all)] + #[instrument(name = "AuthorityComponent::begin_block", skip_all, err)] async fn begin_block( state: &mut Arc, begin_block: &BeginBlock, @@ -70,7 +70,7 @@ impl Component for AuthorityComponent { Ok(()) } - #[instrument(name = "AuthorityComponent::end_block", skip_all)] + #[instrument(name = "AuthorityComponent::end_block", skip_all, err)] async fn end_block( state: &mut Arc, _end_block: &EndBlock, diff --git a/crates/astria-sequencer/src/authority/state_ext.rs b/crates/astria-sequencer/src/authority/state_ext.rs index 3196cd212..7f3e66ddf 100644 --- a/crates/astria-sequencer/src/authority/state_ext.rs +++ b/crates/astria-sequencer/src/authority/state_ext.rs @@ -33,7 +33,7 @@ const VALIDATOR_UPDATES_KEY: &[u8] = b"valupdates"; #[async_trait] pub(crate) trait StateReadExt: StateRead { - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_sudo_address(&self) -> Result<[u8; ADDRESS_LEN]> { let Some(bytes) = self .get_raw(SUDO_STORAGE_KEY) @@ -49,7 +49,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(address_bytes) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_validator_set(&self) -> Result { let Some(bytes) = self .get_raw(VALIDATOR_SET_STORAGE_KEY) @@ -66,7 +66,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(ValidatorSet(validator_set)) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_validator_updates(&self) -> Result { let Some(bytes) = self .nonverifiable_get_raw(VALIDATOR_UPDATES_KEY) @@ -88,7 +88,7 @@ impl StateReadExt for T {} #[async_trait] pub(crate) trait StateWriteExt: StateWrite { - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()), err)] fn put_sudo_address(&mut self, address: T) -> Result<()> { self.put_raw( SUDO_STORAGE_KEY.to_string(), @@ -98,7 +98,7 @@ pub(crate) trait StateWriteExt: StateWrite { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] fn put_validator_set(&mut self, validator_set: ValidatorSet) -> Result<()> { self.put_raw( VALIDATOR_SET_STORAGE_KEY.to_string(), @@ -107,7 +107,7 @@ pub(crate) trait StateWriteExt: StateWrite { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] fn put_validator_updates(&mut self, validator_updates: ValidatorSet) -> Result<()> { self.nonverifiable_put_raw( VALIDATOR_UPDATES_KEY.to_vec(), diff --git a/crates/astria-sequencer/src/bridge/bridge_lock_action.rs b/crates/astria-sequencer/src/bridge/bridge_lock_action.rs index 6c4bc8324..13208f53f 100644 --- a/crates/astria-sequencer/src/bridge/bridge_lock_action.rs +++ b/crates/astria-sequencer/src/bridge/bridge_lock_action.rs @@ -13,6 +13,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::{ @@ -40,10 +44,12 @@ const DEPOSIT_BASE_FEE: u128 = 16; #[async_trait::async_trait] impl ActionHandler for BridgeLockAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/bridge/bridge_sudo_change_action.rs b/crates/astria-sequencer/src/bridge/bridge_sudo_change_action.rs index 39ae6e2e4..bc17f00b0 100644 --- a/crates/astria-sequencer/src/bridge/bridge_sudo_change_action.rs +++ b/crates/astria-sequencer/src/bridge/bridge_sudo_change_action.rs @@ -9,6 +9,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::StateWriteExt as _, @@ -26,10 +30,12 @@ use crate::{ }; #[async_trait::async_trait] impl ActionHandler for BridgeSudoChangeAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/bridge/bridge_unlock_action.rs b/crates/astria-sequencer/src/bridge/bridge_unlock_action.rs index 4868b29b8..4579f919d 100644 --- a/crates/astria-sequencer/src/bridge/bridge_unlock_action.rs +++ b/crates/astria-sequencer/src/bridge/bridge_unlock_action.rs @@ -9,6 +9,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::action::{ @@ -27,6 +31,7 @@ use crate::{ #[async_trait::async_trait] impl ActionHandler for BridgeUnlockAction { // TODO(https://github.com/astriaorg/astria/issues/1430): move checks to the `BridgeUnlock` parsing. + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { ensure!(self.amount > 0, "amount must be greater than zero",); ensure!(self.memo.len() <= 64, "memo must not be more than 64 bytes"); @@ -45,6 +50,7 @@ impl ActionHandler for BridgeUnlockAction { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/bridge/component.rs b/crates/astria-sequencer/src/bridge/component.rs index 0c38b7d17..d722c1df1 100644 --- a/crates/astria-sequencer/src/bridge/component.rs +++ b/crates/astria-sequencer/src/bridge/component.rs @@ -18,7 +18,7 @@ pub(crate) struct BridgeComponent; impl Component for BridgeComponent { type AppState = GenesisAppState; - #[instrument(name = "BridgeComponent::init_chain", skip_all)] + #[instrument(name = "BridgeComponent::init_chain", skip_all, err)] async fn init_chain(mut state: S, app_state: &Self::AppState) -> Result<()> { state.put_init_bridge_account_base_fee(app_state.fees().init_bridge_account_base_fee); state.put_bridge_lock_byte_cost_multiplier( @@ -28,7 +28,7 @@ impl Component for BridgeComponent { Ok(()) } - #[instrument(name = "BridgeComponent::begin_block", skip_all)] + #[instrument(name = "BridgeComponent::begin_block", skip_all, err)] async fn begin_block( _state: &mut Arc, _begin_block: &BeginBlock, @@ -36,7 +36,7 @@ impl Component for BridgeComponent { Ok(()) } - #[instrument(name = "BridgeComponent::end_block", skip_all)] + #[instrument(name = "BridgeComponent::end_block", skip_all, err)] async fn end_block( _state: &mut Arc, _end_block: &EndBlock, diff --git a/crates/astria-sequencer/src/bridge/init_bridge_account_action.rs b/crates/astria-sequencer/src/bridge/init_bridge_account_action.rs index d8a2dedaa..2ca8d1f50 100644 --- a/crates/astria-sequencer/src/bridge/init_bridge_account_action.rs +++ b/crates/astria-sequencer/src/bridge/init_bridge_account_action.rs @@ -10,6 +10,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::{ @@ -31,10 +35,12 @@ use crate::{ #[async_trait::async_trait] impl ActionHandler for InitBridgeAccountAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/bridge/query.rs b/crates/astria-sequencer/src/bridge/query.rs index 2acd2dd23..bb4a9b7be 100644 --- a/crates/astria-sequencer/src/bridge/query.rs +++ b/crates/astria-sequencer/src/bridge/query.rs @@ -16,6 +16,7 @@ use tendermint::abci::{ response, Code, }; +use tracing::instrument; use crate::{ address::StateReadExt, @@ -41,9 +42,7 @@ fn error_query_response( } } -// FIXME (https://github.com/astriaorg/astria/issues/1582): there is a lot of code duplication due to `error_query_response`. -// this could be significantly shortened. -#[expect(clippy::too_many_lines, reason = "should be refactored")] +#[instrument(skip_all, fields(%address))] async fn get_bridge_account_info( snapshot: cnidarium::Snapshot, address: Address, @@ -162,6 +161,7 @@ async fn get_bridge_account_info( })) } +#[instrument(skip_all)] pub(crate) async fn bridge_account_info_request( storage: Storage, request: request::Query, @@ -210,6 +210,7 @@ pub(crate) async fn bridge_account_info_request( } } +#[instrument(skip_all)] pub(crate) async fn bridge_account_last_tx_hash_request( storage: Storage, request: request::Query, diff --git a/crates/astria-sequencer/src/bridge/state_ext.rs b/crates/astria-sequencer/src/bridge/state_ext.rs index f88b6ecfe..5a59d06a4 100644 --- a/crates/astria-sequencer/src/bridge/state_ext.rs +++ b/crates/astria-sequencer/src/bridge/state_ext.rs @@ -210,7 +210,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(asset::IbcPrefixed::new(id.0)) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(bridge_address = %bridge_address.display_address()), err)] async fn get_bridge_account_sudo_address( &self, bridge_address: T, @@ -233,7 +233,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(Some(sudo_address)) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(bridge_address = %bridge_address.display_address()), err)] async fn get_bridge_account_withdrawer_address( &self, bridge_address: T, @@ -265,7 +265,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { self.object_get(DEPOSITS_EPHEMERAL_KEY).unwrap_or_default() } - #[instrument(skip_all)] + #[instrument(skip_all, fields(block_hash = %hex::encode(block_hash), %rollup_id), err)] async fn get_deposits( &self, block_hash: &[u8; 32], @@ -292,7 +292,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(deposits) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_init_bridge_account_base_fee(&self) -> Result { let bytes = self .get_raw(INIT_BRIDGE_ACCOUNT_BASE_FEE_STORAGE_KEY) @@ -304,7 +304,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(fee) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_bridge_lock_byte_cost_multiplier(&self) -> Result { let bytes = self .get_raw(BRIDGE_LOCK_BYTE_COST_MULTIPLIER_STORAGE_KEY) @@ -316,7 +316,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(fee) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_bridge_sudo_change_base_fee(&self) -> Result { let bytes = self .get_raw(BRIDGE_SUDO_CHANGE_FEE_STORAGE_KEY) @@ -328,7 +328,7 @@ pub(crate) trait StateReadExt: StateRead + address::StateReadExt { Ok(fee) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%address), err)] async fn get_last_transaction_id_for_bridge_account( &self, address: &Address, @@ -407,7 +407,7 @@ pub(crate) trait StateWriteExt: StateWrite { ); } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address(), %withdrawal_event_id), err)] async fn check_and_set_withdrawal_event_block_for_bridge_account( &mut self, address: T, @@ -451,7 +451,7 @@ pub(crate) trait StateWriteExt: StateWrite { self.object_put(DEPOSITS_EPHEMERAL_KEY, cached_deposits); } - #[instrument(skip_all)] + #[instrument(skip_all, err)] fn put_deposits( &mut self, block_hash: &[u8; 32], diff --git a/crates/astria-sequencer/src/fee_asset_change.rs b/crates/astria-sequencer/src/fee_asset_change.rs index 00099ffe1..2679ce210 100644 --- a/crates/astria-sequencer/src/fee_asset_change.rs +++ b/crates/astria-sequencer/src/fee_asset_change.rs @@ -7,6 +7,10 @@ use astria_eyre::eyre::{ }; use async_trait::async_trait; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ app::ActionHandler, @@ -20,10 +24,12 @@ use crate::{ #[async_trait] impl ActionHandler for FeeAssetChangeAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/grpc/sequencer.rs b/crates/astria-sequencer/src/grpc/sequencer.rs index f7ddf660c..b5e171120 100644 --- a/crates/astria-sequencer/src/grpc/sequencer.rs +++ b/crates/astria-sequencer/src/grpc/sequencer.rs @@ -48,7 +48,7 @@ impl SequencerServer { #[async_trait::async_trait] impl SequencerService for SequencerServer { /// Given a block height, returns the sequencer block at that height. - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_sequencer_block( self: Arc, request: Request, @@ -78,7 +78,7 @@ impl SequencerService for SequencerServer { /// Given a block height and set of rollup ids, returns a SequencerBlock which /// is filtered to contain only the transactions that are relevant to the given rollup. - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_filtered_sequencer_block( self: Arc, request: Request, @@ -166,7 +166,7 @@ impl SequencerService for SequencerServer { Ok(Response::new(block)) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_pending_nonce( self: Arc, request: Request, diff --git a/crates/astria-sequencer/src/ibc/component.rs b/crates/astria-sequencer/src/ibc/component.rs index 488fcf6eb..7bbfdfc07 100644 --- a/crates/astria-sequencer/src/ibc/component.rs +++ b/crates/astria-sequencer/src/ibc/component.rs @@ -30,7 +30,7 @@ pub(crate) struct IbcComponent; impl Component for IbcComponent { type AppState = GenesisAppState; - #[instrument(name = "IbcComponent::init_chain", skip_all)] + #[instrument(name = "IbcComponent::init_chain", skip_all, err)] async fn init_chain(mut state: S, app_state: &Self::AppState) -> Result<()> { Ibc::init_chain( &mut state, @@ -54,7 +54,7 @@ impl Component for IbcComponent { Ok(()) } - #[instrument(name = "IbcComponent::begin_block", skip_all)] + #[instrument(name = "IbcComponent::begin_block", skip_all, err)] async fn begin_block( state: &mut Arc, begin_block: &BeginBlock, @@ -63,7 +63,7 @@ impl Component for IbcComponent { Ok(()) } - #[instrument(name = "IbcComponent::end_block", skip_all)] + #[instrument(name = "IbcComponent::end_block", skip_all, err)] async fn end_block( state: &mut Arc, end_block: &EndBlock, diff --git a/crates/astria-sequencer/src/ibc/host_interface.rs b/crates/astria-sequencer/src/ibc/host_interface.rs index c8e8aaea7..1e9b24377 100644 --- a/crates/astria-sequencer/src/ibc/host_interface.rs +++ b/crates/astria-sequencer/src/ibc/host_interface.rs @@ -4,6 +4,7 @@ use astria_eyre::{ }; use cnidarium::StateRead; use penumbra_ibc::component::HostInterface; +use tracing::instrument; use crate::state_ext::StateReadExt as _; @@ -12,6 +13,7 @@ pub(crate) struct AstriaHost; #[async_trait::async_trait] impl HostInterface for AstriaHost { + #[instrument(skip_all)] async fn get_chain_id(state: S) -> anyhow::Result { state .get_chain_id() @@ -20,14 +22,17 @@ impl HostInterface for AstriaHost { .map(|s| s.to_string()) } + #[instrument(skip_all)] async fn get_revision_number(state: S) -> anyhow::Result { state.get_revision_number().await.map_err(eyre_to_anyhow) } + #[instrument(skip_all)] async fn get_block_height(state: S) -> anyhow::Result { state.get_block_height().await.map_err(eyre_to_anyhow) } + #[instrument(skip_all)] async fn get_block_timestamp(state: S) -> anyhow::Result { state.get_block_timestamp().await.map_err(eyre_to_anyhow) } diff --git a/crates/astria-sequencer/src/ibc/ibc_relayer_change.rs b/crates/astria-sequencer/src/ibc/ibc_relayer_change.rs index 57c2da04b..abd8e9869 100644 --- a/crates/astria-sequencer/src/ibc/ibc_relayer_change.rs +++ b/crates/astria-sequencer/src/ibc/ibc_relayer_change.rs @@ -6,6 +6,10 @@ use astria_eyre::eyre::{ }; use async_trait::async_trait; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ address::StateReadExt as _, @@ -19,10 +23,12 @@ use crate::{ #[async_trait] impl ActionHandler for IbcRelayerChangeAction { + #[instrument(skip_all)] async fn check_stateless(&self) -> Result<()> { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/ibc/ics20_transfer.rs b/crates/astria-sequencer/src/ibc/ics20_transfer.rs index 0462e9e76..972dae8dc 100644 --- a/crates/astria-sequencer/src/ibc/ics20_transfer.rs +++ b/crates/astria-sequencer/src/ibc/ics20_transfer.rs @@ -179,6 +179,7 @@ pub(crate) struct Ics20Transfer; #[async_trait::async_trait] impl AppHandlerCheck for Ics20Transfer { + #[instrument(skip_all, err)] async fn chan_open_init_check( _: S, msg: &MsgChannelOpenInit, @@ -194,6 +195,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all, err)] async fn chan_open_try_check( _: S, msg: &MsgChannelOpenTry, @@ -209,6 +211,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all, err)] async fn chan_open_ack_check( _: S, msg: &MsgChannelOpenAck, @@ -220,6 +223,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all)] async fn chan_open_confirm_check( _: S, _: &MsgChannelOpenConfirm, @@ -229,6 +233,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all)] async fn chan_close_init_check( _: S, _: &MsgChannelCloseInit, @@ -236,6 +241,7 @@ impl AppHandlerCheck for Ics20Transfer { anyhow::bail!("ics20 always aborts on chan_close_init"); } + #[instrument(skip_all)] async fn chan_close_confirm_check( _: S, _: &MsgChannelCloseConfirm, @@ -244,6 +250,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all, err)] async fn recv_packet_check(_: S, msg: &MsgRecvPacket) -> anyhow::Result<()> { // most checks performed in `execute` // perform stateless checks here @@ -258,6 +265,7 @@ impl AppHandlerCheck for Ics20Transfer { Ok(()) } + #[instrument(skip_all, err)] async fn timeout_packet_check(state: S, msg: &MsgTimeout) -> anyhow::Result<()> { refund_tokens_check( state, @@ -269,6 +277,7 @@ impl AppHandlerCheck for Ics20Transfer { .map_err(eyre_to_anyhow) } + #[instrument(skip_all, err)] async fn acknowledge_packet_check( state: S, msg: &MsgAcknowledgement, @@ -293,6 +302,7 @@ impl AppHandlerCheck for Ics20Transfer { } } +#[instrument(skip_all, fields(%source_port, %source_channel), err)] async fn refund_tokens_check( state: S, data: &[u8], diff --git a/crates/astria-sequencer/src/ibc/ics20_withdrawal.rs b/crates/astria-sequencer/src/ibc/ics20_withdrawal.rs index f843f199d..2196d5cff 100644 --- a/crates/astria-sequencer/src/ibc/ics20_withdrawal.rs +++ b/crates/astria-sequencer/src/ibc/ics20_withdrawal.rs @@ -35,6 +35,10 @@ use penumbra_ibc::component::packet::{ Unchecked, }; use penumbra_proto::core::component::ibc::v1::FungibleTokenPacketData; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::{ @@ -56,6 +60,7 @@ use crate::{ transaction::StateReadExt as _, }; +#[instrument(skip_all, err)] async fn create_ibc_packet_from_withdrawal( withdrawal: &action::Ics20Withdrawal, state: S, @@ -105,6 +110,7 @@ async fn create_ibc_packet_from_withdrawal( /// 1. Errors reading from DB /// 2. `action.bridge_address` is set, but `from` is not the withdrawer address. /// 3. `action.bridge_address` is unset, but `from` is a bridge account. +#[instrument(skip_all, err)] async fn establish_withdrawal_target( action: &action::Ics20Withdrawal, state: &S, @@ -144,6 +150,7 @@ async fn establish_withdrawal_target( #[async_trait::async_trait] impl ActionHandler for action::Ics20Withdrawal { // TODO(https://github.com/astriaorg/astria/issues/1430): move checks to the `Ics20Withdrawal` parsing. + #[instrument(skip_all, err)] async fn check_stateless(&self) -> Result<()> { ensure!(self.timeout_time() != 0, "timeout time must be non-zero",); ensure!(self.amount() > 0, "amount must be greater than zero",); @@ -179,6 +186,7 @@ impl ActionHandler for action::Ics20Withdrawal { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() diff --git a/crates/astria-sequencer/src/ibc/state_ext.rs b/crates/astria-sequencer/src/ibc/state_ext.rs index c490dcb8d..eade54de1 100644 --- a/crates/astria-sequencer/src/ibc/state_ext.rs +++ b/crates/astria-sequencer/src/ibc/state_ext.rs @@ -95,7 +95,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(balance) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_ibc_sudo_address(&self) -> Result<[u8; ADDRESS_LEN]> { let Some(bytes) = self .get_raw(IBC_SUDO_STORAGE_KEY) @@ -111,7 +111,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(address_bytes) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()), err)] async fn is_ibc_relayer(&self, address: T) -> Result { Ok(self .get_raw(&ibc_relayer_key(&address)) @@ -121,7 +121,7 @@ pub(crate) trait StateReadExt: StateRead { .is_some()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_ics20_withdrawal_base_fee(&self) -> Result { let Some(bytes) = self .get_raw(ICS20_WITHDRAWAL_BASE_FEE_STORAGE_KEY) @@ -181,7 +181,7 @@ pub(crate) trait StateWriteExt: StateWrite { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, fields(address = %address.display_address()), err)] fn put_ibc_sudo_address(&mut self, address: T) -> Result<()> { self.put_raw( IBC_SUDO_STORAGE_KEY.to_string(), @@ -201,7 +201,7 @@ pub(crate) trait StateWriteExt: StateWrite { self.delete(ibc_relayer_key(&address)); } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%fee), err)] fn put_ics20_withdrawal_base_fee(&mut self, fee: u128) -> Result<()> { self.put_raw( ICS20_WITHDRAWAL_BASE_FEE_STORAGE_KEY.to_string(), diff --git a/crates/astria-sequencer/src/mempool/mempool_state.rs b/crates/astria-sequencer/src/mempool/mempool_state.rs index 9bcec845e..06c72770d 100644 --- a/crates/astria-sequencer/src/mempool/mempool_state.rs +++ b/crates/astria-sequencer/src/mempool/mempool_state.rs @@ -10,7 +10,7 @@ use crate::accounts::{ StateReadExt as _, }; -#[instrument(skip_all)] +#[instrument(skip_all, fields(address = %address.display_address()), err)] pub(crate) async fn get_account_balances( state: S, address: impl AddressBytes, diff --git a/crates/astria-sequencer/src/mempool/mod.rs b/crates/astria-sequencer/src/mempool/mod.rs index 5916b8512..42654ce3a 100644 --- a/crates/astria-sequencer/src/mempool/mod.rs +++ b/crates/astria-sequencer/src/mempool/mod.rs @@ -162,7 +162,7 @@ impl Mempool { /// Inserts a transaction into the mempool and does not allow for transaction replacement. /// Will return the reason for insertion failure if failure occurs. - #[instrument(skip_all)] + #[instrument(skip_all, fields(%current_account_nonce), err)] pub(crate) async fn insert( &self, tx: Arc, @@ -240,6 +240,7 @@ impl Mempool { /// /// This function should only be used to remove invalid/failing transactions and not executed /// transactions. Executed transactions will be removed in the `run_maintenance()` function. + #[instrument(skip_all)] pub(crate) async fn remove_tx_invalid( &self, signed_tx: Arc, diff --git a/crates/astria-sequencer/src/mempool/transactions_container.rs b/crates/astria-sequencer/src/mempool/transactions_container.rs index 25d5cad27..284200b33 100644 --- a/crates/astria-sequencer/src/mempool/transactions_container.rs +++ b/crates/astria-sequencer/src/mempool/transactions_container.rs @@ -24,7 +24,10 @@ use tokio::time::{ Duration, Instant, }; -use tracing::error; +use tracing::{ + error, + instrument, +}; use super::RemovalReason; use crate::{ @@ -508,6 +511,7 @@ impl TransactionsContainer { /// Recosts transactions for an account. /// /// Logs an error if fails to recost a transaction. + #[instrument(skip_all)] pub(super) async fn recost_transactions( &mut self, address: [u8; 20], @@ -601,6 +605,7 @@ impl TransactionsContainer { } /// Cleans the specified account of stale and expired transactions. + #[instrument(skip_all)] pub(super) fn clean_account_stale_expired( &mut self, address: [u8; 20], @@ -703,6 +708,7 @@ impl TransactionsContainer { /// Returns a copy of transactions and their hashes sorted by nonce difference and then time /// first seen. + #[instrument(skip_all, err)] pub(super) async fn builder_queue( &self, state: &S, diff --git a/crates/astria-sequencer/src/sequence/action.rs b/crates/astria-sequencer/src/sequence/action.rs index d60b7b488..1b34d3ef7 100644 --- a/crates/astria-sequencer/src/sequence/action.rs +++ b/crates/astria-sequencer/src/sequence/action.rs @@ -9,6 +9,10 @@ use astria_eyre::eyre::{ WrapErr as _, }; use cnidarium::StateWrite; +use tracing::{ + instrument, + Level, +}; use crate::{ accounts::{ @@ -26,6 +30,7 @@ use crate::{ #[async_trait::async_trait] impl ActionHandler for SequenceAction { + #[instrument(skip_all, err)] async fn check_stateless(&self) -> Result<()> { // TODO: do we want to place a maximum on the size of the data? // https://github.com/astriaorg/astria/issues/222 @@ -36,6 +41,7 @@ impl ActionHandler for SequenceAction { Ok(()) } + #[instrument(skip_all, err(level = Level::WARN))] async fn check_and_execute(&self, mut state: S) -> Result<()> { let from = state .get_transaction_context() @@ -72,6 +78,7 @@ impl ActionHandler for SequenceAction { } /// Calculates the fee for a sequence `Action` based on the length of the `data`. +#[instrument(skip_all, err)] pub(crate) async fn calculate_fee_from_state( data: &[u8], state: &S, diff --git a/crates/astria-sequencer/src/sequence/component.rs b/crates/astria-sequencer/src/sequence/component.rs index 36fa82736..57e7263b9 100644 --- a/crates/astria-sequencer/src/sequence/component.rs +++ b/crates/astria-sequencer/src/sequence/component.rs @@ -18,7 +18,7 @@ pub(crate) struct SequenceComponent; impl Component for SequenceComponent { type AppState = GenesisAppState; - #[instrument(name = "SequenceComponent::init_chain", skip_all)] + #[instrument(name = "SequenceComponent::init_chain", skip_all, err)] async fn init_chain(mut state: S, app_state: &Self::AppState) -> Result<()> { state.put_sequence_action_base_fee(app_state.fees().sequence_base_fee); state.put_sequence_action_byte_cost_multiplier( @@ -27,7 +27,7 @@ impl Component for SequenceComponent { Ok(()) } - #[instrument(name = "SequenceComponent::begin_block", skip_all)] + #[instrument(name = "SequenceComponent::begin_block", skip_all, err)] async fn begin_block( _state: &mut Arc, _begin_block: &BeginBlock, @@ -35,7 +35,7 @@ impl Component for SequenceComponent { Ok(()) } - #[instrument(name = "SequenceComponent::end_block", skip_all)] + #[instrument(name = "SequenceComponent::end_block", skip_all, err)] async fn end_block( _state: &mut Arc, _end_block: &EndBlock, diff --git a/crates/astria-sequencer/src/sequence/state_ext.rs b/crates/astria-sequencer/src/sequence/state_ext.rs index da8ac996d..2297e7a74 100644 --- a/crates/astria-sequencer/src/sequence/state_ext.rs +++ b/crates/astria-sequencer/src/sequence/state_ext.rs @@ -26,7 +26,7 @@ struct Fee(u128); #[async_trait] pub(crate) trait StateReadExt: StateRead { - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_sequence_action_base_fee(&self) -> Result { let bytes = self .get_raw(SEQUENCE_ACTION_BASE_FEE_STORAGE_KEY) @@ -38,7 +38,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(fee) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_sequence_action_byte_cost_multiplier(&self) -> Result { let bytes = self .get_raw(SEQUENCE_ACTION_BYTE_COST_MULTIPLIER_STORAGE_KEY) @@ -55,7 +55,7 @@ impl StateReadExt for T {} #[async_trait] pub(crate) trait StateWriteExt: StateWrite { - #[instrument(skip_all)] + #[instrument(skip_all, fields(%fee))] fn put_sequence_action_base_fee(&mut self, fee: u128) { self.put_raw( SEQUENCE_ACTION_BASE_FEE_STORAGE_KEY.to_string(), @@ -63,7 +63,7 @@ pub(crate) trait StateWriteExt: StateWrite { ); } - #[instrument(skip_all)] + #[instrument(skip_all, fields(%fee))] fn put_sequence_action_byte_cost_multiplier(&mut self, fee: u128) { self.put_raw( SEQUENCE_ACTION_BYTE_COST_MULTIPLIER_STORAGE_KEY.to_string(), diff --git a/crates/astria-sequencer/src/sequencer.rs b/crates/astria-sequencer/src/sequencer.rs index 3bd1bfd64..6204367f8 100644 --- a/crates/astria-sequencer/src/sequencer.rs +++ b/crates/astria-sequencer/src/sequencer.rs @@ -29,7 +29,9 @@ use tokio::{ use tower_abci::v038::Server; use tracing::{ error, + error_span, info, + info_span, instrument, }; @@ -46,27 +48,22 @@ use crate::{ pub struct Sequencer; impl Sequencer { - #[instrument(skip_all)] + /// Run the sequencer until a stop signal is received. + /// + /// # Errors + /// + /// - If database or storage fail to load. + /// - If the app or info service fail to initialize. + /// - If server builder does not return a server. + /// - If parcing of the configured gRPC address fails. + /// - If sequencer fails to send shutdown signal to gRPC server. + /// - If server task or gRPC server fail. pub async fn run_until_stopped(config: Config, metrics: &'static Metrics) -> Result<()> { cnidarium::register_metrics(); register_histogram_global("cnidarium_get_raw_duration_seconds"); register_histogram_global("cnidarium_nonverifiable_get_raw_duration_seconds"); - if config - .db_filepath - .try_exists() - .context("failed checking for existence of db storage file")? - { - info!( - path = %config.db_filepath.display(), - "opening storage db" - ); - } else { - info!( - path = %config.db_filepath.display(), - "creating storage db" - ); - } + db_open_or_create_from_config(&config)?; let mut signals = spawn_signal_handler(); @@ -124,10 +121,11 @@ impl Sequencer { match server.listen_tcp(&config.listen_addr).await { Ok(()) => { // this shouldn't happen, as there isn't a way for the ABCI server to exit - info!("ABCI server exited successfully"); + report_exit(Ok("ABCI server exited successfully")); } Err(e) => { - error!(err = e.as_ref(), "ABCI server exited with error"); + error_span!("report_exit") + .in_scope(|| error!(err = e.as_ref(), "ABCI server exited with error")); } } let _ = server_exit_tx.send(()); @@ -135,11 +133,11 @@ impl Sequencer { select! { _ = signals.stop_rx.changed() => { - info!("shutting down sequencer"); + report_exit(Ok("shutting down sequencer")); } _ = server_exit_rx => { - error!("ABCI server task exited, this shouldn't happen"); + report_exit(Err(eyre!("ABCI server task exited, this shouldn't happen"))); } } @@ -179,9 +177,9 @@ fn start_grpc_server( .trace_fn(|req| { if let Some(remote_addr) = remote_addr(req) { let addr = remote_addr.to_string(); - tracing::error_span!("grpc", addr) + error_span!("grpc", addr) } else { - tracing::error_span!("grpc") + error_span!("grpc") } }) // (from Penumbra) Allow HTTP/1, which will be used by grpc-web connections. @@ -197,7 +195,7 @@ fn start_grpc_server( .add_service(ConnectionQueryServer::new(ibc.clone())) .add_service(SequencerServiceServer::new(sequencer_api)); - info!(grpc_addr = grpc_addr.to_string(), "starting grpc server"); + info_span!("grpc").in_scope(|| info!(addr = grpc_addr.to_string(), "starting grpc server")); tokio::task::spawn( grpc_server.serve_with_shutdown(grpc_addr, shutdown_rx.unwrap_or_else(|_| ())), ) @@ -219,11 +217,11 @@ fn spawn_signal_handler() -> SignalReceiver { loop { select! { _ = sigint.recv() => { - info!("received SIGINT"); + report_exit(Ok("received SIGINT")); let _ = stop_tx.send(()); } _ = sigterm.recv() => { - info!("received SIGTERM"); + report_exit(Ok("received SIGTERM")); let _ = stop_tx.send(()); } } @@ -234,3 +232,32 @@ fn spawn_signal_handler() -> SignalReceiver { stop_rx, } } + +#[instrument(skip_all, err)] +fn db_open_or_create_from_config(config: &Config) -> Result<()> { + if config + .db_filepath + .try_exists() + .context("failed checking for existence of db storage file")? + { + info!( + path = %config.db_filepath.display(), + "opening storage db" + ); + Ok(()) + } else { + info!( + path = %config.db_filepath.display(), + "creating storage db" + ); + Ok(()) + } +} + +#[instrument(skip_all)] +fn report_exit(result: Result<&str>) { + match result { + Ok(info) => info!(info), + Err(err) => error!("{}", err), + } +} diff --git a/crates/astria-sequencer/src/service/consensus.rs b/crates/astria-sequencer/src/service/consensus.rs index 001d7acea..560e3b50a 100644 --- a/crates/astria-sequencer/src/service/consensus.rs +++ b/crates/astria-sequencer/src/service/consensus.rs @@ -18,6 +18,7 @@ use tracing::{ instrument, warn, Instrument, + Level, }; use crate::app::App; @@ -66,7 +67,7 @@ impl Consensus { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn handle_request( &mut self, req: ConsensusRequest, @@ -153,7 +154,7 @@ impl Consensus { }) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn handle_prepare_proposal( &mut self, prepare_proposal: request::PrepareProposal, @@ -163,7 +164,7 @@ impl Consensus { .await } - #[instrument(skip_all)] + #[instrument(skip_all, err(level = Level::WARN))] async fn handle_process_proposal( &mut self, process_proposal: request::ProcessProposal, @@ -175,7 +176,7 @@ impl Consensus { Ok(()) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn finalize_block( &mut self, finalize_block: request::FinalizeBlock, diff --git a/crates/astria-sequencer/src/service/info/abci_query_router.rs b/crates/astria-sequencer/src/service/info/abci_query_router.rs index 988e0b779..78df97161 100644 --- a/crates/astria-sequencer/src/service/info/abci_query_router.rs +++ b/crates/astria-sequencer/src/service/info/abci_query_router.rs @@ -48,6 +48,7 @@ use tendermint::abci::{ request, response, }; +use tracing::instrument; /// `Router` is a wrapper around [`matchit::Router`] to route abci queries /// to handlers. @@ -92,6 +93,7 @@ impl BoxedAbciQueryHandler { })) } + #[instrument(skip_all)] pub(super) async fn call( self, storage: Storage, diff --git a/crates/astria-sequencer/src/service/info/mod.rs b/crates/astria-sequencer/src/service/info/mod.rs index 072dfcb35..bf18c24a2 100644 --- a/crates/astria-sequencer/src/service/info/mod.rs +++ b/crates/astria-sequencer/src/service/info/mod.rs @@ -93,7 +93,7 @@ impl Info { }) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn handle_info_request(self, request: InfoRequest) -> Result { match request { InfoRequest::Info(_) => { @@ -130,6 +130,7 @@ impl Info { } /// Handles `abci_query` RPCs. + #[instrument(skip_all)] async fn handle_abci_query(self, request: request::Query) -> response::Query { let (handler, params) = match self.query_router.at(&request.path) { Err(err) => { diff --git a/crates/astria-sequencer/src/state_ext.rs b/crates/astria-sequencer/src/state_ext.rs index 1e5f4c69d..bc0963556 100644 --- a/crates/astria-sequencer/src/state_ext.rs +++ b/crates/astria-sequencer/src/state_ext.rs @@ -23,7 +23,7 @@ fn storage_version_by_height_key(height: u64) -> Vec { #[async_trait] pub(crate) trait StateReadExt: StateRead { - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_chain_id(&self) -> Result { let Some(bytes) = self .get_raw("chain_id") @@ -40,7 +40,7 @@ pub(crate) trait StateReadExt: StateRead { .expect("only valid chain ids should be stored in the state")) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_revision_number(&self) -> Result { let Some(bytes) = self .get_raw(REVISION_NUMBER_KEY) @@ -61,7 +61,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(u64::from_be_bytes(bytes)) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_block_height(&self) -> Result { let Some(bytes) = self .get_raw("block_height") @@ -77,7 +77,7 @@ pub(crate) trait StateReadExt: StateRead { Ok(u64::from_be_bytes(bytes)) } - #[instrument(skip_all)] + #[instrument(skip_all, err)] async fn get_block_timestamp(&self) -> Result