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

Block release v3.0.0 #682

Merged
merged 24 commits into from
May 15, 2020
Merged

Block release v3.0.0 #682

merged 24 commits into from
May 15, 2020

Conversation

evertonfraga
Copy link
Contributor

@evertonfraga evertonfraga commented Mar 31, 2020

This PR initially supersedes ethereumjs/ethereumjs-block#74. Given that this is now a monorepo, I aim to perform the respective integrations in downstream libraries (see diagram below).

  • Integrate ethereumjs-block v3.0.0 in ethereumjs-blockchain
  • Integrate ethereumjs-block v3.0.0 in ethereumjs-vm

Closes #680

@codecov
Copy link

codecov bot commented Apr 2, 2020

Codecov Report

Merging #682 into vm/release-v5 will decrease coverage by 1.34%.
The diff coverage is 85.71%.

Impacted file tree graph

@@                Coverage Diff                @@
##           vm/release-v5     #682      +/-   ##
=================================================
- Coverage          91.69%   90.34%   -1.35%     
=================================================
  Files                 47       43       -4     
  Lines               3011     3005       -6     
  Branches             469      469              
=================================================
- Hits                2761     2715      -46     
- Misses               151      194      +43     
+ Partials              99       96       -3     
Flag Coverage Δ
#account 94.11% <ø> (ø)
#block 82.82% <83.78%> (-5.45%) ⬇️
#blockchain 89.22% <85.00%> (+0.21%) ⬆️
#common 94.11% <ø> (-0.26%) ⬇️
#tx 94.02% <ø> (-0.09%) ⬇️
#vm 92.53% <100.00%> (ø)
Impacted Files Coverage Δ
packages/block/src/header.ts 67.21% <0.00%> (-21.32%) ⬇️
packages/blockchain/src/index.ts 87.79% <80.00%> (+0.07%) ⬆️
packages/block/src/block.ts 71.15% <81.81%> (-14.15%) ⬇️
packages/block/src/from-rpc.ts 86.66% <100.00%> (+0.45%) ⬆️
packages/blockchain/src/dbManager.ts 95.31% <100.00%> (+0.07%) ⬆️
packages/vm/lib/evm/evm.ts 91.97% <100.00%> (ø)
packages/vm/lib/runBlock.ts 80.95% <100.00%> (ø)
packages/vm/lib/runCall.ts 86.36% <100.00%> (ø)
packages/vm/lib/runCode.ts 95.45% <100.00%> (ø)
packages/vm/lib/runTx.ts 91.13% <100.00%> (ø)
... and 7 more

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 b5e2958...d63eb98. Read the comment docs.

