Skip to content

Commit

Permalink
Add instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanoroshiba committed Aug 21, 2024
1 parent 781c4c5 commit cd15920
Show file tree
Hide file tree
Showing 40 changed files with 301 additions and 146 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ jobs:
- name: run pedantic clippy on workspace crates
run: |
cargo clippy --all-targets --all-features \
-- --warn clippy::pedantic --warn clippy::arithmetic-side-effects --deny warnings
-- --warn clippy::pedantic --warn clippy::arithmetic-side-effects \
--allow clippy::blocks_in_conditions --deny warnings
- name: run pedantic clippy on tools/protobuf-compiler
run: |
cargo clippy --manifest-path tools/protobuf-compiler/Cargo.toml \
Expand Down
8 changes: 8 additions & 0 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use cnidarium::{
StateRead,
StateWrite,
};
use tracing::{
instrument,
Level,
};

use super::AddressBytes;
use crate::{
Expand All @@ -30,10 +34,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<S: StateWrite>(&self, state: S) -> Result<()> {
let from = state
.get_current_source()
Expand All @@ -56,6 +62,7 @@ impl ActionHandler for TransferAction {
}
}

#[instrument(skip_all, err(level = Level::WARN))]
pub(crate) async fn execute_transfer<S, TAddress>(
action: &TransferAction,
from: TAddress,
Expand Down Expand Up @@ -114,6 +121,7 @@ where
Ok(())
}

#[instrument(skip_all, err(level = Level::WARN))]
pub(crate) async fn check_transfer<S, TAddress>(
action: &TransferAction,
from: TAddress,
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-sequencer/src/accounts/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) struct AccountsComponent;
impl Component for AccountsComponent {
type AppState = astria_core::sequencer::GenesisState;

#[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 All @@ -44,15 +44,15 @@ impl Component for AccountsComponent {
Ok(())
}

#[instrument(name = "AccountsComponent::begin_block", skip_all)]
#[instrument(name = "AccountsComponent::begin_block", skip_all, err)]
async fn begin_block<S: accounts::StateWriteExt + 'static>(
_state: &mut Arc<S>,
_begin_block: &BeginBlock,
) -> Result<()> {
Ok(())
}

#[instrument(name = "AccountsComponent::end_block", skip_all)]
#[instrument(name = "AccountsComponent::end_block", skip_all, err)]
async fn end_block<S: accounts::StateWriteExt + 'static>(
_state: &mut Arc<S>,
_end_block: &EndBlock,
Expand Down
5 changes: 5 additions & 0 deletions crates/astria-sequencer/src/accounts/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ use tendermint::{
},
block::Height,
};
use tracing::instrument;

use crate::{
accounts::state_ext::StateReadExt as _,
state_ext::StateReadExt as _,
};

#[instrument(skip_all)]
pub(crate) async fn balance_request(
storage: Storage,
request: request::Query,
Expand Down Expand Up @@ -61,6 +63,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 @@ -99,6 +102,7 @@ pub(crate) async fn nonce_request(
}
}

