From ee5a23f80eacfa1db05d025a2802003a05b2d48d Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Tue, 12 Mar 2019 21:54:39 +0100 Subject: [PATCH] Initial reference implementation of EIP1789 Untested. Per https://github.com/gitcoinco/ERC-1789/issues/6. --- eth/vm/base.py | 24 ++++++++++++++++++++ eth/vm/forks/petersburg/__init__.py | 33 +++++++++++++++++++++++++++- eth/vm/forks/petersburg/constants.py | 7 ++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/eth/vm/base.py b/eth/vm/base.py index dca2a77dad..c8f37fc3bb 100644 --- a/eth/vm/base.py +++ b/eth/vm/base.py @@ -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: diff --git a/eth/vm/forks/petersburg/__init__.py b/eth/vm/forks/petersburg/__init__.py index 4ccb99fa76..7ca39046a2 100644 --- a/eth/vm/forks/petersburg/__init__.py +++ b/eth/vm/forks/petersburg/__init__.py @@ -1,3 +1,7 @@ +from eth_typing import ( + Address +) + from typing import ( # noqa: F401 Type, ) @@ -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, @@ -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) diff --git a/eth/vm/forks/petersburg/constants.py b/eth/vm/forks/petersburg/constants.py index 0ba9138d13..c8b513e890 100644 --- a/eth/vm/forks/petersburg/constants.py +++ b/eth/vm/forks/petersburg/constants.py @@ -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'')