@@ -61,6 +60,7 @@ function normalizeTxParams(_txParams: any) {
// strict byte length checking
txParams.to = txParams.to ? ethUtil.setLengthLeft(ethUtil.toBuffer(txParams.to), 20) : null
// v as raw signature value {0,1}
txParams.v = txParams.v < 27 ? txParams.v + 27 : txParams.v
const v: number = txParams.v
txParams.v = v < 27 ? v + 27 : v
Copy link
Member

Choose a reason for hiding this comment

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

What is happening here?

Copy link
Contributor Author

@evertonfraga evertonfraga Apr 2, 2020

Choose a reason for hiding this comment

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

tsc fix. This whole method needs a refactor to remove the magic numbers and is on my to-do list.

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
Contributor Author

Choose a reason for hiding this comment

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

@holgerd77 I added a more descriptive comment to explain this magic number.

Copy link
Contributor

Choose a reason for hiding this comment

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

@evertonfraga looks great, would make for a good trivia question 😄

@@ -314,7 +312,7 @@ export default class Blockchain implements BlockchainInterface {
* @hidden
*/
_setCanonicalGenesisBlock(cb: any): void {
const genesisBlock = new Block(null, { common: this._common })
const genesisBlock = new Block(undefined, { common: this._common })
Copy link
Member

Choose a reason for hiding this comment

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

Just for understanding: was this a necessary change which triggered some test failure or something before respectively came along with some code changes in v3.0.0? Or is this just an adjustment to make things cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This first round of changes is to comply with the linter and tsc. There were several compilation failures and Blockchain code was not functional when bumping Block to 3.0.0.

Copy link
Contributor Author

@evertonfraga evertonfraga Apr 2, 2020

Choose a reason for hiding this comment

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

In this specific case, null is not informed as a valid type in the Block constructor().

  constructor(
    data: Buffer | [Buffer[], Buffer[], Buffer[]] | BlockData = {},
    opts: ChainOptions = {},
)

Copy link
Member

Choose a reason for hiding this comment

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

Should we mention this in the v3.0.0 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.

Yes, definitely!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@holgerd77 I am leaning towards allowing null in Block constructor. What are your thoughts?

I can then revert the null to undefined changes made in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Would also have a tendency to keep it "as is".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. In the end, I have changed my mind regarding this.

The TypeScript community in general is not much of a fan of null values representing undefined values. In fact, this is a broad issue on how null is much often misused.

So, as the default code from TypeScript version of Block wasn't allowing null in their signature, I stick to it, and for JavaScript consumers, though, I added this check, which makes sure the method will behave as expected, so if a JS code initializes Block with data === null, data will become its null-object equivalent with value {}.

The impact in our TS code of using new Block(undefined, {}) is super low, only used in Block tests.

@evertonfraga evertonfraga changed the base branch from master to vm/release-v5 April 16, 2020 11:30
@evertonfraga evertonfraga force-pushed the block/release-v3.0.0 branch from 6d32754 to 334e248 Compare April 21, 2020 11:05
@evertonfraga evertonfraga force-pushed the block/release-v3.0.0 branch from 4a540c6 to a526d49 Compare April 30, 2020 18:20
@evertonfraga evertonfraga force-pushed the block/release-v3.0.0 branch from 43aaefa to e11b29a Compare May 1, 2020 18:32
@@ -54,7 +54,6 @@
"@types/node": "^11.13.4",
"@types/tape": "^4.2.33",
"browserify": "^16.2.3",
"ethereumjs-blockchain": "^4.0.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this circular dependency

"bootstrap": {
"ignore": "ethereumjs-block"
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ethereumjs-block is now integrated to Lerna workflow, so this change removes it from the ignore list for the bootstrap command.

@@ -11,8 +11,9 @@
}
},
"scripts": {
"bootstrap": "lerna bootstrap --ignore-scripts && lerna exec npm i --scope=ethereumjs-block",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lerna bootstrap now installs packages for ethereumjs-block as well, so removing npm i here.


[3.0.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fblock%402.2.0...%40ethereumjs%2Fblock%403.0.0

## [2.2.2] - 2019-12-17
Copy link
Contributor Author

Choose a reason for hiding this comment

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

picked 3.0.0, 2.2.1 and 2.2.2 changelog entries from its own branches in ethereumjs-block. Modified a bit 3.0.0 text.

Copy link
Contributor

Choose a reason for hiding this comment

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

looks great 👍

@@ -24,21 +134,21 @@ PR [#64](https://github.com/ethereumjs/ethereumjs-block/pull/64)
- Remove `ethereumjs-testing` dependency (much smaller dev dependencies),
PR [#61](https://github.com/ethereumjs/ethereumjs-block/pull/61)

[2.2.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fvm%402.1.0...%40ethereumjs%2Fvm%402.2.0
[2.2.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fblock%402.1.0...%40ethereumjs%2Fblock%402.2.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed comparison link, somehow the sed command used during the migration substituted it erroneously.


## [2.1.0] - 2018-10-19

- **Constantinople** support, added difficulty bomb delay (EIP-1234), PR [#54](https://github.com/ethereumjs/ethereumjs-block/pull/54)
- Updated test data, added Constantinople tests, PR [#56](https://github.com/ethereumjs/ethereumjs-block/pull/56), [#57](https://github.com/ethereumjs/ethereumjs-block/pull/57)
- Added `timestamp` field to `setGenesisParams()`, PR [#52](https://github.com/ethereumjs/ethereumjs-block/pull/52)

[2.1.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fvm%402.0.1...%40ethereumjs%2Fvm%402.1.0
[2.1.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fblock%402.0.1...%40ethereumjs%2Fblock%402.1.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

monorepo migration fix.


## [2.0.1] - 2018-08-08

- Fixes `BlockHeader.prototype.validate()` bug, see PR [#49](https://github.com/ethereumjs/ethereumjs-block/pull/49)

[2.0.1]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fvm%402.0.0...%40ethereumjs%2Fvm%402.0.1
[2.0.1]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fblock%402.0.0...%40ethereumjs%2Fblock%402.0.1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

monorepo migration fix.

- Correct block validation for all know hardforks, PR
[#47](https://github.com/ethereumjs/ethereumjs-block/pull/47), if no hardfork is set validation logic
is determined by block number in combination with the `chain` set
- Genesis block initialization depending on the `chain` set (see `ethereumjs-common` for supported chains)
- Extensive test additions to cover the newly introduced capabilities and changes
- Fix default value for `nonce` (empty buffer -> `<Buffer 00 00 00 00 00 00 00 00>`), PR [#42](https://github.com/ethereumjs/ethereumjs-block/pull/42)

[2.0.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fvm%401.7.1...%40ethereumjs%2Fvm%402.0.0
[2.0.0]: https://github.com/ethereumjs/ethereumjs-vm/compare/%40ethereumjs%2Fblock%401.7.1...%40ethereumjs%2Fblock%402.0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

monorepo link migration fix.

@@ -52,23 +162,23 @@ Changes in detail:
- New initialization parameters `opts.chain` (default: `mainnet`) and `opts.hardfork`
(default: `null`, block number-based behaviour), PR [#44](https://github.com/ethereumjs/ethereumjs-block/pull/44)
- Alternatively a `Common` class object can be provided directly with the `opts.common` parameter,
see [API](https://github.com/ethereumjs/ethereumjs-block/blob/master/docs/index.md) docs
see [API](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/block/docs/index.md) docs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

migrating link to monorepo structure.

@@ -10,7 +10,7 @@
"scripts": {
"build": "ethereumjs-config-build",
"prepublishOnly": "npm run test && npm run build",
"coverage": "npx nyc npm run test:node",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

npx is irrelevant here as nyc is listed as devDependency.

@@ -20,7 +20,7 @@
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"test": "npm run test:node && npm run test:browser",
"test:node": "npx tape -r ts-node/register test/*.spec.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

npx is irrelevant here as tape is listed as devDependency.

@@ -70,8 +69,5 @@
"typedoc-plugin-markdown": "^2.2.17",
"typescript": "^3.4.3",
"typestrict": "^1.0.2"
},
"publishConfig": {
"directory": "src"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't do the direct typescript code linking yet without handling the browser tests in a cross-package scope.

st.end()
})
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding some basic initialization tests

let body
try {
body = await this.getBody(hash, number)
} catch (e) {
body = [[], []]
}

return new Block([header].concat(body), { common: this._common })
const blockData = [header].concat(body) as [Buffer[], Buffer[], Buffer[]]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TS compiler was erroring out on this block of code.

### Promise-based API

The API of this library is now completely promise-based, the old callback-style
interface has been dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

@evertonfraga
Copy link
Contributor Author

Thanks for the review, @ryanio!

// Checking at runtime, to prevent errors down the path for JavaScript consumers.
if (data === null) {
data = {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

great

const Ethash = require('ethashjs')
const Stoplight = require('flow-stoplight')
const level = require('level-mem')
const semaphore = require('semaphore')

export type Block = any
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@@ -470,28 +468,29 @@ export default class Blockchain implements BlockchainInterface {

async.series(
[
verify,
async.asyncify(async function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh nice 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a full refactor should be done to simplify all these mixed async methods. But that's already planned :)

@@ -182,6 +182,8 @@ function runTests(name, runnerArgs, cb) {
const runner = require(`./${name}Runner.js`)
// Tests for HFs before Istanbul have been moved under `LegacyTests/Constantinople`:
// https://github.com/ethereum/tests/releases/tag/v7.0.0-beta.1

// TODO: Replace with Common.lteHardfork('Istanbul')
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 anything blocking this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no! but I'd rather make in a separate PR, this one is beyond big. It should be handled with care, testing several test scopes.

Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

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

Wow looks great, nice work on everything that needed to happen for this integration @evertonfraga 👍

@holgerd77
Copy link
Member

Whew, this is really a biggy! 😁 Congrats on this, feel free to merge in from my side as well.

@evertonfraga evertonfraga merged commit 4b9a096 into vm/release-v5 May 15, 2020
@evertonfraga evertonfraga deleted the block/release-v3.0.0 branch May 15, 2020 11:45
evertonfraga added a commit that referenced this pull request Jun 2, 2020
* block: version bump

* block: adds changelog from v2.2.1 to v3.0.0

* blockchain: integrating ethereumjs block 3.0.0

* blockchain: converting canonicalDifficulty to buffer

* blockchain: instantiating Block with empty/undefined data

* blockchain: integrating Block 3.0.0

* block: lint:fix changes

* All siloed tests passing.

* vm: lint fix

* leftovers of a rebase

* lint fix

* lint fix

* vm,block: integrating Block with Lerna

* block: remove circular dependency to ethereumjs-blockchain introduced in ethereumjs/ethereumjs-block#93

* block: removing unnecessary npx command

* block: lint fix

* blockchain: removing typo

* vm: fix BlockHeader import

* blockchain: fixing block initialization [Buffer[], Buffer[], Buffer[]] format

* vm: updating methods to async

* vm: misc changes

* block: describing recovery bit normalization statement

* block: removing source linking

* docs: update for all packages
@evertonfraga evertonfraga mentioned this pull request Jun 6, 2020
evertonfraga added a commit that referenced this pull request Jun 9, 2020
* block: version bump

* block: adds changelog from v2.2.1 to v3.0.0

* blockchain: integrating ethereumjs block 3.0.0

* blockchain: converting canonicalDifficulty to buffer

* blockchain: instantiating Block with empty/undefined data

* blockchain: integrating Block 3.0.0

* block: lint:fix changes

* All siloed tests passing.

* vm: lint fix

* leftovers of a rebase

* lint fix

* lint fix

* vm,block: integrating Block with Lerna

* block: remove circular dependency to ethereumjs-blockchain introduced in ethereumjs/ethereumjs-block#93

* block: removing unnecessary npx command

* block: lint fix

* blockchain: removing typo

* vm: fix BlockHeader import

* blockchain: fixing block initialization [Buffer[], Buffer[], Buffer[]] format

* vm: updating methods to async

* vm: misc changes

* block: describing recovery bit normalization statement

* block: removing source linking

* docs: update for all packages
evertonfraga added a commit that referenced this pull request Jun 10, 2020
* block: version bump

* block: adds changelog from v2.2.1 to v3.0.0

* blockchain: integrating ethereumjs block 3.0.0

* blockchain: converting canonicalDifficulty to buffer

* blockchain: instantiating Block with empty/undefined data

* blockchain: integrating Block 3.0.0

* block: lint:fix changes

* All siloed tests passing.

* vm: lint fix

* leftovers of a rebase

* lint fix

* lint fix

* vm,block: integrating Block with Lerna

* block: remove circular dependency to ethereumjs-blockchain introduced in ethereumjs/ethereumjs-block#93

* block: removing unnecessary npx command

* block: lint fix

* blockchain: removing typo

* vm: fix BlockHeader import

* blockchain: fixing block initialization [Buffer[], Buffer[], Buffer[]] format

* vm: updating methods to async

* vm: misc changes

* block: describing recovery bit normalization statement

* block: removing source linking

* docs: update for all packages
@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.

3 participants