Skip to content

Commit

Permalink
Merge branch 'hotfix/0.9.34-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Jun 30, 2015
2 parents 7625b07 + d8fe64a commit a2ce7b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions core/chain_manager.go
Expand Up @@ -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))
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Expand Up @@ -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
Expand Down

0 comments on commit a2ce7b9

Please sign in to comment.