Skip to content

Commit

Permalink
Fix txIndexer
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Sep 21, 2024
1 parent 5fcd172 commit ca3d7ee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,12 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
rawdb.WriteChainConfig(db, genesisHash, chainConfig)
}

if txLookupLimit == nil {
if txLookupLimit != nil {
txLookupLimit = new(uint64)
*txLookupLimit = txLookupCacheLimit
bc.txIndexer = newTxIndexer(*txLookupLimit, bc)
}

bc.txIndexer = newTxIndexer(*txLookupLimit, bc)

return bc, nil
}

Expand Down Expand Up @@ -1569,7 +1568,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// generated.
batch := bc.db.NewBatch()
for i, block := range blockChain {
if bc.txIndexer.limit == 0 || ancientLimit <= bc.txIndexer.limit || block.NumberU64() >= ancientLimit-bc.txIndexer.limit {
if bc.txIndexer == nil || bc.txIndexer.limit == 0 || ancientLimit <= bc.txIndexer.limit || block.NumberU64() >= ancientLimit-bc.txIndexer.limit {
rawdb.WriteTxLookupEntriesByBlock(batch, block)
} else if rawdb.ReadTxIndexTail(bc.db) != nil {
rawdb.WriteTxLookupEntriesByBlock(batch, block)
Expand Down
6 changes: 6 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,18 @@ func (bc *BlockChain) GetVMConfig() *vm.Config {
// 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) {
if bc.txIndexer == nil {
return
}
bc.txIndexer.limit = limit
}

// TxLookupLimit retrieves the txlookup limit used by blockchain to prune
// stale transaction indices.
func (bc *BlockChain) TxLookupLimit() uint64 {
if bc.txIndexer == nil {
return 0
}
return bc.txIndexer.limit
}

Expand Down
1 change: 0 additions & 1 deletion core/blockchain_repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,6 @@ func testLongReorgedSnapSyncingDeepRepair(t *testing.T, snapshots bool) {
}

func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
t.Parallel()
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
testRepairWithScheme(t, tt, snapshots, scheme)
}
Expand Down
2 changes: 0 additions & 2 deletions core/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ func TestLowCommitCrashWithNewSnapshot(t *testing.T) {
// Expected head block : C2
// Expected snapshot disk : C4

t.Parallel()
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
test := &crashSnapshotTest{
snapshotTestBasic{
Expand Down Expand Up @@ -575,7 +574,6 @@ func TestHighCommitCrashWithNewSnapshot(t *testing.T) {
// Expected head block : G
// Expected snapshot disk : C4

t.Parallel()
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
expHead := uint64(0)
if scheme == rawdb.PathScheme {
Expand Down

0 comments on commit ca3d7ee

Please sign in to comment.