#[instrument(skip_all, err)]
async fn get_snapshot_and_height(
storage: &Storage,
height: Height,
Expand All @@ -125,6 +129,7 @@ async fn get_snapshot_and_height(
Ok((snapshot, height))
}

#[instrument(skip_all)]
async fn preprocess_request(
storage: &Storage,
request: &request::Query,
Expand Down
18 changes: 9 additions & 9 deletions crates/astria-sequencer/src/accounts/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn nonce_storage_key<T: AddressBytes>(address: T) -> String {

#[async_trait]
pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt {
#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_account_balances(&self, address: Address) -> Result<Vec<AssetBalance>> {
let prefix = format!("{}/balance/", StorageKey(&address));
let mut balances: Vec<AssetBalance> = Vec::new();
Expand Down Expand Up @@ -120,7 +120,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt {
Ok(balances)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_account_balance<'a, TAddress, TAsset>(
&self,
address: TAddress,
Expand All @@ -141,7 +141,7 @@ pub(crate) trait StateReadExt: StateRead + crate::assets::StateReadExt {
Ok(balance)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_account_nonce<T: AddressBytes>(&self, address: T) -> Result<u32> {
let bytes = self
.get_raw(&nonce_storage_key(address))
Expand All @@ -156,7 +156,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<u128> {
let bytes = self
.get_raw(TRANSFER_BASE_FEE_STORAGE_KEY)
Expand All @@ -175,7 +175,7 @@ impl<T: StateRead + ?Sized> StateReadExt for T {}

#[async_trait]
pub(crate) trait StateWriteExt: StateWrite {
#[instrument(skip_all)]
#[instrument(skip_all, err)]
fn put_account_balance<TAddress, TAsset>(
&mut self,
address: TAddress,
Expand All @@ -191,14 +191,14 @@ pub(crate) trait StateWriteExt: StateWrite {
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
fn put_account_nonce<T: AddressBytes>(&mut self, address: T, nonce: u32) -> Result<()> {
let bytes = borsh::to_vec(&Nonce(nonce)).context("failed to serialize nonce")?;
self.put_raw(nonce_storage_key(address), bytes);
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn increase_balance<TAddress, TAsset>(
&mut self,
address: TAddress,
Expand All @@ -225,7 +225,7 @@ pub(crate) trait StateWriteExt: StateWrite {
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn decrease_balance<TAddress, TAsset>(
&mut self,
address: TAddress,
Expand All @@ -252,7 +252,7 @@ pub(crate) trait StateWriteExt: StateWrite {
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
fn put_transfer_base_fee(&mut self, fee: u128) -> Result<()> {
let bytes = borsh::to_vec(&Fee(fee)).context("failed to serialize fee")?;
self.put_raw(TRANSFER_BASE_FEE_STORAGE_KEY.to_string(), bytes);
Expand Down
6 changes: 4 additions & 2 deletions crates/astria-sequencer/src/address/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn base_prefix_key() -> &'static str {

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

#[instrument(skip_all, err)]
async fn try_base_prefixed(&self, slice: &[u8]) -> anyhow::Result<Address> {
let prefix = self
.get_base_prefix()
Expand All @@ -43,7 +45,7 @@ pub(crate) trait StateReadExt: StateRead {
.context("failed to construct address from byte slice and state-provided base prefix")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_base_prefix(&self) -> Result<String> {
let Some(bytes) = self
.get_raw(base_prefix_key())
Expand All @@ -60,7 +62,7 @@ impl<T: ?Sized + StateRead> StateReadExt for T {}

#[async_trait]
pub(crate) trait StateWriteExt: StateWrite {
#[instrument(skip_all)]
#[instrument(skip_all, err)]
fn put_base_prefix(&mut self, prefix: &str) -> anyhow::Result<()> {
try_construct_dummy_address_from_prefix(prefix)
.context("failed constructing a dummy address from the provided prefix")?;
Expand Down
16 changes: 8 additions & 8 deletions crates/astria-sequencer/src/api_state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl From<RollupId> for RollupIdSer {

#[async_trait]
pub(crate) trait StateReadExt: StateRead {
#[instrument(skip_all)]
#[instrument(skip_all, 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
Expand All @@ -149,7 +149,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(hash)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_sequencer_block_header_by_hash(
&self,
hash: &[u8],
Expand All @@ -170,7 +170,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(header)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_rollup_ids_by_block_hash(&self, hash: &[u8]) -> Result<Vec<RollupId>> {
let key = rollup_ids_by_hash_key(hash);
let Some(rollup_ids_bytes) = self
Expand All @@ -186,7 +186,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(rollup_ids)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_sequencer_block_by_hash(&self, hash: &[u8]) -> Result<SequencerBlock> {
let Some(header_bytes) = self
.get_raw(&sequencer_block_header_by_hash_key(hash))
Expand Down Expand Up @@ -256,7 +256,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(block)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_sequencer_block_by_height(&self, height: u64) -> Result<SequencerBlock> {
let hash = self
.get_block_hash_by_height(height)
Expand All @@ -267,7 +267,7 @@ pub(crate) trait StateReadExt: StateRead {
.context("failed to get sequencer block by hash")
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_rollup_data(
&self,
hash: &[u8],
Expand All @@ -290,7 +290,7 @@ pub(crate) trait StateReadExt: StateRead {
Ok(rollup_transactions)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_block_proofs_by_block_hash(
&self,
hash: &[u8],
Expand Down Expand Up @@ -325,7 +325,7 @@ pub(crate) trait StateReadExt: StateRead {
impl<T: StateRead> StateReadExt for T {}

pub(crate) trait StateWriteExt: StateWrite {
#[instrument(skip_all)]
#[instrument(skip_all, 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
Expand Down
Loading

0 comments on commit cd15920

Please sign in to comment.