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

feat: metrics for the send_transaction wallet method #45

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ reth-network = { git = "https://github.com/paradigmxyz/reth.git", rev = "75dda1c
reth-network-types = { git = "https://github.com/paradigmxyz/reth.git", rev = "75dda1c" }
reth-chain-state = { git = "https://github.com/paradigmxyz/reth.git", rev = "75dda1c" }

# metrics
metrics = "0.23.0"
metrics-derive = "0.1.0"

# rpc
jsonrpsee = "0.24"

Expand Down
3 changes: 3 additions & 0 deletions crates/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ thiserror.workspace = true
tracing.workspace = true
tokio = { workspace = true, features = ["sync"] }

metrics.workspace = true
metrics-derive.workspace = true

[dev-dependencies]
serde_json.workspace = true
jsonrpsee = { workspace = true, features = ["server", "client", "macros"] }
Expand Down
25 changes: 24 additions & 1 deletion crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
};
use metrics::Counter;
use metrics_derive::Metrics;
use reth_primitives::{revm_primitives::Bytecode, BlockId};
use reth_rpc_eth_api::helpers::{EthCall, EthState, EthTransactions, FullEthApi, LoadFee};
use reth_storage_api::{StateProvider, StateProviderFactory};
Expand Down Expand Up @@ -186,6 +188,7 @@ impl<Provider, Eth> OdysseyWallet<Provider, Eth> {
Capabilities { delegation: DelegationCapability { addresses: valid_designations } },
)])),
permit: Default::default(),
metrics: WalletMetrics::default(),
};
Self { inner: Arc::new(inner) }
}
Expand All @@ -210,7 +213,15 @@ where
trace!(target: "rpc::wallet", ?request, "Serving wallet_sendTransaction");

// validate fields common to eip-7702 and eip-1559
validate_tx_request(&request)?;
match validate_tx_request(&request) {
Ok(_) => {
self.inner.metrics.valid_send_transaction_calls.increment(1);
}
Err(err) => {
self.inner.metrics.invalid_send_transaction_calls.increment(1);
return Err(err.into());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tx is only valid if it passes all the checks before EthTransactions::send_raw_transaction

}

let valid_delegations: &[Address] = self
.inner
Expand Down Expand Up @@ -322,6 +333,8 @@ struct OdysseyWalletInner<Provider, Eth> {
capabilities: WalletCapabilities,
/// Used to guard tx signing
permit: Mutex<()>,
/// Metrics for a `wallet`.
onbjerg marked this conversation as resolved.
Show resolved Hide resolved
metrics: WalletMetrics,
}

fn validate_tx_request(request: &TransactionRequest) -> Result<(), OdysseyWalletError> {
Expand All @@ -343,6 +356,16 @@ fn validate_tx_request(request: &TransactionRequest) -> Result<(), OdysseyWallet
Ok(())
}

/// Metrics for a `wallet`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Metrics for a `wallet`.
/// Metrics for the `wallet_` RPC namespace.

#[derive(Metrics)]
#[metrics(scope = "wallet")]
struct WalletMetrics {
/// Number of invalid calls to `wallet_sendTransaction`
invalid_send_transaction_calls: Counter,
/// Number of valid calls to `wallet_sendTransaction`
valid_send_transaction_calls: Counter,
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down