core: seperated proccing mutex and getting mutex

This commit is contained in:
obscuren 2015-04-28 17:48:46 +02:00
parent 9f32117457
commit 7ac24d551b
2 changed files with 51 additions and 45 deletions

View File

@ -21,7 +21,7 @@ import (
const (
// must be bumped when consensus algorithm is changed, this forces the upgradedb
// command to be run (forces the blocks to be imported again using the new algorithm)
BlockChainVersion = 3
BlockChainVersion = 2
)
var statelogger = logger.NewLogger("BLOCK")

View File

@ -76,6 +76,8 @@ type ChainManager struct {
// Last known total difficulty
mu sync.RWMutex
tsmu sync.RWMutex
insertMu sync.Mutex
td *big.Int
currentBlock *types.Block
lastBlockHash common.Hash
@ -496,8 +498,8 @@ func (self *ChainManager) procFutureBlocks() {
}
func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.mu.Lock()
defer self.mu.Unlock()
self.insertMu.Lock()
defer self.insertMu.Unlock()
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
var (
@ -546,6 +548,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
block.Td = new(big.Int).Set(CalculateTD(block, self.GetBlock(block.ParentHash())))
self.mu.Lock()
{
cblock := self.currentBlock
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
// not in the canonical chain.
@ -591,6 +595,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
queue[i] = ChainSideEvent{block, logs}
queueEvent.sideCount++
}
}
self.mu.Unlock()
stats.processed++