diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 804eccd0cb..90313efd77 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -57,6 +57,12 @@ var AppHelpFlagGroups = []flags.FlagGroup{ utils.WhitelistFlag, }, }, + { + Name: "NOTRACE CLIENT", + Flags: []cli.Flag{ + utils.TraceCacheLimit, + }, + }, { Name: "LIGHT CLIENT", Flags: []cli.Flag{ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 8ebe731638..3a893f571f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -249,6 +249,12 @@ var ( Name: "override.arrowglacier", Usage: "Manually specify Arrow Glacier fork-block, overriding the bundled setting", } + // NoTrace settings + TraceCacheLimit = cli.IntFlag{ + Name: "trace.limit", + Usage: "Handle the latest several blockResults", + Value: ethconfig.Defaults.TraceCacheLimit, + } // Light server and client settings LightServeFlag = cli.IntFlag{ Name: "light.serve", @@ -1094,6 +1100,13 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error return accs[index], nil } +func setTrace(ctx *cli.Context, cfg *ethconfig.Config) { + // NoTrace flag + if ctx.GlobalIsSet(TraceCacheLimit.Name) { + cfg.TraceCacheLimit = ctx.GlobalInt(TraceCacheLimit.Name) + } +} + // setEtherbase retrieves the etherbase either from the directly specified // command line flags or from the keystore if CLI indexed. func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *ethconfig.Config) { @@ -1485,6 +1498,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 { ks = keystores[0].(*keystore.KeyStore) } + setTrace(ctx, cfg) setEtherbase(ctx, ks, cfg) setGPO(ctx, &cfg.GPO, ctx.GlobalString(SyncModeFlag.Name) == "light") setTxPool(ctx, &cfg.TxPool) diff --git a/core/blockchain.go b/core/blockchain.go index 61d6f417f7..9068a43248 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -133,6 +133,7 @@ type CacheConfig struct { TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory Preimages bool // Whether to store preimage of trie key to the disk + TraceCacheLimit int SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it } @@ -140,11 +141,12 @@ type CacheConfig struct { // defaultCacheConfig are the default caching values if none are specified by the // user (also used during testing). var defaultCacheConfig = &CacheConfig{ - TrieCleanLimit: 256, - TrieDirtyLimit: 256, - TrieTimeLimit: 5 * time.Minute, - SnapshotLimit: 256, - SnapshotWait: true, + TrieCleanLimit: 256, + TrieDirtyLimit: 256, + TrieTimeLimit: 5 * time.Minute, + SnapshotLimit: 256, + SnapshotWait: true, + TraceCacheLimit: 32, } // BlockChain represents the canonical chain given a database with a genesis @@ -231,6 +233,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par txLookupCache, _ := lru.New(txLookupCacheLimit) futureBlocks, _ := lru.New(maxFutureBlocks) blockResultCache, _ := lru.New(blockResultCacheLimit) + if cacheConfig.TraceCacheLimit != 0 { + blockResultCache, _ = lru.New(cacheConfig.TraceCacheLimit) + } bc := &BlockChain{ chainConfig: chainConfig, diff --git a/eth/backend.go b/eth/backend.go index 4e3ae461a7..ab5e65541b 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -188,6 +188,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { TrieTimeLimit: config.TrieTimeout, SnapshotLimit: config.SnapshotCache, Preimages: config.Preimages, + TraceCacheLimit: config.TraceCacheLimit, } ) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b315843752..ce0e453611 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -87,11 +87,12 @@ var Defaults = Config{ GasPrice: big.NewInt(params.GWei), Recommit: 3 * time.Second, }, - TxPool: core.DefaultTxPoolConfig, - RPCGasCap: 50000000, - RPCEVMTimeout: 5 * time.Second, - GPO: FullNodeGPO, - RPCTxFeeCap: 1, // 1 ether + TxPool: core.DefaultTxPoolConfig, + RPCGasCap: 50000000, + RPCEVMTimeout: 5 * time.Second, + GPO: FullNodeGPO, + RPCTxFeeCap: 1, // 1 ether + TraceCacheLimit: 32, } func init() { @@ -204,6 +205,9 @@ type Config struct { // Arrow Glacier block override (TODO: remove after the fork) OverrideArrowGlacier *big.Int `toml:",omitempty"` + + // Trace option + TraceCacheLimit int } // CreateConsensusEngine creates a consensus engine for the given chain configuration.