diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-30 17:15:08 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-30 17:15:08 +0800 |
commit | 9226369b5daf8c1bf738369cd838963a5d58362d (patch) | |
tree | cfc13acdd1af6918b7b917f78b8a81504f1aafdd | |
parent | b047f05e7e9d941348cba960f8cc16a9874340d0 (diff) | |
parent | d8fe64acaa94fc5a12e53cec110e57cace52ced9 (diff) | |
download | dexon-9226369b5daf8c1bf738369cd838963a5d58362d.tar.gz dexon-9226369b5daf8c1bf738369cd838963a5d58362d.tar.zst dexon-9226369b5daf8c1bf738369cd838963a5d58362d.zip |
Merge branch 'hotfix/0.9.34-1' into develop
-rw-r--r-- | core/chain_manager.go | 33 | ||||
-rw-r--r-- | miner/worker.go | 2 |
2 files changed, 19 insertions, 16 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 7c78b6bb7..808ccd201 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -364,14 +364,12 @@ func (bc *ChainManager) insert(block *types.Block) { func (bc *ChainManager) write(block *types.Block) { tstart := time.Now() - go func() { - enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block)) - key := append(blockHashPre, block.Hash().Bytes()...) - err := bc.blockDb.Put(key, enc) - if err != nil { - glog.Fatal("db write fail:", err) - } - }() + enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block)) + key := append(blockHashPre, block.Hash().Bytes()...) + err := bc.blockDb.Put(key, enc) + if err != nil { + glog.Fatal("db write fail:", err) + } if glog.V(logger.Debug) { glog.Infof("wrote block #%v %s. Took %v\n", block.Number(), common.PP(block.Hash().Bytes()), time.Since(tstart)) @@ -555,7 +553,8 @@ const ( sideStatTy ) -func (self *ChainManager) WriteBlock(block *types.Block) (status writeStatus, err error) { +// WriteBlock writes the block to the chain (or pending queue) +func (self *ChainManager) WriteBlock(block *types.Block, queued bool) (status writeStatus, err error) { self.wg.Add(1) defer self.wg.Done() @@ -587,11 +586,15 @@ func (self *ChainManager) WriteBlock(block *types.Block) (status writeStatus, er status = sideStatTy } - // Write block to database. Eventually we'll have to improve on this and throw away blocks that are - // not in the canonical chain. - self.mu.Lock() - self.enqueueForWrite(block) - self.mu.Unlock() + if queued { + // Write block to database. Eventually we'll have to improve on this and throw away blocks that are + // not in the canonical chain. + self.mu.Lock() + self.enqueueForWrite(block) + self.mu.Unlock() + } else { + self.write(block) + } // Delete from future blocks self.futureBlocks.Remove(block.Hash()) @@ -693,7 +696,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) { txcount += len(block.Transactions()) // write the block to the chain and get the status - status, err := self.WriteBlock(block) + status, err := self.WriteBlock(block, true) if err != nil { return i, err } diff --git a/miner/worker.go b/miner/worker.go index 0971bd957..f06b6afa1 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -233,7 +233,7 @@ func (self *worker) wait() { continue } - _, err := self.chain.WriteBlock(block) + _, err := self.chain.WriteBlock(block, false) if err != nil { glog.V(logger.Error).Infoln("error writing block to chain", err) continue |