core: seperated proccing mutex and getting mutex

pull/825/head
obscuren 10 years ago
parent 9f32117457
commit 7ac24d551b
  1. 2
      core/block_processor.go
  2. 10
      core/chain_manager.go

@ -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")

@ -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++

Loading…
Cancel
Save