@@ -5,7 +5,8 @@ use vise::{
5
5
Metrics ,
6
6
} ;
7
7
use zksync_types:: {
8
- api:: state_override:: { OverrideState , StateOverride } ,
8
+ api:: state_override:: { BytecodeOverride , OverrideState , StateOverride } ,
9
+ bytecode:: BytecodeMarker ,
9
10
H256 ,
10
11
} ;
11
12
@@ -100,6 +101,30 @@ struct StateOverrideLabels {
100
101
kind : OverrideKind ,
101
102
}
102
103
104
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , EncodeLabelValue ) ]
105
+ #[ metrics( rename_all = "snake_case" ) ]
106
+ enum BytecodeMarkerLabel {
107
+ EraVm ,
108
+ DetectedEraVm ,
109
+ Evm ,
110
+ DetectedEvm ,
111
+ }
112
+
113
+ impl BytecodeMarkerLabel {
114
+ fn detected ( kind : BytecodeMarker ) -> Self {
115
+ match kind {
116
+ BytecodeMarker :: EraVm => Self :: DetectedEraVm ,
117
+ BytecodeMarker :: Evm => Self :: DetectedEvm ,
118
+ }
119
+ }
120
+ }
121
+
122
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , EncodeLabelSet ) ]
123
+ struct BytecodeOverrideLabels {
124
+ method : & ' static str ,
125
+ kind : BytecodeMarkerLabel ,
126
+ }
127
+
103
128
#[ derive( Debug , Metrics ) ]
104
129
#[ metrics( prefix = "api_web3" ) ]
105
130
pub ( crate ) struct SandboxMetrics {
@@ -123,6 +148,8 @@ pub(crate) struct SandboxMetrics {
123
148
pub estimate_gas_optimistic_gas_limit_relative_diff : Histogram < f64 > ,
124
149
/// Statistics on state overrides.
125
150
state_overrides : Family < StateOverrideLabels , Counter > ,
151
+ /// Statistics on bytecode kinds supplied in overrides.
152
+ bytecode_overrides : Family < BytecodeOverrideLabels , Counter > ,
126
153
}
127
154
128
155
impl SandboxMetrics {
@@ -140,8 +167,23 @@ impl SandboxMetrics {
140
167
141
168
pub fn observe_override_metrics ( & self , method : & ' static str , state_overrides : & StateOverride ) {
142
169
for ( _, account_override) in state_overrides. iter ( ) {
143
- if account_override. code . is_some ( ) {
170
+ if let Some ( code_override ) = & account_override. code {
144
171
self . state_overrides [ & OverrideKind :: Code . for_method ( method) ] . inc ( ) ;
172
+
173
+ let bytecode_kind = match code_override {
174
+ BytecodeOverride :: Evm ( _) => BytecodeMarkerLabel :: Evm ,
175
+ BytecodeOverride :: EraVm ( _) => BytecodeMarkerLabel :: EraVm ,
176
+ BytecodeOverride :: Unspecified ( bytes) => {
177
+ // Bytecode kind detection is very cheap, so it's permissible to do it here
178
+ let kind = BytecodeMarker :: detect ( & bytes. 0 ) ;
179
+ BytecodeMarkerLabel :: detected ( kind)
180
+ }
181
+ } ;
182
+ let labels = BytecodeOverrideLabels {
183
+ method,
184
+ kind : bytecode_kind,
185
+ } ;
186
+ self . bytecode_overrides [ & labels] . inc ( ) ;
145
187
}
146
188
if account_override. nonce . is_some ( ) {
147
189
self . state_overrides [ & OverrideKind :: Nonce . for_method ( method) ] . inc ( ) ;
0 commit comments