From 725d55514bb3f31881e4cb410e0962ae4fc296cb Mon Sep 17 00:00:00 2001 From: junnm Date: Wed, 13 Sep 2023 17:39:56 +0800 Subject: [PATCH] close #50 , reduce reorged blocks --- consensus/posa/amazon.go | 2 +- consensus/posa/posa.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/consensus/posa/amazon.go b/consensus/posa/amazon.go index 529c32559506..3fb31ab68ad7 100644 --- a/consensus/posa/amazon.go +++ b/consensus/posa/amazon.go @@ -9,7 +9,7 @@ import ( // // The Amazon Hardfork includes the following upgrades: // - KCC Staking Contract: Add a new method to migrate GoDao's KCS -// - KCC Peg Token: Add a method to migrate stuck tokens +// - KCC Peg Token: Add a method to migrate tokens // - Consensus: Reduce reorged blocks // diff --git a/consensus/posa/posa.go b/consensus/posa/posa.go index 075ad105d00f..9526b8bce006 100644 --- a/consensus/posa/posa.go +++ b/consensus/posa/posa.go @@ -1044,10 +1044,16 @@ func (c *POSA) Seal(chain consensus.ChainHeaderReader, block *types.Block, resul delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple if header.Difficulty.Cmp(diffNoTurn) == 0 { // It's not our turn explicitly to sign, delay it a bit - wiggle := time.Duration(len(snap.Validators)/2+1) * wiggleTime - delay += time.Duration(rand.Int63n(int64(wiggle))) + wiggleMax := time.Duration(len(snap.Validators)/2+1) * wiggleTime + wiggle := time.Duration(rand.Int63n(int64(wiggleMax))) - log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle)) + if wiggle < wiggleTime { + wiggle = wiggleTime + } + + delay += wiggle + + log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggleMax)) } // Sign all the things! sighash, err := signFn(accounts.Account{Address: val}, accounts.MimetypePOSA, POSARLP(header))