Skip to content

Commit

Permalink
Merge pull request #33 from primevprotocol/revert-modify-chain-to-ms-…
Browse files Browse the repository at this point in the history
…timestamps

revert: Updates timestamps to Millisecond Precision - Pre-Confirmations Decay
  • Loading branch information
mrekucci authored Mar 20, 2024
2 parents 8b89ba7 + 7b28ce8 commit 0172aa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import (
"bytes"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/metrics"
"io"
"math/big"
"math/rand"
"sync"
"time"

"github.com/ethereum/go-ethereum/metrics"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -53,7 +52,7 @@ const (
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
inmemorySignatures = 4096 // Number of recent block signatures to keep in memory

wiggleTime = 100 * time.Millisecond // Random delay (per signer) to allow concurrent signers
wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
)

// Clique proof-of-authority protocol constants.
Expand Down Expand Up @@ -256,7 +255,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
number := header.Number.Uint64()

// Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().UnixMilli()) {
if header.Time > uint64(time.Now().Unix()) {
return consensus.ErrFutureBlock
}
// Checkpoint blocks need to enforce zero beneficiary
Expand Down Expand Up @@ -347,7 +346,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
return consensus.ErrUnknownAncestor
}
if parent.Time+c.config.PeriodMs > header.Time {
if parent.Time+c.config.PeriodMs/1000 > header.Time {
return errInvalidTimestamp
}
// Verify that the gasUsed is <= gasLimit
Expand Down Expand Up @@ -576,10 +575,9 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
if parent == nil {
return consensus.ErrUnknownAncestor
}

header.Time = parent.Time + c.config.PeriodMs
if header.Time < uint64(time.Now().UnixMilli()) {
header.Time = uint64(time.Now().UnixMilli())
header.Time = parent.Time + c.config.PeriodMs/1000
if header.Time < uint64(time.Now().Unix()) {
header.Time = uint64(time.Now().Unix())
}
return nil
}
Expand Down Expand Up @@ -659,7 +657,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
}
}
// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.UnixMilli(int64(header.Time)).Sub(time.Now()) // nolint: gosimple
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.Signers)/2+1) * wiggleTime
Expand Down
2 changes: 1 addition & 1 deletion geth-poa/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"nonce": "0x0",
"timestamp": "0x18E0A4E0D22",
"timestamp": "0x6546df6d",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000d9cd8E5DE6d55f796D980B818D350C0746C25b97788EBABe5c3dD422Ef92Ca6714A69e2eabcE1Ee4f6ba5bca9b489de3a4ac3a57823d5d97d608feb90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1c9c380",
"difficulty": "0x1",
Expand Down

0 comments on commit 0172aa6

Please sign in to comment.