@@ -27,10 +27,10 @@ import (
27
27
var (
28
28
_ block.Visitor = (* verifier )(nil )
29
29
30
- ErrConflictingBlockTxs = errors .New ("block contains conflicting transactions" )
30
+ ErrConflictingBlockTxs = errors .New ("block contains conflicting transactions" )
31
+ ErrStandardBlockWithoutChanges = errors .New ("BanffStandardBlock performs no state changes" )
31
32
32
33
errApricotBlockIssuedAfterFork = errors .New ("apricot block issued after fork" )
33
- errBanffStandardBlockWithoutChanges = errors .New ("BanffStandardBlock performs no state changes" )
34
34
errIncorrectBlockHeight = errors .New ("incorrect block height" )
35
35
errOptionBlockTimestampNotMatchingParent = errors .New ("option block proposed timestamp not matching parent block one" )
36
36
)
@@ -46,14 +46,14 @@ func (v *verifier) BanffAbortBlock(b *block.BanffAbortBlock) error {
46
46
if err := v .banffOptionBlock (b ); err != nil {
47
47
return err
48
48
}
49
- return v .abortBlock (b )
49
+ return v .abortBlock (b ) // Must be the last validity check on the block
50
50
}
51
51
52
52
func (v * verifier ) BanffCommitBlock (b * block.BanffCommitBlock ) error {
53
53
if err := v .banffOptionBlock (b ); err != nil {
54
54
return err
55
55
}
56
- return v .commitBlock (b )
56
+ return v .commitBlock (b ) // Must be the last validity check on the block
57
57
}
58
58
59
59
func (v * verifier ) BanffProposalBlock (b * block.BanffProposalBlock ) error {
@@ -94,7 +94,7 @@ func (v *verifier) BanffProposalBlock(b *block.BanffProposalBlock) error {
94
94
return err
95
95
}
96
96
97
- return v .proposalBlock (
97
+ return v .proposalBlock ( // Must be the last validity check on the block
98
98
b ,
99
99
b .Tx ,
100
100
onDecisionState ,
@@ -130,41 +130,27 @@ func (v *verifier) BanffStandardBlock(b *block.BanffStandardBlock) error {
130
130
}
131
131
132
132
feeCalculator := state .PickFeeCalculator (v .txExecutorBackend .Config , onAcceptState )
133
- lowBalanceL1ValidatorsEvicted , err := v .standardBlock (
133
+ return v .standardBlock ( // Must be the last validity check on the block
134
134
b ,
135
135
b .Transactions ,
136
136
feeCalculator ,
137
137
onAcceptState ,
138
+ changed ,
138
139
)
139
- if err != nil {
140
- return err
141
- }
142
-
143
- // Verify that the block performs changes. If it does not, it never should
144
- // have been issued. Prior to the F upgrade, evicting L1 validators that
145
- // don't have enough balance for the next second is not considered a change.
146
- // After the F upgrade, it is.
147
- if ! changed &&
148
- len (b .Transactions ) == 0 &&
149
- (! v .txExecutorBackend .Config .UpgradeConfig .IsFortunaActivated (b .Timestamp ()) || ! lowBalanceL1ValidatorsEvicted ) {
150
- return errBanffStandardBlockWithoutChanges
151
- }
152
-
153
- return nil
154
140
}
155
141
156
142
func (v * verifier ) ApricotAbortBlock (b * block.ApricotAbortBlock ) error {
157
143
if err := v .apricotCommonBlock (b ); err != nil {
158
144
return err
159
145
}
160
- return v .abortBlock (b )
146
+ return v .abortBlock (b ) // Must be the last validity check on the block
161
147
}
162
148
163
149
func (v * verifier ) ApricotCommitBlock (b * block.ApricotCommitBlock ) error {
164
150
if err := v .apricotCommonBlock (b ); err != nil {
165
151
return err
166
152
}
167
- return v .commitBlock (b )
153
+ return v .commitBlock (b ) // Must be the last validity check on the block
168
154
}
169
155
170
156
func (v * verifier ) ApricotProposalBlock (b * block.ApricotProposalBlock ) error {
@@ -183,7 +169,7 @@ func (v *verifier) ApricotProposalBlock(b *block.ApricotProposalBlock) error {
183
169
}
184
170
185
171
feeCalculator := txfee .NewSimpleCalculator (0 )
186
- return v .proposalBlock (
172
+ return v .proposalBlock ( // Must be the last validity check on the block
187
173
b ,
188
174
b .Tx ,
189
175
nil ,
@@ -209,13 +195,13 @@ func (v *verifier) ApricotStandardBlock(b *block.ApricotStandardBlock) error {
209
195
}
210
196
211
197
feeCalculator := txfee .NewSimpleCalculator (0 )
212
- _ , err = v .standardBlock (
198
+ return v .standardBlock ( // Must be the last validity check on the block
213
199
b ,
214
200
b .Transactions ,
215
201
feeCalculator ,
216
202
onAcceptState ,
203
+ true ,
217
204
)
218
- return err
219
205
}
220
206
221
207
func (v * verifier ) ApricotAtomicBlock (b * block.ApricotAtomicBlock ) error {
@@ -360,7 +346,10 @@ func (v *verifier) commonBlock(b block.Block) error {
360
346
return nil
361
347
}
362
348
363
- // abortBlock populates the state of this block if [nil] is returned
349
+ // abortBlock populates the state of this block if [nil] is returned.
350
+ //
351
+ // Invariant: The call to abortBlock must be the last validity check on the
352
+ // block. If this function returns [nil], the block is cached as valid.
364
353
func (v * verifier ) abortBlock (b block.Block ) error {
365
354
parentID := b .Parent ()
366
355
onAbortState , ok := v .getOnAbortState (parentID )
@@ -384,7 +373,10 @@ func (v *verifier) abortBlock(b block.Block) error {
384
373
return nil
385
374
}
386
375
387
- // commitBlock populates the state of this block if [nil] is returned
376
+ // commitBlock populates the state of this block if [nil] is returned.
377
+ //
378
+ // Invariant: The call to commitBlock must be the last validity check on the
379
+ // block. If this function returns [nil], the block is cached as valid.
388
380
func (v * verifier ) commitBlock (b block.Block ) error {
389
381
parentID := b .Parent ()
390
382
onCommitState , ok := v .getOnCommitState (parentID )
@@ -408,7 +400,10 @@ func (v *verifier) commitBlock(b block.Block) error {
408
400
return nil
409
401
}
410
402
411
- // proposalBlock populates the state of this block if [nil] is returned
403
+ // proposalBlock populates the state of this block if [nil] is returned.
404
+ //
405
+ // Invariant: The call to proposalBlock must be the last validity check on the
406
+ // block. If this function returns [nil], the block is cached as valid.
412
407
func (v * verifier ) proposalBlock (
413
408
b block.Block ,
414
409
tx * txs.Tx ,
@@ -468,21 +463,35 @@ func (v *verifier) proposalBlock(
468
463
return nil
469
464
}
470
465
471
- // standardBlock populates the state of this block if [nil] is returned
466
+ // standardBlock populates the state of this block if [nil] is returned.
467
+ //
468
+ // Invariant: The call to standardBlock must be the last validity check on the
469
+ // block. If this function returns [nil], the block is cached as valid.
472
470
func (v * verifier ) standardBlock (
473
471
b block.Block ,
474
472
txs []* txs.Tx ,
475
473
feeCalculator txfee.Calculator ,
476
474
onAcceptState state.Diff ,
477
- ) (bool , error ) {
475
+ changedDuringAdvanceTime bool ,
476
+ ) error {
478
477
inputs , atomicRequests , onAcceptFunc , gasConsumed , lowBalanceL1ValidatorsEvicted , err := v .processStandardTxs (
479
478
txs ,
480
479
feeCalculator ,
481
480
onAcceptState ,
482
481
b .Parent (),
483
482
)
484
483
if err != nil {
485
- return false , err
484
+ return err
485
+ }
486
+
487
+ // Verify that the block performs changes. If it does not, it never should
488
+ // have been issued. Prior to Fortuna, evicting L1 validators that don't
489
+ // have enough balance for the next second is not considered a change. After
490
+ // Fortuna, it is.
491
+ timestamp := onAcceptState .GetTimestamp ()
492
+ isFortuna := v .txExecutorBackend .Config .UpgradeConfig .IsFortunaActivated (timestamp )
493
+ if hasChanges := changedDuringAdvanceTime || len (txs ) > 0 || (isFortuna && lowBalanceL1ValidatorsEvicted ); ! hasChanges {
494
+ return ErrStandardBlockWithoutChanges
486
495
}
487
496
488
497
v .Mempool .Remove (txs ... )
@@ -494,7 +503,7 @@ func (v *verifier) standardBlock(
494
503
onAcceptState : onAcceptState ,
495
504
onAcceptFunc : onAcceptFunc ,
496
505
497
- timestamp : onAcceptState . GetTimestamp () ,
506
+ timestamp : timestamp ,
498
507
inputs : inputs ,
499
508
atomicRequests : atomicRequests ,
500
509
verifiedHeights : set .Of (v .pChainHeight ),
@@ -505,7 +514,7 @@ func (v *verifier) standardBlock(
505
514
gasConsumed ,
506
515
),
507
516
}
508
- return lowBalanceL1ValidatorsEvicted , nil
517
+ return nil
509
518
}
510
519
511
520
func (v * verifier ) processStandardTxs (txs []* txs.Tx , feeCalculator txfee.Calculator , diff state.Diff , parentID ids.ID ) (
0 commit comments