feat: add config for blockResult cache_limit (#97)

* Let blockResult limit settable

* fix bug

* Update cmd/geth/usage.go

Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>

Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
This commit is contained in:
maskpp 2022-05-16 18:41:40 +08:00 committed by GitHub
parent a79e72f697
commit 0541145fd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 10 deletions

View file

@ -57,6 +57,12 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.WhitelistFlag,
},
},
{
Name: "NOTRACE CLIENT",
Flags: []cli.Flag{
utils.TraceCacheLimit,
},
},
{
Name: "LIGHT CLIENT",
Flags: []cli.Flag{

View file

@ -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)

View file

@ -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,

View file

@ -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)

View file

@ -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.