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

Remove async dependency #779

Merged
merged 6 commits into from
Aug 7, 2020
Merged

Remove async dependency #779

merged 6 commits into from
Aug 7, 2020

Conversation

jochem-brouwer
Copy link
Member

This is a WIP.

Closes #734

@evertonfraga
Copy link
Contributor

LMK if you need help here with testing, reviewing, rebasing :)

@ryanio
Copy link
Contributor

ryanio commented Jun 24, 2020

@jochem-brouwer just a note I removed the async dep in testUtil.setupPreConditions in #788 so if you rebase onto master you'll get those changes 👍

Feel free to ask for any help as you keep working on this PR! Thanks for taking it on.

@jochem-brouwer
Copy link
Member Author

@ryanio Thank you. That change seems to explicitly remove promisify. I am not sure that this is within the scope of this PR/issue: this is not part of the async package. Correct me if I'm wrong.

@ryanio
Copy link
Contributor

ryanio commented Jun 24, 2020

@jochem-brouwer it does remove an async.series and async.eachSeries

@jochem-brouwer
Copy link
Member Author

@ryanio missed this when skimming over the PR. Great! 😄

@jochem-brouwer jochem-brouwer marked this pull request as draft June 26, 2020 19:57
@jochem-brouwer
Copy link
Member Author

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.

@codecov
Copy link

codecov bot commented Jun 29, 2020

Codecov Report

Merging #779 into master will decrease coverage by 0.64%.
The diff coverage is 73.75%.

Impacted file tree graph

Flag Coverage Δ
#account 92.85% <ø> (ø)
#block 79.28% <79.20%> (-0.69%) ⬇️
#blockchain 83.09% <79.20%> (-1.42%) ⬇️
#common 94.14% <ø> (+0.15%) ⬆️
#ethash 81.37% <28.57%> (-4.93%) ⬇️
#tx 94.16% <ø> (ø)
#vm 92.91% <76.92%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@@ -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
Copy link
Contributor

@ryanio ryanio Jun 29, 2020

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'

Copy link
Member Author

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.

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, 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.

Copy link
Member Author

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!

Copy link
Contributor

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.

Comment on lines 134 to 168
if (isRunningInKarma()) {
st.skip('skip slow test when running in karma')
return st.end()
}
Copy link
Contributor

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)

Copy link
Member Author

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 🤔

Copy link
Contributor

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) =>
Copy link
Contributor

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.

Copy link
Member Author

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 😄

@evertonfraga evertonfraga changed the title WIP: Remove async dependency Remove async dependency Jun 30, 2020
@jochem-brouwer jochem-brouwer marked this pull request as ready for review July 13, 2020 13:04
@jochem-brouwer
Copy link
Member Author

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 <void> we could now return a Promise<T> and therefore make these things async (this will definitely improve the code a lot). But this might also be something to consider for a different PR?

CC @holgerd77 @ryanio

@holgerd77
Copy link
Member

Hi @jochem, can you do a rebase of this on top of the TangerineWhistle changes (I would recommend to do a local repo backup before)?

@ryanio can you take over the review here, you would be very suited here with all your rewrite experience on the topic! 😄

@jochem
Copy link

jochem commented Jul 15, 2020

Hi @jochem, can you do a rebase of this on top of the TangerineWhistle changes (I would recommend to do a local repo backup before)?

Let me relay this one to @jochem-brouwer ;)

@holgerd77
Copy link
Member

@jochem That's reasonable. Lol. 😜

@jochem-brouwer
Copy link
Member Author

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?

@jochem-brouwer
Copy link
Member Author

If it makes it easier to review, I might also build on top of this one the changes necessary to remove the callbacks from blockchain? Right now the blockchain package is the only one which still uses callbacks; we can asyncify these functions (which would be a PR built in the future anyways). It would also make sense to introduce this in our next V5 release?

@evertonfraga
Copy link
Contributor

evertonfraga commented Jul 30, 2020

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) => {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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 👍

Copy link
Member Author

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 😄

Comment on lines +50 to +56
await new Promise((resolve) => genesisBlock(resolve))
.then(function () {
return new Promise((resolve) => validBlockTest(resolve))
})
.then(function () {
return new Promise((resolve) => invalidblockTest(resolve))
})
Copy link
Contributor

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

account: acnt,
testData: testData,
})
q.push(new Promise((resolve, reject) => {
Copy link
Contributor

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

@ryanio
Copy link
Contributor

ryanio commented Jul 30, 2020

looking good! i still see quite a few new Promises that can be simplified further

@holgerd77
Copy link
Member

@jochem-brouwer can you address the latest requests from Ryan and rebase so that we can bring this over the finish line? 🙂

@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented Aug 6, 2020

@holgerd77 yes, will prioritize this after the weekend! 😄 (+squash commits)

@jochem-brouwer
Copy link
Member Author

Never mind, should be done (if discussions are resolved) 😄

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.

Approved after review of Ryan.

@holgerd77 holgerd77 merged commit ca426da into master Aug 7, 2020
@holgerd77 holgerd77 deleted the remove-async-dependency branch August 7, 2020 09:02
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.

5 participants