mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-31 20:18:37 +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.ExitWhenSyncedFlag,
|
||||||
utils.GCModeFlag,
|
utils.GCModeFlag,
|
||||||
utils.SnapshotFlag,
|
utils.SnapshotFlag,
|
||||||
|
utils.TxSenderIndexFlag,
|
||||||
utils.TxLookupLimitFlag, // deprecated
|
utils.TxLookupLimitFlag, // deprecated
|
||||||
utils.TransactionHistoryFlag,
|
utils.TransactionHistoryFlag,
|
||||||
utils.ChainHistoryFlag,
|
utils.ChainHistoryFlag,
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,12 @@ var (
|
||||||
Value: true,
|
Value: true,
|
||||||
Category: flags.EthCategory,
|
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{
|
LightKDFFlag = &cli.BoolFlag{
|
||||||
Name: "lightkdf",
|
Name: "lightkdf",
|
||||||
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
|
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) {
|
if ctx.IsSet(StateSchemeFlag.Name) {
|
||||||
cfg.StateScheme = ctx.String(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
|
// Parse transaction history flag, if user is still using legacy config
|
||||||
// file with 'TxLookupLimit' configured, copy the value to 'TransactionHistory'.
|
// file with 'TxLookupLimit' configured, copy the value to 'TransactionHistory'.
|
||||||
if cfg.TransactionHistory == ethconfig.Defaults.TransactionHistory && cfg.TxLookupLimit != ethconfig.Defaults.TxLookupLimit {
|
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.
|
// If the value is -1, indexing is disabled.
|
||||||
TxLookupLimit int64
|
TxLookupLimit int64
|
||||||
|
|
||||||
|
// Enable sender+nonce transaction indexing
|
||||||
|
TxIndexSender bool
|
||||||
|
|
||||||
// StateSizeTracking indicates whether the state size tracking is enabled.
|
// StateSizeTracking indicates whether the state size tracking is enabled.
|
||||||
StateSizeTracking bool
|
StateSizeTracking bool
|
||||||
|
|
||||||
|
|
@ -1282,9 +1285,10 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) {
|
||||||
rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64())
|
rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64())
|
||||||
rawdb.WriteTxLookupEntriesByBlock(batch, block)
|
rawdb.WriteTxLookupEntriesByBlock(batch, block)
|
||||||
|
|
||||||
signer := types.MakeSigner(bc.chainConfig, block.Number(), block.Time())
|
if bc.cfg.TxIndexSender {
|
||||||
// Write sender+nonce index
|
signer := types.MakeSigner(bc.chainConfig, block.Number(), block.Time())
|
||||||
rawdb.WriteTxSenderNonceEntryByBlock(batch, block, signer)
|
rawdb.WriteTxSenderNonceEntryByBlock(batch, block, signer)
|
||||||
|
}
|
||||||
|
|
||||||
rawdb.WriteHeadBlockHash(batch, block.Hash())
|
rawdb.WriteHeadBlockHash(batch, block.Hash())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
StateScheme: scheme,
|
StateScheme: scheme,
|
||||||
ChainHistoryMode: config.HistoryMode,
|
ChainHistoryMode: config.HistoryMode,
|
||||||
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
|
TxLookupLimit: int64(min(config.TransactionHistory, math.MaxInt64)),
|
||||||
|
TxIndexSender: config.TxIndexSender,
|
||||||
VmConfig: vm.Config{
|
VmConfig: vm.Config{
|
||||||
EnablePreimageRecording: config.EnablePreimageRecording,
|
EnablePreimageRecording: config.EnablePreimageRecording,
|
||||||
EnableWitnessStats: config.EnableWitnessStats,
|
EnableWitnessStats: config.EnableWitnessStats,
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ var Defaults = Config{
|
||||||
TxLookupLimit: 2350000,
|
TxLookupLimit: 2350000,
|
||||||
TransactionHistory: 2350000,
|
TransactionHistory: 2350000,
|
||||||
LogHistory: 2350000,
|
LogHistory: 2350000,
|
||||||
|
TxIndexSender: false,
|
||||||
StateHistory: pathdb.Defaults.StateHistory,
|
StateHistory: pathdb.Defaults.StateHistory,
|
||||||
TrienodeHistory: pathdb.Defaults.TrienodeHistory,
|
TrienodeHistory: pathdb.Defaults.TrienodeHistory,
|
||||||
NodeFullValueCheckpoint: pathdb.Defaults.FullValueCheckpoint,
|
NodeFullValueCheckpoint: pathdb.Defaults.FullValueCheckpoint,
|
||||||
|
|
@ -107,6 +108,7 @@ type Config struct {
|
||||||
// Deprecated: use 'TransactionHistory' instead.
|
// Deprecated: use 'TransactionHistory' instead.
|
||||||
TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
|
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.
|
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.
|
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.
|
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 {
|
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 := core.DefaultConfig().WithArchive(true)
|
||||||
options.TxLookupLimit = 0 // index all txs
|
options.TxLookupLimit = 0 // index all txs
|
||||||
|
options.TxIndexSender = true
|
||||||
|
|
||||||
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)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue