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

Replace account package with ethereumjs-util Account #911

Merged
merged 4 commits into from Oct 15, 2020

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Oct 13, 2020

This PR replaces the account package in the monorepo for the new Account class in ethereumjs-util.

This PR also updates some types and removes redundant new BN() syntax if the value is already a BN.

@codecov
Copy link

codecov bot commented Oct 13, 2020

Codecov Report

Merging #911 into master will decrease coverage by 0.13%.
The diff coverage is 86.20%.

Impacted file tree graph

Flag Coverage Δ
#account ?
#block 77.05% <100.00%> (ø)
#blockchain 80.86% <100.00%> (ø)
#common 93.01% <ø> (ø)
#ethash 82.97% <100.00%> (+0.75%) ⬆️
#tx 90.38% <ø> (ø)
#vm 87.98% <82.60%> (-0.56%) ⬇️

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

@ryanio ryanio force-pushed the remove-account-package branch 4 times, most recently from 332a47a to fd108a3 Compare October 13, 2020 19:48
@@ -1,5 +1,4 @@
import BN = require('bn.js')
import Account from '@ethereumjs/account'
import { Account, BN } from 'ethereumjs-util'
Copy link
Member

Choose a reason for hiding this comment

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

There is still a reference to ethereumjs-account left in the code docs of this file (on the step event).

Side note: does the step event also need some attention on this regard? 🤔 At least a mention in the release notes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in 12ff416, yes I think we should mention in the release notes.

balance: '0x01',
}),
),
this.stateManager.putAccount(address, new Account(new BN(0), new BN(1))),
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to generally avoid to use the main constructor. This makes the code less readable since one can't distinguish on the type of values directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 done in 588912a

@@ -216,7 +215,7 @@ async function applyBlock(this: VM, block: any, opts: RunBlockOpts) {
* @param {Block} block
* @param {RunBlockOpts} opts
*/
async function applyTransactions(this: VM, block: any, opts: RunBlockOpts) {
async function applyTransactions(this: VM, block: Block, opts: RunBlockOpts) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

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.

Already looks pretty good, some comments.

@@ -1,4 +1,4 @@
import Account from '@ethereumjs/account'
import { Account } from 'ethereumjs-util'
Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, so this DOES change the StateManager interface, also something worth to be mentioned in the release notes.

// EIP-161: "An account is considered empty when it has no code and zero nonce and zero balance."
return (
account.nonce.isZero() && account.balance.isZero() && account.codeHash.equals(KECCAK256_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, we should I would assume remove the stateRoot check again? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I am still discussing with @jochem-brouwer but I think that is what we will end up doing. this is still safe to merge in, and once updated in util then I can update here back to account.isEmpty()

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, this looks good now. Nice!

nonce: 0,
balance: new BN(10).pow(new BN(19)), // 10 eth
}
const account = Account.fromAccountData(acctData)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! 🙂

* @property {Buffer} address the address of the `account`
* @property {Number} depth the current number of calls deep the contract is
* @property {Buffer} memory the memory of the VM as a `buffer`
* @property {BN} memoryWordCount current size of memory in words
* @property {StateManager} stateManager a [`StateManager`](stateManager.md) instance (Beta API)
* @property {StateManager} stateManager a [[StateManager]] instance
Copy link
Member

Choose a reason for hiding this comment

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

Had to look up these symbol references (double square brackets) - so linking to internal classes, members or functions, really nice functionality! 😄 Just dropping here for others as a reference.

@holgerd77 holgerd77 merged commit 2d74d4c into master Oct 15, 2020
@holgerd77 holgerd77 deleted the remove-account-package branch October 15, 2020 08:42
@holgerd77
Copy link
Member

Absolutely no criticism, but just realizing what has been forgotten here: switching to our new CHANGELOG procedure and updating the release notes along the way. 😋

Just as some general reminder, think we are all not yet completely in this mode and this will likely take some time to settle in. 😀

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.

None yet

2 participants