From 76b546c15b6fa51b68b2effdfae276bfdf74df6e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 24 Apr 2025 13:50:46 +0200 Subject: [PATCH] core/types: rename ReceiptsToRLP -> EncodeBlockReceiptLists --- cmd/utils/cmd.go | 2 +- core/blockchain_test.go | 22 +++++++++++----------- core/rawdb/accessors_chain_test.go | 6 +++--- core/txindexer_test.go | 6 +++--- core/types/receipt.go | 4 ++-- eth/downloader/downloader_test.go | 2 +- eth/downloader/queue_test.go | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index b5734eace2..b332a060de 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -309,7 +309,7 @@ func ImportHistory(chain *core.BlockChain, dir string, network string) error { if err != nil { return fmt.Errorf("error reading receipts %d: %w", it.Number(), err) } - encReceipts := types.ReceiptsToRLP([]types.Receipts{receipts}) + encReceipts := types.EncodeBlockReceiptLists([]types.Receipts{receipts}) if _, err := chain.InsertReceiptChain([]*types.Block{block}, encReceipts, 2^64-1); err != nil { return fmt.Errorf("error inserting body %d: %w", it.Number(), err) } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 9ee8e35f77..434b494490 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -734,7 +734,7 @@ func testFastVsFullChains(t *testing.T, scheme string) { fast, _ := NewBlockChain(fastDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) defer fast.Stop() - if n, err := fast.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), 0); err != nil { + if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } // Freezer style fast import the chain. @@ -747,7 +747,7 @@ func testFastVsFullChains(t *testing.T, scheme string) { ancient, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) defer ancient.Stop() - if n, err := ancient.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), uint64(len(blocks)/2)); err != nil { + if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(len(blocks)/2)); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } @@ -871,7 +871,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { fast, _ := NewBlockChain(fastDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) defer fast.Stop() - if n, err := fast.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), 0); err != nil { + if n, err := fast.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } assert(t, "fast", fast, height, height, 0) @@ -884,7 +884,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) { ancient, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) defer ancient.Stop() - if n, err := ancient.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), uint64(3*len(blocks)/4)); err != nil { + if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } assert(t, "ancient", ancient, height, height, 0) @@ -1696,7 +1696,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) { defer ancientDb.Close() ancient, _ := NewBlockChain(ancientDb, DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil) - if n, err := ancient.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), uint64(3*len(blocks)/4)); err != nil { + if n, err := ancient.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), uint64(3*len(blocks)/4)); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } rawdb.WriteLastPivotNumber(ancientDb, blocks[len(blocks)-1].NumberU64()) // Force fast sync behavior @@ -1991,7 +1991,7 @@ func testInsertKnownChainData(t *testing.T, typ string, scheme string) { } } else if typ == "receipts" { inserter = func(blocks []*types.Block, receipts []types.Receipts) error { - _, err = chain.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), 0) + _, err = chain.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0) return err } asserter = func(t *testing.T, block *types.Block) { @@ -2157,7 +2157,7 @@ func testInsertKnownChainDataWithMerging(t *testing.T, typ string, mergeHeight i } } else if typ == "receipts" { inserter = func(blocks []*types.Block, receipts []types.Receipts) error { - _, err = chain.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), 0) + _, err = chain.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), 0) return err } asserter = func(t *testing.T, block *types.Block) { @@ -4205,10 +4205,10 @@ func testChainReorgSnapSync(t *testing.T, ancientLimit uint64) { chain, _ := NewBlockChain(db, DefaultCacheConfigWithScheme(rawdb.PathScheme), gspec, nil, beacon.New(ethash.NewFaker()), vm.Config{}, nil) defer chain.Stop() - if n, err := chain.InsertReceiptChain(blocks, types.ReceiptsToRLP(receipts), ancientLimit); err != nil { + if n, err := chain.InsertReceiptChain(blocks, types.EncodeBlockReceiptLists(receipts), ancientLimit); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } - if n, err := chain.InsertReceiptChain(chainA, types.ReceiptsToRLP(receiptsA), ancientLimit); err != nil { + if n, err := chain.InsertReceiptChain(chainA, types.EncodeBlockReceiptLists(receiptsA), ancientLimit); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } // If the common ancestor is below the ancient limit, rewind the chain head. @@ -4218,7 +4218,7 @@ func testChainReorgSnapSync(t *testing.T, ancientLimit uint64) { rawdb.WriteLastPivotNumber(db, ancestor) chain.SetHead(ancestor) } - if n, err := chain.InsertReceiptChain(chainB, types.ReceiptsToRLP(receiptsB), ancientLimit); err != nil { + if n, err := chain.InsertReceiptChain(chainB, types.EncodeBlockReceiptLists(receiptsB), ancientLimit); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } head := chain.CurrentSnapBlock() @@ -4336,7 +4336,7 @@ func testInsertChainWithCutoff(t *testing.T, cutoff uint64, ancientLimit uint64, if n, err := chain.InsertHeadersBeforeCutoff(headersBefore); err != nil { t.Fatalf("failed to insert headers before cutoff %d: %v", n, err) } - if n, err := chain.InsertReceiptChain(blocksAfter, types.ReceiptsToRLP(receiptsAfter), ancientLimit); err != nil { + if n, err := chain.InsertReceiptChain(blocksAfter, types.EncodeBlockReceiptLists(receiptsAfter), ancientLimit); err != nil { t.Fatalf("failed to insert receipt %d: %v", n, err) } headSnap := chain.CurrentSnapBlock() diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index a3dce3e3be..d98fc9a1eb 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -443,7 +443,7 @@ func TestAncientStorage(t *testing.T) { } // Write and verify the header in the database - WriteAncientBlocks(db, []*types.Block{block}, types.ReceiptsToRLP([]types.Receipts{nil})) + WriteAncientBlocks(db, []*types.Block{block}, types.EncodeBlockReceiptLists([]types.Receipts{nil})) if blob := ReadHeaderRLP(db, hash, number); len(blob) == 0 { t.Fatalf("no header returned") @@ -613,7 +613,7 @@ func BenchmarkWriteAncientBlocks(b *testing.B) { blocks := allBlocks[i : i+length] receipts := batchReceipts[:length] - writeSize, err := WriteAncientBlocks(db, blocks, types.ReceiptsToRLP(receipts)) + writeSize, err := WriteAncientBlocks(db, blocks, types.EncodeBlockReceiptLists(receipts)) if err != nil { b.Fatal(err) } @@ -913,7 +913,7 @@ func TestHeadersRLPStorage(t *testing.T) { } receipts := make([]types.Receipts, 100) // Write first half to ancients - WriteAncientBlocks(db, chain[:50], types.ReceiptsToRLP(receipts[:50])) + WriteAncientBlocks(db, chain[:50], types.EncodeBlockReceiptLists(receipts[:50])) // Write second half to db for i := 50; i < 100; i++ { WriteCanonicalHash(db, chain[i].Hash(), chain[i].NumberU64()) diff --git a/core/txindexer_test.go b/core/txindexer_test.go index a21978cbad..615a34de41 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -117,7 +117,7 @@ func TestTxIndexer(t *testing.T) { } for _, c := range cases { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) - rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), types.ReceiptsToRLP(append([]types.Receipts{{}}, receipts...))) + rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), types.EncodeBlockReceiptLists(append([]types.Receipts{{}}, receipts...))) // Index the initial blocks from ancient store indexer := &txIndexer{ @@ -236,7 +236,7 @@ func TestTxIndexerRepair(t *testing.T) { } for _, c := range cases { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) - encReceipts := types.ReceiptsToRLP(append([]types.Receipts{{}}, receipts...)) + encReceipts := types.EncodeBlockReceiptLists(append([]types.Receipts{{}}, receipts...)) rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), encReceipts) // Index the initial blocks from ancient store @@ -427,7 +427,7 @@ func TestTxIndexerReport(t *testing.T) { } for _, c := range cases { db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false) - encReceipts := types.ReceiptsToRLP(append([]types.Receipts{{}}, receipts...)) + encReceipts := types.EncodeBlockReceiptLists(append([]types.Receipts{{}}, receipts...)) rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), encReceipts) // Index the initial blocks from ancient store diff --git a/core/types/receipt.go b/core/types/receipt.go index 3aabab516c..5d13ddb649 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -378,8 +378,8 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu return nil } -// ReceiptsToRLP encodes a slice of receipts into RLP. -func ReceiptsToRLP(receipts []Receipts) []rlp.RawValue { +// EncodeBlockReceiptLists encodes a list of block receipt lists into RLP. +func EncodeBlockReceiptLists(receipts []Receipts) []rlp.RawValue { result := make([]rlp.RawValue, 0) for _, receipt := range receipts { storageReceipts := make([]*ReceiptForStorage, len(receipt)) diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 901448c2c5..ecc820fd35 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -269,7 +269,7 @@ func (dlp *downloadTesterPeer) RequestReceipts(hashes []common.Hash, sink chan * req := ð.Request{ Peer: dlp.id, } - resp := eth.ReceiptsRLPResponse(types.ReceiptsToRLP(receipts)) + resp := eth.ReceiptsRLPResponse(types.EncodeBlockReceiptLists(receipts)) res := ð.Response{ Req: req, Res: &resp, diff --git a/eth/downloader/queue_test.go b/eth/downloader/queue_test.go index 8c3df24b65..854acf3d8f 100644 --- a/eth/downloader/queue_test.go +++ b/eth/downloader/queue_test.go @@ -367,7 +367,7 @@ func XTestDelivery(t *testing.T) { for i, receipt := range rcs { hashes[i] = types.DeriveSha(receipt, hasher) } - _, err := q.DeliverReceipts(peer.id, types.ReceiptsToRLP(rcs), hashes) + _, err := q.DeliverReceipts(peer.id, types.EncodeBlockReceiptLists(rcs), hashes) if err != nil { fmt.Printf("delivered %d receipts %v\n", len(rcs), err) }