1
1
use crate :: { hashed_cursor:: HashedCursor , trie_cursor:: TrieCursor , walker:: TrieWalker , Nibbles } ;
2
2
use alloy_primitives:: B256 ;
3
+ use metrics:: Counter ;
4
+ use reth_metrics:: Metrics ;
3
5
use reth_storage_errors:: db:: DatabaseError ;
4
6
5
7
/// Represents a branch node in the trie.
@@ -49,11 +51,13 @@ pub struct TrieNodeIter<C, H: HashedCursor> {
49
51
current_hashed_entry : Option < ( B256 , <H as HashedCursor >:: Value ) > ,
50
52
/// Flag indicating whether we should check the current walker key.
51
53
current_walker_key_checked : bool ,
54
+
55
+ metrics : NodeIterMetrics ,
52
56
}
53
57
54
58
impl < C , H : HashedCursor > TrieNodeIter < C , H > {
55
59
/// Creates a new [`TrieNodeIter`].
56
- pub const fn new ( walker : TrieWalker < C > , hashed_cursor : H ) -> Self {
60
+ pub fn new ( walker : TrieWalker < C > , hashed_cursor : H , node_iter_type : TrieNodeIterType ) -> Self {
57
61
Self {
58
62
walker,
59
63
hashed_cursor,
@@ -62,6 +66,7 @@ impl<C, H: HashedCursor> TrieNodeIter<C, H> {
62
66
hashed_cursor_next : false ,
63
67
current_hashed_entry : None ,
64
68
current_walker_key_checked : false ,
69
+ metrics : NodeIterMetrics :: new_with_labels ( & [ ( "type" , node_iter_type. as_str ( ) ) ] ) ,
65
70
}
66
71
}
67
72
@@ -118,6 +123,8 @@ where
118
123
} else {
119
124
self . current_hashed_entry = entry;
120
125
}
126
+
127
+ self . metrics . hashed_cursor_seeks . increment ( 1 ) ;
121
128
}
122
129
123
130
// If there's a hashed entry...
@@ -158,3 +165,28 @@ where
158
165
Ok ( None )
159
166
}
160
167
}
168
+
169
+ /// The type of the node iter.
170
+ #[ derive( Debug ) ]
171
+ pub enum TrieNodeIterType {
172
+ /// The node iter for the account trie.
173
+ Account ,
174
+ /// The node iter for the storage trie.
175
+ Storage ,
176
+ }
177
+
178
+ impl TrieNodeIterType {
179
+ fn as_str ( & self ) -> & ' static str {
180
+ match self {
181
+ Self :: Account => "account" ,
182
+ Self :: Storage => "storage" ,
183
+ }
184
+ }
185
+ }
186
+
187
+ #[ derive( Metrics ) ]
188
+ #[ metrics( scope = "trie.node_iter" ) ]
189
+ struct NodeIterMetrics {
190
+ /// The number of times the hashed cursor was seeked.
191
+ pub hashed_cursor_seeks : Counter ,
192
+ }
0 commit comments