diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-05 00:23:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-05 00:23:51 +0800 |
commit | 7a18a39351c229d15729abcbc1b6b7f7ce92708d (patch) | |
tree | 17f0f83af9e146ea6a9693c09ec3f7682f25d167 | |
parent | f9488cb763d218683904fe0f46b409d8ef42f963 (diff) | |
download | dexon-7a18a39351c229d15729abcbc1b6b7f7ce92708d.tar.gz dexon-7a18a39351c229d15729abcbc1b6b7f7ce92708d.tar.zst dexon-7a18a39351c229d15729abcbc1b6b7f7ce92708d.zip |
prevent deadlock
-rw-r--r-- | blockpool/blockpool.go | 2 | ||||
-rw-r--r-- | core/block_processor.go | 8 | ||||
-rw-r--r-- | core/chain_manager.go | 19 |
3 files changed, 12 insertions, 17 deletions
diff --git a/blockpool/blockpool.go b/blockpool/blockpool.go index e65032fb5..79b6f8cc0 100644 --- a/blockpool/blockpool.go +++ b/blockpool/blockpool.go @@ -622,6 +622,8 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { entry := self.get(hash) + fmt.Println("block number", block.Number()) + defer fmt.Println("AddBlock done") // a peer's current head block is appearing the first time if hash == sender.currentBlockHash { if sender.currentBlock == nil { diff --git a/core/block_processor.go b/core/block_processor.go index 6b18d4cf9..39134c63e 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -268,15 +268,15 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { return BlockNumberErr } + if block.Time <= parent.Time { + return BlockEqualTSErr //ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time) + } + // Verify the nonce of the block. Return an error if it's not valid if !sm.Pow.Verify(types.NewBlockWithHeader(block)) { return ValidationError("Block's nonce is invalid (= %x)", block.Nonce) } - if block.Time <= parent.Time { - return BlockEqualTSErr //ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time) - } - return nil } diff --git a/core/chain_manager.go b/core/chain_manager.go index 7b4034b63..2a5d2f2c5 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -437,21 +437,20 @@ type queueEvent struct { } func (self *ChainManager) procFutureBlocks() { - self.futureBlocks.mu.Lock() - blocks := make([]*types.Block, len(self.futureBlocks.blocks)) for i, hash := range self.futureBlocks.hashes { blocks[i] = self.futureBlocks.Get(hash) } - self.futureBlocks.mu.Unlock() types.BlockBy(types.Number).Sort(blocks) self.InsertChain(blocks) } func (self *ChainManager) InsertChain(chain types.Blocks) error { - //self.tsmu.Lock() - //defer self.tsmu.Unlock() + if len(chain) > 0 { + fmt.Println("insert chain", len(chain)) + defer fmt.Println("insert chain done") + } // A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring. var queue = make([]interface{}, len(chain)) @@ -472,23 +471,17 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { // Do not penelise on future block. We'll need a block queue eventually that will queue // future block for future use if err == BlockFutureErr { + fmt.Println("added future block", block.Number()) self.futureBlocks.Push(block) continue } if IsParentErr(err) && self.futureBlocks.Has(block.ParentHash()) { + fmt.Println("added future block 2", block.Number()) self.futureBlocks.Push(block) continue } - /* - if err == BlockEqualTSErr { - //queue[i] = ChainSideEvent{block, logs} - // XXX silently discard it? - continue - } - */ - h := block.Header() chainlogger.Errorf("INVALID block #%v (%x)\n", h.Number, h.Hash().Bytes()[:4]) chainlogger.Errorln(err) |