diff --git a/core/blockchain.go b/core/blockchain.go index 432aee2147..7ac5910cb0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -175,15 +175,12 @@ type BlockChainConfig struct { Overrides *ChainOverrides // Optional chain config overrides VmConfig vm.Config // Config options for the EVM Interpreter - // TxLookupLimit specifies the maximum number of blocks from head whose tx - // indices are reserved. + // TxLookupLimit specifies the maximum number of blocks from head for which + // transaction hashes will be indexed. // - // If the value is zero, then the transaction indexes of the entire chain - // should be reserved. - // - // If the value is nil, it means the transaction indexing is disabled. - // For instance, the chain is opened in read-only mode. - TxLookupLimit *uint64 + // If the value is zero, all transactions of the entire chain will be indexed. + // If the value is -1, indexing is disabled. This is the default setting. + TxLookupLimit int64 } // DefaultConfig returns the default config. @@ -197,6 +194,9 @@ func DefaultConfig() *BlockChainConfig { SnapshotLimit: 256, SnapshotWait: true, 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. - if bc.cfg.TxLookupLimit != nil { - bc.txIndexer = newTxIndexer(*bc.cfg.TxLookupLimit, bc) + if bc.cfg.TxLookupLimit >= 0 { + bc.txIndexer = newTxIndexer(uint64(bc.cfg.TxLookupLimit), bc) } return bc, nil } diff --git a/eth/backend.go b/eth/backend.go index cd45ba4ed7..0852661676 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -20,6 +20,7 @@ package eth import ( "encoding/json" "fmt" + "math" "math/big" "runtime" "sync" @@ -205,10 +206,11 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { StateHistory: config.StateHistory, StateScheme: scheme, ChainHistoryMode: config.HistoryMode, + TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)), VmConfig: vmConfig, - TxLookupLimit: &config.TransactionHistory, } ) + if config.VMTrace != "" { traceConfig := json.RawMessage("{}") if config.VMTraceJsonConfig != "" { diff --git a/eth/filters/filter_test.go b/eth/filters/filter_test.go index a80cd4260f..850d77034d 100644 --- a/eth/filters/filter_test.go +++ b/eth/filters/filter_test.go @@ -276,9 +276,8 @@ func testFilters(t *testing.T, history uint64, noHistory bool) { gen.AddTx(tx) } }) - var l uint64 options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) - options.TxLookupLimit = &l + options.TxLookupLimit = 0 // index all txs bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) if err != nil { 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) {}) - var l uint64 options := core.DefaultConfig().WithStateScheme(rawdb.HashScheme) - options.TxLookupLimit = &l + options.TxLookupLimit = 0 // index all txs bc, err := core.NewBlockChain(db, gspec, ethash.NewFaker(), options) if err != nil { t.Fatal(err) diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 0b6d19e00f..4d1834d757 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -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 { - var ( - txLookupLimit = uint64(0) - options = &core.BlockChainConfig{ - TrieCleanLimit: 256, - TrieDirtyLimit: 256, - TrieTimeLimit: 5 * time.Minute, - SnapshotLimit: 0, - ArchiveMode: true, // Archive mode - TxLookupLimit: &txLookupLimit, - } - ) + options := core.DefaultConfig().WithArchive(true) + options.TxLookupLimit = 0 // index all txs + accman, acc := newTestAccountManager(t) gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)} + // Generate blocks for testing db, blocks, _ := core.GenerateChainWithGenesis(gspec, engine, n, generator)