core: seperated proccing mutex and getting mutex
This commit is contained in:
parent
9f32117457
commit
7ac24d551b
@ -21,7 +21,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
// must be bumped when consensus algorithm is changed, this forces the upgradedb
|
// 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)
|
// command to be run (forces the blocks to be imported again using the new algorithm)
|
||||||
BlockChainVersion = 3
|
BlockChainVersion = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var statelogger = logger.NewLogger("BLOCK")
|
var statelogger = logger.NewLogger("BLOCK")
|
||||||
|
@ -76,6 +76,8 @@ type ChainManager struct {
|
|||||||
// Last known total difficulty
|
// Last known total difficulty
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
tsmu sync.RWMutex
|
tsmu sync.RWMutex
|
||||||
|
insertMu sync.Mutex
|
||||||
|
|
||||||
td *big.Int
|
td *big.Int
|
||||||
currentBlock *types.Block
|
currentBlock *types.Block
|
||||||
lastBlockHash common.Hash
|
lastBlockHash common.Hash
|
||||||
@ -496,8 +498,8 @@ func (self *ChainManager) procFutureBlocks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||||
self.mu.Lock()
|
self.insertMu.Lock()
|
||||||
defer self.mu.Unlock()
|
defer self.insertMu.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 (
|
||||||
@ -546,6 +548,8 @@ 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.
|
||||||
@ -591,6 +595,8 @@ 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