1
1
use derivative:: Derivative ;
2
2
use smallvec:: { smallvec, SmallVec } ;
3
3
use ssz:: { Decode , Encode } ;
4
- use state_processing:: { SigVerifiedOp , VerifyOperation } ;
4
+ use state_processing:: { SigVerifiedOp , VerifyOperation , VerifyOperationAt } ;
5
5
use std:: collections:: HashSet ;
6
6
use std:: marker:: PhantomData ;
7
7
use types:: {
8
- AttesterSlashing , BeaconState , ChainSpec , EthSpec , ForkName , ProposerSlashing ,
8
+ AttesterSlashing , BeaconState , ChainSpec , Epoch , EthSpec , ForkName , ProposerSlashing ,
9
9
SignedBlsToExecutionChange , SignedVoluntaryExit , Slot ,
10
10
} ;
11
11
@@ -87,12 +87,16 @@ impl<E: EthSpec> ObservableOperation<E> for SignedBlsToExecutionChange {
87
87
}
88
88
89
89
impl < T : ObservableOperation < E > , E : EthSpec > ObservedOperations < T , E > {
90
- pub fn verify_and_observe (
90
+ pub fn verify_and_observe_parametric < F > (
91
91
& mut self ,
92
92
op : T ,
93
+ validate : F ,
93
94
head_state : & BeaconState < E > ,
94
95
spec : & ChainSpec ,
95
- ) -> Result < ObservationOutcome < T , E > , T :: Error > {
96
+ ) -> Result < ObservationOutcome < T , E > , T :: Error >
97
+ where
98
+ F : Fn ( T ) -> Result < SigVerifiedOp < T , E > , T :: Error > ,
99
+ {
96
100
self . reset_at_fork_boundary ( head_state. slot ( ) , spec) ;
97
101
98
102
let observed_validator_indices = & mut self . observed_validator_indices ;
@@ -112,7 +116,7 @@ impl<T: ObservableOperation<E>, E: EthSpec> ObservedOperations<T, E> {
112
116
}
113
117
114
118
// Validate the op using operation-specific logic (`verify_attester_slashing`, etc).
115
- let verified_op = op . validate ( head_state , spec ) ?;
119
+ let verified_op = validate ( op ) ?;
116
120
117
121
// Add the relevant indices to the set of known indices to prevent processing of duplicates
118
122
// in the future.
@@ -121,6 +125,16 @@ impl<T: ObservableOperation<E>, E: EthSpec> ObservedOperations<T, E> {
121
125
Ok ( ObservationOutcome :: New ( verified_op) )
122
126
}
123
127
128
+ pub fn verify_and_observe (
129
+ & mut self ,
130
+ op : T ,
131
+ head_state : & BeaconState < E > ,
132
+ spec : & ChainSpec ,
133
+ ) -> Result < ObservationOutcome < T , E > , T :: Error > {
134
+ let validate = |op : T | op. validate ( head_state, spec) ;
135
+ self . verify_and_observe_parametric ( op, validate, head_state, spec)
136
+ }
137
+
124
138
/// Reset the cache when crossing a fork boundary.
125
139
///
126
140
/// This prevents an attacker from crafting a self-slashing which is only valid before the fork
@@ -140,3 +154,16 @@ impl<T: ObservableOperation<E>, E: EthSpec> ObservedOperations<T, E> {
140
154
}
141
155
}
142
156
}
157
+
158
+ impl < T : ObservableOperation < E > + VerifyOperationAt < E > , E : EthSpec > ObservedOperations < T , E > {
159
+ pub fn verify_and_observe_at (
160
+ & mut self ,
161
+ op : T ,
162
+ verify_at_epoch : Epoch ,
163
+ head_state : & BeaconState < E > ,
164
+ spec : & ChainSpec ,
165
+ ) -> Result < ObservationOutcome < T , E > , T :: Error > {
166
+ let validate = |op : T | op. validate_at ( head_state, verify_at_epoch, spec) ;
167
+ self . verify_and_observe_parametric ( op, validate, head_state, spec)
168
+ }
169
+ }
0 commit comments