Skip to content

Commit

Permalink
close #50 , reduce reorged blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
junnm committed Sep 13, 2023
1 parent 18510c2 commit 725d555
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion consensus/posa/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//

Expand Down
12 changes: 9 additions & 3 deletions consensus/posa/posa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 725d555

Please sign in to comment.