From 8b06546af43bf073fd99f3f9d82b8afb51872489 Mon Sep 17 00:00:00 2001 From: noot <36753753+noot@users.noreply.github.com> Date: Thu, 4 Apr 2024 18:23:53 -0400 Subject: [PATCH] tower-trace: add support for v038 (#4160) ## Describe your changes implement support for ABCI v038 for the tower-trace util crate. required for eventual upgrade to ABCI v038 :) ## Issue ticket number and link n/a ## Checklist before requesting a review - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: it only affects the tower-trace util crate --- crates/util/tower-trace/src/lib.rs | 5 + .../util/tower-trace/src/v038/request_ext.rs | 124 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 crates/util/tower-trace/src/v038/request_ext.rs diff --git a/crates/util/tower-trace/src/lib.rs b/crates/util/tower-trace/src/lib.rs index 47e90f1a03..5e60baf249 100644 --- a/crates/util/tower-trace/src/lib.rs +++ b/crates/util/tower-trace/src/lib.rs @@ -28,3 +28,8 @@ pub mod v037 { mod request_ext; pub use request_ext::RequestExt; } + +pub mod v038 { + mod request_ext; + pub use request_ext::RequestExt; +} diff --git a/crates/util/tower-trace/src/v038/request_ext.rs b/crates/util/tower-trace/src/v038/request_ext.rs new file mode 100644 index 0000000000..a3bd9046c5 --- /dev/null +++ b/crates/util/tower-trace/src/v038/request_ext.rs @@ -0,0 +1,124 @@ +use sha2::{Digest, Sha256}; +use tendermint::v0_38::abci::request::{CheckTx, FinalizeBlock, InitChain, Query, Request}; +use tendermint::v0_38::abci::request::{ + ConsensusRequest, InfoRequest, MempoolRequest, SnapshotRequest, +}; +use tendermint::v0_38::abci::request::{ExtendVote, VerifyVoteExtension}; +use tendermint::v0_38::abci::request::{PrepareProposal, ProcessProposal}; +use tracing::error_span; + +pub trait RequestExt { + /// Create a [`tracing::Span`] for this request, including the request name + /// and some relevant context (but not including the entire request data). + fn create_span(&self) -> tracing::Span; +} + +impl RequestExt for ConsensusRequest { + fn create_span(&self) -> tracing::Span { + // Create a parent "abci" span. All of these spans are at error level, so they're always recorded. + let p = error_span!("abci"); + match self { + ConsensusRequest::FinalizeBlock(FinalizeBlock { hash, height, .. }) => { + error_span!(parent: &p, "FinalizeBlock", height = ?height, hash = ?hex::encode(hash.as_ref())) + } + ConsensusRequest::Commit => error_span!(parent: &p, "Commit"), + ConsensusRequest::InitChain(InitChain { chain_id, .. }) => { + error_span!(parent: &p, "InitChain", ?chain_id) + } + ConsensusRequest::PrepareProposal(PrepareProposal { height, .. }) => { + error_span!(parent: &p, "PrepareProposal", ?height) + } + ConsensusRequest::ProcessProposal(ProcessProposal { height, .. }) => { + error_span!(parent: &p, "ProcessProposal", ?height) + } + ConsensusRequest::ExtendVote(ExtendVote { hash, height, .. }) => { + error_span!(parent: &p, "ExtendVote", height = ?height, hash = ?hex::encode(hash.as_ref())) + } + ConsensusRequest::VerifyVoteExtension(VerifyVoteExtension { hash, height, .. }) => { + error_span!(parent: &p, "VerifyVoteExtension", height = ?height, hash = ?hex::encode(hash.as_ref())) + } + } + } +} + +impl RequestExt for MempoolRequest { + fn create_span(&self) -> tracing::Span { + // Create a parent "abci" span. All of these spans are at error level, so they're always recorded. + let p = error_span!("abci"); + match self { + MempoolRequest::CheckTx(CheckTx { kind, tx }) => { + error_span!(parent: &p, "CheckTx", ?kind, txid = ?hex::encode(Sha256::digest(tx.as_ref()))) + } + } + } +} + +impl RequestExt for InfoRequest { + fn create_span(&self) -> tracing::Span { + // Create a parent "abci" span. All of these spans are at error level, so they're always recorded. + let p = error_span!("abci"); + match self { + InfoRequest::Info(_) => error_span!(parent: &p, "Info"), + InfoRequest::Query(Query { + path, + height, + prove, + .. + }) => { + error_span!(parent: &p, "Query", ?path, ?height, prove) + } + InfoRequest::Echo(_) => error_span!(parent: &p, "Echo"), + } + } +} + +impl RequestExt for SnapshotRequest { + fn create_span(&self) -> tracing::Span { + // Create a parent "abci" span. All of these spans are at error level, so they're always recorded. + let p = error_span!("abci"); + match self { + SnapshotRequest::ListSnapshots => error_span!(parent: &p, "ListSnapshots"), + SnapshotRequest::OfferSnapshot(_) => error_span!(parent: &p, "OfferSnapshot"), + SnapshotRequest::LoadSnapshotChunk(_) => error_span!(parent: &p, "LoadSnapshotChunk"), + SnapshotRequest::ApplySnapshotChunk(_) => error_span!(parent: &p, "ApplySnapshotChunk"), + } + } +} + +impl RequestExt for Request { + fn create_span(&self) -> tracing::Span { + // Create a parent "abci" span. All of these spans are at error level, so they're always recorded. + let p = error_span!("abci"); + match self { + Request::Info(_) => error_span!(parent: &p, "Info"), + Request::Query(Query { + path, + height, + prove, + .. + }) => { + error_span!(parent: &p, "Query", ?path, ?height, prove) + } + Request::CheckTx(CheckTx { kind, tx }) => { + error_span!(parent: &p, "CheckTx", ?kind, txid = ?hex::encode(Sha256::digest(tx.as_ref()))) + } + Request::FinalizeBlock(FinalizeBlock { hash, height, .. }) => { + error_span!(parent: &p, "FinalizeBlock", height = ?height, hash = ?hex::encode(hash.as_ref())) + } + Request::Commit => error_span!(parent: &p, "Commit"), + Request::InitChain(InitChain { chain_id, .. }) => { + error_span!(parent: &p, "InitChain", ?chain_id) + } + Request::Flush => error_span!(parent: &p, "Flush"), + Request::Echo(_) => error_span!(parent: &p, "Echo"), + Request::ListSnapshots => error_span!(parent: &p, "ListSnapshots"), + Request::OfferSnapshot(_) => error_span!(parent: &p, "OfferSnapshot"), + Request::LoadSnapshotChunk(_) => error_span!(parent: &p, "LoadSnapshotChunk"), + Request::ApplySnapshotChunk(_) => error_span!(parent: &p, "ApplySnapshotChunk"), + Request::PrepareProposal(_) => error_span!(parent: &p, "PrepareProposal"), + Request::ProcessProposal(_) => error_span!(parent: &p, "ProcessProposal"), + Request::ExtendVote(_) => error_span!(parent: &p, "ExtendVote"), + Request::VerifyVoteExtension(_) => error_span!(parent: &p, "VerifyVoteExtension"), + } + } +}