Skip to content

Commit 2f568fe

Browse files
envestccCoderZhi
andauthored
enable wake height (#4617)
Co-authored-by: CoderZhi <[email protected]>
1 parent a0a08d4 commit 2f568fe

File tree

9 files changed

+20
-19
lines changed

9 files changed

+20
-19
lines changed

action/protocol/context.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ func WithFeatureCtx(ctx context.Context) context.Context {
315315
UnstakedButNotClearSelfStakeAmount: !g.IsVanuatu(height),
316316
CheckStakingDurationUpperLimit: g.IsVanuatu(height),
317317
FixRevertSnapshot: g.IsVanuatu(height),
318-
TimestampedStakingContract: g.IsToBeEnabled(height),
319-
MakeUpBlockReward: g.IsToBeEnabled(height),
318+
TimestampedStakingContract: g.IsWake(height),
319+
MakeUpBlockReward: g.IsWake(height),
320320
},
321321
)
322322
}

action/protocol/rewarding/protocol.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager
111111
return p.migrateValueGreenland(ctx, sm)
112112
case g.KamchatkaBlockHeight:
113113
return p.setFoundationBonusExtension(ctx, sm)
114-
case g.ToBeEnabledBlockHeight: // todo: change to wake block height
114+
case g.WakeBlockHeight:
115115
return p.SetReward(ctx, sm, g.WakeBlockReward(), true)
116116
}
117117
return nil

