mirror of https://github.com/poanetwork/quorum.git
Always use InsertChain to extend the chain
This fixes posting of logs on the minter.
This commit is contained in:
parent
0d4d5b9555
commit
b89d59f9c7
|
@ -839,51 +839,6 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
|
|||
return
|
||||
}
|
||||
|
||||
// Only writes the block without inserting it as the head of the chain
|
||||
func (self *BlockChain) WriteDetachedBlock(block *types.Block) (err error) {
|
||||
self.wg.Add(1)
|
||||
defer self.wg.Done()
|
||||
|
||||
// Calculate the total difficulty of the block
|
||||
ptd := self.GetTdByHash(block.ParentHash())
|
||||
if ptd == nil {
|
||||
return ParentError(block.ParentHash())
|
||||
}
|
||||
|
||||
externTd := new(big.Int).Add(block.Difficulty(), ptd)
|
||||
|
||||
self.mu.Lock()
|
||||
defer self.mu.Unlock()
|
||||
|
||||
// Write the block itself to the database
|
||||
if err := self.hc.WriteTd(block.Hash(), block.Number().Uint64(), externTd); err != nil {
|
||||
glog.Fatalf("failed to write block total difficulty: %v", err)
|
||||
}
|
||||
if err := WriteBlock(self.chainDb, block); err != nil {
|
||||
glog.Fatalf("failed to write block contents: %v", err)
|
||||
}
|
||||
|
||||
self.futureBlocks.Remove(block.Hash())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Sets a "detached block" to be the new head of the chain.
|
||||
//
|
||||
// See WriteDetachedBlock.
|
||||
func (self *BlockChain) SetNewHeadBlock(block *types.Block) {
|
||||
self.wg.Add(1)
|
||||
defer self.wg.Done()
|
||||
|
||||
self.chainmu.Lock()
|
||||
defer self.chainmu.Unlock()
|
||||
|
||||
self.mu.Lock()
|
||||
defer self.mu.Unlock()
|
||||
|
||||
self.insert(block)
|
||||
}
|
||||
|
||||
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
|
||||
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
|
||||
func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||
|
|
|
@ -631,25 +631,12 @@ func (pm *ProtocolManager) applyNewChainHead(block *types.Block) {
|
|||
logCheckpoint(txAccepted, tx.Hash().Hex())
|
||||
}
|
||||
|
||||
if pm.blockchain.HasBlock(block.Hash()) {
|
||||
// This node mined the block, so it was already in the
|
||||
// DB. We simply extend the chain:
|
||||
pm.blockchain.SetNewHeadBlock(block)
|
||||
} else {
|
||||
//
|
||||
// This will broadcast a CHE *almost always*. It does its
|
||||
// broadcasting at the end in a goroutine, but only conditionally if
|
||||
// the chain head is in a certain state. For now, we will broadcast
|
||||
// a CHE ourselves below to guarantee correctness.
|
||||
//
|
||||
_, err := pm.blockchain.InsertChain([]*types.Block{block})
|
||||
_, err := pm.blockchain.InsertChain([]*types.Block{block})
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to extend chain: %s", err.Error()))
|
||||
}
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to extend chain: %s", err.Error()))
|
||||
}
|
||||
|
||||
pm.eventMux.Post(core.ChainHeadEvent{Block: block})
|
||||
glog.V(logger.Info).Infof("Successfully extended chain: %x\n", block.Hash())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,33 +314,10 @@ func (minter *minter) mintNewBlock() {
|
|||
if _, err := work.publicState.Commit(); err != nil {
|
||||
panic(fmt.Sprint("error committing public state: ", err))
|
||||
}
|
||||
privateStateRoot, privStateErr := work.privateState.Commit()
|
||||
if privStateErr != nil {
|
||||
if _, privStateErr := work.privateState.Commit(); privStateErr != nil {
|
||||
panic(fmt.Sprint("error committing private state: ", privStateErr))
|
||||
}
|
||||
|
||||
if err := core.WritePrivateStateRoot(minter.chainDb, block.Root(), privateStateRoot); err != nil {
|
||||
panic(fmt.Sprint("error writing private state root: ", err))
|
||||
}
|
||||
if err := minter.chain.WriteDetachedBlock(block); err != nil {
|
||||
panic(fmt.Sprint("error writing block to chain: ", err))
|
||||
}
|
||||
if err := core.WriteTransactions(minter.chainDb, block); err != nil {
|
||||
panic(fmt.Sprint("error writing txes: ", err))
|
||||
}
|
||||
if err := core.WriteReceipts(minter.chainDb, allReceipts); err != nil {
|
||||
panic(fmt.Sprint("error writing receipts: ", err))
|
||||
}
|
||||
if err := core.WriteMipmapBloom(minter.chainDb, block.NumberU64(), allReceipts); err != nil {
|
||||
panic(fmt.Sprint("error writing mipmap bloom: ", err))
|
||||
}
|
||||
if err := core.WritePrivateBlockBloom(minter.chainDb, block.NumberU64(), privateReceipts); err != nil {
|
||||
panic(fmt.Sprint("error writing private block bloom: ", err))
|
||||
}
|
||||
if err := core.WriteBlockReceipts(minter.chainDb, block.Hash(), block.Number().Uint64(), allReceipts); err != nil {
|
||||
panic(fmt.Sprint("error writing block receipts: ", err))
|
||||
}
|
||||
|
||||
minter.speculativeChain.extend(block)
|
||||
|
||||
minter.mux.Post(core.NewMinedBlockEvent{Block: block})
|
||||
|
@ -396,10 +373,6 @@ func (env *work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, g
|
|||
publicSnapshot := env.publicState.Snapshot()
|
||||
privateSnapshot := env.privateState.Snapshot()
|
||||
|
||||
//
|
||||
// TODO(bts): look into that core.ApplyTransaction is not currently
|
||||
// returning any logs?
|
||||
//
|
||||
publicReceipt, privateReceipt, _, err := core.ApplyTransaction(env.config, bc, gp, env.publicState, env.privateState, env.header, tx, env.header.GasUsed, env.config.VmConfig)
|
||||
if err != nil {
|
||||
env.publicState.RevertToSnapshot(publicSnapshot)
|
||||
|
|
Loading…
Reference in New Issue