@@ -4,7 +4,6 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
4
4
"""
5
5
alias LambdaEthereumConsensus.StateTransition.Accessors
6
6
alias LambdaEthereumConsensus.StateTransition.Misc
7
- alias LambdaEthereumConsensus.Validator
8
7
alias LambdaEthereumConsensus.Validator.Utils
9
8
alias LambdaEthereumConsensus.ValidatorSet
10
9
alias Types.BeaconState
@@ -36,15 +35,12 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
36
35
def compute_proposers_for_epoch ( % BeaconState { } = state , epoch , validators ) do
37
36
with { :ok , epoch } <- check_valid_epoch ( state , epoch ) ,
38
37
{ start_slot , end_slot } <- boundary_slots ( epoch ) do
39
- start_slot .. end_slot
40
- |> Enum . flat_map ( fn slot ->
41
- { :ok , proposer_index } = Accessors . get_beacon_proposer_index ( state , slot )
42
-
43
- if Map . has_key? ( validators , proposer_index ) ,
44
- do: [ { slot , proposer_index } ] ,
45
- else: [ ]
46
- end )
47
- |> Map . new ( )
38
+ for slot <- start_slot .. end_slot ,
39
+ { :ok , proposer_index } = Accessors . get_beacon_proposer_index ( state , slot ) ,
40
+ Map . has_key? ( validators , proposer_index ) ,
41
+ into: % { } do
42
+ { slot , proposer_index }
43
+ end
48
44
end
49
45
end
50
46
@@ -58,59 +54,37 @@ defmodule LambdaEthereumConsensus.Validator.Duties do
58
54
start_slot .. end_slot
59
55
|> Enum . flat_map ( fn slot ->
60
56
0 .. ( committee_count_per_slot - 1 )
61
- |> Enum . flat_map ( & compute_attester_duties ( state , epoch , slot , validators , & 1 ) )
57
+ |> Enum . flat_map ( & compute_duties_per_committee ( state , epoch , slot , validators , & 1 ) )
58
+ |> Enum . map ( & { slot , & 1 } )
62
59
end )
63
60
|> Map . new ( )
64
61
end
65
62
end
66
63
67
- @ spec compute_attester_duties (
68
- state :: BeaconState . t ( ) ,
69
- epoch :: Types . epoch ( ) ,
70
- slot :: Types . slot ( ) ,
71
- validators :: % { Types . validator_index ( ) => Validator . t ( ) } ,
72
- committee_index :: Types . uint64 ( )
73
- ) :: [ { Types . slot ( ) , attester_duty ( ) } ]
74
- defp compute_attester_duties ( state , epoch , slot , validators , committee_index ) do
64
+ defp compute_duties_per_committee ( state , epoch , slot , validators , committee_index ) do
75
65
case Accessors . get_beacon_committee ( state , slot , committee_index ) do
76
66
{ :ok , committee } ->
77
- compute_cometee_duties ( state , epoch , slot , committee , committee_index , validators )
67
+ for { validator_index , index_in_committee } <- Enum . with_index ( committee ) ,
68
+ validator = Map . get ( validators , validator_index ) ,
69
+ duty =
70
+ % {
71
+ slot: slot ,
72
+ validator_index: validator_index ,
73
+ index_in_committee: index_in_committee ,
74
+ committee_length: length ( committee ) ,
75
+ committee_index: committee_index ,
76
+ attested?: false
77
+ }
78
+ |> update_with_aggregation_duty ( state , validator . keystore . privkey )
79
+ |> update_with_subnet_id ( state , epoch ) do
80
+ duty
81
+ end
78
82
79
83
{ :error , _ } ->
80
84
[ ]
81
85
end
82
86
end
83
87
84
- defp compute_cometee_duties ( state , epoch , slot , committee , committee_index , validators ) do
85
- committee
86
- |> Stream . with_index ( )
87
- |> Stream . flat_map ( fn { validator_index , index_in_committee } ->
88
- case Map . get ( validators , validator_index ) do
89
- nil ->
90
- [ ]
91
-
92
- validator ->
93
- [
94
- % {
95
- slot: slot ,
96
- validator_index: validator_index ,
97
- index_in_committee: index_in_committee ,
98
- committee_length: length ( committee ) ,
99
- committee_index: committee_index ,
100
- attested?: false
101
- }
102
- |> update_with_aggregation_duty ( state , validator . keystore . privkey )
103
- |> update_with_subnet_id ( state , epoch )
104
- ]
105
- end
106
- end )
107
- |> Enum . into ( [ ] )
108
- |> case do
109
- [ ] -> [ ]
110
- duties -> [ { slot , duties } ]
111
- end
112
- end
113
-
114
88
defp update_with_aggregation_duty ( duty , beacon_state , privkey ) do
115
89
proof = Utils . get_slot_signature ( beacon_state , duty . slot , privkey )
116
90
0 commit comments