action/protocol/rewarding/reward_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestProtocol_GrantBlockReward(t *testing.T) {
4949
g := genesis.MustExtractGenesisContext(ctx)
5050
g.WakeBlockRewardStr = tv.blockReward.String()
5151
blkCtx := protocol.MustGetBlockCtx(ctx)
52-
blkCtx.BlockHeight = g.ToBeEnabledBlockHeight
52+
blkCtx.BlockHeight = g.WakeBlockHeight
5353
ctx = genesis.WithGenesisContext(protocol.WithBlockCtx(ctx, blkCtx), g)
5454
req.NoError(p.CreatePreStates(ctx, sm))
5555
}
@@ -582,7 +582,7 @@ func TestProtocol_CalculateReward(t *testing.T) {
582582
blkCtx.AccumulatedTips.Set(tv.accumuTips)
583583
if tv.isWakeBlock {
584584
g.WakeBlockRewardStr = wakeBlockReward.String()
585-
blkCtx.BlockHeight = g.ToBeEnabledBlockHeight
585+
blkCtx.BlockHeight = g.WakeBlockHeight
586586
ctx = protocol.WithFeatureCtx(genesis.WithGenesisContext(protocol.WithBlockCtx(ctx, blkCtx), g))
587587
req.NoError(p.CreatePreStates(ctx, sm))
588588
} else {

action/protocol/staking/vote_reviser_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func TestVoteRevise_CorrectEndorsement(t *testing.T) {
316316
ctrl := gomock.NewController(t)
317317
g := deepcopy.Copy(genesis.Default).(genesis.Genesis)
318318
g.TsunamiBlockHeight = 2
319-
g.ToBeEnabledBlockHeight = 2
319+
g.WakeBlockHeight = 2
320320
ctx := protocol.WithBlockCtx(context.Background(), protocol.BlockCtx{BlockHeight: 2})
321321
ctx = genesis.WithGenesisContext(ctx, g)
322322
ctx = protocol.WithFeatureCtx(ctx)

chainservice/builder.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (builder *Builder) buildContractStakingIndexer(forTest bool) error {
355355
dbConfig.DbPath = builder.cfg.Chain.ContractStakingIndexDBPath
356356
kvstore := db.NewBoltDB(dbConfig)
357357
blockDurationFn := func(start uint64, end uint64, viewAt uint64) time.Duration {
358-
if viewAt < cfg.Genesis.ToBeEnabledBlockHeight {
358+
if viewAt < cfg.Genesis.WakeBlockHeight {
359359
return time.Duration(end-start) * cfg.DardanellesUpgrade.BlockInterval
360360
}
361361
return time.Duration(end-start) * cfg.WakeUpgrade.BlockInterval
@@ -385,7 +385,7 @@ func (builder *Builder) buildContractStakingIndexer(forTest bool) error {
385385
builder.cfg.Genesis.SystemStakingContractV2Address,
386386
builder.cfg.Genesis.SystemStakingContractV2Height,
387387
blockDurationFn,
388-
stakingindex.WithMuteHeight(builder.cfg.Genesis.ToBeEnabledBlockHeight),
388+
stakingindex.WithMuteHeight(builder.cfg.Genesis.WakeBlockHeight),
389389
)
390390
builder.cs.contractStakingIndexerV2 = indexer
391391
}
@@ -727,7 +727,7 @@ func (builder *Builder) registerRollDPoSProtocol() error {
727727
builder.cfg.Genesis.NumDelegates,
728728
builder.cfg.Genesis.NumSubEpochs,
729729
rolldpos.EnableDardanellesSubEpoch(builder.cfg.Genesis.DardanellesBlockHeight, builder.cfg.Genesis.DardanellesNumSubEpochs),
730-
rolldpos.EnableWakeSubEpoch(builder.cfg.Genesis.ToBeEnabledBlockHeight, builder.cfg.Genesis.WakeNumSubEpochs),
730+
rolldpos.EnableWakeSubEpoch(builder.cfg.Genesis.WakeBlockHeight, builder.cfg.Genesis.WakeNumSubEpochs),
731731
).Register(builder.cs.registry); err != nil {
732732
return err
733733
}
@@ -881,7 +881,7 @@ func (builder *Builder) build(forSubChain, forTest bool) (*ChainService, error)
881881
// it ignores the influence of the block missing in the blockchain
882882
// it must >= the real head height of the block
883883
func estimateTipHeight(cfg *config.Config, blk *block.Block, duration time.Duration) uint64 {
884-
heights, intervals := []uint64{0, cfg.Genesis.DardanellesBlockHeight, cfg.Genesis.ToBeEnabledBlockHeight}, []time.Duration{cfg.Genesis.BlockInterval, cfg.DardanellesUpgrade.BlockInterval, cfg.WakeUpgrade.BlockInterval}
884+
heights, intervals := []uint64{0, cfg.Genesis.DardanellesBlockHeight, cfg.Genesis.WakeBlockHeight}, []time.Duration{cfg.Genesis.BlockInterval, cfg.DardanellesUpgrade.BlockInterval, cfg.WakeUpgrade.BlockInterval}
885885
tip := blk.Height()
886886
interval := intervals[0]
887887
for i := 1; i < len(heights); i++ {
@@ -902,7 +902,7 @@ func estimateTipHeight(cfg *config.Config, blk *block.Block, duration time.Durat
902902

903903
// blockDistance calculates the time duration between two blocks
904904
func blockDistance(cfg *config.Config, start, end, viewAt uint64) time.Duration {
905-
origHeights := []uint64{0, cfg.Genesis.DardanellesBlockHeight, cfg.Genesis.ToBeEnabledBlockHeight}
905+
origHeights := []uint64{0, cfg.Genesis.DardanellesBlockHeight, cfg.Genesis.WakeBlockHeight}
906906
origIntervals := []time.Duration{
907907
cfg.Genesis.BlockInterval,
908908
cfg.DardanellesUpgrade.BlockInterval,

chainservice/builder_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ func TestEstimateTipHeight(t *testing.T) {
1616
r := require.New(t)
1717
cfg := deepcopy.Copy(config.Default).(config.Config)
1818
cfg.Genesis.DardanellesBlockHeight = 10000
19-
cfg.Genesis.ToBeEnabledBlockHeight = 20000
19+
cfg.Genesis.WakeBlockHeight = 20000
2020
sk := identityset.PrivateKey(1)
2121
t.Run("after dardanelles", func(t *testing.T) {
2222
blk, err := block.NewBuilder(block.RunnableActions{}).SetHeight(cfg.Genesis.DardanellesBlockHeight + 1).SignAndBuild(sk)
2323
r.NoError(err)
2424
r.Equal(blk.Height()+2, estimateTipHeight(&cfg, &blk, 10*time.Second))
25-
blk, err = block.NewBuilder(block.RunnableActions{}).SetHeight(cfg.Genesis.ToBeEnabledBlockHeight - 3).SignAndBuild(sk)
25+
blk, err = block.NewBuilder(block.RunnableActions{}).SetHeight(cfg.Genesis.WakeBlockHeight - 3).SignAndBuild(sk)
2626
r.NoError(err)
2727
r.Equal(blk.Height()+2, estimateTipHeight(&cfg, &blk, 10*time.Second))
2828
r.Equal(blk.Height()+3, estimateTipHeight(&cfg, &blk, 13*time.Second))
@@ -37,7 +37,7 @@ func TestEstimateTipHeight(t *testing.T) {
3737
r.Equal(blk.Height()+4, estimateTipHeight(&cfg, &blk, 20*time.Second))
3838
})
3939
t.Run("after wake", func(t *testing.T) {
40-
blk, err := block.NewBuilder(block.RunnableActions{}).SetHeight(cfg.Genesis.ToBeEnabledBlockHeight).SignAndBuild(sk)
40+
blk, err := block.NewBuilder(block.RunnableActions{}).SetHeight(cfg.Genesis.WakeBlockHeight).SignAndBuild(sk)
4141
r.NoError(err)
4242
r.Equal(blk.Height()+1, estimateTipHeight(&cfg, &blk, 3*time.Second))
4343
r.Equal(blk.Height()+1, estimateTipHeight(&cfg, &blk, 5*time.Second))
@@ -49,7 +49,7 @@ func TestBlockDistance(t *testing.T) {
4949
r := require.New(t)
5050
cfg := deepcopy.Copy(config.Default).(config.Config)
5151
cfg.Genesis.DardanellesBlockHeight = 10
52-
cfg.Genesis.ToBeEnabledBlockHeight = 20
52+
cfg.Genesis.WakeBlockHeight = 20
5353
t.Run("before dardanelles", func(t *testing.T) {
5454
r.Equal(3*cfg.Genesis.BlockInterval, blockDistance(&cfg, 5, 8, 0))
5555
r.Equal(10*cfg.Genesis.BlockInterval, blockDistance(&cfg, 5, 15, 0))

consensus/consensusfsm/consensus_ttl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func NewConsensusConfig(timing ConsensusTiming, dardanelles DardanellesUpgrade,
104104
blockInterval: g.Blockchain.BlockInterval,
105105
delay: delay,
106106
wake: wake,
107-
wakeHeight: g.ToBeEnabledBlockHeight,
107+
wakeHeight: g.WakeBlockHeight,
108108
}
109109
}
110110

e2etest/contract_staking_v2_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestContractStakingV2(t *testing.T) {
5151
cfg := initCfg(require)
5252
cfg.Genesis.UpernavikBlockHeight = 1
5353
cfg.Genesis.VanuatuBlockHeight = 100
54-
cfg.Genesis.ToBeEnabledBlockHeight = 120 // mute staking v2
54+
cfg.Genesis.WakeBlockHeight = 120 // mute staking v2
5555
cfg.Genesis.SystemStakingContractV2Address = contractAddress
5656
cfg.Genesis.SystemStakingContractV2Height = 1
5757
cfg.DardanellesUpgrade.BlockInterval = time.Second * 8640
@@ -305,7 +305,7 @@ func TestContractStakingV3(t *testing.T) {
305305
cfg := initCfg(require)
306306
cfg.Genesis.UpernavikBlockHeight = 1
307307
cfg.Genesis.VanuatuBlockHeight = 100
308-
cfg.Genesis.ToBeEnabledBlockHeight = 120 // mute staking v2 & enable staking v3
308+
cfg.Genesis.WakeBlockHeight = 120 // mute staking v2 & enable staking v3
309309
cfg.Genesis.SystemStakingContractV2Address = contractV2Address
310310
cfg.Genesis.SystemStakingContractV2Height = 1
311311
cfg.Genesis.SystemStakingContractV3Address = contractV3Address
@@ -583,7 +583,7 @@ func TestMigrateStake(t *testing.T) {
583583
cfg.Genesis.SystemStakingContractV3Address = contractAddress
584584
cfg.Genesis.SystemStakingContractV3Height = 1
585585
cfg.Genesis.VanuatuBlockHeight = 1
586-
cfg.Genesis.ToBeEnabledBlockHeight = 1
586+
cfg.Genesis.WakeBlockHeight = 1
587587
testutil.NormalizeGenesisHeights(&cfg.Genesis.Blockchain)
588588
cfg.DardanellesUpgrade.BlockInterval = time.Second * 8640
589589
cfg.Plugins[config.GatewayPlugin] = nil

testutil/genesis.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NormalizeGenesisHeights(g *genesis.Blockchain) {
3131
&g.TsunamiBlockHeight,
3232
&g.UpernavikBlockHeight,
3333
&g.VanuatuBlockHeight,
34+
&g.WakeBlockHeight,
3435
&g.ToBeEnabledBlockHeight,
3536
}
3637
for i := len(heights) - 2; i >= 0; i-- {

0 commit comments

Comments
 (0)