mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 08:49:29 +00:00
feat: make index configurable
This commit is contained in:
parent
3250556eb9
commit
695ede28e0
6 changed files with 21 additions and 3 deletions
|
|
@ -87,6 +87,7 @@ var (
|
|||
utils.ExitWhenSyncedFlag,
|
||||
utils.GCModeFlag,
|
||||
utils.SnapshotFlag,
|
||||
utils.TxSenderIndexFlag,
|
||||
utils.TxLookupLimitFlag, // deprecated
|
||||
utils.TransactionHistoryFlag,
|
||||
utils.ChainHistoryFlag,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)}
|
||||
|
|
|
|||
Loading…
Reference in a new issue