Raft: private state tridb commit added

This commit is contained in:
vsmk98 2018-09-14 03:59:10 +00:00 committed by amalrajmani
parent 912809810a
commit 8d3f8bb3d5
2 changed files with 17 additions and 3 deletions

View File

@ -903,7 +903,7 @@ func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (e
}
// WriteBlockWithState writes the block and all associated state to the database.
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) (status WriteStatus, err error) {
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state , privateState *state.StateDB) (status WriteStatus, err error) {
bc.wg.Add(1)
defer bc.wg.Done()
@ -929,16 +929,30 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
rawdb.WriteBlock(batch, block)
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
if err != nil {
return NonStatTy, err
}
triedb := bc.stateCache.TrieDB()
// Explicit commit for privateStateTriedb to handle Raft
if privateState != nil {
privateRoot, err := privateState.Commit(bc.chainConfig.IsEIP158(block.Number()))
if err != nil {
return NonStatTy, err
}
privateTriedb := bc.privateStateCache.TrieDB()
if err := privateTriedb.Commit(privateRoot, false); err != nil {
return NonStatTy, err
}
}
// If we're running an archive node, always flush
if bc.cacheConfig.Disabled {
if err := triedb.Commit(root, false); err != nil {
return NonStatTy, err
}
} else {
// Full but not archive node, do proper garbage collection
triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive
@ -1234,7 +1248,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
proctime := time.Since(bstart)
// Write the block to the chain and get the status.
status, err := bc.WriteBlockWithState(block, allReceipts, state)
status, err := bc.WriteBlockWithState(block, allReceipts, state, privateState)
if err != nil {
return i, events, coalescedLogs, err
}

View File

@ -339,7 +339,7 @@ func (self *worker) wait() {
core.WritePrivateStateRoot(self.chainDb, block.Root(), privateStateRoot)
allReceipts := mergeReceipts(work.receipts, work.privateReceipts)
stat, err := self.chain.WriteBlockWithState(block, allReceipts, work.state)
stat, err := self.chain.WriteBlockWithState(block, allReceipts, work.state, nil)
if err != nil {
log.Error("Failed writWriteBlockAndStating block to chain", "err", err)
continue