From b629f30e90e56a04c3e85a304eb2b0171128b021 Mon Sep 17 00:00:00 2001 From: Tei Im Date: Thu, 22 Jun 2023 15:22:52 +0900 Subject: [PATCH 1/3] Allow snap sync from bedrock genesis block --- eth/handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index b39f5d0fd8..4e5f26d3ad 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -162,7 +162,9 @@ 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 + // [Optimism] Allow snap sync from bedrock genesis block + if blockNumber.Uint64() > 0 && blockNumber.Cmp(config.Chain.Config().BedrockBlock) != 0 { // Print warning log if database is not empty to run snap sync. log.Warn("Switch sync mode from snap sync to full sync") } else { From 72befd40dae156ec4de7f9201fcbd8418927191b Mon Sep 17 00:00:00 2001 From: Tei Im Date: Thu, 22 Jun 2023 15:23:33 +0900 Subject: [PATCH 2/3] Fallback to legacy bytecode key when handling GetByteCodes --- eth/protocols/snap/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/protocols/snap/handler.go b/eth/protocols/snap/handler.go index 55781ac54b..c57ac5e2e3 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 041faffebc3d31752d2059bcf20f64c40773aa88 Mon Sep 17 00:00:00 2001 From: Tei Im Date: Mon, 3 Jul 2023 14:27:35 +0900 Subject: [PATCH 3/3] Add IsOptimism condition for snap sync --- eth/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 4e5f26d3ad..d72be2883a 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -163,9 +163,9 @@ func newHandler(config *handlerConfig) (*handler, error) { } } else { blockNumber := h.chain.CurrentBlock().Number - // [Optimism] Allow snap sync from bedrock genesis block - if blockNumber.Uint64() > 0 && blockNumber.Cmp(config.Chain.Config().BedrockBlock) != 0 { + 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