Skip to content

Commit

Permalink
feat(bpos): instead RevertToPOWV1Height with new change view height
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Aug 4, 2023
1 parent a9e7725 commit 70d7bf9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
20 changes: 7 additions & 13 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -930,9 +925,8 @@ func (p *Configuration) newRewardPerBlock(targetTimePerBlock time.Duration, heig
generatedBlocksPerYear := 365 * 24 * 60 * 60 / blockGenerateInterval
factor := uint32(1)
if height >= p.HalvingRewardHeight {
factor = 2 + (height-p.HalvingRewardHeight)/p.HalvingRewardInterval
factor = 2 + (height-p.HalvingRewardHeight)/p.HalvingRewardInterval // HalvingRewardHeight: 1051200
}

return common.Fixed64(float64(newInflationPerYear) / float64(generatedBlocksPerYear) / math.Pow(2, float64(factor-1)))
}

Expand Down
3 changes: 1 addition & 2 deletions core/transaction/illegalproposaltransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func (t *IllegalProposalTransaction) HeightVersionCheck() error {

if blockHeight < chainParams.DPoSConfiguration.ChangeViewV1Height {
return errors.New(fmt.Sprintf("not support %s transaction "+
"with payload version %d after IllegalV2Height",
t.TxType().Name(), t.PayloadVersion()))
"before ChangeViewV1Height", t.TxType().Name()))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/transaction/reverttopowtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dpos/arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ 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
stopConfirmTime = a.cfg.ChainParams.DPoSConfiguration.StopConfirmBlockTimeV1
}

if localTimestamp-lastBlockTimestamp >= stopConfirmTime {
Expand Down
2 changes: 1 addition & 1 deletion dpos/manager/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
consensusReady = iota
consensusRunning

DefaultViewOffset = 10
DefaultViewOffset = 0
)

type Consensus struct {
Expand Down
2 changes: 1 addition & 1 deletion pow/revertlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70d7bf9

Please sign in to comment.