Skip to content

accounts/abi refactor#15731

Merged
holiman merged 8 commits into
ethereum:masterfrom
holiman:revamp_abi
Dec 22, 2017
Merged

accounts/abi refactor#15731
holiman merged 8 commits into
ethereum:masterfrom
holiman:revamp_abi

Conversation

@holiman
Copy link
Copy Markdown
Contributor

@holiman holiman commented Dec 21, 2017

This PR changes the ABI-model, since ABI is an encoding of arguments, the unpack logic has been moved away from Method/ Event, and on to the new type Arguments (alias for []Argument).

This PR removes a lot of duplicated code and also makes it easier to unpack method inputs as well as outputs, and also simplifies the logic in the abi-package.

This PR also incorporates (and supersedes) #15452 , with some extra testcases taken from #15568 .

This is a large PR, but I believe the abi-package to be fairly well covered by testcases at this point.

Event.tupleUnpack doesn't handle correctly Indexed arguments,
hence it can't unpack an event with indexed arguments.
+ The event slice unpacker doesn't correctly extract element from the
slice. The indexed arguments are not ignored as they should be
(the data offset should not include the indexed arguments).

+ The `Elem()` call in the slice unpack doesn't work.
The Slice related tests fails because of that.

+ the check in the loop are suboptimal and have been extracted
out of the loop.

+ extracted common code from event and method tupleUnpack
+ adding missing comments
+ small cleanups which won't significantly change
  function body.
+ unify Method receiver name
+ Reworked Method Unpack tests into more readable components
+ Added Method Unpack into slice test
@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 21, 2017

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 21, 2017

To the people on cc: I have done my best to ensure that the functionality of the preceding PR:s in this package has been kept intact, but if I've messed with anything, please yell.

@robert-zaremba
Copy link
Copy Markdown
Contributor

Why we are redoing this changes instead of merging long hanging PR (around 2 months already) and then updating?

@gballet
Copy link
Copy Markdown
Member

gballet commented Dec 22, 2017

@robert-zaremba it's not "redone", if you look at it your PR has been integrated into this one.

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 22, 2017

instead of merging long hanging PR (around 2 months already) and then updating?

The reason is that we started merging a couple of PR:s in that section, which made your PR conflict. So we had to fix it up. Since I did not want to get stuck waiting for someone to fix it, I did it myself (at the same time that @gballet was also doing it), and then rebased my pr on top of your commits.

So I've spent quite some time to ensure that everyone gets credit (commits) and that all functionality is intact.

Now, in hindsight, I should've/could've the rebased version of you PR back into your PR... But as I noticed halfway through that @gballet was also rebasing that one, it seemed like quite a tangle.

@robert-zaremba
Copy link
Copy Markdown
Contributor

@holiman
OK, Thanks for handling it. It's a pity that at the end this takes so much work.
Let me know if you need some help.

Copy link
Copy Markdown
Contributor

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

I had a quick overview of the code and left few comments.

Comment thread accounts/abi/abi.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to return a pointer? It's a small structure. How about returning (Method, bool)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, that would work too... Don't know why that would be better really...

Comment thread accounts/abi/abi_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about using testify?

6 lines above could be substituted with:

require.True
require.Equal

Also this solves another issue: if the first if fails then the second one shouldn't be executed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I haven't gotten used to testify yet, that's the reason :)
I'll keep it in mind for future reference

Comment thread accounts/abi/abi_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above.

Comment thread accounts/abi/abi_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can use testify:

require.NoError

Comment thread accounts/abi/abi_test.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

comment should be removed

Comment thread accounts/abi/argument.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you don't need this if. for will handle empty / nil slice

Copy link
Copy Markdown
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

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

Minor nitpicks. Great cleanup!

Comment thread accounts/abi/abi.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couldn't there be a lookup table for method.Id() <=> method ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There could be, but I don't think this will be extensively used; I'll use it from the signer, but it's a one-off operation. So might as well do it lazily.

Comment thread accounts/abi/argument.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some linters will complain if there is no consistency when implementing methods for a type. I advise that you call all methods arguments instead of a

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 22, 2017

Travis failures unrelated:
Go 1.8.x:

?   	github.com/ethereum/go-ethereum/dashboard	[no test files]
ok  	github.com/ethereum/go-ethereum/eth	4.733s	coverage: 25.0% of statements
--- FAIL: TestFastCriticalRestarts (0.00s)
    --- FAIL: TestFastCriticalRestarts/protocol_63_progress_true (4.70s)
    	downloader_test.go:1818: pivot block not locked in after critical section failure
FAIL
coverage: 79.3% of statements

Go 1.7.x:

ok  	github.com/ethereum/go-ethereum/node	0.902s	coverage: 43.5% of statements
# cover github.com/ethereum/go-ethereum/p2p
cover: internal error: block 17 overlaps block 19
	/home/travis/gopath/src/github.com/ethereum/go-ethereum/p2p/server.go:#8021,#8156 /home/travis/gopath/src/github.com/ethereum/go-ethereum/p2p/server.go:#8078,#8106
cover: internal error: block 23 overlaps block 25
	/home/travis/gopath/src/github.com/ethereum/go-ethereum/p2p/server.go:#8307,#8400 /home/travis/gopath/src/github.com/ethereum/go-ethereum/p2p/server.go:#8361,#8380
ok  	github.com/ethereum/go-ethereum/p2p	0.213s	coverage: 73.8% of statements

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 22, 2017

I pushed some fixes to the comments, thanks for reviewing!

@holiman
Copy link
Copy Markdown
Contributor Author

holiman commented Dec 22, 2017

Squashed for niceness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants