-
Notifications
You must be signed in to change notification settings - Fork 808
Remove async dependency #779
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
Conversation
LMK if you need help here with testing, reviewing, rebasing :) |
@jochem-brouwer just a note I removed the async dep in Feel free to ask for any help as you keep working on this PR! Thanks for taking it on. |
@ryanio Thank you. That change seems to explicitly remove |
@jochem-brouwer it does remove an |
@ryanio missed this when skimming over the PR. Great! 😄 |
Hey @evertonfraga, could you rebase master on top of this here? I am almost done with this PR, except I need one extra file in the VM tests where @ryanio has removed some async package calls already. I did rebase before but it seems that this went wrong. The files changed also have files changed which are changed from rebasing master, I expected that those would not show up in "files changed". I instead expected that I would still only see the files I changed and not the files changed due to the rebase. But I think I did something wrong 😅 If this yields a lot of conflicts and the code is confusing: I intend to clean it up later, but if that makes rebasing easier let me know, then I'll do that now. |
6c85e79
to
573421a
Compare
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
packages/blockchain/src/index.ts
Outdated
@@ -20,6 +19,21 @@ const Stoplight = require('flow-stoplight') | |||
const level = require('level-mem') | |||
const semaphore = require('semaphore') | |||
|
|||
// promisify a function: resolves this promise if callback is called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, you can actually just import { promisify } from 'util'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an external package right? I am not sure if this does what this intends to do; this is a much simpler variant I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no, this is a build-in Node.js functionality (see link from Ryan) and we are using this all over the place. Please use here as well, otherwise this bloats the code unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware of it, I thought it was an external package. Will change, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great :) if it has trouble erroring out in karma test runner then you might need to import from util-promisify
for a browser-friendly version, as used elsewhere in the monorepo, but it's a very small package and we can hopefully remove the need for it soon.
if (isRunningInKarma()) { | ||
st.skip('skip slow test when running in karma') | ||
return st.end() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like the ci check failure is due to these lines being removed (it times out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why I deleted this 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could've been on my rebase. It was a nasty one.
.runBlock({ | ||
block: block, | ||
root: parentState, | ||
await new Promise((resolve, reject) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can make your life a lot easier using node.js util promisify and callbackify along with async/await syntax to flatten all this code, but no worries i can do that in a follow-up pr (or here if you'd prefer)
after blockchain (+ ethash) are converted the entire monorepo will be promise-based (as i don't think there's any more internal usage of callbacks) so that will be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean up all these promises, it makes more sense to do it in this PR 😄
Hey guys! This PR is open for review. However, for some reason the tests seem to fail - they /do/ work locally, after bootstrapping and re-building everything, so I'm not sure what's going wrong here (looks like some timeouts). This PR looks huge but it seems like the changes which were rebased-in from master a while back are also in the diff. I'm not sure if it's possible to only show my changes on the diff? @evertonfraga I'm not super proud of this code as I don't think it's that elegant. I have thus changed (mostly in the Blockchain package) every async call now to a native promise call. However, before we start to review, we might want to consider to actually remove all the callbacks from Blockchain and thus change the signature of each function where each function would normally return a |
Let me relay this one to @jochem-brouwer ;) |
@jochem That's reasonable. Lol. 😜 |
066c57b
to
3f91f89
Compare
Rebased! These tests will need some inspection though; looks like the API tests pass, but if they are done in browser they timeout (!?). Someone has an idea why this happens? This could of course be due to browser handling the async stuff different than in node? |
If it makes it easier to review, I might also build on top of this one the changes necessary to remove the callbacks from |
test:API and test:API:browser are executing different amounts of test cases. Then, there are some assertions with no apparent output. I'm taking a deep look at this now @jochem-brouwer. Thanks! |
if (error) { | ||
cb(false) | ||
} | ||
await new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this code be cleaned up/flattened further? we can consider removing the callback and just supporting promises since ethash is mostly an internal lib just used in the blockchain package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just took a look here: if we change this, this means we also have to "asyncify" the blockchain package. I agree it should be cleaned up and removed (we should be consistent and thus not have callback functions but instead promise functions in all packages of this monorepo; ethash and blockchain are exceptions currently). However I think this might be too much for this PR as this is likely to involves code changes for every call to the blockchain or ethash package (we thus have to convert every callback function call into a Promise function call).
If you are OK with that then I'll follow up with a new PR, if not then I'll build it on top of this one and we merge if that is ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, ok that sounds good to me. i'm fine with either integrating into this PR or opening a new one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Could you approve this? Your other comment on ethash has the same remark and the nit one has been resolved 😄
await new Promise((resolve) => genesisBlock(resolve)) | ||
.then(function () { | ||
return new Promise((resolve) => validBlockTest(resolve)) | ||
}) | ||
.then(function () { | ||
return new Promise((resolve) => invalidblockTest(resolve)) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, i think we can convert these functions to async
packages/vm/tests/util.js
Outdated
account: acnt, | ||
testData: testData, | ||
}) | ||
q.push(new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can use promisify here
looking good! i still see quite a few |
@jochem-brouwer can you address the latest requests from Ryan and rebase so that we can bring this over the finish line? 🙂 |
@holgerd77 yes, will prioritize this after the weekend! 😄 (+squash commits) |
3f91f89
to
ed079c8
Compare
remove async from ethash tests
restore skip test in state manager change promisify to util.promisify
[VM] fix browser test [VM] promisify util
ed079c8
to
bc9d567
Compare
Never mind, should be done (if discussions are resolved) 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved after review of Ryan.
This is a WIP.
Closes #734