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

Update ethereumjs-util to v7 #748

Merged
merged 3 commits into from Jun 1, 2020
Merged

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented May 16, 2020

This PR updates ethereumjs-util to v7 for various improvements and benefits (see changelog) including keccak prebuilds.

This PR also:

  • Switches some last ethereumjs-util wildcard imports for explicit imports
  • Upgrades typescript dep

@codecov
Copy link

codecov bot commented May 16, 2020

Codecov Report

Merging #748 into vm/release-v5 will decrease coverage by 0.01%.
The diff coverage is 90.32%.

Impacted file tree graph

@@                Coverage Diff                @@
##           vm/release-v5     #748      +/-   ##
=================================================
- Coverage          90.31%   90.29%   -0.02%     
=================================================
  Files                 46       44       -2     
  Lines               3004     2999       -5     
  Branches             470      470              
=================================================
- Hits                2713     2708       -5     
  Misses               194      194              
  Partials              97       97              
Flag Coverage Δ
#account 94.11% <ø> (ø)
#block 82.47% <83.33%> (-0.03%) ⬇️
#blockchain 88.81% <ø> (ø)
#common 94.11% <ø> (-0.26%) ⬇️
#tx 94.16% <ø> (+0.13%) ⬆️
#vm 92.53% <100.00%> (ø)
Impacted Files Coverage Δ
packages/tx/src/transaction.ts 94.73% <ø> (ø)
packages/block/src/header-from-rpc.ts 87.50% <66.66%> (ø)
packages/block/src/header.ts 66.94% <66.66%> (-0.28%) ⬇️
packages/block/src/block.ts 71.15% <100.00%> (ø)
packages/block/src/from-rpc.ts 86.66% <100.00%> (ø)
packages/vm/lib/evm/opFns.ts 89.60% <100.00%> (ø)
packages/common/src/chains/index.ts
packages/common/src/hardforks/index.ts
packages/common/src/genesisStates/index.ts
packages/tx/src/index.ts 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b9a096...9b4c55e. Read the comment docs.

import { Blockchain, BlockHeaderData, BufferLike, ChainOptions, PrefixedHexString } from './types'
import { Buffer } from 'buffer'
import { Block } from './block'

const { BN } = require('ethereumjs-util')
import IBN = require('bn.js')
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the back story on BN vs. IBN?

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'm not too sure what was going on, I was just trying to resolve some typescript build errors. The error was "Type originates at this import" regarding bn.js in ethereumjs-util externals.d.ts - might be some confusion because the bn.js types are defined in a @types package. I did check and they are in deps and not devDeps for ethereumjs-util though so I would have hoped for them to be included in a clean way, but it did not let me simply do import { BN } from 'ethereumjs-util'.

@evertonfraga
Copy link
Contributor

The changes look good! I just wanted to understand the context of BN vs. IBN there.

I will also learn more about the 6.x to 7.0.0 changes and discussion around 7.0.1, so my review can be more solid.

:)

@ryanio
Copy link
Contributor Author

ryanio commented May 18, 2020

Thanks!

Check out the ethereumjs-util/CHANGELOG.md

bn.js issues regarding 7.0.1 still being explored here: ethereumjs/ethereumjs-wallet#121 (comment) (edit: concluded with patch fix releases in bn.js v4 and v5)

@holgerd77
Copy link
Member

Please take ethereumjs/ethereumjs-util#253 into account respectively upgrade on a new release before merging

@ryanio ryanio force-pushed the update-ethereumjs-util-to-v7 branch from 4108730 to e9f6396 Compare May 26, 2020 17:55
@holgerd77
Copy link
Member

Let me know if you need a review here.

@ryanio
Copy link
Contributor Author

ryanio commented May 27, 2020

sounds good thanks, I think the PR is ready for review other than the weird BN type interface issue I outlined above, I will give it another look to see if it is something I can fix here or perhaps some additional configuration we need in ethereumjs-util in passing the BN types down.

@holgerd77
Copy link
Member

