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

Eip1283 #17383

Merged
merged 4 commits into from
Sep 21, 2018
Merged

Eip1283 #17383

merged 4 commits into from
Sep 21, 2018

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Aug 12, 2018

This PR implements [EIP 1283(https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1283.md#specification-version-ii). 1283 is an alternative to 1087, which does not require as much post-processing.

The cost for SSTORE operations rely on current value, new value and original value, where original means 'what is currently in the trie' a.k.a 'the value that would remain if this current transaction was wholly reverted'.

This PR uses a map in state_object to store original value whenever a slot is updated.
This PR is experimental, in that it does not contain any testcases whatsoever, the intention being more to test how complex it would be to implement rather than being a fully-fledged merge-ready PR.

@holiman holiman requested a review from karalabe August 12, 2018 12:51
@AlexeyAkhunov
Copy link
Contributor

This is probably outside of remit of this PR, but now that you have "originalStorage" and "dirtyStorage", you don't need "cachedStorage", which existed only to avoid repeated reads. Now you can avoid repeated reads like so: https://github.com/ethereum/go-ethereum/pull/17208/files#diff-e6890b729fad8d7cf6c1a35a31080af7R165, and "originalStorage" also allows skipping writes that do not change the stored value: https://github.com/ethereum/go-ethereum/pull/17208/files#diff-e6890b729fad8d7cf6c1a35a31080af7R193

@holiman
Copy link
Contributor Author

holiman commented Aug 14, 2018

Thanks for checking, @AlexeyAkhunov ! I had a feeling that the implementation could be done better, by making better use of the existing structures, but didn't really go in for it. If we decide to move forward with this EIP, I'll update it according to your observations.

@holiman
Copy link
Contributor Author

holiman commented Aug 14, 2018

(or, actually, might be better just rewrite it based on @karalabe's PR instead)

if original == (common.Hash{}) { // 2.1.1
return 20000, nil
// The legacy gas metering only takes into consideration the current state
if !evm.chainRules.IsConstantinople {
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 personally think it was cleaner to have two separate gas calc functions, one enabled in Constantinople and one earlier. That makes the respective methods smaller, and saves this check on every SSTORE.

Copy link
Member

Choose a reason for hiding this comment

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

It's a single bool comparison vs. an sstore potentially loads of data from disk. Other gas calculations (e.g. gasSuicide) also use the same logic of having a single method per opcode and potentially checking whether a fork is enabled or not. It feels a bit cleaner for me to have a single method, but if you really disagree we can split 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.

Yeah, it's not a heavy toll, the main reason for me was more that it allowed splitting the methods into two separate units.
I don't feel strongly about it, you're the main maintainer :)

@holiman
Copy link
Contributor Author

holiman commented Sep 19, 2018

A lot of the tests are failing, since this PR messes with a lot of things that use SSTORE. I'll take a look and see if those can be updated.

@holiman
Copy link
Contributor Author

holiman commented Sep 19, 2018

See ethereum/tests#511 (comment) -- before all tests are regenerated, not much we can do to turn travis green ...

@karalabe
Copy link
Member

See ethereum/tests#511 (comment) -- before all tests are regenerated, not much we can do to turn travis green ...

Perhaps we should disable the Constantinople tests and reenable them when they're updated. I'd very much like to keep pre-Constantinople tests live in our repo.

@holiman
Copy link
Contributor Author

holiman commented Sep 19, 2018

I can fix that

@karalabe karalabe added this to the 1.8.17 milestone Sep 20, 2018
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM! Let's merge after release (just so we have a bit more time running on Rinkeby before dumping it onto mainnet).

@karalabe karalabe modified the milestones: 1.8.17, 1.8.16 Sep 21, 2018
@karalabe karalabe merged commit ee92bc5 into ethereum:master Sep 21, 2018
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.

5 participants