1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use lazy_static;
use prometheus::{IntCounter, IntGauge};
use solana_libra_metrics::OpMetrics;
use solana_libra_types::{
transaction::TransactionStatus,
vm_error::{StatusCode, StatusType, VMStatus},
};
use std::{convert::TryFrom, time::Instant};
const TXN_EXECUTION_KEEP: &str = "txn.execution.keep";
const TXN_EXECUTION_DISCARD: &str = "txn.execution.discard";
const TXN_VERIFICATION_SUCCESS: &str = "txn.verification.success";
const TXN_VERIFICATION_FAIL: &str = "txn.verification.fail";
const TXN_BLOCK_COUNT: &str = "txn.block.count";
pub const TXN_TOTAL_TIME_TAKEN: &str = "txn_gas_total_time_taken";
pub const TXN_VERIFICATION_TIME_TAKEN: &str = "txn_gas_verification_time_taken";
pub const TXN_VALIDATION_TIME_TAKEN: &str = "txn_gas_validation_time_taken";
pub const TXN_EXECUTION_TIME_TAKEN: &str = "txn_gas_execution_time_taken";
pub const TXN_PROLOGUE_TIME_TAKEN: &str = "txn_gas_prologue_time_taken";
pub const TXN_EPILOGUE_TIME_TAKEN: &str = "txn_gas_epilogue_time_taken";
pub const TXN_EXECUTION_GAS_USAGE: &str = "txn_gas_execution_gas_usage";
pub const TXN_TOTAL_GAS_USAGE: &str = "txn_gas_total_gas_usage";
lazy_static::lazy_static! {
pub static ref VM_COUNTERS: OpMetrics = OpMetrics::new_and_registered("move_vm");
static ref VERIFIED_TRANSACTION: IntCounter = VM_COUNTERS.counter(TXN_VERIFICATION_SUCCESS);
static ref BLOCK_TRANSACTION_COUNT: IntGauge = VM_COUNTERS.gauge(TXN_BLOCK_COUNT);
}
pub fn start_profile() -> Instant {
Instant::now()
}
pub fn report_block_count(count: usize) {
match i64::try_from(count) {
Ok(val) => BLOCK_TRANSACTION_COUNT.set(val),
Err(_) => BLOCK_TRANSACTION_COUNT.set(std::i64::MAX),
}
}
#[macro_export]
macro_rules! record_stats {
(info | $($stmt:stmt);+;) => {
$($stmt);+;
};
(gauge set | $ident:ident | $amount:expr) => {
VM_COUNTERS.set($ident, $amount as f64)
};
(gauge inc | $ident:ident | $amount:expr) => {
VM_COUNTERS.add($ident, $amount as f64)
};
(gauge dec | $ident:ident | $amount:expr) => {
VM_COUNTERS.sub($ident, $amount as f64)
};
(counter set | $ident:ident | $amount:expr) => {
VM_COUNTERS.set($ident, $amount as f64)
};
(counter inc | $ident:ident | $amount:expr) => {
VM_COUNTERS.add($ident, $amount as f64)
};
(counter dec | $ident:ident | $amount:expr) => {
VM_COUNTERS.sub($ident, $amount as f64)
};
(observe | $ident:ident | $amount:expr) => {
VM_COUNTERS.observe($ident, $amount as f64)
};
(time_hist | $ident:ident | $block:block) => {{
let timer = start_profile();
let tmp = $block;
let duration = timer.elapsed();
VM_COUNTERS.observe_duration($ident, duration);
tmp
}};
}
pub fn report_execution_status(status: &TransactionStatus) {
match status {
TransactionStatus::Keep(vm_status) => inc_counter(TXN_EXECUTION_KEEP, vm_status),
TransactionStatus::Discard(vm_status) => inc_counter(TXN_EXECUTION_DISCARD, vm_status),
}
}
pub fn report_verification_status(result: &Option<VMStatus>) {
match result {
None => VERIFIED_TRANSACTION.inc(),
Some(status) => inc_counter(TXN_VERIFICATION_FAIL, status),
}
}
fn inc_counter(prefix: &str, status: &VMStatus) {
match status.status_type() {
StatusType::Deserialization => {
VM_COUNTERS.inc(&format!("{}.deserialization", prefix));
}
StatusType::Execution => {
VM_COUNTERS.inc(&format!("{}.{}", prefix, status));
}
StatusType::InvariantViolation => {
VM_COUNTERS.inc(&format!("{}.invariant_violation.{}", prefix, status));
}
StatusType::Validation => {
VM_COUNTERS.inc(&format!(
"{}.validation.{}",
prefix,
get_validation_status(status.major_status)
));
}
StatusType::Verification => {
VM_COUNTERS.inc(&format!("{}.verifier_error", prefix));
}
StatusType::Unknown => {
VM_COUNTERS.inc(&format!("{}.Unknown", prefix));
}
}
}
fn get_validation_status(validation_status: StatusCode) -> &'static str {
match validation_status {
StatusCode::INVALID_SIGNATURE => "InvalidSignature",
StatusCode::INVALID_AUTH_KEY => "InvalidAuthKey",
StatusCode::SEQUENCE_NUMBER_TOO_OLD => "SequenceNumberTooOld",
StatusCode::SEQUENCE_NUMBER_TOO_NEW => "SequenceNumberTooNew",
StatusCode::INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE => {
"InsufficientBalanceForTransactionFee"
}
StatusCode::TRANSACTION_EXPIRED => "TransactionExpired",
StatusCode::SENDING_ACCOUNT_DOES_NOT_EXIST => "SendingAccountDoesNotExist",
StatusCode::EXCEEDED_MAX_TRANSACTION_SIZE => "ExceededMaxTransactionSize",
StatusCode::UNKNOWN_SCRIPT => "UnknownScript",
StatusCode::UNKNOWN_MODULE => "UnknownModule",
StatusCode::MAX_GAS_UNITS_EXCEEDS_MAX_GAS_UNITS_BOUND
| StatusCode::MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS
| StatusCode::GAS_UNIT_PRICE_BELOW_MIN_BOUND
| StatusCode::GAS_UNIT_PRICE_ABOVE_MAX_BOUND => "GasError",
StatusCode::REJECTED_WRITE_SET | StatusCode::INVALID_WRITE_SET => "WriteSetError",
_ => "UnknownValidationStatus",
}
}