Skip to content

Commit

Permalink
fix: testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
anshalshukla committed Sep 3, 2024
1 parent 43043ed commit cec3ee1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions core/blockchain_repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ var (
)

func TestProcessVerkle(t *testing.T) {
t.Skip("not relevant to bor")
var (
config = &params.ChainConfig{
ChainID: big.NewInt(1),
Expand Down
11 changes: 8 additions & 3 deletions core/txindexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package core

import (
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -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()
Expand Down Expand Up @@ -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{
Expand All @@ -237,5 +241,6 @@ func TestTxIndexer(t *testing.T) {
verify(db, 0, indexer)

db.Close()
os.RemoveAll(frdir)
}
}
15 changes: 8 additions & 7 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cec3ee1

Please sign in to comment.