fix: testcases

This commit is contained in:
anshalshukla 2024-09-03 16:21:20 +05:30
parent 43043ed7ec
commit cec3ee18d8
No known key found for this signature in database
GPG key ID: 84BE5474523D8CBC
7 changed files with 39 additions and 13 deletions

View file

@ -542,6 +542,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
if txLookupLimit == nil { if txLookupLimit == nil {
txLookupLimit = new(uint64) txLookupLimit = new(uint64)
*txLookupLimit = txLookupCacheLimit
} }
bc.txIndexer = newTxIndexer(*txLookupLimit, bc) bc.txIndexer = newTxIndexer(*txLookupLimit, bc)

View file

@ -436,6 +436,18 @@ func (bc *BlockChain) GetVMConfig() *vm.Config {
return &bc.vmConfig 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. // TxIndexProgress returns the transaction indexing progress.
func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) { func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) {
if bc.txIndexer == nil { if bc.txIndexer == nil {

View file

@ -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 // 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 // detect that it was fast syncing and not delete anything, since we can just pick
// up directly where we left off. // up directly where we left off.
func TestShortSnapSyncingRepair(t *testing.T) { testShortSnapSyncingRepair(t, false) } func TestShortSnapSyncingRepair(t *testing.T) {
func TestShortSnapSyncingRepairWithSnapshots(t *testing.T) { testShortSnapSyncingRepair(t, true) } 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) { func testShortSnapSyncingRepair(t *testing.T, snapshots bool) {
// Chain: // Chain:

View file

@ -62,7 +62,7 @@ func TestGeneratePOSChain(t *testing.T) {
config.ShanghaiBlock = common.Big0 config.ShanghaiBlock = common.Big0
config.CancunBlock = common.Big0 config.CancunBlock = common.Big0
config.PragueBlock = common.Big0 config.PragueBlock = common.Big0
config.VerkleBlock = common.Big0 // config.VerkleBlock = common.Big0
// init 0xaa with some storage elements // init 0xaa with some storage elements
storage := make(map[common.Hash]common.Hash) storage := make(map[common.Hash]common.Hash)

View file

@ -442,6 +442,7 @@ var (
) )
func TestProcessVerkle(t *testing.T) { func TestProcessVerkle(t *testing.T) {
t.Skip("not relevant to bor")
var ( var (
config = &params.ChainConfig{ config = &params.ChainConfig{
ChainID: big.NewInt(1), ChainID: big.NewInt(1),

View file

@ -18,6 +18,7 @@ package core
import ( import (
"math/big" "math/big"
"os"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -29,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/params" "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) { func TestTxIndexer(t *testing.T) {
var ( var (
testBankKey, _ = crypto.GenerateKey() testBankKey, _ = crypto.GenerateKey()
@ -210,9 +211,12 @@ func TestTxIndexer(t *testing.T) {
}, },
} }
borReceipts := make([]types.Receipts, len(receipts))
for _, c := range cases { for _, c := range cases {
db, _ := rawdb.NewDatabaseWithFreezer(rawdb.NewMemoryDatabase(), "", "", false, false, false) frdir := t.TempDir()
rawdb.WriteAncientBlocks(db, append([]*types.Block{gspec.ToBlock()}, blocks...), append([]types.Receipts{{}}, receipts...), nil, big.NewInt(0)) 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 // Index the initial blocks from ancient store
indexer := &txIndexer{ indexer := &txIndexer{
@ -237,5 +241,6 @@ func TestTxIndexer(t *testing.T) {
verify(db, 0, indexer) verify(db, 0, indexer)
db.Close() db.Close()
os.RemoveAll(frdir)
} }
} }

View file

@ -22,6 +22,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common" "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/core/txpool"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/protocols/eth" "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 // 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 // that user can't change limit during the snap sync. If changed, Geth
// will just blindly use the original one. // will just blindly use the original one.
// limit := h.chain.TxLookupLimit() limit := h.chain.TxLookupLimit()
// if stored := rawdb.ReadFastTxLookupLimit(h.database); stored == nil { if stored := rawdb.ReadFastTxLookupLimit(h.database); stored == nil {
// rawdb.WriteFastTxLookupLimit(h.database, limit) rawdb.WriteFastTxLookupLimit(h.database, limit)
// } else if *stored != limit { } else if *stored != limit {
// h.chain.SetTxLookupLimit(*stored) h.chain.SetTxLookupLimit(*stored)
// log.Warn("Update txLookup limit", "provided", limit, "updated", *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 // 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) err := h.downloader.LegacySync(op.peer.ID(), op.head, op.td, h.chain.Config().TerminalTotalDifficulty, op.mode)