Skip to content

Commit

Permalink
Fix runBlockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
axic authored and holgerd77 committed Jul 11, 2018
1 parent 41aa974 commit b51c864
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/runBlockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ module.exports = function (blockchain, cb) {
// parse arguments
if (typeof blockchain === 'function') {
cb = blockchain
} else if (blockchain) {
self.stateManager.blockchain = blockchain
blockchain = undefined
}

blockchain = blockchain || self.stateManager.blockchain

// setup blockchain iterator
self.stateManager.blockchain.iterator('vm', processBlock, cb)
blockchain.iterator('vm', processBlock, cb)
function processBlock (block, reorg, cb) {
async.series([
getStartingState,
Expand All @@ -28,7 +29,7 @@ module.exports = function (blockchain, cb) {
function getStartingState (cb) {
// if we are just starting or if a chain re-org has happened
if (!headBlock || reorg) {
self.stateManager.blockchain.getBlock(block.header.parentHash, function (err, parentBlock) {
blockchain.getBlock(block.header.parentHash, function (err, parentBlock) {
parentState = parentBlock.header.stateRoot
// generate genesis state if we are at the genesis block
// we don't have the genesis state
Expand All @@ -53,7 +54,7 @@ module.exports = function (blockchain, cb) {
if (err) {
// remove invalid block
console.log('Invalid block error:', err)
self.stateManager.blockchain.delBlock(block.header.hash(), cb)
blockchain.delBlock(block.header.hash(), cb)
} else {
// set as new head block
headBlock = block
Expand Down

0 comments on commit b51c864

Please sign in to comment.