From 985399b609945c03367b5d48bd087a5e0a939594 Mon Sep 17 00:00:00 2001 From: Dustin Xie Date: Thu, 16 Feb 2023 12:48:47 -0800 Subject: [PATCH 1/2] [config] enable web3 staking and broadcast node info at Queensland height --- action/protocol/context.go | 4 ++-- api/coreservice.go | 2 +- blockchain/genesis/genesis.go | 11 ++++++++++- blockchain/genesis/heightupgrade_test.go | 3 +++ config/config.go | 2 ++ config/config_test.go | 5 +++++ e2etest/nodeinfo_test.go | 2 +- nodeinfo/manager_test.go | 6 +++--- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/action/protocol/context.go b/action/protocol/context.go index 18b33e902f..a84b406953 100644 --- a/action/protocol/context.go +++ b/action/protocol/context.go @@ -246,8 +246,8 @@ func WithFeatureCtx(ctx context.Context) context.Context { FixUnproductiveDelegates: g.IsOkhotsk(height), CorrectGasRefund: g.IsOkhotsk(height), FixRewardErroCheckPosition: g.IsOkhotsk(height), - EnableWeb3Rewarding: g.IsToBeEnabled(height), - EnableNodeInfo: g.IsToBeEnabled(height), + EnableWeb3Rewarding: g.IsQueensland(height), + EnableNodeInfo: g.IsQueensland(height), }, ) } diff --git a/api/coreservice.go b/api/coreservice.go index e1ee057dbf..b137b9c0d2 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -459,7 +459,7 @@ func (core *coreService) validateChainID(chainID uint32) error { } func (core *coreService) validateWeb3Rewarding(selp action.SealedEnvelope) error { - if ge := core.bc.Genesis(); ge.IsToBeEnabled(core.bc.TipHeight()) || selp.Encoding() != uint32(iotextypes.Encoding_ETHEREUM_RLP) { + if ge := core.bc.Genesis(); ge.IsQueensland(core.bc.TipHeight()) || selp.Encoding() != uint32(iotextypes.Encoding_ETHEREUM_RLP) { return nil } switch selp.Action().(type) { diff --git a/blockchain/genesis/genesis.go b/blockchain/genesis/genesis.go index e4ed1c662e..62589b2b9c 100644 --- a/blockchain/genesis/genesis.go +++ b/blockchain/genesis/genesis.go @@ -69,6 +69,7 @@ func defaultConfig() Genesis { MidwayBlockHeight: 16509241, NewfoundlandBlockHeight: 17662681, OkhotskBlockHeight: 21542761, + QueenslandBlockHeight: 31542761, ToBeEnabledBlockHeight: math.MaxUint64, }, Account: Account{ @@ -225,9 +226,12 @@ type ( // 3. fix gas and nonce update // 4. fix unproductive delegates in staking protocol OkhotskBlockHeight uint64 `yaml:"okhotskHeight"` + // QueenslandBlockHeight is the the start height to + // 1. enable rewarding action via web3 + // 2. broadcast node info into the p2p network + QueenslandBlockHeight uint64 `yaml:"queenslandHeight"` // ToBeEnabledBlockHeight is a fake height that acts as a gating factor for WIP features // upon next release, change IsToBeEnabled() to IsNextHeight() for features to be released - // 1. web3 rewarding api ToBeEnabledBlockHeight uint64 `yaml:"toBeEnabledHeight"` } // Account contains the configs for account protocol @@ -541,6 +545,11 @@ func (g *Blockchain) IsOkhotsk(height uint64) bool { return g.isPost(g.OkhotskBlockHeight, height) } +// IsQueensland checks whether height is equal to or larger than queensland height +func (g *Blockchain) IsQueensland(height uint64) bool { + return g.isPost(g.QueenslandBlockHeight, height) +} + // IsToBeEnabled checks whether height is equal to or larger than toBeEnabled height func (g *Blockchain) IsToBeEnabled(height uint64) bool { return g.isPost(g.ToBeEnabledBlockHeight, height) diff --git a/blockchain/genesis/heightupgrade_test.go b/blockchain/genesis/heightupgrade_test.go index 0069b7d2a5..6fcf68c26e 100644 --- a/blockchain/genesis/heightupgrade_test.go +++ b/blockchain/genesis/heightupgrade_test.go @@ -53,6 +53,8 @@ func TestNewHeightChange(t *testing.T) { require.True(cfg.IsNewfoundland(uint64(17662681))) require.False(cfg.IsOkhotsk(uint64(21542760))) require.True(cfg.IsOkhotsk(uint64(21542761))) + require.False(cfg.IsQueensland(uint64(31542760))) + require.True(cfg.IsQueensland(uint64(31542761))) require.Equal(cfg.PacificBlockHeight, uint64(432001)) require.Equal(cfg.AleutianBlockHeight, uint64(864001)) @@ -72,4 +74,5 @@ func TestNewHeightChange(t *testing.T) { require.Equal(cfg.MidwayBlockHeight, uint64(16509241)) require.Equal(cfg.NewfoundlandBlockHeight, uint64(17662681)) require.Equal(cfg.OkhotskBlockHeight, uint64(21542761)) + require.Equal(cfg.QueenslandBlockHeight, uint64(31542761)) } diff --git a/config/config.go b/config/config.go index 0c295be452..62438c9c2f 100644 --- a/config/config.go +++ b/config/config.go @@ -321,6 +321,8 @@ func ValidateForkHeights(cfg Config) error { return errors.Wrap(ErrInvalidCfg, "Midway is heigher than Newfoundland") case hu.NewfoundlandBlockHeight > hu.OkhotskBlockHeight: return errors.Wrap(ErrInvalidCfg, "Newfoundland is heigher than Okhotsk") + case hu.OkhotskBlockHeight > hu.QueenslandBlockHeight: + return errors.Wrap(ErrInvalidCfg, "Okhotsk is heigher than Queensland") } return nil } diff --git a/config/config_test.go b/config/config_test.go index ce6931b46a..b4853e5e92 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -365,6 +365,9 @@ func TestValidateForkHeights(t *testing.T) { { "Newfoundland", ErrInvalidCfg, "Newfoundland is heigher than Okhotsk", }, + { + "Okhotsk", ErrInvalidCfg, "Okhotsk is heigher than Queensland", + }, { "", nil, "", }, @@ -415,6 +418,8 @@ func newTestCfg(fork string) Config { cfg.Genesis.MidwayBlockHeight = cfg.Genesis.NewfoundlandBlockHeight + 1 case "Newfoundland": cfg.Genesis.NewfoundlandBlockHeight = cfg.Genesis.OkhotskBlockHeight + 1 + case "Okhotsk": + cfg.Genesis.OkhotskBlockHeight = cfg.Genesis.QueenslandBlockHeight + 1 } return cfg } diff --git a/e2etest/nodeinfo_test.go b/e2etest/nodeinfo_test.go index 7d14207545..0b0fd9e2e9 100644 --- a/e2etest/nodeinfo_test.go +++ b/e2etest/nodeinfo_test.go @@ -22,7 +22,7 @@ func newConfigForNodeInfoTest(triePath, dBPath, idxDBPath string) (config.Config if err != nil { return cfg, nil, err } - cfg.Genesis.ToBeEnabledBlockHeight = 0 + cfg.Genesis.QueenslandBlockHeight = 0 testTriePath, err := testutil.PathOfTempFile(triePath) if err != nil { return cfg, nil, err diff --git a/nodeinfo/manager_test.go b/nodeinfo/manager_test.go index 05cddeee85..e4f641371a 100644 --- a/nodeinfo/manager_test.go +++ b/nodeinfo/manager_test.go @@ -47,7 +47,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(2)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.ToBeEnabledBlockHeight = 1 + g.QueenslandBlockHeight = 1 return g }).MinTimes(1) err := dm.Start(context.Background()) @@ -69,7 +69,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(10)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.ToBeEnabledBlockHeight = 1 + g.QueenslandBlockHeight = 1 return g }).MinTimes(1) tMock.EXPECT().BroadcastOutbound(gomock.Any(), gomock.Any()).Return(nil).MinTimes(1) @@ -97,7 +97,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(10)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.ToBeEnabledBlockHeight = 1 + g.QueenslandBlockHeight = 1 return g }).MinTimes(1) tMock.EXPECT().BroadcastOutbound(gomock.Any(), gomock.Any()).Return(nil).MinTimes(1) From 27738dfa5a964e0f05058d924965041024d7cd53 Mon Sep 17 00:00:00 2001 From: Dustin Xie Date: Fri, 17 Feb 2023 13:47:53 -0800 Subject: [PATCH 2/2] address comment --- action/protocol/context.go | 4 ++-- api/coreservice.go | 2 +- api/types/types.go | 4 ++-- blockchain/genesis/genesis.go | 12 ++++++------ blockchain/genesis/heightupgrade_test.go | 6 +++--- config/config.go | 4 ++-- config/config_test.go | 4 ++-- e2etest/nodeinfo_test.go | 2 +- nodeinfo/manager_test.go | 6 +++--- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/action/protocol/context.go b/action/protocol/context.go index a84b406953..4d724cce9a 100644 --- a/action/protocol/context.go +++ b/action/protocol/context.go @@ -246,8 +246,8 @@ func WithFeatureCtx(ctx context.Context) context.Context { FixUnproductiveDelegates: g.IsOkhotsk(height), CorrectGasRefund: g.IsOkhotsk(height), FixRewardErroCheckPosition: g.IsOkhotsk(height), - EnableWeb3Rewarding: g.IsQueensland(height), - EnableNodeInfo: g.IsQueensland(height), + EnableWeb3Rewarding: g.IsPalau(height), + EnableNodeInfo: g.IsPalau(height), }, ) } diff --git a/api/coreservice.go b/api/coreservice.go index b137b9c0d2..54a832d7ad 100644 --- a/api/coreservice.go +++ b/api/coreservice.go @@ -459,7 +459,7 @@ func (core *coreService) validateChainID(chainID uint32) error { } func (core *coreService) validateWeb3Rewarding(selp action.SealedEnvelope) error { - if ge := core.bc.Genesis(); ge.IsQueensland(core.bc.TipHeight()) || selp.Encoding() != uint32(iotextypes.Encoding_ETHEREUM_RLP) { + if ge := core.bc.Genesis(); ge.IsPalau(core.bc.TipHeight()) || selp.Encoding() != uint32(iotextypes.Encoding_ETHEREUM_RLP) { return nil } switch selp.Action().(type) { diff --git a/api/types/types.go b/api/types/types.go index f3ebf48f45..9f10402b17 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -63,8 +63,8 @@ type BatchWriter struct { // NewBatchWriter returns a new BatchWriter func NewBatchWriter(singleWriter Web3ResponseWriter) *BatchWriter { return &BatchWriter{ - writer: singleWriter, - buf: make([]json.RawMessage, 0), + writer: singleWriter, + buf: make([]json.RawMessage, 0), } } diff --git a/blockchain/genesis/genesis.go b/blockchain/genesis/genesis.go index 62589b2b9c..3f93a3b573 100644 --- a/blockchain/genesis/genesis.go +++ b/blockchain/genesis/genesis.go @@ -69,7 +69,7 @@ func defaultConfig() Genesis { MidwayBlockHeight: 16509241, NewfoundlandBlockHeight: 17662681, OkhotskBlockHeight: 21542761, - QueenslandBlockHeight: 31542761, + PalauBlockHeight: 31542761, ToBeEnabledBlockHeight: math.MaxUint64, }, Account: Account{ @@ -226,10 +226,10 @@ type ( // 3. fix gas and nonce update // 4. fix unproductive delegates in staking protocol OkhotskBlockHeight uint64 `yaml:"okhotskHeight"` - // QueenslandBlockHeight is the the start height to + // PalauBlockHeight is the the start height to // 1. enable rewarding action via web3 // 2. broadcast node info into the p2p network - QueenslandBlockHeight uint64 `yaml:"queenslandHeight"` + PalauBlockHeight uint64 `yaml:"palauHeight"` // ToBeEnabledBlockHeight is a fake height that acts as a gating factor for WIP features // upon next release, change IsToBeEnabled() to IsNextHeight() for features to be released ToBeEnabledBlockHeight uint64 `yaml:"toBeEnabledHeight"` @@ -545,9 +545,9 @@ func (g *Blockchain) IsOkhotsk(height uint64) bool { return g.isPost(g.OkhotskBlockHeight, height) } -// IsQueensland checks whether height is equal to or larger than queensland height -func (g *Blockchain) IsQueensland(height uint64) bool { - return g.isPost(g.QueenslandBlockHeight, height) +// IsPalau checks whether height is equal to or larger than palau height +func (g *Blockchain) IsPalau(height uint64) bool { + return g.isPost(g.PalauBlockHeight, height) } // IsToBeEnabled checks whether height is equal to or larger than toBeEnabled height diff --git a/blockchain/genesis/heightupgrade_test.go b/blockchain/genesis/heightupgrade_test.go index 6fcf68c26e..dfc27365d6 100644 --- a/blockchain/genesis/heightupgrade_test.go +++ b/blockchain/genesis/heightupgrade_test.go @@ -53,8 +53,8 @@ func TestNewHeightChange(t *testing.T) { require.True(cfg.IsNewfoundland(uint64(17662681))) require.False(cfg.IsOkhotsk(uint64(21542760))) require.True(cfg.IsOkhotsk(uint64(21542761))) - require.False(cfg.IsQueensland(uint64(31542760))) - require.True(cfg.IsQueensland(uint64(31542761))) + require.False(cfg.IsPalau(uint64(31542760))) + require.True(cfg.IsPalau(uint64(31542761))) require.Equal(cfg.PacificBlockHeight, uint64(432001)) require.Equal(cfg.AleutianBlockHeight, uint64(864001)) @@ -74,5 +74,5 @@ func TestNewHeightChange(t *testing.T) { require.Equal(cfg.MidwayBlockHeight, uint64(16509241)) require.Equal(cfg.NewfoundlandBlockHeight, uint64(17662681)) require.Equal(cfg.OkhotskBlockHeight, uint64(21542761)) - require.Equal(cfg.QueenslandBlockHeight, uint64(31542761)) + require.Equal(cfg.PalauBlockHeight, uint64(31542761)) } diff --git a/config/config.go b/config/config.go index 62438c9c2f..0d34506416 100644 --- a/config/config.go +++ b/config/config.go @@ -321,8 +321,8 @@ func ValidateForkHeights(cfg Config) error { return errors.Wrap(ErrInvalidCfg, "Midway is heigher than Newfoundland") case hu.NewfoundlandBlockHeight > hu.OkhotskBlockHeight: return errors.Wrap(ErrInvalidCfg, "Newfoundland is heigher than Okhotsk") - case hu.OkhotskBlockHeight > hu.QueenslandBlockHeight: - return errors.Wrap(ErrInvalidCfg, "Okhotsk is heigher than Queensland") + case hu.OkhotskBlockHeight > hu.PalauBlockHeight: + return errors.Wrap(ErrInvalidCfg, "Okhotsk is heigher than Palau") } return nil } diff --git a/config/config_test.go b/config/config_test.go index b4853e5e92..506be47bdf 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -366,7 +366,7 @@ func TestValidateForkHeights(t *testing.T) { "Newfoundland", ErrInvalidCfg, "Newfoundland is heigher than Okhotsk", }, { - "Okhotsk", ErrInvalidCfg, "Okhotsk is heigher than Queensland", + "Okhotsk", ErrInvalidCfg, "Okhotsk is heigher than Palau", }, { "", nil, "", @@ -419,7 +419,7 @@ func newTestCfg(fork string) Config { case "Newfoundland": cfg.Genesis.NewfoundlandBlockHeight = cfg.Genesis.OkhotskBlockHeight + 1 case "Okhotsk": - cfg.Genesis.OkhotskBlockHeight = cfg.Genesis.QueenslandBlockHeight + 1 + cfg.Genesis.OkhotskBlockHeight = cfg.Genesis.PalauBlockHeight + 1 } return cfg } diff --git a/e2etest/nodeinfo_test.go b/e2etest/nodeinfo_test.go index 0b0fd9e2e9..368564e4a4 100644 --- a/e2etest/nodeinfo_test.go +++ b/e2etest/nodeinfo_test.go @@ -22,7 +22,7 @@ func newConfigForNodeInfoTest(triePath, dBPath, idxDBPath string) (config.Config if err != nil { return cfg, nil, err } - cfg.Genesis.QueenslandBlockHeight = 0 + cfg.Genesis.PalauBlockHeight = 0 testTriePath, err := testutil.PathOfTempFile(triePath) if err != nil { return cfg, nil, err diff --git a/nodeinfo/manager_test.go b/nodeinfo/manager_test.go index e4f641371a..cb1bcda5f1 100644 --- a/nodeinfo/manager_test.go +++ b/nodeinfo/manager_test.go @@ -47,7 +47,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(2)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.QueenslandBlockHeight = 1 + g.PalauBlockHeight = 1 return g }).MinTimes(1) err := dm.Start(context.Background()) @@ -69,7 +69,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(10)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.QueenslandBlockHeight = 1 + g.PalauBlockHeight = 1 return g }).MinTimes(1) tMock.EXPECT().BroadcastOutbound(gomock.Any(), gomock.Any()).Return(nil).MinTimes(1) @@ -97,7 +97,7 @@ func TestNewDelegateManager(t *testing.T) { hMock.EXPECT().TipHeight().Return(uint64(10)).MinTimes(1) hMock.EXPECT().Genesis().DoAndReturn(func() genesis.Genesis { g := genesis.TestDefault() - g.QueenslandBlockHeight = 1 + g.PalauBlockHeight = 1 return g }).MinTimes(1) tMock.EXPECT().BroadcastOutbound(gomock.Any(), gomock.Any()).Return(nil).MinTimes(1)