Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #79 from ethereumjs/fix-save-heads
Browse files Browse the repository at this point in the history
Fix putBlock() edge case
  • Loading branch information
whymarrh authored Dec 7, 2018
2 parents f96aa9a + 24e2744 commit 4283cae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ Blockchain.prototype._putBlockOrHeader = function (item, cb, isGenesis) {
getCurrentTd,
getBlockTd,
rebuildInfo,
(cb) => self._saveHeads(cb),
(cb) => self._batchDbOps(dbOps, cb)
(cb) => self._batchDbOps(dbOps.concat(self._saveHeadOps()), cb)
], cb)

function verify (next) {
Expand Down Expand Up @@ -623,8 +622,8 @@ Blockchain.prototype.selectNeededHashes = function (hashes, cb) {
})
}

Blockchain.prototype._saveHeads = function (cb) {
var dbOps = [{
Blockchain.prototype._saveHeadOps = function () {
return [{
type: 'put',
key: 'heads',
keyEncoding: 'binary',
Expand All @@ -643,7 +642,10 @@ Blockchain.prototype._saveHeads = function (cb) {
valueEncoding: 'binary',
value: this._headBlock
}]
this._batchDbOps(dbOps, cb)
}

Blockchain.prototype._saveHeads = function (cb) {
this._batchDbOps(this._saveHeadOps(), cb)
}

// delete canonical number assignments for specified number and above
Expand Down

0 comments on commit 4283cae

Please sign in to comment.