From 366fc471a1c6e8e01267a01fc74614ab4c6647da Mon Sep 17 00:00:00 2001 From: jiangzehua <1092431698@qq.com> Date: Thu, 29 Jun 2023 10:55:04 +0800 Subject: [PATCH] feat(bpos): instead RevertToPOWV1Height with new change view height --- common/config/config.go | 17 ++++++----------- core/transaction/reverttopowtransaction.go | 2 +- dpos/arbitrator.go | 2 +- pow/revertlistener.go | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index ed9dacf5c..28b11af9d 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -180,7 +180,6 @@ func GetDefaultParams() *Configuration { MaxInactiveRoundsOfRandomNode: 36 * 8, RevertToPOWNoBlockTime: 12 * 3600, StopConfirmBlockTime: 11 * 3600, - RevertToPOWV1Height: math.MaxUint32, // todo complete me RevertToPOWNoBlockTimeV1: 2 * 3600, // todo complete me StopConfirmBlockTimeV1: 6600, // todo complete me ChangeViewV1Height: math.MaxUint32, // todo complete me @@ -364,10 +363,9 @@ func (p *Configuration) TestNet() *Configuration { p.MaxReservedCustomIDLength = 255 p.DPoSConfiguration.RevertToPOWNoBlockTime = 12 * 3600 p.DPoSConfiguration.StopConfirmBlockTime = 11 * 3600 - p.DPoSConfiguration.RevertToPOWV1Height = math.MaxUint32 // todo complete me - p.DPoSConfiguration.RevertToPOWNoBlockTimeV1 = 2 * 3600 // todo complete me - p.DPoSConfiguration.StopConfirmBlockTimeV1 = 6600 // todo complete me - p.DPoSConfiguration.ChangeViewV1Height = math.MaxUint32 // todo complete me + p.DPoSConfiguration.RevertToPOWNoBlockTimeV1 = 2 * 3600 // todo complete me + p.DPoSConfiguration.StopConfirmBlockTimeV1 = 6600 // todo complete me + p.DPoSConfiguration.ChangeViewV1Height = math.MaxUint32 // todo complete me p.DPoSConfiguration.RevertToPOWStartHeight = 815060 p.HalvingRewardHeight = 877880 //767000 + 154 * 720 p.HalvingRewardInterval = 1051200 //4 * 365 * 720 @@ -492,10 +490,9 @@ func (p *Configuration) RegNet() *Configuration { p.MaxReservedCustomIDLength = 255 p.DPoSConfiguration.RevertToPOWNoBlockTime = 12 * 3600 p.DPoSConfiguration.StopConfirmBlockTime = 11 * 3600 - p.DPoSConfiguration.RevertToPOWV1Height = math.MaxUint32 // todo complete me - p.DPoSConfiguration.RevertToPOWNoBlockTimeV1 = 2 * 3600 // todo complete me - p.DPoSConfiguration.StopConfirmBlockTimeV1 = 6600 // todo complete me - p.DPoSConfiguration.ChangeViewV1Height = math.MaxUint32 // todo complete me + p.DPoSConfiguration.RevertToPOWNoBlockTimeV1 = 2 * 3600 // todo complete me + p.DPoSConfiguration.StopConfirmBlockTimeV1 = 6600 // todo complete me + p.DPoSConfiguration.ChangeViewV1Height = math.MaxUint32 // todo complete me p.DPoSConfiguration.RevertToPOWStartHeight = 706240 p.HalvingRewardHeight = 801240 //690360 + 154 * 720 p.HalvingRewardInterval = 1051200 //4 * 365 * 720 @@ -733,8 +730,6 @@ type DPoSConfiguration struct { RevertToPOWNoBlockTime int64 `screw:"--reverttopownoblocktime" usage:"defines how long time does it take to revert to POW mode"` // StopConfirmBlockTime defines how long time dose it take before stop confirm block. StopConfirmBlockTime int64 `screw:"--stopconfirmblocktime" usage:"defines how long time does it take to stop confirm block"` - // RevertToPOWV1Height defines how the height of POW mode of version 1.0 - RevertToPOWV1Height uint32 `screw:"--reverttopowv1height" usage:"defines how the height of POW mode of version 1.0"` // RevertToPOWInterval defines how long time does it take to revert to POW mode. RevertToPOWNoBlockTimeV1 int64 `screw:"--reverttopownoblocktimev1" usage:"defines how long time does it take to revert to POW mode"` // StopConfirmBlockTime defines how long time dose it take before stop confirm block. diff --git a/core/transaction/reverttopowtransaction.go b/core/transaction/reverttopowtransaction.go index ba6f1ed23..3db25c6d8 100644 --- a/core/transaction/reverttopowtransaction.go +++ b/core/transaction/reverttopowtransaction.go @@ -82,7 +82,7 @@ func (t *RevertToPOWTransaction) SpecialContextCheck() (result elaerr.ELAError, lastBlockTime := int64(t.parameters.BlockChain.BestChain.Timestamp) var noBlockTime int64 - if t.parameters.BlockHeight < t.parameters.Config.DPoSConfiguration.RevertToPOWV1Height { + if t.parameters.BlockHeight < t.parameters.Config.DPoSConfiguration.ChangeViewV1Height { noBlockTime = t.parameters.Config.DPoSConfiguration.RevertToPOWNoBlockTime } else { noBlockTime = t.parameters.Config.DPoSConfiguration.RevertToPOWNoBlockTimeV1 diff --git a/dpos/arbitrator.go b/dpos/arbitrator.go index edae3230a..c85298965 100644 --- a/dpos/arbitrator.go +++ b/dpos/arbitrator.go @@ -206,7 +206,7 @@ func (a *Arbitrator) OnBlockReceived(b *types.Block, confirmed bool) { localTimestamp := a.cfg.Chain.TimeSource.AdjustedTime().Unix() var stopConfirmTime int64 - if b.Height < a.cfg.ChainParams.DPoSConfiguration.RevertToPOWV1Height { + if b.Height < a.cfg.ChainParams.DPoSConfiguration.ChangeViewV1Height { stopConfirmTime = a.cfg.ChainParams.DPoSConfiguration.StopConfirmBlockTime } else { stopConfirmTime = a.cfg.ChainParams.DPoSConfiguration.StopConfirmBlockTime diff --git a/pow/revertlistener.go b/pow/revertlistener.go index 87e8e4c9f..d0ca7b3d8 100644 --- a/pow/revertlistener.go +++ b/pow/revertlistener.go @@ -31,7 +31,7 @@ func (pow *Service) ListenForRevert() { lastBlockTimestamp := int64(pow.arbiters.GetLastBlockTimestamp()) localTimestamp := pow.chain.TimeSource.AdjustedTime().Unix() var noBlockTime int64 - if currentHeight < pow.chainParams.DPoSConfiguration.RevertToPOWV1Height { + if currentHeight < pow.chainParams.DPoSConfiguration.ChangeViewV1Height { noBlockTime = pow.chainParams.DPoSConfiguration.RevertToPOWNoBlockTime } else { noBlockTime = pow.chainParams.DPoSConfiguration.RevertToPOWNoBlockTimeV1