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