Skip to content

Enable empty standard block check #3776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions vms/platformvm/block/executor/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/components/gas"
Expand Down Expand Up @@ -488,9 +489,18 @@ func (v *verifier) standardBlock(
// have been issued. Prior to Fortuna, evicting L1 validators that don't
// have enough balance for the next second is not considered a change. After
// Fortuna, it is.
timestamp := onAcceptState.GetTimestamp()
isFortuna := v.txExecutorBackend.Config.UpgradeConfig.IsFortunaActivated(timestamp)
if hasChanges := changedDuringAdvanceTime || len(txs) > 0 || (isFortuna && lowBalanceL1ValidatorsEvicted); !hasChanges {
var (
hasPreFortunaChanges = changedDuringAdvanceTime || len(txs) > 0

timestamp = onAcceptState.GetTimestamp()
isFortuna = v.txExecutorBackend.Config.UpgradeConfig.IsFortunaActivated(timestamp)

includeFortunaChangesPreActivation = v.ctx.NetworkID == constants.FujiID
includePostFortunaChanges = isFortuna || includeFortunaChangesPreActivation

hasChanges = hasPreFortunaChanges || (includePostFortunaChanges && lowBalanceL1ValidatorsEvicted)
)
if !hasChanges {
return ErrStandardBlockWithoutChanges
}

Expand Down
20 changes: 20 additions & 0 deletions vms/platformvm/block/executor/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1343,38 +1343,58 @@ func TestDeactivateLowBalanceL1ValidatorBlockChanges(t *testing.T) {
name string
currentFork upgradetest.Fork
durationToAdvance time.Duration
networkID uint32
expectedErr error
}{
{
name: "Before F Upgrade - no L1 validators evicted",
currentFork: upgradetest.Etna,
durationToAdvance: 0,
networkID: constants.UnitTestID,
expectedErr: ErrStandardBlockWithoutChanges,
},
{
name: "After F Upgrade - no L1 validators evicted",
currentFork: upgradetest.Fortuna,
durationToAdvance: 0,
networkID: constants.UnitTestID,
expectedErr: ErrStandardBlockWithoutChanges,
},
{
name: "Before F Upgrade - L1 validators evicted",
currentFork: upgradetest.Etna,
durationToAdvance: time.Second,
networkID: constants.UnitTestID,
expectedErr: ErrStandardBlockWithoutChanges,
},
{
name: "After F Upgrade - L1 validators evicted",
currentFork: upgradetest.Fortuna,
durationToAdvance: time.Second,
networkID: constants.UnitTestID,
},
{
name: "Before F Upgrade - L1 validators evicted - on Fuji",
currentFork: upgradetest.Etna,
durationToAdvance: time.Second,
networkID: constants.FujiID,
},
{
name: "After F Upgrade - L1 validators evicted - on Fuji",
currentFork: upgradetest.Fortuna,
durationToAdvance: time.Second,
networkID: constants.FujiID,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)

ctx := snowtest.Context(t, constants.PlatformChainID)
ctx.NetworkID = test.networkID
verifier := newTestVerifier(t, testVerifierConfig{
Upgrades: upgradetest.GetConfig(test.currentFork),
Context: ctx,
ValidatorFeeConfig: validatorfee.Config{
Capacity: genesis.LocalParams.ValidatorFeeConfig.Capacity,
Target: genesis.LocalParams.ValidatorFeeConfig.Target,
Expand Down
8 changes: 6 additions & 2 deletions vms/platformvm/genesis/genesistest/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func init() {
}

type Config struct {
NetworkID uint32
NodeIDs []ids.NodeID
ValidatorWeight uint64
ValidatorStartTime time.Time
Expand All @@ -68,6 +69,9 @@ type Config struct {
}

func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
if c.NetworkID == 0 {
c.NetworkID = constants.UnitTestID
}
if len(c.NodeIDs) == 0 {
c.NodeIDs = DefaultNodeIDs
}
Expand Down Expand Up @@ -123,7 +127,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis {
}
validator := &txs.AddValidatorTx{
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
NetworkID: constants.UnitTestID,
NetworkID: c.NetworkID,
BlockchainID: constants.PlatformChainID,
}},
Validator: txs.Validator{
Expand Down Expand Up @@ -152,7 +156,7 @@ func New(t testing.TB, c Config) *platformvmgenesis.Genesis {

chain := &txs.CreateChainTx{
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
NetworkID: constants.UnitTestID,
NetworkID: c.NetworkID,
BlockchainID: constants.PlatformChainID,
}},
SubnetID: constants.PrimaryNetworkID,
Expand Down
18 changes: 10 additions & 8 deletions vms/platformvm/state/statetest/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ func New(t testing.TB, c Config) state.State {
if c.DB == nil {
c.DB = memdb.New()
}
if c.Context == nil {
c.Context = &snow.Context{
NetworkID: constants.UnitTestID,
NodeID: DefaultNodeID,
Log: logging.NoLog{},
}
}
if len(c.Genesis) == 0 {
c.Genesis = genesistest.NewBytes(t, genesistest.Config{})
c.Genesis = genesistest.NewBytes(t, genesistest.Config{
NetworkID: c.Context.NetworkID,
})
}
if c.Registerer == nil {
c.Registerer = prometheus.NewRegistry()
Expand All @@ -60,13 +69,6 @@ func New(t testing.TB, c Config) state.State {
if c.Config == (config.Config{}) {
c.Config = config.Default
}
if c.Context == nil {
c.Context = &snow.Context{
NetworkID: constants.UnitTestID,
NodeID: DefaultNodeID,
Log: logging.NoLog{},
}
}
if c.Metrics == nil {
c.Metrics = metrics.Noop
}
Expand Down
Loading