-
Notifications
You must be signed in to change notification settings - Fork 239
Conversation
@holgerd77 This might be ready to go, depending on whether we want to resolve the following: This implemenation of For instance, that To see an example of this, run
If not, we need to explicitly handle these other forks in some way. |
Hi Dan, thanks for the update! This whole Would probably be optimal to have this PR merged and then work here on top of the hardfork and chain integration work. |
I put "blocked" in the title as the latest commit makes this PR dependent on #130 Once that is merged, I will rebase here |
… to be undefined.
…eumjs-common (PR #130)
50dddbd
to
857c685
Compare
@holgerd77 This is ready for final review and merge. I'll confirm tomorrow, but the latest changes likely make #132 redundant. |
Great! 👍 |
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.
We should have a closer look at this chainId
redundancy, one minor formatting suggestions, otherwise looks good! Thanks Dan! 😄
index.js
Outdated
@@ -151,7 +151,7 @@ class Transaction { | |||
if (chainId < 0) chainId = 0 | |||
|
|||
// set chainId | |||
this._chainId = chainId || data.chainId || 0 | |||
this._chainId = opts.chainId || chainId || data.chainId || 0 |
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.
The Common
object is set with a specific chain and can be used to access the chain ID, can we use this instead of adding yet another option here?
I would also tend to remove the date.chainId
parameter and also set this from Common
after instantiation.
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.
Good suggestions, thanks. I also overlooked how the opts.chain
param was added with #130.
So we might also be able to get rid of the code on lines 150, 151 and 152. No need to calculate the chainId from the signature. Either an opts.chain
is passed or we assume it is mainnet. Then Common can do the rest.
index.js
Outdated
@@ -179,7 +179,8 @@ class Transaction { | |||
if (includeSignature) { | |||
items = this.raw | |||
} else { | |||
if (this._chainId > 0) { | |||
const v = ethUtil.bufferToInt(this.v) | |||
if ((v === this._chainId * 2 + 35 || v === this._chainId * 2 + 36) && this._common.gteHardfork('spuriousDragon')) { |
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.
I would prefer to have this separated into two if clauses so that this get's more readable. So first the hardfork check on spuriousDragon
to indicate the HF dependent logic and then a separate v === this._chainId * 2 + 35 || v === this._chainId * 2 + 36
check. For the second check a short comment what's happening would also be helpful for readability.
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.
Changes made in 812c99d
I didn't quite use two if statements, probably because of stylistic preference. It should be much clearer. I'm fine to go with two if
statements explicitly if that is your preference :)
this._senderPubKey = ethUtil.ecrecover(msgHash, v, this.r, this.s) | ||
const v = ethUtil.bufferToInt(this.v) | ||
const useChainIdWhileRecoveringPubKey = v >= this._chainId * 2 + 35 && this._common.gteHardfork('spuriousDragon') | ||
this._senderPubKey = ethUtil.ecrecover(msgHash, v, this.r, this.s, useChainIdWhileRecoveringPubKey && this._chainId) |
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.
Ok.
.then(() => { | ||
t.end() | ||
}) | ||
}) |
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.
Looks good, clean and nice and easy to read test setup! 👍
Also: can you still confirm regarding #132? |
@holgerd77 I've closed #132, this PR covers the important pieces of it |
In addition to the above changes, I am going to give myself one more task before I merge:
|
Oops, my latest update broke the build. I will fix it. |
Sounds good, let me know once this is ready for re-review! |
What's the status of this? |
c011704
to
8ea361a
Compare
Previously
|
…gh 'chain' and 'common' opts.
…mjs common updates.
8773c7b
to
d7c98ea
Compare
d7c98ea
to
4d75731
Compare
@holgerd77 I have revised this PR so that my previous comment is no longer true: there are no longer breaking changes. Instead, this PR updates the codebase to support the new way of setting chainId and the legacy approach:
Developers that us opts.chain or opts.common will be able to explicitly set chainId to a value of their choice. Developers that do not set it will have it set by default according to the existing rules:
I've decided to leave support for the use of Meanwhile, this PR includes an update to run all transaction tests on mainnet, which seems to be an assumption baked into those tests. Also not that #143 is based off this PR. Among other things, it addresses an outstanding issue with this PR. I believe this PR is now complete and ready to merge, notwithstanding the a possible decision on the removal of |
Trusting your choices here, will try to do a short-term final review. I am thinking a bit if you guys want to completely take over responsibility for the continued work and directly do cross-reviews with e.g. @chikeichan and eventually new contributors from Nomic, I think you are understanding this library at least as good as me anyhow. And I would rather watch from the sideline and try to make sure it fits into overall strategy, modernization efforts and technical guidelines. So Jacky e.g., if you want to do a review on this and then merge, feel free (but generally: please take reviews seriously, you can very well take 1-2 hours for this and also put this in the timesheet, this is as important as the work itself). Best |
Or @s1na could eventually also do a review on this |
I reviewed this PR today, and it looks good. Note that this is my first review here, so I may be missing something. I didn't make any comment on style either, as I'm still getting used to the ethereumjs's standards. The only thing that raised my attention is that after this PR the function I created this test which can be added to t.test('EIP155 hashing when singing', function (st) {
txFixtures.slice(0, 3).forEach(function (txData) {
const tx = new Transaction(txData.raw.slice(0, 6), {chain: 1})
var privKey = new Buffer(txData.privateKey, 'hex')
tx.sign(privKey)
st.equal(
tx.getSenderAddress().toString("hex"),
txData.sendersAddress,
'computed sender address should equal the fixture\'s one'
)
});
st.end()
}) |
|
||
const onEIP155BlockOrLater = this._common.gteHardfork('spuriousDragon') | ||
const v = ethUtil.bufferToInt(this.v) | ||
const vAndChainIdMeetEIP155Conditions = v === this._chainId * 2 + 35 || v === this._chainId * 2 + 36 |
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.
nice
reviewed coding style and structure - LGTM! I also agree with the decision to not introduce breaking changes without a waring period. And thanks for the detailed review @alcuadrado - @danjm can you please take a look at the |
if (opts.chain || opts.common) { | ||
this._chainId = this._common.chainId() | ||
} else { | ||
this._chainId = chainId || data.chainId || 0 |
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.
The discussion on here is pretty useful - can we add an inline comment to summarize (or paste the link to comment)? This would help future devs to gather context quickly.
Great catch @alcuadrado. That bug has been addressed on #143 I just pushed the test you wrote to that branch. It passed for me locally. |
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.
Seems we are ready, thanks Dan, feel free to merge! 😀
Ok, will now merge here myself so that we can move on on top of the work here. |
Opening this PR instead of #126 as this branch is in the main repo.
fixes #115
Updates the transactionRunner.js tests as per the changes and instructions described here: ethereum/tests#373
Each test is run for each of the hardforks. If the
tx
is defined but has an invalid signature after creation, the test passes if the test data for the given hardfork is empty. If thetx
is undefined after creation, the test passes if the test data for the given hardfork is empty. If thetx
has a sender and hash that matches that in the test data for the given hard fork, the test passes.This PR also adds the ability to run a single test by passing an exact filename match. For example:
npm run test:node -- -t --file=TransactionWithHighGas | tap-spec