Commit a4b79f1d authored by obscuren's avatar obscuren

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.
parent 04a09b7e
...@@ -496,6 +496,9 @@ func (self *ChainManager) procFutureBlocks() { ...@@ -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 { ...@@ -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 { ...@@ -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++
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment