Add block reward contract config to ethash and allow off-chain contracts (#9312)

This adds block reward contract config to ethash. A new config `blockRewardContractCode` is also added to both Aura and ethash. When specified, it will execute the code directly and overrides any `blockRewardContractAddress` config. Having this `blockRewardContractCode` config allows chains to deploy hard fork by simply replacing the current config value, without the need from us to support any `multi` block reward scheme.
This commit is contained in:
Wei Tang
2018-08-29 23:17:18 +08:00
committed by André Silva
parent 1073d56245
commit 74ce0f738e
8 changed files with 261 additions and 116 deletions

View File

@@ -16,8 +16,9 @@
//! Authority params deserialization.
use ethereum_types::Address;
use hash::Address;
use uint::Uint;
use bytes::Bytes;
use super::ValidatorSet;
/// Authority params deserialization.
@@ -51,6 +52,9 @@ pub struct AuthorityRoundParams {
/// overrides the static block reward definition).
#[serde(rename="blockRewardContractAddress")]
pub block_reward_contract_address: Option<Address>,
/// Block reward code. This overrides the block reward contract address.
#[serde(rename="blockRewardContractCode")]
pub block_reward_contract_code: Option<Bytes>,
/// Block at which maximum uncle count should be considered.
#[serde(rename="maximumUncleCountTransition")]
pub maximum_uncle_count_transition: Option<Uint>,

View File

@@ -17,6 +17,7 @@
//! Ethash params deserialization.
use uint::{self, Uint};
use bytes::Bytes;
use hash::Address;
/// Deserializable doppelganger of EthashParams.
@@ -48,6 +49,16 @@ pub struct EthashParams {
/// Reward per block in wei.
#[serde(rename="blockReward")]
pub block_reward: Option<Uint>,
/// Block at which the block reward contract should start being used.
#[serde(rename="blockRewardContractTransition")]
pub block_reward_contract_transition: Option<Uint>,
/// Block reward contract address (setting the block reward contract
/// overrides all other block reward parameters).
#[serde(rename="blockRewardContractAddress")]
pub block_reward_contract_address: Option<Address>,
/// Block reward code. This overrides the block reward contract address.
#[serde(rename="blockRewardContractCode")]
pub block_reward_contract_code: Option<Bytes>,
/// See main EthashParams docs.
#[serde(rename="daoHardforkTransition")]
@@ -183,7 +194,7 @@ mod tests {
let deserialized: Ethash = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, Ethash {
params: EthashParams{
params: EthashParams {
minimum_difficulty: Uint(U256::from(0x020000)),
difficulty_bound_divisor: Uint(U256::from(0x0800)),
difficulty_increment_divisor: None,
@@ -191,6 +202,9 @@ mod tests {
duration_limit: Some(Uint(U256::from(0x0d))),
homestead_transition: Some(Uint(U256::from(0x42))),
block_reward: Some(Uint(U256::from(0x100))),
block_reward_contract_address: None,
block_reward_contract_code: None,
block_reward_contract_transition: None,
dao_hardfork_transition: Some(Uint(U256::from(0x08))),
dao_hardfork_beneficiary: Some(Address(H160::from("0xabcabcabcabcabcabcabcabcabcabcabcabcabca"))),
dao_hardfork_accounts: Some(vec![
@@ -256,6 +270,9 @@ mod tests {
duration_limit: None,
homestead_transition: None,
block_reward: None,
block_reward_contract_address: None,
block_reward_contract_code: None,
block_reward_contract_transition: None,
dao_hardfork_transition: None,
dao_hardfork_beneficiary: None,
dao_hardfork_accounts: None,