From cec3ee18d8042c21b723f406ffb84ae9b871b272 Mon Sep 17 00:00:00 2001 From: anshalshukla Date: Tue, 3 Sep 2024 16:21:20 +0530 Subject: [PATCH] fix: testcases --- core/blockchain.go | 1 + core/blockchain_reader.go | 12 ++++++++++++ core/blockchain_repair_test.go | 10 ++++++++-- core/chain_makers_test.go | 2 +- core/state_processor_test.go | 1 + core/txindexer_test.go | 11 ++++++++--- eth/sync.go | 15 ++++++++------- 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 3b78e9a15d..cc036ade0e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -542,6 +542,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis if txLookupLimit == nil { txLookupLimit = new(uint64) + *txLookupLimit = txLookupCacheLimit } bc.txIndexer = newTxIndexer(*txLookupLimit, bc) diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 568512e75f..e8e325ad8a 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -436,6 +436,18 @@ func (bc *BlockChain) GetVMConfig() *vm.Config { return &bc.vmConfig } +// SetTxLookupLimit is responsible for updating the txlookup limit to the +// original one stored in db if the new mismatches with the old one. +func (bc *BlockChain) SetTxLookupLimit(limit uint64) { + bc.txIndexer.limit = limit +} + +// TxLookupLimit retrieves the txlookup limit used by blockchain to prune +// stale transaction indices. +func (bc *BlockChain) TxLookupLimit() uint64 { + return bc.txIndexer.limit +} + // TxIndexProgress returns the transaction indexing progress. func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) { if bc.txIndexer == nil { diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index aa6427841b..a4f4d24f76 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -118,8 +118,14 @@ func testShortSnapSyncedRepair(t *testing.T, snapshots bool) { // not yet committed, but the process crashed. In this case we expect the chain to // detect that it was fast syncing and not delete anything, since we can just pick // up directly where we left off. -func TestShortSnapSyncingRepair(t *testing.T) { testShortSnapSyncingRepair(t, false) } -func TestShortSnapSyncingRepairWithSnapshots(t *testing.T) { testShortSnapSyncingRepair(t, true) } +func TestShortSnapSyncingRepair(t *testing.T) { + t.Skip("snap sync not supported in bor") + testShortSnapSyncingRepair(t, false) +} +func TestShortSnapSyncingRepairWithSnapshots(t *testing.T) { + t.Skip("snap sync not supported in bor") + testShortSnapSyncingRepair(t, true) +} func testShortSnapSyncingRepair(t *testing.T, snapshots bool) { // Chain: diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index f5d2873ee7..cc41f12177 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -62,7 +62,7 @@ func TestGeneratePOSChain(t *testing.T) { config.ShanghaiBlock = common.Big0 config.CancunBlock = common.Big0 config.PragueBlock = common.Big0 - config.VerkleBlock = common.Big0 + // config.VerkleBlock = common.Big0 // init 0xaa with some storage elements storage := make(map[common.Hash]common.Hash) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 604a8a314e..8804dff26b 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -442,6 +442,7 @@ var ( ) func TestProcessVerkle(t *testing.T) { + t.Skip("not relevant to bor") var ( config = ¶ms.ChainConfig{ ChainID: big.NewInt(1), diff --git a/core/txindexer_test.go b/core/txindexer_test.go index 329e3e67dd..ca1c86a055 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -18,6 +18,7 @@ package core import ( "math/big" + "os" "testing" "github.com/ethereum/go-ethereum/common" @@ -29,7 +30,7 @@ import ( "github.com/ethereum/go-ethereum/params" ) -// TestTxIndexer tests the functionalities for managing transaction indexes. +// TestTxIndexer tests the tx indexes are updated correctly. func TestTxIndexer(t *testing.T) { var ( testBankKey, _ = crypto.GenerateKey() @@ -210,9 +211,12 @@ func TestTxIndexer(t *testing.T) { }, } + borReceipts := make([]types.Receipts, len(receipts)) + for _, c := range cases { - db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false, false, false) - rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), nil, big.NewInt(0)) + frdir := t.TempDir() + db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), frdir, "", false, false, false) + _, _ = rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), append([]types.Receipts{{}}, borReceipts...), big.NewInt(0)) // Index the initial blocks from ancient store indexer := &txIndexer{ @@ -237,5 +241,6 @@ func TestTxIndexer(t *testing.T) { verify(db, 0, indexer) db.Close() + os.RemoveAll(frdir) } } diff --git a/eth/sync.go b/eth/sync.go index b614ca8f1e..eeb2781091 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -22,6 +22,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/protocols/eth" @@ -261,13 +262,13 @@ func (h *handler) doSync(op *chainSyncOp) error { // has been indexed. So here for the user-experience wise, it's non-optimal // that user can't change limit during the snap sync. If changed, Geth // will just blindly use the original one. - // limit := h.chain.TxLookupLimit() - // if stored := rawdb.ReadFastTxLookupLimit(h.database); stored == nil { - // rawdb.WriteFastTxLookupLimit(h.database, limit) - // } else if *stored != limit { - // h.chain.SetTxLookupLimit(*stored) - // log.Warn("Update txLookup limit", "provided", limit, "updated", *stored) - // } + limit := h.chain.TxLookupLimit() + if stored := rawdb.ReadFastTxLookupLimit(h.database); stored == nil { + rawdb.WriteFastTxLookupLimit(h.database, limit) + } else if *stored != limit { + h.chain.SetTxLookupLimit(*stored) + log.Warn("Update txLookup limit", "provided", limit, "updated", *stored) + } } // Run the sync cycle, and disable snap sync if we're past the pivot block err := h.downloader.LegacySync(op.peer.ID(), op.head, op.td, h.chain.Config().TerminalTotalDifficulty, op.mode)