From 4ca268658344f02440eac89a298f256926c3798d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 18 Apr 2024 16:42:22 +0300 Subject: [PATCH] core: distinguish empty Hardforks map from nil Ensure that Blockchain constructor is able to distinguish empty Hardforks map (no hardforks should be enabled) from nil hardforks map (the default value should be used in this case, i.e. all hardforks should be active from genesis). Signed-off-by: Anna Shaleva --- pkg/core/blockchain.go | 2 +- pkg/core/blockchain_core_test.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 72039a61c..3df35e004 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -289,7 +289,7 @@ func NewBlockchain(s storage.Store, cfg config.Blockchain, log *zap.Logger) (*Bl cfg.Hardforks[hf.String()] = 0 } log.Info("Hardforks are not set, using default value") - } else { + } else if len(cfg.Hardforks) != 0 { // Explicitly set the height of all old omitted hardforks to 0 for proper // IsHardforkEnabled behaviour. for _, hf := range config.Hardforks { diff --git a/pkg/core/blockchain_core_test.go b/pkg/core/blockchain_core_test.go index dac7abee2..c431d508e 100644 --- a/pkg/core/blockchain_core_test.go +++ b/pkg/core/blockchain_core_test.go @@ -361,9 +361,9 @@ func TestBlockchain_IsRunning(t *testing.T) { } func TestNewBlockchain_InitHardforks(t *testing.T) { - t.Run("empty set", func(t *testing.T) { + t.Run("nil set", func(t *testing.T) { bc := newTestChainWithCustomCfg(t, func(c *config.Config) { - c.ProtocolConfiguration.Hardforks = map[string]uint32{} + c.ProtocolConfiguration.Hardforks = nil require.NoError(t, c.ProtocolConfiguration.Validate()) }) require.Equal(t, map[string]uint32{ @@ -372,6 +372,13 @@ func TestNewBlockchain_InitHardforks(t *testing.T) { config.HFCockatrice.String(): 0, }, bc.GetConfig().Hardforks) }) + t.Run("empty set", func(t *testing.T) { + bc := newTestChainWithCustomCfg(t, func(c *config.Config) { + c.ProtocolConfiguration.Hardforks = map[string]uint32{} + require.NoError(t, c.ProtocolConfiguration.Validate()) + }) + require.Equal(t, map[string]uint32{}, bc.GetConfig().Hardforks) + }) t.Run("missing old", func(t *testing.T) { bc := newTestChainWithCustomCfg(t, func(c *config.Config) { c.ProtocolConfiguration.Hardforks = map[string]uint32{config.HFBasilisk.String(): 5}