Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sequencer): add instrumentation #1761

Merged
merged 9 commits into from
Dec 19, 2024
7 changes: 7 additions & 0 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use cnidarium::{
StateRead,
StateWrite,
};
use tracing::{
instrument,
Level,
};

use super::AddressBytes;
use crate::{
Expand All @@ -27,6 +31,7 @@ impl ActionHandler for Transfer {
Ok(())
}

#[instrument(skip_all, err(level = Level::WARN))]
async fn check_and_execute<S: StateWrite>(&self, state: S) -> Result<()> {
let from = state
.get_transaction_context()
Expand All @@ -49,6 +54,7 @@ impl ActionHandler for Transfer {
}
}

#[instrument(skip_all, err(level = Level::WARN))]
pub(crate) async fn execute_transfer<S, TAddress>(
action: &Transfer,
from: &TAddress,
Expand All @@ -71,6 +77,7 @@ where
Ok(())
}

#[instrument(skip_all, err(level = Level::WARN))]
pub(crate) async fn check_transfer<S, TAddress>(
action: &Transfer,
from: &TAddress,
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/accounts/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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<S>(mut state: S, app_state: &Self::AppState) -> Result<()>
where
S: accounts::StateWriteExt + assets::StateReadExt,
Expand Down
7 changes: 6 additions & 1 deletion crates/astria-sequencer/src/accounts/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
assets::StateReadExt as _,
};

#[instrument(skip_all, fields(%asset), err)]
async fn ibc_to_trace<S: StateRead>(
state: S,
asset: &asset::IbcPrefixed,
Expand All @@ -47,7 +48,7 @@ async fn ibc_to_trace<S: StateRead>(
.ok_or_eyre("asset not found when user has balance of it; this is a bug")
}

#[instrument(skip_all, fields(%address))]
#[instrument(skip_all, fields(%address), err)]
async fn get_trace_prefixed_account_balances<S: StateRead>(
state: &S,
address: &Address,
Expand All @@ -70,6 +71,7 @@ async fn get_trace_prefixed_account_balances<S: StateRead>(

/// Returns a list of [`AssetBalance`]s for the provided address. `AssetBalance`s are sorted
/// alphabetically by [`asset::Denom`].
#[instrument(skip_all)]
pub(crate) async fn balance_request(
storage: Storage,
request: request::Query,
Expand Down Expand Up @@ -112,6 +114,7 @@ pub(crate) async fn balance_request(
}
}

#[instrument(skip_all)]
pub(crate) async fn nonce_request(
storage: Storage,
request: request::Query,
Expand Down Expand Up @@ -150,6 +153,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(),
Expand All @@ -173,6 +177,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,
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-sequencer/src/accounts/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt {
.wrap_err("invalid balance bytes")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_account_nonce<T: AddressBytes>(&self, address: &T) -> Result<u32> {
let bytes = self
.get_raw(&keys::nonce(address))
Expand Down Expand Up @@ -205,7 +205,7 @@ pub(crate) trait StateWriteExt: StateWrite {
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, fields(address = %address.display_address(), nonce), err)]
fn put_account_nonce<T: AddressBytes>(&mut self, address: &T, nonce: u32) -> Result<()> {
let bytes = StoredValue::from(storage::Nonce::from(nonce))
.serialize()
Expand Down Expand Up @@ -241,7 +241,7 @@ pub(crate) trait StateWriteExt: StateWrite {
Ok(())
}

#[instrument(skip_all, fields(address = %address.display_address(), %asset, amount))]
#[instrument(skip_all, fields(address = %address.display_address(), %asset, amount), err)]
async fn decrease_balance<'a, TAddress, TAsset>(
&mut self,
address: &TAddress,
Expand Down
7 changes: 6 additions & 1 deletion crates/astria-sequencer/src/address/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ use super::storage::{
self,
keys,
};
use crate::storage::StoredValue;
use crate::{
accounts::AddressBytes as _,
storage::StoredValue,
};

#[async_trait]
pub(crate) trait StateReadExt: StateRead {
#[instrument(skip_all, fields(address = %address.display_address()), err)]
async fn ensure_base_prefix(&self, address: &Address<Bech32m>) -> Result<()> {
let prefix = self
.get_base_prefix()
Expand All @@ -39,6 +43,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(())
}

#[instrument(skip_all, err)]
async fn try_base_prefixed(&self, slice: &[u8]) -> Result<Address> {
let prefix = self
.get_base_prefix()
Expand Down
21 changes: 11 additions & 10 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ pub(crate) struct App {
}

impl App {
#[instrument(name = "App::new", skip_all, err)]
pub(crate) async fn new(
snapshot: Snapshot,
mempool: Mempool,
Expand Down Expand Up @@ -267,7 +268,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,
Expand Down Expand Up @@ -354,7 +355,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,
Expand Down Expand Up @@ -404,7 +405,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)]
pub(crate) async fn process_proposal(
&mut self,
process_proposal: abci::request::ProcessProposal,
Expand Down Expand Up @@ -564,7 +565,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,
Expand Down Expand Up @@ -744,7 +745,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)]
async fn execute_transactions_process_proposal(
&mut self,
txs: Vec<Transaction>,
Expand Down Expand Up @@ -877,7 +878,7 @@ impl App {
/// `SequencerBlock`.
///
/// this must be called after a block's transactions are executed.
#[instrument(name = "App::post_execute_transactions", skip_all)]
#[instrument(name = "App::post_execute_transactions", skip_all, err)]
async fn post_execute_transactions(
&mut self,
block_hash: Hash,
Expand Down Expand Up @@ -961,7 +962,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,
Expand Down Expand Up @@ -1112,7 +1113,7 @@ impl App {
Ok(app_hash)
}

#[instrument(name = "App::begin_block", skip_all)]
#[instrument(name = "App::begin_block", skip_all, err)]
async fn begin_block(
&mut self,
begin_block: &abci::request::BeginBlock,
Expand Down Expand Up @@ -1148,7 +1149,7 @@ impl App {
}

/// Executes a signed transaction.
#[instrument(name = "App::execute_transaction", skip_all)]
#[instrument(name = "App::execute_transaction", skip_all, err)]
async fn execute_transaction(&mut self, signed_tx: Arc<Transaction>) -> Result<Vec<Event>> {
signed_tx
.check_stateless()
Expand Down Expand Up @@ -1176,7 +1177,7 @@ impl App {
Ok(state_tx.apply().1)
}

#[instrument(name = "App::end_block", skip_all)]
#[instrument(name = "App::end_block", skip_all, err)]
async fn end_block(
&mut self,
height: u64,
Expand Down
10 changes: 5 additions & 5 deletions crates/astria-sequencer/src/app/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::storage::StoredValue;

#[async_trait]
pub(crate) trait StateReadExt: StateRead {
#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_chain_id(&self) -> Result<tendermint::chain::Id> {
let Some(bytes) = self
.get_raw(keys::CHAIN_ID)
Expand All @@ -37,7 +37,7 @@ pub(crate) trait StateReadExt: StateRead {
.wrap_err("invalid chain id bytes")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_revision_number(&self) -> Result<u64> {
let Some(bytes) = self
.get_raw(keys::REVISION_NUMBER)
Expand All @@ -52,7 +52,7 @@ pub(crate) trait StateReadExt: StateRead {
.wrap_err("invalid revision number bytes")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_block_height(&self) -> Result<u64> {
let Some(bytes) = self
.get_raw(keys::BLOCK_HEIGHT)
Expand All @@ -67,7 +67,7 @@ pub(crate) trait StateReadExt: StateRead {
.context("invalid block height bytes")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_block_timestamp(&self) -> Result<Time> {
let Some(bytes) = self
.get_raw(keys::BLOCK_TIMESTAMP)
Expand All @@ -82,7 +82,7 @@ pub(crate) trait StateReadExt: StateRead {
.wrap_err("invalid block timestamp bytes")
}

#[instrument(skip_all)]
#[instrument(skip_all, fields(%height), err)]
async fn get_storage_version_by_height(&self, height: u64) -> Result<u64> {
use astria_eyre::eyre::WrapErr as _;

Expand Down
2 changes: 2 additions & 0 deletions crates/astria-sequencer/src/assets/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use tendermint::abci::{
response,
Code,
};
use tracing::instrument;

use crate::{
app::StateReadExt as _,
Expand All @@ -21,6 +22,7 @@ use crate::{
//
// Example:
// `abci-cli query --path=asset/denom/<DENOM_ID>`
#[instrument(skip_all)]
pub(crate) async fn denom_request(
storage: Storage,
request: request::Query,
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-sequencer/src/assets/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::storage::StoredValue;

#[async_trait]
pub(crate) trait StateReadExt: StateRead {
#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_native_asset(&self) -> Result<Option<asset::TracePrefixed>> {
let Some(bytes) = self
.get_raw(keys::NATIVE_ASSET)
Expand All @@ -43,7 +43,7 @@ pub(crate) trait StateReadExt: StateRead {
.map(Option::Some)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn has_ibc_asset<'a, TAsset>(&self, asset: &'a TAsset) -> Result<bool>
where
TAsset: Sync,
Expand Down
7 changes: 7 additions & 0 deletions crates/astria-sequencer/src/authority/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use astria_eyre::eyre::{
WrapErr as _,
};
use cnidarium::StateWrite;
use tracing::{
instrument,
Level,
};

use crate::{
address::StateReadExt as _,
Expand All @@ -28,6 +32,7 @@ impl ActionHandler for ValidatorUpdate {
Ok(())
}

#[instrument(skip_all, err(level = Level::WARN))]
async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
let from = state
.get_transaction_context()
Expand Down Expand Up @@ -79,6 +84,7 @@ impl ActionHandler for SudoAddressChange {

/// 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<S: StateWrite>(&self, mut state: S) -> Result<()> {
let from = state
.get_transaction_context()
Expand Down Expand Up @@ -107,6 +113,7 @@ impl ActionHandler for IbcSudoChange {
Ok(())
}

#[instrument(skip_all, err(level = Level::WARN))]
async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
let from = state
.get_transaction_context()
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-sequencer/src/authority/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: StateWriteExt>(mut state: S, app_state: &Self::AppState) -> Result<()> {
// set sudo key and initial validator set
state
Expand All @@ -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<S: StateWriteExt + 'static>(
state: &mut Arc<S>,
begin_block: &BeginBlock,
Expand All @@ -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<S: StateWriteExt + StateReadExt + 'static>(
state: &mut Arc<S>,
_end_block: &EndBlock,
Expand Down
Loading
Loading