From d03d9e3b307bc08be25046fc8651be257d346868 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 4 Mar 2024 11:39:30 -0500 Subject: [PATCH 1/4] Update Timestamps to millisecond percision. --- consensus/clique/clique.go | 16 +++++++++------- geth-poa/genesis.json | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index e9db5be56ad4..cd6e29f57fde 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -21,13 +21,14 @@ 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" @@ -255,7 +256,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().Unix()) { + if header.Time > uint64(time.Now().UnixMilli()) { return consensus.ErrFutureBlock } // Checkpoint blocks need to enforce zero beneficiary @@ -346,7 +347,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/1000 > header.Time { + if parent.Time+c.config.PeriodMs > header.Time { return errInvalidTimestamp } // Verify that the gasUsed is <= gasLimit @@ -575,9 +576,10 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header if parent == nil { return consensus.ErrUnknownAncestor } - header.Time = parent.Time + c.config.PeriodMs/1000 - if header.Time < uint64(time.Now().Unix()) { - header.Time = uint64(time.Now().Unix()) + + header.Time = parent.Time + c.config.PeriodMs + if header.Time < uint64(time.Now().UnixMilli()) { + header.Time = uint64(time.Now().UnixMilli()) } return nil } @@ -657,7 +659,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.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple + delay := time.UnixMilli(int64(header.Time)).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 diff --git a/geth-poa/genesis.json b/geth-poa/genesis.json index a3696f308707..a3653833e99d 100644 --- a/geth-poa/genesis.json +++ b/geth-poa/genesis.json @@ -20,7 +20,7 @@ } }, "nonce": "0x0", - "timestamp": "0x6546df6d", + "timestamp": "0x18E0A4E0D22", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000d9cd8E5DE6d55f796D980B818D350C0746C25b97788EBABe5c3dD422Ef92Ca6714A69e2eabcE1Ee4f6ba5bca9b489de3a4ac3a57823d5d97d608feb90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "gasLimit": "0x1c9c380", "difficulty": "0x1", From 471c224e133d8f4de0e0e1c89331edabb37ad651 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Mon, 11 Mar 2024 12:31:47 -0400 Subject: [PATCH 2/4] Reduce wiggle to 100ms. --- consensus/clique/clique.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index cd6e29f57fde..e4a8a6d77aa1 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -53,7 +53,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 = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers + wiggleTime = 100 * time.Millisecond // Random delay (per signer) to allow concurrent signers ) // Clique proof-of-authority protocol constants. From 928d262dfa7b1eabb9b7f3a4c38ca76d5c4c2848 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Wed, 24 Apr 2024 09:48:08 -0400 Subject: [PATCH 3/4] feat: removes deadlock causing delay reassignment --- consensus/clique/clique.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index e4a8a6d77aa1..ecf5be129ccf 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -674,10 +674,6 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res } copy(header.Extra[len(header.Extra)-extraSeal:], sighash) - // For now, hard code delay to 20ms less than block period. - // This may cause deadlocks with certain numbers of nodes, more testing is needed. - delay = time.Millisecond * (time.Duration(c.config.PeriodMs - 20)) - // Wait until sealing is terminated or delay timeout. log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay)) go func() { From d9d88c0578a68aa7e4cda580103edb1938d42d6a Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Wed, 24 Apr 2024 09:48:40 -0400 Subject: [PATCH 4/4] comments out issue causing if statement for fullsync --- eth/handler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 1a6dc38207cf..ed9b2a04a18a 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -240,10 +240,10 @@ func newHandler(config *handlerConfig) (*handler, error) { // accept each others' blocks until a restart. Unfortunately we haven't figured // out a way yet where nodes can decide unilaterally whether the network is new // or not. This should be fixed if we figure out a solution. - if !h.synced.Load() && config.Sync != downloader.FullSync { - log.Warn("Syncing, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash()) - return 0, nil - } + // if !h.synced.Load() && config.Sync != downloader.FullSync { + // log.Warn("Syncing, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash()) + // return 0, nil + // } if h.merger.TDDReached() { // The blocks from the p2p network is regarded as untrusted // after the transition. In theory block gossip should be disabled