Skip to content

Commit 478f5fd

Browse files
Enable empty standard block check (#3776)
Signed-off-by: Stephen Buttolph <stephen@avalabs.org> Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
1 parent 2862be8 commit 478f5fd

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

vms/platformvm/block/executor/verifier.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/ava-labs/avalanchego/chains/atomic"
1111
"github.com/ava-labs/avalanchego/ids"
12+
"github.com/ava-labs/avalanchego/utils/constants"
1213
"github.com/ava-labs/avalanchego/utils/math"
1314
"github.com/ava-labs/avalanchego/utils/set"
1415
"github.com/ava-labs/avalanchego/vms/components/gas"
@@ -488,9 +489,18 @@ func (v *verifier) standardBlock(
488489
// have been issued. Prior to Fortuna, evicting L1 validators that don't
489490
// have enough balance for the next second is not considered a change. After
490491
// 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 {
492+
var (
493+
hasPreFortunaChanges = changedDuringAdvanceTime || len(txs) > 0
494+
495+
timestamp = onAcceptState.GetTimestamp()
496+
isFortuna = v.txExecutorBackend.Config.UpgradeConfig.IsFortunaActivated(timestamp)
497+
498+
includeFortunaChangesPreActivation = v.ctx.NetworkID == constants.FujiID
499+
includePostFortunaChanges = isFortuna || includeFortunaChangesPreActivation
500+
501+
hasChanges = hasPreFortunaChanges || (includePostFortunaChanges && lowBalanceL1ValidatorsEvicted)
502+
)
503+
if !hasChanges {
494504
return ErrStandardBlockWithoutChanges
495505
}
496506

vms/platformvm/block/executor/verifier_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,38 +1343,58 @@ func TestDeactivateLowBalanceL1ValidatorBlockChanges(t *testing.T) {
13431343
name string
13441344
currentFork upgradetest.Fork
13451345
durationToAdvance time.Duration
1346+
networkID uint32
13461347
expectedErr error
13471348
}{
13481349
{
13491350
name: "Before F Upgrade - no L1 validators evicted",
13501351
currentFork: upgradetest.Etna,
13511352
durationToAdvance: 0,
1353+
networkID: constants.UnitTestID,
13521354
expectedErr: ErrStandardBlockWithoutChanges,
13531355
},
13541356
{
13551357
name: "After F Upgrade - no L1 validators evicted",
13561358
currentFork: upgradetest.Fortuna,
13571359
durationToAdvance: 0,
1360+
networkID: constants.UnitTestID,
13581361
expectedErr: ErrStandardBlockWithoutChanges,
13591362
},
13601363
{
13611364
name: "Before F Upgrade - L1 validators evicted",
13621365
currentFork: upgradetest.Etna,
13631366
durationToAdvance: time.Second,
1367+
networkID: constants.UnitTestID,
13641368
expectedErr: ErrStandardBlockWithoutChanges,
13651369
},
13661370
{
13671371
name: "After F Upgrade - L1 validators evicted",
13681372
currentFork: upgradetest.Fortuna,
13691373
durationToAdvance: time.Second,
1374+
networkID: constants.UnitTestID,
1375+
},
1376+
{
1377+
name: "Before F Upgrade - L1 validators evicted - on Fuji",
1378+
currentFork: upgradetest.Etna,
1379+
durationToAdvance: time.Second,
1380+
networkID: constants.FujiID,
1381+
},
1382+
{
1383+
name: "After F Upgrade - L1 validators evicted - on Fuji",
1384+
currentFork: upgradetest.Fortuna,
1385+
durationToAdvance: time.Second,
1386+
networkID: constants.FujiID,
13701387
},
13711388
}
13721389
for _, test := range tests {
13731390
t.Run(test.name, func(t *testing.T) {
13741391
require := require.New(t)
13751392

1393+
ctx := snowtest.Context(t, constants.PlatformChainID)
1394+
ctx.NetworkID = test.networkID
13761395
verifier := newTestVerifier(t, testVerifierConfig{
13771396
Upgrades: upgradetest.GetConfig(test.currentFork),
1397+
Context: ctx,
13781398
ValidatorFeeConfig: validatorfee.Config{
13791399
Capacity: genesis.LocalParams.ValidatorFeeConfig.Capacity,
13801400
Target: genesis.LocalParams.ValidatorFeeConfig.Target,

vms/platformvm/genesis/genesistest/genesis.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func init() {
5858
}
5959

6060
type Config struct {
61+
NetworkID uint32
6162
NodeIDs []ids.NodeID
6263
ValidatorWeight uint64
6364
ValidatorStartTime time.Time
@@ -68,6 +69,9 @@ type Config struct {
6869
}
6970

7071
func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
72+
if c.NetworkID == 0 {
73+
c.NetworkID = constants.UnitTestID
74+
}
7175
if len(c.NodeIDs) == 0 {
7276
c.NodeIDs = DefaultNodeIDs
7377
}
@@ -123,7 +127,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
123127
}
124128
validator := &txs.AddValidatorTx{
125129
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
126-
NetworkID: constants.UnitTestID,
130+
NetworkID: c.NetworkID,
127131
BlockchainID: constants.PlatformChainID,
128132
}},
129133
Validator: txs.Validator{
@@ -152,7 +156,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
152156

153157
chain := &txs.CreateChainTx{
154158
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
155-
NetworkID: constants.UnitTestID,
159+
NetworkID: c.NetworkID,
156160
BlockchainID: constants.PlatformChainID,
157161
}},
158162
SubnetID: constants.PrimaryNetworkID,

vms/platformvm/state/statetest/state.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ func New(t testing.TB, c Config) state.State {
4545
if c.DB == nil {
4646
c.DB = memdb.New()
4747
}
48+
if c.Context == nil {
49+
c.Context = &snow.Context{
50+
NetworkID: constants.UnitTestID,
51+
NodeID: DefaultNodeID,
52+
Log: logging.NoLog{},
53+
}
54+
}
4855
if len(c.Genesis) == 0 {
49-
c.Genesis = genesistest.NewBytes(t, genesistest.Config{})
56+
c.Genesis = genesistest.NewBytes(t, genesistest.Config{
57+
NetworkID: c.Context.NetworkID,
58+
})
5059
}
5160
if c.Registerer == nil {
5261
c.Registerer = prometheus.NewRegistry()
@@ -60,13 +69,6 @@ func New(t testing.TB, c Config) state.State {
6069
if c.Config == (config.Config{}) {
6170
c.Config = config.Default
6271
}
63-
if c.Context == nil {
64-
c.Context = &snow.Context{
65-
NetworkID: constants.UnitTestID,
66-
NodeID: DefaultNodeID,
67-
Log: logging.NoLog{},
68-
}
69-
}
7072
if c.Metrics == nil {
7173
c.Metrics = metrics.Noop
7274
}

0 commit comments

Comments
 (0)