core: moved mutex locks in insert blocks to start of function
Insert blocks will no longer allow processing of multiple chains at the same time. The block lock has been moved to start of the function.
This commit is contained in:
parent
04a09b7e2d
commit
a4b79f1dac
@ -496,6 +496,9 @@ func (self *ChainManager) procFutureBlocks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||||
|
self.mu.Lock()
|
||||||
|
defer self.mu.Unlock()
|
||||||
|
|
||||||
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
|
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
|
||||||
var (
|
var (
|
||||||
queue = make([]interface{}, len(chain))
|
queue = make([]interface{}, len(chain))
|
||||||
@ -543,8 +546,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
|
|
||||||
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
|
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
|
||||||
|
|
||||||
self.mu.Lock()
|
|
||||||
{
|
|
||||||
cblock := self.currentBlock
|
cblock := self.currentBlock
|
||||||
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
|
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
|
||||||
// not in the canonical chain.
|
// not in the canonical chain.
|
||||||
@ -590,8 +591,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
queue[i] = ChainSideEvent{block, logs}
|
queue[i] = ChainSideEvent{block, logs}
|
||||||
queueEvent.sideCount++
|
queueEvent.sideCount++
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.mu.Unlock()
|
|
||||||
|
|
||||||
stats.processed++
|
stats.processed++
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user