From 80662702734cda3923095a3cbbe526704aeaacf5 Mon Sep 17 00:00:00 2001 From: krish Date: Mon, 24 Jul 2023 10:12:34 +0800 Subject: [PATCH 1/3] feat: merge PR #105 --- eth/handler.go | 4 +++- eth/protocols/snap/handler.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 77ac554ce3..bcca1ff3b1 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -168,8 +168,10 @@ func newHandler(config *handlerConfig) (*handler, error) { log.Warn("Switch sync mode from full sync to snap sync") } } else { - if h.chain.CurrentBlock().Number.Uint64() > 0 { + blockNumber := h.chain.CurrentBlock().Number + if blockNumber.Uint64() > 0 && (!config.Chain.Config().IsOptimism() || blockNumber.Cmp(config.Chain.Config().BedrockBlock) != 0) { // Print warning log if database is not empty to run snap sync. + // For OP chains, snap sync from bedrock block is allowed. log.Warn("Switch sync mode from snap sync to full sync") } else { // If snap sync was requested and our database is empty, grant it diff --git a/eth/protocols/snap/handler.go b/eth/protocols/snap/handler.go index d7c9400440..e8ed0fd3eb 100644 --- a/eth/protocols/snap/handler.go +++ b/eth/protocols/snap/handler.go @@ -469,7 +469,7 @@ func ServiceGetByteCodesQuery(chain *core.BlockChain, req *GetByteCodesPacket) [ // Peers should not request the empty code, but if they do, at // least sent them back a correct response without db lookups codes = append(codes, []byte{}) - } else if blob, err := chain.ContractCodeWithPrefix(hash); err == nil { + } else if blob, err := chain.ContractCode(hash); err == nil { codes = append(codes, blob) bytes += uint64(len(blob)) } From 5c2d863a7ed865cf614a8ddbbe50d59580254355 Mon Sep 17 00:00:00 2001 From: krish Date: Mon, 4 Dec 2023 18:16:21 +0800 Subject: [PATCH 2/3] debug: add debug info for SharedPool --- core/state/state_object.go | 4 ++++ core/state/statedb.go | 1 + 2 files changed, 5 insertions(+) diff --git a/core/state/state_object.go b/core/state/state_object.go index 2bf9dd2f4e..ed0d7f21b5 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" @@ -178,8 +179,10 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) { } // if L1 cache miss, try to get it from shared pool if s.sharedOriginStorage != nil { + log.Info("debug: sharedOriginStorage enabled") val, ok := s.sharedOriginStorage.Load(key) if !ok { + log.Info("debug: get OriginStorage", "key", key, "value", val) return common.Hash{}, false } s.originStorage[key] = val.(common.Hash) @@ -190,6 +193,7 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) { func (s *stateObject) setOriginStorage(key common.Hash, value common.Hash) { if s.db.writeOnSharedStorage && s.sharedOriginStorage != nil { + log.Info("debug: set OriginStorage", "key", key, "value", value) s.sharedOriginStorage.Store(key, value) } s.originStorage[key] = value diff --git a/core/state/statedb.go b/core/state/statedb.go index b4296a9498..952ffa6e94 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -169,6 +169,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) // NewWithSharedPool creates a new state with sharedStorge on layer 1.5 func NewWithSharedPool(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) { + log.Info("debug: NewWithSharedPool called") statedb, err := New(root, db, snaps) if err != nil { return nil, err From d3c9baafa5f08addd0e3bc58a62e283adf5579a5 Mon Sep 17 00:00:00 2001 From: Krish Date: Wed, 21 Feb 2024 17:08:15 +0800 Subject: [PATCH 3/3] fix: disconnect peer when header is lower as static peer can reassign header tasks --- core/state/state_object.go | 4 ---- core/state/statedb.go | 1 - eth/protocols/eth/handler.go | 10 ++++------ 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/core/state/state_object.go b/core/state/state_object.go index ed0d7f21b5..2bf9dd2f4e 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -27,7 +27,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" @@ -179,10 +178,8 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) { } // if L1 cache miss, try to get it from shared pool if s.sharedOriginStorage != nil { - log.Info("debug: sharedOriginStorage enabled") val, ok := s.sharedOriginStorage.Load(key) if !ok { - log.Info("debug: get OriginStorage", "key", key, "value", val) return common.Hash{}, false } s.originStorage[key] = val.(common.Hash) @@ -193,7 +190,6 @@ func (s *stateObject) getOriginStorage(key common.Hash) (common.Hash, bool) { func (s *stateObject) setOriginStorage(key common.Hash, value common.Hash) { if s.db.writeOnSharedStorage && s.sharedOriginStorage != nil { - log.Info("debug: set OriginStorage", "key", key, "value", value) s.sharedOriginStorage.Store(key, value) } s.originStorage[key] = value diff --git a/core/state/statedb.go b/core/state/statedb.go index 952ffa6e94..b4296a9498 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -169,7 +169,6 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) // NewWithSharedPool creates a new state with sharedStorge on layer 1.5 func NewWithSharedPool(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) { - log.Info("debug: NewWithSharedPool called") statedb, err := New(root, db, snaps) if err != nil { return nil, err diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 5643e6b767..397cefdc2b 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -17,7 +17,6 @@ package eth import ( - "errors" "fmt" "math/big" "time" @@ -25,7 +24,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/eth/etherror" "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" @@ -162,11 +160,11 @@ func Handle(backend Backend, peer *Peer) error { case errors.Is(err, etherror.ErrNoHeadersDelivered): // ignore no headers delivered peer.Log().Warn("Message handling failed with no headers") - */ - case errors.Is(err, etherror.ErrHeaderBatchAnchorLow): - // ignore lower header anchor within tolerance - peer.Log().Warn("Message handling failed with lower batch anchor") + case errors.Is(err, etherror.ErrHeaderBatchAnchorLow): + // ignore lower header anchor within tolerance + peer.Log().Warn("Message handling failed with lower batch anchor") + */ case err != nil: peer.Log().Debug("Message handling failed in `eth`", "err", err) return err