Skip to content

Commit

Permalink
Add sponsored tx num as metrics (MystenLabs#9779)
Browse files Browse the repository at this point in the history
## Description 

As title

## Test Plan 

CI

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
Added sponsored tx number as metrics
  • Loading branch information
longbowlu authored Mar 29, 2023
1 parent 4575e93 commit 3307e91
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub struct AuthorityMetrics {
total_cert_attempts: IntCounter,
total_effects: IntCounter,
pub shared_obj_tx: IntCounter,
sponsored_tx: IntCounter,
tx_already_processed: IntCounter,
num_input_objs: Histogram,
num_shared_objects: Histogram,
Expand Down Expand Up @@ -251,6 +252,14 @@ impl AuthorityMetrics {
registry,
)
.unwrap(),

sponsored_tx: register_int_counter_with_registry!(
"num_sponsored_tx",
"Number of sponsored transactions",
registry,
)
.unwrap(),

tx_already_processed: register_int_counter_with_registry!(
"num_tx_already_processed",
"Number of transaction orders already processed previously",
Expand Down Expand Up @@ -928,6 +937,10 @@ impl AuthorityState {
self.metrics.shared_obj_tx.inc();
}

if certificate.is_sponsored_tx() {
self.metrics.sponsored_tx.inc();
}

self.metrics
.num_input_objs
.observe(input_object_count as f64);
Expand Down
12 changes: 12 additions & 0 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,9 @@ pub trait TransactionDataAPI {
fn is_change_epoch_tx(&self) -> bool;
fn is_genesis_tx(&self) -> bool;

/// Check if the transaction is sponsored (namely gas owner != sender)
fn is_sponsored_tx(&self) -> bool;

#[cfg(test)]
fn sender_mut(&mut self) -> &mut SuiAddress;

Expand Down Expand Up @@ -1613,6 +1616,11 @@ impl TransactionDataAPI for TransactionDataV1 {
self.check_sponsorship()
}

/// Check if the transaction is sponsored (namely gas owner != sender)
fn is_sponsored_tx(&self) -> bool {
self.gas_owner() != self.sender
}

/// Check if the transaction is compliant with sponsorship.
fn check_sponsorship(&self) -> UserInputResult {
// Not a sponsored transaction, nothing to check
Expand Down Expand Up @@ -1855,6 +1863,10 @@ impl<S> Envelope<SenderSignedData, S> {
pub fn is_system_tx(&self) -> bool {
self.data().intent_message().value.is_system_tx()
}

pub fn is_sponsored_tx(&self) -> bool {
self.data().intent_message().value.is_sponsored_tx()
}
}

impl Transaction {
Expand Down

0 comments on commit 3307e91

Please sign in to comment.