|
|
|
@ -57,18 +57,19 @@ var ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
bodyCacheLimit = 256 |
|
|
|
|
blockCacheLimit = 256 |
|
|
|
|
receiptsCacheLimit = 32 |
|
|
|
|
maxFutureBlocks = 256 |
|
|
|
|
maxTimeFutureBlocks = 30 |
|
|
|
|
badBlockLimit = 10 |
|
|
|
|
triesInMemory = 128 |
|
|
|
|
shardCacheLimit = 2 |
|
|
|
|
commitsCacheLimit = 10 |
|
|
|
|
epochCacheLimit = 10 |
|
|
|
|
randomnessCacheLimit = 10 |
|
|
|
|
stakingCacheLimit = 256 |
|
|
|
|
bodyCacheLimit = 256 |
|
|
|
|
blockCacheLimit = 256 |
|
|
|
|
receiptsCacheLimit = 32 |
|
|
|
|
maxFutureBlocks = 256 |
|
|
|
|
maxTimeFutureBlocks = 30 |
|
|
|
|
badBlockLimit = 10 |
|
|
|
|
triesInMemory = 128 |
|
|
|
|
shardCacheLimit = 2 |
|
|
|
|
commitsCacheLimit = 10 |
|
|
|
|
epochCacheLimit = 10 |
|
|
|
|
randomnessCacheLimit = 10 |
|
|
|
|
stakingCacheLimit = 256 |
|
|
|
|
validatorListCacheLimit = 2 |
|
|
|
|
|
|
|
|
|
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
|
|
|
|
|
BlockChainVersion = 3 |
|
|
|
@ -121,17 +122,18 @@ type BlockChain struct { |
|
|
|
|
currentBlock atomic.Value // Current head of the block chain
|
|
|
|
|
currentFastBlock atomic.Value // Current head of the fast-sync chain (may be above the block chain!)
|
|
|
|
|
|
|
|
|
|
stateCache state.Database // State database to reuse between imports (contains state cache)
|
|
|
|
|
bodyCache *lru.Cache // Cache for the most recent block bodies
|
|
|
|
|
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
|
|
|
|
|
receiptsCache *lru.Cache // Cache for the most recent receipts per block
|
|
|
|
|
blockCache *lru.Cache // Cache for the most recent entire blocks
|
|
|
|
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
|
|
|
|
shardStateCache *lru.Cache |
|
|
|
|
lastCommitsCache *lru.Cache |
|
|
|
|
epochCache *lru.Cache // Cache epoch number → first block number
|
|
|
|
|
randomnessCache *lru.Cache // Cache for vrf/vdf
|
|
|
|
|
stakingCache *lru.Cache // Cache for staking validator
|
|
|
|
|
stateCache state.Database // State database to reuse between imports (contains state cache)
|
|
|
|
|
bodyCache *lru.Cache // Cache for the most recent block bodies
|
|
|
|
|
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
|
|
|
|
|
receiptsCache *lru.Cache // Cache for the most recent receipts per block
|
|
|
|
|
blockCache *lru.Cache // Cache for the most recent entire blocks
|
|
|
|
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
|
|
|
|
shardStateCache *lru.Cache |
|
|
|
|
lastCommitsCache *lru.Cache |
|
|
|
|
epochCache *lru.Cache // Cache epoch number → first block number
|
|
|
|
|
randomnessCache *lru.Cache // Cache for vrf/vdf
|
|
|
|
|
stakingCache *lru.Cache // Cache for staking validator
|
|
|
|
|
validatorListCache *lru.Cache // Cache of validator list
|
|
|
|
|
|
|
|
|
|
quit chan struct{} // blockchain quit channel
|
|
|
|
|
running int32 // running must be called atomically
|
|
|
|
@ -169,28 +171,30 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par |
|
|
|
|
epochCache, _ := lru.New(epochCacheLimit) |
|
|
|
|
randomnessCache, _ := lru.New(randomnessCacheLimit) |
|
|
|
|
stakingCache, _ := lru.New(stakingCacheLimit) |
|
|
|
|
validatorListCache, _ := lru.New(validatorListCacheLimit) |
|
|
|
|
|
|
|
|
|
bc := &BlockChain{ |
|
|
|
|
chainConfig: chainConfig, |
|
|
|
|
cacheConfig: cacheConfig, |
|
|
|
|
db: db, |
|
|
|
|
triegc: prque.New(nil), |
|
|
|
|
stateCache: state.NewDatabase(db), |
|
|
|
|
quit: make(chan struct{}), |
|
|
|
|
shouldPreserve: shouldPreserve, |
|
|
|
|
bodyCache: bodyCache, |
|
|
|
|
bodyRLPCache: bodyRLPCache, |
|
|
|
|
receiptsCache: receiptsCache, |
|
|
|
|
blockCache: blockCache, |
|
|
|
|
futureBlocks: futureBlocks, |
|
|
|
|
shardStateCache: shardCache, |
|
|
|
|
lastCommitsCache: commitsCache, |
|
|
|
|
epochCache: epochCache, |
|
|
|
|
randomnessCache: randomnessCache, |
|
|
|
|
stakingCache: stakingCache, |
|
|
|
|
engine: engine, |
|
|
|
|
vmConfig: vmConfig, |
|
|
|
|
badBlocks: badBlocks, |
|
|
|
|
chainConfig: chainConfig, |
|
|
|
|
cacheConfig: cacheConfig, |
|
|
|
|
db: db, |
|
|
|
|
triegc: prque.New(nil), |
|
|
|
|
stateCache: state.NewDatabase(db), |
|
|
|
|
quit: make(chan struct{}), |
|
|
|
|
shouldPreserve: shouldPreserve, |
|
|
|
|
bodyCache: bodyCache, |
|
|
|
|
bodyRLPCache: bodyRLPCache, |
|
|
|
|
receiptsCache: receiptsCache, |
|
|
|
|
blockCache: blockCache, |
|
|
|
|
futureBlocks: futureBlocks, |
|
|
|
|
shardStateCache: shardCache, |
|
|
|
|
lastCommitsCache: commitsCache, |
|
|
|
|
epochCache: epochCache, |
|
|
|
|
randomnessCache: randomnessCache, |
|
|
|
|
stakingCache: stakingCache, |
|
|
|
|
validatorListCache: validatorListCache, |
|
|
|
|
engine: engine, |
|
|
|
|
vmConfig: vmConfig, |
|
|
|
|
badBlocks: badBlocks, |
|
|
|
|
} |
|
|
|
|
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine)) |
|
|
|
|
bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine)) |
|
|
|
@ -2276,6 +2280,34 @@ func (bc *BlockChain) WriteStakingValidator(v *staking.Validator) error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ReadValidatorList reads the addresses of current all validators
|
|
|
|
|
func (bc *BlockChain) ReadValidatorList() ([]common.Address, error) { |
|
|
|
|
if cached, ok := bc.validatorListCache.Get("validatorList"); ok { |
|
|
|
|
by := cached.([]byte) |
|
|
|
|
list := []common.Address{} |
|
|
|
|
if err := rlp.DecodeBytes(by, &list); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return list, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rawdb.ReadValidatorList(bc.db) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WriteValidatorList writes the list of validator addresses to database
|
|
|
|
|
func (bc *BlockChain) WriteValidatorList(addrs []common.Address) error { |
|
|
|
|
err := rawdb.WriteValidatorList(bc.db, addrs) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
by, err := rlp.EncodeToBytes(addrs) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
bc.validatorListCache.Add("validatorList", by) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CurrentValidatorAddresses returns the address of active validators for current epoch
|
|
|
|
|
func (bc *BlockChain) CurrentValidatorAddresses() []common.Address { |
|
|
|
|
return nil |
|
|
|
|