@@ -43,20 +43,21 @@ type BeaconPoint struct {
43
43
// been posted on chain.
44
44
type RandomBeacon interface {
45
45
Entry (context.Context , uint64 ) <- chan Response
46
- VerifyEntry (types.BeaconEntry , types. BeaconEntry ) error
46
+ VerifyEntry (entry types.BeaconEntry , prevEntrySig [] byte ) error
47
47
MaxBeaconRoundForEpoch (network.Version , abi.ChainEpoch ) uint64
48
48
}
49
49
50
50
func ValidateBlockValues (bSchedule Schedule , nv network.Version , h * types.BlockHeader , parentEpoch abi.ChainEpoch ,
51
51
prevEntry types.BeaconEntry ) error {
52
- {
52
+ // Before nv22 we had "chained" beacons, and so required two entries at a fork
53
+ if nv < network .Version22 {
53
54
parentBeacon := bSchedule .BeaconForEpoch (parentEpoch )
54
55
currBeacon := bSchedule .BeaconForEpoch (h .Height )
55
56
if parentBeacon != currBeacon {
56
57
if len (h .BeaconEntries ) != 2 {
57
58
return xerrors .Errorf ("expected two beacon entries at beacon fork, got %d" , len (h .BeaconEntries ))
58
59
}
59
- err := currBeacon .VerifyEntry (h .BeaconEntries [1 ], h .BeaconEntries [0 ])
60
+ err := currBeacon .VerifyEntry (h .BeaconEntries [1 ], h .BeaconEntries [0 ]. Data )
60
61
if err != nil {
61
62
return xerrors .Errorf ("beacon at fork point invalid: (%v, %v): %w" ,
62
63
h .BeaconEntries [1 ], h .BeaconEntries [0 ], err )
@@ -65,9 +66,9 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH
65
66
}
66
67
}
67
68
68
- // TODO: fork logic
69
69
b := bSchedule .BeaconForEpoch (h .Height )
70
70
maxRound := b .MaxBeaconRoundForEpoch (nv , h .Height )
71
+ // We don't expect to ever actually meet this condition
71
72
if maxRound == prevEntry .Round {
72
73
if len (h .BeaconEntries ) != 0 {
73
74
return xerrors .Errorf ("expected not to have any beacon entries in this block, got %d" , len (h .BeaconEntries ))
@@ -79,7 +80,11 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH
79
80
return xerrors .Errorf ("expected to have beacon entries in this block, but didn't find any" )
80
81
}
81
82
82
- // Verify that the last beacon entry's round corresponds to the round we expect
83
+ if nv < network .Version22 && prevEntry .Round == 0 {
84
+ // We skip verifying the genesis entry before nv22, since that was "chained" randomness.
85
+ return nil
86
+ }
87
+
83
88
last := h .BeaconEntries [len (h .BeaconEntries )- 1 ]
84
89
if last .Round != maxRound {
85
90
return xerrors .Errorf ("expected final beacon entry in block to be at round %d, got %d" , maxRound , last .Round )
@@ -95,7 +100,7 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH
95
100
96
101
// Verify the beacon entries themselves
97
102
for i , e := range h .BeaconEntries {
98
- if err := b .VerifyEntry (e , prevEntry ); err != nil {
103
+ if err := b .VerifyEntry (e , prevEntry . Data ); err != nil {
99
104
return xerrors .Errorf ("beacon entry %d (%d - %x (%d)) was invalid: %w" , i , e .Round , e .Data , len (e .Data ), err )
100
105
}
101
106
prevEntry = e
@@ -105,7 +110,8 @@ func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockH
105
110
}
106
111
107
112
func BeaconEntriesForBlock (ctx context.Context , bSchedule Schedule , nv network.Version , epoch abi.ChainEpoch , parentEpoch abi.ChainEpoch , prev types.BeaconEntry ) ([]types.BeaconEntry , error ) {
108
- {
113
+ // Before nv22 we had "chained" beacons, and so required two entries at a fork
114
+ if nv < network .Version22 {
109
115
parentBeacon := bSchedule .BeaconForEpoch (parentEpoch )
110
116
currBeacon := bSchedule .BeaconForEpoch (epoch )
111
117
if parentBeacon != currBeacon {
@@ -133,6 +139,7 @@ func BeaconEntriesForBlock(ctx context.Context, bSchedule Schedule, nv network.V
133
139
start := build .Clock .Now ()
134
140
135
141
maxRound := beacon .MaxBeaconRoundForEpoch (nv , epoch )
142
+ // We don't expect this to ever be the case
136
143
if maxRound == prev .Round {
137
144
return nil , nil
138
145
}
0 commit comments