From 585fc9455e07ca094700cb6826437d49bc7b9dfe Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 3 Jun 2025 12:49:58 +0200 Subject: [PATCH 1/5] debug missing receipt --- core/rawdb/accessors_chain.go | 3 +++ eth/downloader/downloader.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 2386246caf76..008ecc438b3a 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -623,6 +623,9 @@ func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rec // WriteRawReceipts stores all the transaction receipts belonging to a block. func WriteRawReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, receipts rlp.RawValue) { + if len(receipts) == 0 { + panic("empty receipts in snap sync block") + } // Store the flattened receipt slice if err := db.Put(blockReceiptsKey(number, hash), receipts); err != nil { log.Crit("Failed to store block receipts", "err", err) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 762fb9283ea0..74975f79fc13 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1039,7 +1039,11 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state for i, result := range results { blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()) receipts[i] = result.Receipts + if len(result.Receipts) == 0 { + panic("empty receipts in snap sync block") + } } + fmt.Printf(">>>> Committing %d snap-sync blocks, first %d, last %d\n", len(results), first.Number.Uint64(), last.Number.Uint64()) if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil { log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err) return fmt.Errorf("%w: %v", errInvalidChain, err) From 7a4f4ff5b28a7fad771f5611662452063225e861 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 3 Jun 2025 13:10:36 +0200 Subject: [PATCH 2/5] try fix --- eth/downloader/downloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 74975f79fc13..3c764c467499 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1040,7 +1040,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()) receipts[i] = result.Receipts if len(result.Receipts) == 0 { - panic("empty receipts in snap sync block") + receipts[i] = rlp.EmptyList } } fmt.Printf(">>>> Committing %d snap-sync blocks, first %d, last %d\n", len(results), first.Number.Uint64(), last.Number.Uint64()) From d9f529d0758c45ee249a0a3356668c115b2502ac Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 3 Jun 2025 13:12:56 +0200 Subject: [PATCH 3/5] remove debuggging code --- core/rawdb/accessors_chain.go | 3 --- eth/downloader/downloader.go | 1 - 2 files changed, 4 deletions(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 008ecc438b3a..2386246caf76 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -623,9 +623,6 @@ func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, rec // WriteRawReceipts stores all the transaction receipts belonging to a block. func WriteRawReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, receipts rlp.RawValue) { - if len(receipts) == 0 { - panic("empty receipts in snap sync block") - } // Store the flattened receipt slice if err := db.Put(blockReceiptsKey(number, hash), receipts); err != nil { log.Crit("Failed to store block receipts", "err", err) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 3c764c467499..2183cc0a4a6d 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1043,7 +1043,6 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state receipts[i] = rlp.EmptyList } } - fmt.Printf(">>>> Committing %d snap-sync blocks, first %d, last %d\n", len(results), first.Number.Uint64(), last.Number.Uint64()) if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil { log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err) return fmt.Errorf("%w: %v", errInvalidChain, err) From 2bad9dbca9dab642640555aa449068b0b6f75aa9 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 3 Jun 2025 15:52:53 +0200 Subject: [PATCH 4/5] add comment --- eth/downloader/downloader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 2183cc0a4a6d..26d0c841aa77 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1039,6 +1039,10 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state for i, result := range results { blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()) receipts[i] = result.Receipts + // Blockchain expects the receipts to be properly encoded + // as they are inserted into the db as they are. + // This workaround makes sure that blocks with no receipts + // have a valid encoding. if len(result.Receipts) == 0 { receipts[i] = rlp.EmptyList } From d8bed16fa7ead035bd2b0f0a624bb624deb98b29 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 4 Jun 2025 14:32:55 +0200 Subject: [PATCH 5/5] eth/downloader: different fix --- eth/downloader/downloader.go | 7 ------- eth/downloader/queue.go | 9 +++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 26d0c841aa77..762fb9283ea0 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -1039,13 +1039,6 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state for i, result := range results { blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body()) receipts[i] = result.Receipts - // Blockchain expects the receipts to be properly encoded - // as they are inserted into the db as they are. - // This workaround makes sure that blocks with no receipts - // have a valid encoding. - if len(result.Receipts) == 0 { - receipts[i] = rlp.EmptyList - } } if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil { log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index bd7acadfc4e8..9fe169d5f741 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -83,8 +83,13 @@ func newFetchResult(header *types.Header, snapSync bool) *fetchResult { } else if header.WithdrawalsHash != nil { item.Withdrawals = make(types.Withdrawals, 0) } - if snapSync && !header.EmptyReceipts() { - item.pending.Store(item.pending.Load() | (1 << receiptType)) + if snapSync { + if header.EmptyReceipts() { + // Ensure the receipts list is valid even if it isn't actively fetched. + item.Receipts = rlp.EmptyList + } else { + item.pending.Store(item.pending.Load() | (1 << receiptType)) + } } return item }