@@ -7,6 +7,7 @@ defmodule LambdaEthereumConsensus.Validator do
7
7
defstruct [
8
8
:slot ,
9
9
:root ,
10
+ :epoch ,
10
11
:duties ,
11
12
:validator ,
12
13
:payload_builder
@@ -41,6 +42,7 @@ defmodule LambdaEthereumConsensus.Validator do
41
42
# just at the begining of every epoch, and then just update them as needed.
42
43
@ type state :: % __MODULE__ {
43
44
slot: Types . slot ( ) ,
45
+ epoch: Types . epoch ( ) ,
44
46
root: Types . root ( ) ,
45
47
duties: Duties . duties ( ) ,
46
48
validator: validator ( ) ,
@@ -51,6 +53,7 @@ defmodule LambdaEthereumConsensus.Validator do
51
53
def new ( { head_slot , head_root , { pubkey , privkey } } ) do
52
54
state = % __MODULE__ {
53
55
slot: head_slot ,
56
+ epoch: Misc . compute_epoch_at_slot ( head_slot ) ,
54
57
root: head_root ,
55
58
duties: Duties . empty_duties ( ) ,
56
59
validator: % {
@@ -152,17 +155,8 @@ defmodule LambdaEthereumConsensus.Validator do
152
155
153
156
defp update_state ( % { slot: slot , root: root } = state , slot , root ) , do: state
154
157
155
- defp update_state ( % { slot: slot , root: _other_root } = state , slot , head_root ) do
156
- # TODO: this log is appearing for every block
157
- # Logger.warning("[Validator] Block came late", slot: slot, root: head_root)
158
-
159
- # TODO: rollback stale data instead of the whole cache
160
- epoch = Misc . compute_epoch_at_slot ( slot + 1 )
161
- recompute_duties ( state , 0 , epoch , slot , head_root )
162
- end
163
-
164
- defp update_state ( % { slot: last_slot } = state , slot , head_root ) do
165
- last_epoch = Misc . compute_epoch_at_slot ( last_slot + 1 )
158
+ # Epoch as part of the state now avoids recomputing the duties at every block
159
+ defp update_state ( % { epoch: last_epoch } = state , slot , head_root ) do
166
160
epoch = Misc . compute_epoch_at_slot ( slot + 1 )
167
161
168
162
if last_epoch == epoch do
@@ -187,7 +181,7 @@ defmodule LambdaEthereumConsensus.Validator do
187
181
move_subnets ( state . duties , new_duties )
188
182
Duties . log_duties ( new_duties , state . validator . index )
189
183
190
- % { state | slot: slot , root: head_root , duties: new_duties }
184
+ % { state | slot: slot , root: head_root , duties: new_duties , epoch: epoch }
191
185
end
192
186
193
187
@ spec fetch_target_state ( Types . epoch ( ) , Types . root ( ) ) :: Types.BeaconState . t ( )
@@ -254,8 +248,9 @@ defmodule LambdaEthereumConsensus.Validator do
254
248
log_md = [ slot: attestation . data . slot , attestation: attestation , subnet_id: subnet_id ]
255
249
log_debug ( validator . index , "publishing attestation" , log_md )
256
250
257
- Gossip.Attestation . publish ( subnet_id , attestation )
258
- |> log_info_result ( validator . index , "published attestation" , log_md )
251
+ # FIXME: Uncommenting this line generates the invalid signature errors upon proposals
252
+ # Gossip.Attestation.publish(subnet_id, attestation)
253
+ # |> log_info_result(validator.index, "published attestation", log_md)
259
254
260
255
if current_duty . should_aggregate? do
261
256
log_debug ( validator . index , "collecting for future aggregation" , log_md )
@@ -400,16 +395,16 @@ defmodule LambdaEthereumConsensus.Validator do
400
395
401
396
defp start_payload_builder ( % { validator: validator } = state , proposed_slot , head_root ) do
402
397
# TODO: handle reorgs and late blocks
403
- log_debug ( validator . index , "starting building payload" , slot: proposed_slot )
398
+ log_debug ( validator . index , "starting building payload for slot #{ proposed_slot } " )
404
399
405
400
case BlockBuilder . start_building_payload ( proposed_slot , head_root ) do
406
401
{ :ok , payload_id } ->
407
- log_debug ( validator . index , "payload built" , slot: proposed_slot )
402
+ log_info ( validator . index , "payload built for slot #{ proposed_slot } " )
408
403
409
404
% { state | payload_builder: { proposed_slot , head_root , payload_id } }
410
405
411
406
{ :error , reason } ->
412
- log_error ( validator . index , "start building payload" , reason , slot: proposed_slot )
407
+ log_error ( validator . index , "start building payload for slot #{ proposed_slot } " , reason )
413
408
414
409
% { state | payload_builder: nil }
415
410
end
@@ -517,10 +512,10 @@ defmodule LambdaEthereumConsensus.Validator do
517
512
defp log_result ( { :error , reason } , _level , index , message , metadata ) ,
518
513
do: log_error ( index , message , reason , metadata )
519
514
520
- defp log_info ( index , message , metadata ) ,
515
+ defp log_info ( index , message , metadata \\ [ ] ) ,
521
516
do: Logger . info ( "[Validator] #{ index } #{ message } " , metadata )
522
517
523
- defp log_debug ( index , message , metadata ) ,
518
+ defp log_debug ( index , message , metadata \\ [ ] ) ,
524
519
do: Logger . debug ( "[Validator] #{ index } #{ message } " , metadata )
525
520
526
521
defp log_error ( index , message , reason , metadata \\ [ ] ) ,
0 commit comments