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

Commit 4283cae

Browse files
authored
Merge pull request #79 from ethereumjs/fix-save-heads
Fix putBlock() edge case
2 parents f96aa9a + 24e2744 commit 4283cae

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ Blockchain.prototype._putBlockOrHeader = function (item, cb, isGenesis) {
344344
getCurrentTd,
345345
getBlockTd,
346346
rebuildInfo,
347-
(cb) => self._saveHeads(cb),
348-
(cb) => self._batchDbOps(dbOps, cb)
347+
(cb) => self._batchDbOps(dbOps.concat(self._saveHeadOps()), cb)
349348
], cb)
350349

351350
function verify (next) {
@@ -623,8 +622,8 @@ Blockchain.prototype.selectNeededHashes = function (hashes, cb) {
623622
})
624623
}
625624

626-
Blockchain.prototype._saveHeads = function (cb) {
627-
var dbOps = [{
625+
Blockchain.prototype._saveHeadOps = function () {
626+
return [{
628627
type: 'put',
629628
key: 'heads',
630629
keyEncoding: 'binary',
@@ -643,7 +642,10 @@ Blockchain.prototype._saveHeads = function (cb) {
643642
valueEncoding: 'binary',
644643
value: this._headBlock
645644
}]
646-
this._batchDbOps(dbOps, cb)
645+
}
646+
647+
Blockchain.prototype._saveHeads = function (cb) {
648+
this._batchDbOps(this._saveHeadOps(), cb)
647649
}
648650

649651
// delete canonical number assignments for specified number and above

0 commit comments

Comments
 (0)