@@ -79,11 +79,21 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH
79
79
return xerrors .Errorf ("expected to have beacon entries in this block, but didn't find any" )
80
80
}
81
81
82
+ // Verify that the last beacon entry's round corresponds to the round we expect
82
83
last := h .BeaconEntries [len (h .BeaconEntries )- 1 ]
83
84
if last .Round != maxRound {
84
85
return xerrors .Errorf ("expected final beacon entry in block to be at round %d, got %d" , maxRound , last .Round )
85
86
}
86
87
88
+ // Verify that all other entries' rounds are as expected for the epochs in between parentEpoch and h.Height
89
+ for i , e := range h .BeaconEntries {
90
+ correctRound := b .MaxBeaconRoundForEpoch (nv , parentEpoch + abi .ChainEpoch (i )+ 1 )
91
+ if e .Round != correctRound {
92
+ return xerrors .Errorf ("unexpected beacon round %d, expected %d for epoch %d" , e .Round , correctRound , parentEpoch + abi .ChainEpoch (i ))
93
+ }
94
+ }
95
+
96
+ // Verify the beacon entries themselves
87
97
for i , e := range h .BeaconEntries {
88
98
if err := b .VerifyEntry (e , prevEntry ); err != nil {
89
99
return xerrors .Errorf ("beacon entry %d (%d - %x (%d)) was invalid: %w" , i , e .Round , e .Data , len (e .Data ), err )
@@ -132,18 +142,17 @@ func BeaconEntriesForBlock(ctx context.Context, bSchedule Schedule, nv network.V
132
142
prev .Round = maxRound - 1
133
143
}
134
144
135
- cur := maxRound
136
145
var out []types.BeaconEntry
137
- for cur > prev .Round {
138
- rch := beacon .Entry (ctx , cur )
146
+ for currEpoch := epoch ; currEpoch > parentEpoch ; currEpoch -- {
147
+ currRound := beacon .MaxBeaconRoundForEpoch (nv , currEpoch )
148
+ rch := beacon .Entry (ctx , currRound )
139
149
select {
140
150
case resp := <- rch :
141
151
if resp .Err != nil {
142
152
return nil , xerrors .Errorf ("beacon entry request returned error: %w" , resp .Err )
143
153
}
144
154
145
155
out = append (out , resp .Entry )
146
- cur = resp .Entry .Round - 1
147
156
case <- ctx .Done ():
148
157
return nil , xerrors .Errorf ("context timed out waiting on beacon entry to come back for epoch %d: %w" , epoch , ctx .Err ())
149
158
}
0 commit comments