-
Notifications
You must be signed in to change notification settings - Fork 493
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
refactor(@embark/blockchain): consistently merge config accounts and node accounts #1733
Conversation
DeepCode Report (#6e7dbb)DeepCode analyzed this pull request. |
06e6b9e
to
cb738b4
Compare
Really nice work, I love the descriptiveness and the lengths you went through to really try to tackle this issue!! Unfortunately, I do not think this will fix the issue and would still require a restart, because Embark is adding all node accounts plus wallet accounts to its web3 wallet, and thus will always return those accounts for any subsequent |
Thanks!
Despite appearances, i.e. the branch names involved in the web3 PR you linked to, those changes aren't and won't be part of web3 https://github.com/ethereum/web3.js/blob/1.x/packages/web3-eth/src/index.js#L226 https://github.com/ethereum/web3.js/blob/release/1.0/packages/web3-eth/src/index.js#L226 What makes the true behavior of Summary:
This PR already fixes it: there's no need to intercept Let's back up a bit... What embark is actually doing, effectively, is making the accounts from the dapp config behave like unlocked node accounts. The reason the list of accounts returned by Once the misunderstanding about the behavior of There's probably some additional cleanup and refactoring needed in this PR. I'm wondering if we really need to intercept While it may seem like a bandaid approach, I don't think there's another good solution. In fact, making all of the accounts seem like unlocked node accounts from the perspective of browsers and the cli dashboard — which is exactly what we were doing and this PR doesn't change that, just improves it — is probably the best and simplest thing we can do, i.e. for the sake of a smooth development experience. Dapp authors simply want to configure accounts and then use them without having to worry about wallet management during development. |
cb738b4
to
22f4e24
Compare
Thanks for clearing that up, I will take another look. The web3 branching names definitely were causing the confusion here. It makes complete sense that the provider could be the source of error. Can we assume that what I described will be included in web3 2.0? If it is, we may have this problem again as soon as we make the switch.
This is another point of confusion, because when the developer adds wallet accounts to the config (ie via mnemonic), these accounts are added to embark's wallet, they appear in DApp calls to |
@emizzle can you give an example of a web3 call that I could run in the browser console of |
Before I get to your last question, I wanted to follow up and confirm that you are correct in that
|
Using the v5 config updates branch as a base, I created a new demo. Then, I added the following to
After that, I ran In the browser, I ran
You can see the first account is the unlocked Running
works because the Running
fails because the Under the hood, the browser is sending |
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.
Very nice work. Two small comments
@@ -226,6 +235,10 @@ export class Proxy { | |||
}); | |||
}()); | |||
|
|||
const web3 = new Web3(`${ws ? 'ws' : 'http'}://${canonicalHost(host)}:${port}`); | |||
accounts = (await web3.eth.getAccounts() || []).concat(accounts || []); | |||
accounts = [...new Set(accounts.map(ethUtil.toChecksumAddress))]; |
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.
Why do you do this? We already do that in the response handling, no?
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's bootstrapping logic and is supposed to mirror how the blockchain provider bootstraps the accounts list.
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.
Yeah, I understand your idea, but it's not necessary to keep the list of updated accounts, for the moment at least.
accounts
can stay just the blockchain config accounts (custom accounts using mnemonic
, etc) and above, we just return the result + accounts
.
So, in the end, your changes in proxy.js are not really needed, because the proxy already always returned the up to date accounts.
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.
Yes, but what it led to was the eth.getAccounts()
having a different result when comparing web3 usage in the cli dashboard to web3 usage in a browser or a plain Node.js REPL connected to the proxy.
The changes in the provider and the proxy in this PR are intended to keep the getAccounts()
list up-to-date, consistently ordered, and free of duplicates.
Ideally, I'd like us to discuss and explore doing this operation in just one place, that's why the PR is a WIP.
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.
Makes sense for the ordering, even though it's not gonna be perfect in terms of matching the array the user puts in blockchain.js
. I had an old branch where I did some work to order the accounts as per the user's config, but never made a PR because I found that using custom accounts in the Dapp didn't work. You can see the branch here: https://github.com/embark-framework/embark/tree/fix/order-blockchain-accounts
IMO, we can go ahead with your changes as is, since it fixes the problem. We can and will come up with a better solution anyway once we do the refactor, so no need for anything fancy for now.
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.
Makes sense, thanks for the link and the feedback.
Thanks @emizzle, that makes a lot of sense. It seems we are intercepting But I guess we need to generalize that for all RPC calls that require signing, i.e. if there are others besides |
22f4e24
to
85406a6
Compare
85406a6
to
6e7dbb0
Compare
This is most definitely a WIP.Main points:
eth_accounts
andpersonal_listAccounts
do exactly the same things in geth's source code (see here and here in the same file; parity should be reviewed too) and thereforeweb3.eth.getAccounts()
andweb3.eth.personal.getAccounts()
are the same thing. The web3 docs website is not up-to-date and the published docs are misleading and incorrect. Compare these:https://web3js.readthedocs.io/en/1.0/web3-eth.html#getaccounts
web3/web3.js#2124
So
getAccounts()
, eithereth
orpersonal
, simply returns a list of accounts controlled by the node.What we're really doing in our blockchain connector's provider and the blockchain proxy is making config accounts look as if they're node accounts.
In the case of the provider, the accounts list was always being overwritten by the initial output of
getAccounts
combined with config accounts.In the case of the proxy, we were concat'ing the config accounts onto a live result of
eth_accounts
RPC.So this
WIPPR is trying to make the operations consistent, and it does seem successful. I added something like this to a freshembark_demo
:When connecting from a node REPL in a fresh project (
npm init -y
, not an embark dapp) that only hasweb3@1.0.0-beta.37
installed, I compared the output ofgetAccounts
when connecting to 8545 vs 8555 ofembark blockchain
. I did the same in a browser with web3 beta.37. And I compared those with the output inembark run
cli dashboard. I made sure to use theweb3.eth.personal.newAccount()
method and rangetAccounts()
in all the environments and I got consistent and expected results, i.e.[eth|personal].getAccounts()
is always up-to-date after adding node accounts withpersonal.newAccount()
, and 8555 lacks the{ privateKey: "<some valid key>"}
account.I'm not 100% sure yet that the output of the account parser is being handled in exactly the same way when comparing the blockchain connector's provider withSee: #1733 (comment).embark-blockchain-process/src/{blockchain,proxy}
. Also, seems like some more refactoring could be done to reduce duplicated logic.This PR doesn't doesn't directly address the decisions we're making as a team re: account config semantics, but hopefully it sheds some light on things that are easily misunderstood. I'm 100% sure I was totally confused before I dove into the code and started messing with web3, our provider, and our proxy. I believe these changes would fix @emizzle's problem re: lightchain and the manual creation of node accounts with web3.