Skip to content

Commit

Permalink
ENG-670 Add instrumentation to bridge-withdrawer
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanoroshiba committed Jul 31, 2024
1 parent 7953133 commit d77142e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions crates/astria-bridge-withdrawer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use http::status::StatusCode;
use hyper::server::conn::AddrIncoming;
use serde::Serialize;
use tokio::sync::watch;
use tracing::instrument;

use crate::bridge_withdrawer::StateSnapshot;

Expand Down Expand Up @@ -51,6 +52,7 @@ pub(crate) fn start(socket_addr: SocketAddr, withdrawer_state: WithdrawerState)
}

#[allow(clippy::unused_async)] // Permit because axum handlers must be async
#[instrument(skip_all)]
async fn get_healthz(State(withdrawer_state): State<WithdrawerState>) -> Healthz {
if withdrawer_state.borrow().is_healthy() {
Healthz::Ok
Expand All @@ -66,6 +68,7 @@ async fn get_healthz(State(withdrawer_state): State<WithdrawerState>) -> Healthz
/// + there is a current sequencer height (implying a block from sequencer was received)
/// + there is a current data availability height (implying a height was received from the DA)
#[allow(clippy::unused_async)] // Permit because axum handlers must be async
#[instrument(skip_all)]
async fn get_readyz(State(withdrawer_state): State<WithdrawerState>) -> Readyz {
let is_withdrawer_online = withdrawer_state.borrow().is_ready();
if is_withdrawer_online {
Expand All @@ -76,6 +79,7 @@ async fn get_readyz(State(withdrawer_state): State<WithdrawerState>) -> Readyz {
}

#[allow(clippy::unused_async)] // Permit because axum handlers must be async
#[instrument(skip_all)]
async fn get_status(State(withdrawer_state): State<WithdrawerState>) -> Json<StateSnapshot> {
Json(withdrawer_state.borrow().clone())
}
Expand Down
17 changes: 12 additions & 5 deletions crates/astria-bridge-withdrawer/src/bridge_withdrawer/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use tracing::{
instrument,
warn,
Instrument as _,
Level,
Span,
};
use tryhard::backoff_strategies::ExponentialBackoff;
Expand Down Expand Up @@ -120,6 +121,7 @@ impl InfoHandle {
}
}

#[instrument(skip_all, err)]
pub(super) async fn get_info(&mut self) -> eyre::Result<Info> {
let state = self
.rx
Expand Down Expand Up @@ -202,6 +204,7 @@ impl Startup {
/// - `self.chain_id` does not match the value returned from the sequencer node
/// - `self.fee_asset` is not a valid fee asset on the sequencer node
/// - `self.sequencer_bridge_address` does not have a sufficient balance of `self.fee_asset`.
#[instrument(skip_all, err)]
async fn confirm_sequencer_config(&self) -> eyre::Result<()> {
// confirm the sequencer chain id
let actual_chain_id =
Expand Down Expand Up @@ -250,6 +253,7 @@ impl Startup {
/// in the sequencer logic).
/// 5. Failing to convert the transaction data from bytes to proto.
/// 6. Failing to convert the transaction data from proto to `SignedTransaction`.
#[instrument(skip_all, err)]
async fn get_last_transaction(&self) -> eyre::Result<Option<SignedTransaction>> {
// get last transaction hash by the bridge account, if it exists
let last_transaction_hash_resp = get_bridge_account_last_transaction_hash(
Expand Down Expand Up @@ -323,6 +327,7 @@ impl Startup {
/// the sequencer logic)
/// 3. The last transaction by the bridge account did not contain a withdrawal action
/// 4. The memo of the last transaction by the bridge account could not be parsed
#[instrument(skip_all, err)]
async fn get_starting_rollup_height(&mut self) -> eyre::Result<u64> {
let signed_transaction = self
.get_last_transaction()
Expand All @@ -347,6 +352,7 @@ impl Startup {
}
}

#[instrument(skip_all, err(level = Level::WARN))]
async fn ensure_mempool_empty(
cometbft_client: sequencer_client::HttpClient,
sequencer_client: sequencer_service_client::SequencerServiceClient<Channel>,
Expand Down Expand Up @@ -391,6 +397,7 @@ async fn ensure_mempool_empty(
/// 2. Failing to get the latest nonce from cometBFT's mempool.
/// 3. The pending nonce from the Sequencer's app-side mempool does not match the latest nonce from
/// cometBFT's mempool after the exponential backoff times out.
#[instrument(skip_all, err)]
async fn wait_for_empty_mempool(
cometbft_client: sequencer_client::HttpClient,
sequencer_grpc_endpoint: String,
Expand Down Expand Up @@ -485,7 +492,7 @@ fn rollup_height_from_signed_transaction(
Ok(last_batch_rollup_height)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_bridge_account_last_transaction_hash(
client: sequencer_client::HttpClient,
state: Arc<State>,
Expand All @@ -507,7 +514,7 @@ async fn get_bridge_account_last_transaction_hash(
res
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_sequencer_transaction_at_hash(
client: sequencer_client::HttpClient,
state: Arc<State>,
Expand All @@ -525,7 +532,7 @@ async fn get_sequencer_transaction_at_hash(
res
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_sequencer_chain_id(
client: sequencer_client::HttpClient,
state: Arc<State>,
Expand All @@ -542,7 +549,7 @@ async fn get_sequencer_chain_id(
Ok(genesis.chain_id)
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_allowed_fee_assets(
client: sequencer_client::HttpClient,
state: Arc<State>,
Expand All @@ -559,7 +566,7 @@ async fn get_allowed_fee_assets(
res
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn get_latest_nonce(
client: sequencer_client::HttpClient,
state: Arc<State>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use astria_eyre::eyre::{
};
use tokio::sync::mpsc;
use tokio_util::sync::CancellationToken;
use tracing::info;
use tracing::{
info,
instrument,
};

use super::state::State;
use crate::{
Expand All @@ -30,6 +33,7 @@ impl Handle {
}
}

#[instrument(skip_all, err)]
pub(crate) async fn send_batch(&self, batch: Batch) -> eyre::Result<()> {
self.batches_tx
.send(batch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Submitter {
Ok(())
}

#[instrument(skip_all)]
#[instrument(skip_all, err)]
async fn process_batch(
&self,
sequencer_grpc_client: SequencerServiceClient<Channel>,
Expand Down Expand Up @@ -224,7 +224,8 @@ impl Submitter {
fields(
nonce = tx.nonce(),
transaction.hash = %telemetry::display::hex(&tx.sha256_of_proto_encoding()),
)
),
err
)]
async fn submit_tx(
client: sequencer_client::HttpClient,
Expand Down Expand Up @@ -279,6 +280,7 @@ async fn submit_tx(
res
}

#[instrument(skip_all, err)]
pub(crate) async fn get_pending_nonce(
client: sequencer_service_client::SequencerServiceClient<Channel>,
address: Address,
Expand Down

0 comments on commit d77142e

Please sign in to comment.