Address PR comments
This commit is contained in:
parent
f2047cc503
commit
272d2f7ef8
@ -71,11 +71,11 @@ const (
|
|||||||
// CacheConfig contains the configuration values for the trie caching/pruning
|
// CacheConfig contains the configuration values for the trie caching/pruning
|
||||||
// that's resident in a blockchain.
|
// that's resident in a blockchain.
|
||||||
type CacheConfig struct {
|
type CacheConfig struct {
|
||||||
Disabled bool // Whether to disable trie write caching (archive node)
|
Disabled bool // Whether to disable trie write caching (archive node)
|
||||||
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
|
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
|
||||||
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
|
TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk
|
||||||
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
|
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
|
||||||
ProcessStateDiffs bool
|
ProcessingStateDiffs bool // Whether statediffs processing should be taken into a account before a trie is pruned
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockChain represents the canonical chain given a database with a genesis
|
// BlockChain represents the canonical chain given a database with a genesis
|
||||||
@ -928,14 +928,8 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BlockChain) AddToStateDiffProcessedCollection(hash common.Hash) {
|
func (bc *BlockChain) AddToStateDiffProcessedCollection(hash common.Hash) {
|
||||||
count, ok := bc.stateDiffsProcessed[hash]
|
count := bc.stateDiffsProcessed[hash]
|
||||||
|
bc.stateDiffsProcessed[hash] = count + 1
|
||||||
if ok {
|
|
||||||
count++
|
|
||||||
bc.stateDiffsProcessed[hash] = count
|
|
||||||
} else {
|
|
||||||
bc.stateDiffsProcessed[hash] = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteBlockWithState writes the block and all associated state to the database.
|
// WriteBlockWithState writes the block and all associated state to the database.
|
||||||
@ -1011,7 +1005,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if bc.cacheConfig.ProcessStateDiffs {
|
if bc.cacheConfig.ProcessingStateDiffs {
|
||||||
if !bc.allowedRootToBeDereferenced(root.(common.Hash)) {
|
if !bc.allowedRootToBeDereferenced(root.(common.Hash)) {
|
||||||
bc.triegc.Push(root, number)
|
bc.triegc.Push(root, number)
|
||||||
break
|
break
|
||||||
@ -1074,7 +1068,9 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
|||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//if we haven't processed the statediff for a given state root and it's child, don't dereference it yet
|
// since we need the state tries of the current block and its parent in-memory
|
||||||
|
// in order to process statediffs, we should avoid dereferencing roots until
|
||||||
|
// its statediff and its child have been processed
|
||||||
func (bc *BlockChain) allowedRootToBeDereferenced(root common.Hash) bool {
|
func (bc *BlockChain) allowedRootToBeDereferenced(root common.Hash) bool {
|
||||||
diffProcessedForSelfAndChildCount := 2
|
diffProcessedForSelfAndChildCount := 2
|
||||||
count := bc.stateDiffsProcessed[root]
|
count := bc.stateDiffsProcessed[root]
|
||||||
|
@ -1489,11 +1489,11 @@ func TestProcessingStateDiffs(t *testing.T) {
|
|||||||
defaultTrieDirtyCache := 256
|
defaultTrieDirtyCache := 256
|
||||||
defaultTrieTimeout := 60 * time.Minute
|
defaultTrieTimeout := 60 * time.Minute
|
||||||
cacheConfig := &CacheConfig{
|
cacheConfig := &CacheConfig{
|
||||||
Disabled: false,
|
Disabled: false,
|
||||||
TrieCleanLimit: defaultTrieCleanCache,
|
TrieCleanLimit: defaultTrieCleanCache,
|
||||||
TrieDirtyLimit: defaultTrieDirtyCache,
|
TrieDirtyLimit: defaultTrieDirtyCache,
|
||||||
TrieTimeLimit: defaultTrieTimeout,
|
TrieTimeLimit: defaultTrieTimeout,
|
||||||
ProcessStateDiffs: true,
|
ProcessingStateDiffs: true,
|
||||||
}
|
}
|
||||||
db := ethdb.NewMemDatabase()
|
db := ethdb.NewMemDatabase()
|
||||||
genesis := new(Genesis).MustCommit(db)
|
genesis := new(Genesis).MustCommit(db)
|
||||||
|
@ -157,11 +157,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||||||
EVMInterpreter: config.EVMInterpreter,
|
EVMInterpreter: config.EVMInterpreter,
|
||||||
}
|
}
|
||||||
cacheConfig = &core.CacheConfig{
|
cacheConfig = &core.CacheConfig{
|
||||||
Disabled: config.NoPruning,
|
Disabled: config.NoPruning,
|
||||||
TrieCleanLimit: config.TrieCleanCache,
|
TrieCleanLimit: config.TrieCleanCache,
|
||||||
TrieDirtyLimit: config.TrieDirtyCache,
|
TrieDirtyLimit: config.TrieDirtyCache,
|
||||||
TrieTimeLimit: config.TrieTimeout,
|
TrieTimeLimit: config.TrieTimeout,
|
||||||
ProcessStateDiffs: config.StateDiff,
|
ProcessingStateDiffs: config.StateDiff,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
|
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
|
||||||
|
Loading…
Reference in New Issue
Block a user