Skip to content

Commit

Permalink
Initial reference implementation of EIP1789
Browse files Browse the repository at this point in the history
  • Loading branch information
lrettig committed Mar 12, 2019
1 parent 9daec39 commit ee5a23f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
24 changes: 24 additions & 0 deletions eth/vm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,30 @@ def get_block_reward() -> int:
"""
raise NotImplementedError("VM classes must implement this method")

@staticmethod
@abstractmethod
def get_devfund_reward() -> int:
"""
Return the amount in **wei** that should be given to the dev fund as a reward
for this block.
.. note::
This is an abstract method that must be implemented in subclasses
"""
raise NotImplementedError("VM classes must implement this method")

@staticmethod
@abstractmethod
def get_devfund_beneficiary() -> Address:
"""
Return the address that should be given to the dev fund reward
for this block.
.. note::
This is an abstract method that must be implemented in subclasses
"""
raise NotImplementedError("VM classes must implement this method")

@classmethod
@abstractmethod
def get_nephew_reward(cls) -> int:
Expand Down
33 changes: 32 additions & 1 deletion eth/vm/forks/petersburg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from eth_typing import (
Address
)

from typing import ( # noqa: F401
Type,
)
Expand All @@ -10,7 +14,7 @@
from eth.vm.state import BaseState # noqa: F401

from .blocks import PetersburgBlock
from .constants import EIP1234_BLOCK_REWARD
from .constants import EIP1234_BLOCK_REWARD, EIP1789_DEVFUND_REWARD, EIP1789_DEVFUND_BENEFICIARY
from .headers import (
compute_petersburg_difficulty,
configure_petersburg_header,
Expand All @@ -36,3 +40,30 @@ class PetersburgVM(ByzantiumVM):
@staticmethod
def get_block_reward() -> int:
return EIP1234_BLOCK_REWARD

@staticmethod
def get_devfund_reward() -> int:
return EIP1789_DEVFUND_REWARD

@staticmethod
def get_devfund_beneficiary() -> Address:
return EIP1789_DEVFUND_BENEFICIARY

#
# Finalization
#
def finalize_block(self, block: BaseBlock) -> BaseBlock:
"""
Perform any finalization steps like awarding the block mining reward.
"""
devfund_reward = self.get_devfund_reward()
devfund_beneficiary = self.get_devfund_beneficiary()

self.state.account_db.delta_balance(devfund_beneficiary, devfund_reward)
self.logger.debug(
"DEVDFUND REWARD: %s -> %s",
devfund_reward,
devfund_beneficiary,
)

return super(block)
7 changes: 7 additions & 0 deletions eth/vm/forks/petersburg/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from eth_utils import denoms
from eth_typing import (
Address
)


GAS_EXTCODEHASH_EIP1052 = 400

EIP1234_BLOCK_REWARD = 2 * denoms.ether

# Currently no reward is issued.
EIP1789_DEVFUND_REWARD = 0
EIP1789_DEVFUND_BENEFICIARY = Address(b'')

0 comments on commit ee5a23f

Please sign in to comment.