aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-03-12 01:26:57 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-03-12 01:26:57 +0800
commit8a3ce5450a309866c4cb1acc1e783324f8597293 (patch)
tree7dc6f3204262bad3019696c7c7ff3a22c6fcbff4
parent08759b0aaff8455138fcaf03b3dfed2b0c9120c4 (diff)
parent558d18d2b036e4598babf65e12a4907da0946086 (diff)
downloaddexon-8a3ce5450a309866c4cb1acc1e783324f8597293.tar.gz
dexon-8a3ce5450a309866c4cb1acc1e783324f8597293.tar.zst
dexon-8a3ce5450a309866c4cb1acc1e783324f8597293.zip
Merge pull request #2311 from obscuren/future-proc-fix
core: added future proc mutex lock
-rw-r--r--core/blockchain.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 4940899a5..284c549e3 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -85,10 +85,9 @@ type BlockChain struct {
eventMux *event.TypeMux
genesisBlock *types.Block
- mu sync.RWMutex
- chainmu sync.RWMutex
- tsmu sync.RWMutex
- procmu sync.RWMutex
+ mu sync.RWMutex // global mutex for locking chain operations
+ chainmu sync.RWMutex // blockchain insertion lock
+ procmu sync.RWMutex // block processor lock
checkpoint int // checkpoint counts towards the new checkpoint
currentBlock *types.Block // Current head of the block chain
@@ -99,15 +98,15 @@ type BlockChain struct {
blockCache *lru.Cache // Cache for the most recent entire blocks
futureBlocks *lru.Cache // future blocks are blocks added for later processing
- quit chan struct{}
- running int32 // running must be called automically
+ quit chan struct{} // blockchain quit channel
+ running int32 // running must be called automically
// procInterrupt must be atomically called
- procInterrupt int32 // interrupt signaler for block processing
- wg sync.WaitGroup
+ procInterrupt int32 // interrupt signaler for block processing
+ wg sync.WaitGroup // chain processing wait group for shutting down
pow pow.PoW
- processor Processor
- validator Validator
+ processor Processor // block processor interface
+ validator Validator // block and state validator interface
}
// NewBlockChain returns a fully initialised block chain using information
@@ -567,10 +566,11 @@ func (bc *BlockChain) Stop() {
}
func (self *BlockChain) procFutureBlocks() {
- blocks := make([]*types.Block, self.futureBlocks.Len())
- for i, hash := range self.futureBlocks.Keys() {
- block, _ := self.futureBlocks.Get(hash)
- blocks[i] = block.(*types.Block)
+ blocks := make([]*types.Block, 0, self.futureBlocks.Len())
+ for _, hash := range self.futureBlocks.Keys() {
+ if block, exist := self.futureBlocks.Get(hash); exist {
+ blocks = append(blocks, block.(*types.Block))
+ }
}
if len(blocks) > 0 {
types.BlockBy(types.Number).Sort(blocks)
@@ -794,6 +794,7 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
if err := WriteBlock(self.chainDb, block); err != nil {
glog.Fatalf("filed to write block contents: %v", err)
}
+
self.futureBlocks.Remove(block.Hash())
return