From 6e6b5087f19fb726d75d01059cda5c5b43164b06 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:38:35 +0200 Subject: [PATCH] cmd/geth: fix legacy receipt detection for empty db (#25609) --- cmd/geth/config.go | 5 +++-- cmd/geth/dbcmd.go | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 30565fda61..d877e2b5dd 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -175,12 +175,13 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { if cfg.Eth.NetworkId == 1 && ghash == params.MainnetGenesisHash { firstIdx = 46147 } - isLegacy, _, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx) + isLegacy, firstLegacy, err := dbHasLegacyReceipts(eth.ChainDb(), firstIdx) if err != nil { log.Error("Failed to check db for legacy receipts", "err", err) } else if isLegacy { stack.Close() - utils.Fatalf("Database has receipts with a legacy format. Please run `geth db freezer-migrate`.") + log.Error("Database has receipts with a legacy format", "firstLegacy", firstLegacy) + utils.Fatalf("Aborting. Please run `geth db freezer-migrate`.") } } diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index ab74277123..bb53a632e8 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -822,11 +822,15 @@ func dbHasLegacyReceipts(db ethdb.Database, firstIdx uint64) (bool, uint64, erro } } } - // Is first non-empty receipt legacy? first, err := db.Ancient("receipts", firstIdx) if err != nil { return false, 0, err } + // We looped over all receipts and they were all empty + if bytes.Equal(first, emptyRLPList) { + return false, 0, nil + } + // Is first non-empty receipt legacy? legacy, err = types.IsLegacyStoredReceipts(first) return legacy, firstIdx, err }