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

Commit f0070b5

Browse files
authored
Merge pull request #29 from jwasinger/fix-bc-general-state-tests
Make sure blockchain init is complete before adding blocks
2 parents 1598106 + 23e4fd3 commit f0070b5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ Blockchain.prototype.putBlocks = function (blocks, cb) {
139139
Blockchain.prototype.putBlock = function (block, cb, isGenesis) {
140140
const self = this
141141

142-
// perform put with mutex dance
143-
lockUnlock(function (done) {
144-
self._putBlock(block, done, isGenesis)
145-
}, cb)
142+
// make sure init has completed
143+
self._initLock.await(() => {
144+
// perform put with mutex dance
145+
lockUnlock(function (done) {
146+
self._putBlock(block, done, isGenesis)
147+
}, cb)
148+
})
146149

147150
// lock, call fn, unlock
148151
function lockUnlock (fn, cb) {

0 commit comments

Comments
 (0)