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

Fix putBlock() edge case #79

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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