Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promisify public API #546

Merged
merged 3 commits into from
Jun 17, 2019
Merged

Promisify public API #546

merged 3 commits into from
Jun 17, 2019

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jun 13, 2019

I'd appreciate having a broader look here to see I haven't missed anything.

As per discussion in #455 and #544

@coveralls
Copy link

coveralls commented Jun 13, 2019

Coverage Status

Coverage increased (+0.09%) to 95.087% when pulling e4bdfb9 on promisify-runBlockchain into e13503b on master.

@holgerd77
Copy link
Member

There is a WASM file in here. ? 😋

s1na added 2 commits June 13, 2019 16:53
Regenerate docs

Rm mistakenly pushed wasm file
@s1na
Copy link
Contributor Author

s1na commented Jun 13, 2019

Oops 😄 Removed and rebased

holgerd77
holgerd77 previously approved these changes Jun 14, 2019
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, some questions, but from my side this looks good, thanks so much! 😄

runBlockchain(blockchain: any, cb: any): void {
runBlockchain.bind(this)(blockchain, cb)
runBlockchain(blockchain: any): Promise<void> {
return promisify(runBlockchain.bind(this))(blockchain)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be so explicitly done to use promisify here and not make runBlockchain itself async that I'm sure you have a reason, so I won't make this a review blocker.

Can you nevertheless give a short (eventually) post-merge explanation on this please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: explanation here, no need to give an answer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explanation here, no need to give an answer.

Yeah that was the reason, but on the other hand what I could have done is to return a promise in runBlockchain without using promises within it internally. I did this now and pushed, so we won't need to promisify in the VM.

@@ -219,7 +200,7 @@ async function applyTransactions(this: VM, block: any) {
}

// Run the tx through the VM
const txRes = await promisify(this.runTx).bind(this)({
const txRes = await this.runTx({
tx: tx,
block: block,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, also had a look at the whole file to get some broader picture.

blockchain.delBlock(block.header.hash(), function() {
cb(err)
})
})
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated runBlock call.

} catch (e) {
await state.revert()
throw e
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whew. This is beautiful. 😄

} catch (e) {
await state.revert()
throw e
}
}

async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it possible here to eliminate this inner _runTx method similar like in runBlock? Won't make this a blocker either, just please give a short explanation (or update if just forgotten).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it's a clean separation that the outer function performs checkpointing, commit on success and revert on any error. And the internal method modifies the state without being aware of this.

I can change this however if it doesn't make sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, that's a good reasoning, thanks.

interpreter
.executeMessage(message)
.then(results => cb(null, results))
.catch(err => cb(err, null))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the result from executeMessage is now returned directly.

.runLoop(opts.message, { pc: opts.pc })
.then(res => cb(null, res))
.catch(err => cb(err, null))
return interpreter.runLoop(opts.message, { pc: opts.pc })
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, similar here, runLoop result is directly returned.

}
t.comment(JSON.stringify(stateRoot))
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some cleaning up of conditional expression boxing if I get this correctly.

} else {
done()
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, different result handling due to promisified API.

st.end()
})
st.assert(!err)
st.end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-review comment: this is also a nice simplification.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have reapproved, thanks for the update.

@s1na s1na merged commit 0d6ccfc into master Jun 17, 2019
@s1na s1na deleted the promisify-runBlockchain branch June 17, 2019 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants