core: remove *uint64 for TxLookupLimit

This commit is contained in:
Felix Lange 2025-06-18 23:20:05 +02:00
parent 43cb1eed45
commit 6fa66e40a3
4 changed files with 19 additions and 26 deletions

View file

@ -175,15 +175,12 @@ type BlockChainConfig struct {
Overrides *ChainOverrides // Optional chain config overrides Overrides *ChainOverrides // Optional chain config overrides
VmConfig vm.Config // Config options for the EVM Interpreter VmConfig vm.Config // Config options for the EVM Interpreter
// TxLookupLimit specifies the maximum number of blocks from head whose tx // TxLookupLimit specifies the maximum number of blocks from head for which
// indices are reserved. // transaction hashes will be indexed.
// //
// If the value is zero, then the transaction indexes of the entire chain // If the value is zero, all transactions of the entire chain will be indexed.
// should be reserved. // If the value is -1, indexing is disabled. This is the default setting.
// TxLookupLimit int64
// If the value is nil, it means the transaction indexing is disabled.
// For instance, the chain is opened in read-only mode.
TxLookupLimit *uint64
} }
// DefaultConfig returns the default config. // DefaultConfig returns the default config.
@ -197,6 +194,9 @@ func DefaultConfig() *BlockChainConfig {
SnapshotLimit: 256, SnapshotLimit: 256,
SnapshotWait: true, SnapshotWait: true,
ChainHistoryMode: history.KeepAll, ChainHistoryMode: history.KeepAll,
// Transaction indexing is disabled by default.
// This is appropriate for most unit tests.
TxLookupLimit: -1,
} }
} }
@ -501,8 +501,8 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
} }
// Start tx indexer if it's enabled. // Start tx indexer if it's enabled.
if bc.cfg.TxLookupLimit != nil { if bc.cfg.TxLookupLimit >= 0 {
bc.txIndexer = newTxIndexer(*bc.cfg.TxLookupLimit, bc) bc.txIndexer = newTxIndexer(uint64(bc.cfg.TxLookupLimit), bc)
} }
return bc, nil return bc, nil
} }

View file

@ -20,6 +20,7 @@ package eth
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math"
"math/big" "math/big"
"runtime" "runtime"
"sync" "sync"
@ -205,10 +206,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
StateHistory: config.StateHistory, StateHistory: config.StateHistory,
StateScheme: scheme, StateScheme: scheme,
ChainHistoryMode: config.HistoryMode, ChainHistoryMode: config.HistoryMode,
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
VmConfig: vmConfig, VmConfig: vmConfig,
TxLookupLimit: &config.TransactionHistory,
} }
) )
if config.VMTrace != "" { if config.VMTrace != "" {
traceConfig := json.RawMessage("{}") traceConfig := json.RawMessage("{}")
if config.VMTraceJsonConfig != "" { if config.VMTraceJsonConfig != "" {

View file

@ -276,9 +276,8 @@ func testFilters(t *testing.T, history uint64, noHistory bool) {
gen.AddTx(tx) gen.AddTx(tx)
} }
}) })
var l uint64
options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme)
options.TxLookupLimit = &l options.TxLookupLimit = 0 // index all txs
bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -436,9 +435,8 @@ func TestRangeLogs(t *testing.T) {
} }
chain, _ := core.GenerateChain(gspec.Config, gspec.ToBlock(), ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {}) chain, _ := core.GenerateChain(gspec.Config, gspec.ToBlock(), ethash.NewFaker(), db, 1000, func(i int, gen *core.BlockGen) {})
var l uint64
options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme)
options.TxLookupLimit = &l options.TxLookupLimit = 0 // index all txs
bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -442,19 +442,12 @@ type testBackend struct {
} }
func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend { func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend {
var ( options := core.DefaultConfig().WithArchive(true)
txLookupLimit = uint64(0) options.TxLookupLimit = 0 // index all txs
options = &core.BlockChainConfig{
TrieCleanLimit: 256,
TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 0,
ArchiveMode: true, // Archive mode
TxLookupLimit: &txLookupLimit,
}
)
accman, acc := newTestAccountManager(t) accman, acc := newTestAccountManager(t)
gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)} gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)}
// Generate blocks for testing // Generate blocks for testing
db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator) db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator)