From 695ede28e06b4b958eb4e0a9a83fcc7cc348fb3e Mon Sep 17 00:00:00 2001 From: jeevan-sid Date: Tue, 17 Feb 2026 18:50:01 +0530 Subject: [PATCH] feat: make index configurable --- cmd/geth/main.go | 1 + cmd/utils/flags.go | 9 +++++++++ core/blockchain.go | 10 +++++++--- eth/backend.go | 1 + eth/ethconfig/config.go | 2 ++ internal/ethapi/api_test.go | 1 + 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 2291e0aafa..1a197743d6 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -87,6 +87,7 @@ var ( utils.ExitWhenSyncedFlag, utils.GCModeFlag, utils.SnapshotFlag, + utils.TxSenderIndexFlag, utils.TxLookupLimitFlag, // deprecated utils.TransactionHistoryFlag, utils.ChainHistoryFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3cb365b108..c172579da5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -225,6 +225,12 @@ var ( Value: true, Category: flags.EthCategory, } + TxSenderIndexFlag = &cli.BoolFlag{ + Name: "tx.index-sender", + Usage: "Enable transaction indexing by sender and nonce", + Category: flags.EthCategory, + Value: ethconfig.Defaults.TxIndexSender, + } LightKDFFlag = &cli.BoolFlag{ Name: "lightkdf", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", @@ -1803,6 +1809,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.IsSet(StateSchemeFlag.Name) { cfg.StateScheme = ctx.String(StateSchemeFlag.Name) } + if ctx.IsSet(TxSenderIndexFlag.Name) { + cfg.TxIndexSender = ctx.Bool(TxSenderIndexFlag.Name) + } // Parse transaction history flag, if user is still using legacy config // file with 'TxLookupLimit' configured, copy the value to 'TransactionHistory'. if cfg.TransactionHistory == ethconfig.Defaults.TransactionHistory && cfg.TxLookupLimit != ethconfig.Defaults.TxLookupLimit { diff --git a/core/blockchain.go b/core/blockchain.go index f6443c92b3..4756fde632 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -210,6 +210,9 @@ type BlockChainConfig struct { // If the value is -1, indexing is disabled. TxLookupLimit int64 + // Enable sender+nonce transaction indexing + TxIndexSender bool + // StateSizeTracking indicates whether the state size tracking is enabled. StateSizeTracking bool @@ -1282,9 +1285,10 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) { rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64()) rawdb.WriteTxLookupEntriesByBlock(batch, block) - signer := types.MakeSigner(bc.chainConfig, block.Number(), block.Time()) - // Write sender+nonce index - rawdb.WriteTxSenderNonceEntryByBlock(batch, block, signer) + if bc.cfg.TxIndexSender { + signer := types.MakeSigner(bc.chainConfig, block.Number(), block.Time()) + rawdb.WriteTxSenderNonceEntryByBlock(batch, block, signer) + } rawdb.WriteHeadBlockHash(batch, block.Hash()) diff --git a/eth/backend.go b/eth/backend.go index eaa68b501c..5a487ea2ad 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -235,6 +235,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { StateScheme: scheme, ChainHistoryMode: config.HistoryMode, TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)), + TxIndexSender: config.TxIndexSender, VmConfig: vm.Config{ EnablePreimageRecording: config.EnablePreimageRecording, EnableWitnessStats: config.EnableWitnessStats, diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 8aa6e4ef09..05bf524c09 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -56,6 +56,7 @@ var Defaults = Config{ TxLookupLimit: 2350000, TransactionHistory: 2350000, LogHistory: 2350000, + TxIndexSender: false, StateHistory: pathdb.Defaults.StateHistory, TrienodeHistory: pathdb.Defaults.TrienodeHistory, NodeFullValueCheckpoint: pathdb.Defaults.FullValueCheckpoint, @@ -107,6 +108,7 @@ type Config struct { // Deprecated: use 'TransactionHistory' instead. TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. + TxIndexSender bool `toml:",omitempty"` // Enables transaction indexing by sender and nonce (increases disk usage). TransactionHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. LogHistory uint64 `toml:",omitempty"` // The maximum number of blocks from head where a log search index is maintained. LogNoHistory bool `toml:",omitempty"` // No log search index is maintained. diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 5d4d1e7b26..11949fca16 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -465,6 +465,7 @@ func fakeBlockHash(txh common.Hash) common.Hash { func newTestBackend(t *testing.T, n int, gspec *core.Genesis, engine consensus.Engine, generator func(i int, b *core.BlockGen)) *testBackend { options := core.DefaultConfig().WithArchive(true) options.TxLookupLimit = 0 // index all txs + options.TxIndexSender = true accman, acc := newTestAccountManager(t) gspec.Alloc[acc.Address] = types.Account{Balance: big.NewInt(params.Ether)}