@ryanio @evertonfraga Ah, sorry, didn't re-read the thread so closely, yeah, you're right, the BN issue should likely figured out here.

Not sure if this helps, just posting here for the marginal chance that it could: 😋

On a clean ethereumjs-util v7.0.2 install this works without problems with ts-node:

$ ts-node
> import { BN } from 'ethereumjs-util'
{}
> BN
[Function: BN] {
  BN: [Circular],
  wordSize: 26,
  isBN: [Function: isBN],
  max: [Function: max],
  min: [Function: min],
  red: [Function: red],
  _prime: [Function: prime],
  mont: [Function: mont]
}
>

@ryanio
Copy link
Contributor Author

ryanio commented May 27, 2020

@holgerd77 ah thanks for that.

OK I found some more information here: https://stackoverflow.com/a/49256285

Basically, block has esModuleInterop: true which is causing the compiler to do an extra check that throws a bunch of errors like:

TSError: ⨯ Unable to compile TypeScript:
src/header.ts:144:25 - error TS2351: This expression is not constructable.
  Type 'typeof BN' has no construct signatures.

144     const blockTs = new BN(this.timestamp)
                            ~~

  node_modules/ethereumjs-util/dist/externals.d.ts:7:1
    7 import * as BN from 'bn.js';
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
src/header.ts:145:26 - error TS2351: This expression is not constructable.
  Type 'typeof BN' has no construct signatures.

145     const parentTs = new BN(parentBlock.header.timestamp)
                             ~~

  node_modules/ethereumjs-util/dist/externals.d.ts:7:1
    7 import * as BN from 'bn.js';
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
src/header.ts:146:27 - error TS2351: This expression is not constructable.
  Type 'typeof BN' has no construct signatures.

146     const parentDif = new BN(parentBlock.header.difficulty)
                              ~~

Removing esModuleInterop (or setting to false) fixes the issue, however I'm not sure if there are any other consequences (i.e. why it was added). However our new ethereumjs-config tsconfig (as compared to old) will have esModuleInterop set to true so it may come back to haunt us again.

edit: pushed a commit (ffc943b) to try this out (cc @evertonfraga)

@holgerd77 holgerd77 mentioned this pull request May 29, 2020
27 tasks
@evertonfraga evertonfraga self-requested a review June 1, 2020 12:15
@@ -41,7 +41,7 @@
"ethashjs": "~0.0.7",
"ethereumjs-block": "~3.0.0",
"ethereumjs-common": "^1.5.0",
"ethereumjs-util": "~6.1.0",
"ethereumjs-util": "^7.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

I have reverted it back to a caret range, to comply with the other monorepo packages.
Looking at old versions of this line led to this PR ethereumjs/ethereumjs-blockchain#33, proving this was a protection mechanism for a hardfork changes.

Any opinions here, @holgerd77?

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 from some really old ages 😄 , no reason for special rules here any more.

Think its very beneficial if we end up using caret ranges at least for our own internal dependencies all over the place and just follow semver without exception. This was quite different some time (2-3 years) ago but we have gotten quite some way here and I think we are now with most (all?) of the (actively worked on) libraries in a semver-compliant release process.

Copy link
Contributor

@evertonfraga evertonfraga left a comment

Choose a reason for hiding this comment

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

Unless there's any specific reason to keep ethereumjs-util under a tilde version, we're good to go!

@evertonfraga
Copy link
Contributor

I will test the esModuleInterop change now and see if there's any implication on the Block side.

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, also had another short look, I will merge this in now since this is so relatively heavy and I would like to do some rebases on top.

@holgerd77 holgerd77 merged commit 09de6f4 into vm/release-v5 Jun 1, 2020
@holgerd77 holgerd77 deleted the update-ethereumjs-util-to-v7 branch June 1, 2020 14:52
@evertonfraga evertonfraga mentioned this pull request Jun 9, 2020
@evertonfraga evertonfraga added this to the VM v5 milestone Jun 12, 2020
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

3 participants