-
Notifications
You must be signed in to change notification settings - Fork 650
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
Implement EIP 1234 #1303
Merged
Merged
Implement EIP 1234 #1303
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
from eth_utils import denoms | ||
|
||
|
||
GAS_EXTCODEHASH_EIP1052 = 400 | ||
|
||
EIP1234_BLOCK_REWARD = 2 * denoms.ether |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from eth.vm.forks.byzantium.headers import ( | ||
configure_header, | ||
create_header_from_parent, | ||
compute_difficulty, | ||
) | ||
|
||
|
||
compute_constantinople_difficulty = compute_difficulty(5000000) | ||
|
||
create_constantinople_header_from_parent = create_header_from_parent( | ||
compute_constantinople_difficulty | ||
) | ||
configure_constantinople_header = configure_header(compute_constantinople_difficulty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pytest | ||
|
||
from eth_utils import ( | ||
to_wei | ||
) | ||
|
||
from eth.chains.base import ( | ||
MiningChain | ||
) | ||
from eth.tools.builder.chain import ( | ||
at_block_number, | ||
build, | ||
disable_pow_check, | ||
mine_block, | ||
byzantium_at, | ||
frontier_at, | ||
homestead_at, | ||
spurious_dragon_at, | ||
tangerine_whistle_at, | ||
constantinople_at, | ||
genesis, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'vm_fn, miner_1_balance, miner_2_balance', | ||
( | ||
(frontier_at, 15.15625, 4.375), | ||
(homestead_at, 15.15625, 4.375), | ||
(tangerine_whistle_at, 15.15625, 4.375), | ||
(spurious_dragon_at, 15.15625, 4.375), | ||
(byzantium_at, 9.09375, 2.625), | ||
(constantinople_at, 6.0625, 1.75), | ||
) | ||
) | ||
def test_rewards(vm_fn, miner_1_balance, miner_2_balance): | ||
|
||
OTHER_MINER_ADDRESS = 20 * b'\x01' | ||
TOTAL_BLOCKS_CANONICAL_CHAIN = 3 | ||
|
||
chain = build( | ||
MiningChain, | ||
vm_fn(0), | ||
disable_pow_check(), | ||
genesis(), | ||
mine_block(), # 1 | ||
mine_block(), # 2 | ||
) | ||
|
||
fork_chain = build( | ||
chain, | ||
at_block_number(1), | ||
mine_block(extra_data=b'fork-it!', coinbase=OTHER_MINER_ADDRESS), # fork 2 | ||
) | ||
|
||
# we don't use canonical head here because the fork chain is non-canonical. | ||
uncle = fork_chain.get_block_header_by_hash(fork_chain.header.parent_hash) | ||
assert uncle.block_number == 2 | ||
assert uncle != chain.get_canonical_head() | ||
|
||
chain = build( | ||
chain, | ||
mine_block(uncles=[uncle]), # 3 | ||
) | ||
|
||
header = chain.get_canonical_head() | ||
block = chain.get_block_by_hash(header.hash) | ||
assert len(block.uncles) == 1 | ||
assert block.uncles[0] == uncle | ||
|
||
vm = chain.get_vm() | ||
coinbase_balance = vm.state.account_db.get_balance(block.header.coinbase) | ||
other_miner_balance = vm.state.account_db.get_balance(uncle.coinbase) | ||
|
||
# We first test if the balance matches what we would determine | ||
# if we made all the API calls involved ourselves. | ||
assert coinbase_balance == (vm.get_block_reward() * | ||
TOTAL_BLOCKS_CANONICAL_CHAIN + | ||
vm.get_nephew_reward()) | ||
assert other_miner_balance == vm.get_uncle_reward(block.number, uncle) | ||
|
||
# But we also ensure the balance matches the numbers that we calculated on paper | ||
assert coinbase_balance == to_wei(miner_1_balance, 'ether') | ||
assert other_miner_balance == to_wei(miner_2_balance, 'ether') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Alternatively, we could make this a
@classmethod
and then access the block reward oncls.block_reward
which would allow us drop any uncle reward refinement inConstantinopleVM
. Thoughts?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.
Conceptually I'm fine with that but I think it goes against the direction we're trying to go with composition > inheritance. I like the mechanism you've got in place now with the curried re-usable utilities so if you're happy with that I say keep it (and maybe backport it to the
ByzantiumVM
)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.
Yup, I like it as-is, too. I kind of like the idea of pushing the
get_uncle_reward(...)
definition as far back as possible, so that even the import carries semantic meaning, like:Would mean that the uncle mechanism has stayed the same since frontier, with only the block reward changing in:
get_uncle_reward = staticmethod(get_uncle_reward(EIP649_BLOCK_REWARD))
.(I don't remember when/if the uncle mechanism changed, but the general concept stands.)
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.
SGTM 👍
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.
It was last changed in
byzantium
so I think it is already pushed as far back as possible.