mirror of https://github.com/poanetwork/quorum.git
Raft: private state tridb commit added
This commit is contained in:
parent
912809810a
commit
8d3f8bb3d5
|
@ -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.
|
// 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)
|
bc.wg.Add(1)
|
||||||
defer bc.wg.Done()
|
defer bc.wg.Done()
|
||||||
|
|
||||||
|
@ -929,16 +929,30 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
||||||
rawdb.WriteBlock(batch, block)
|
rawdb.WriteBlock(batch, block)
|
||||||
|
|
||||||
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
|
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NonStatTy, err
|
return NonStatTy, err
|
||||||
}
|
}
|
||||||
triedb := bc.stateCache.TrieDB()
|
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 we're running an archive node, always flush
|
||||||
if bc.cacheConfig.Disabled {
|
if bc.cacheConfig.Disabled {
|
||||||
if err := triedb.Commit(root, false); err != nil {
|
if err := triedb.Commit(root, false); err != nil {
|
||||||
return NonStatTy, err
|
return NonStatTy, err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Full but not archive node, do proper garbage collection
|
// Full but not archive node, do proper garbage collection
|
||||||
triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive
|
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)
|
proctime := time.Since(bstart)
|
||||||
|
|
||||||
// Write the block to the chain and get the status.
|
// 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 {
|
if err != nil {
|
||||||
return i, events, coalescedLogs, err
|
return i, events, coalescedLogs, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,7 +339,7 @@ func (self *worker) wait() {
|
||||||
core.WritePrivateStateRoot(self.chainDb, block.Root(), privateStateRoot)
|
core.WritePrivateStateRoot(self.chainDb, block.Root(), privateStateRoot)
|
||||||
allReceipts := mergeReceipts(work.receipts, work.privateReceipts)
|
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 {
|
if err != nil {
|
||||||
log.Error("Failed writWriteBlockAndStating block to chain", "err", err)
|
log.Error("Failed writWriteBlockAndStating block to chain", "err", err)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue