From c483bfb8e86d4994a3e0e6f9451b46b84a6ca3e5 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Thu, 5 Dec 2019 13:12:52 +0100 Subject: [PATCH] Make the randomness contract option a map; disable Clique (doesn't build). --- ethcore/src/engines/authority_round/mod.rs | 19 ++++++++++++------- ethcore/src/engines/clique/mod.rs | 21 ++------------------- json/src/spec/authority_round.rs | 15 +++++++++++---- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 65395c43c11..93f0fe8cecc 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -111,8 +111,8 @@ pub struct AuthorityRoundParams { pub maximum_empty_steps: usize, /// Transition block to strict empty steps validation. pub strict_empty_steps_transition: u64, - /// If set, enables random number contract integration. - pub randomness_contract_address: Option
, + /// If set, enables random number contract integration. It maps the transition block to the contract address. + pub randomness_contract_address: BTreeMap, /// If set, this is the block number at which the consensus engine switches from AuRa to AuRa /// with POSDAO modifications. pub posdao_transition: Option, @@ -173,6 +173,11 @@ impl From for AuthorityRoundParams { .into_iter() .map(|(block_num, address)| (block_num.into(), address.into())) .collect(); + let randomness_contract_address = p.randomness_contract_address.map_or_else(BTreeMap::new, |transitions| { + transitions.into_iter().map(|(ethjson::uint::Uint(block), addr)| { + (block.as_u64(), addr.into()) + }).collect() + }); AuthorityRoundParams { step_durations, validators: new_validator_set_posdao(p.validators, p.posdao_transition.map(Into::into)), @@ -188,9 +193,9 @@ impl From for AuthorityRoundParams { maximum_empty_steps: p.maximum_empty_steps.map_or(0, Into::into), two_thirds_majority_transition: p.two_thirds_majority_transition.map_or_else(BlockNumber::max_value, Into::into), strict_empty_steps_transition: p.strict_empty_steps_transition.map_or(0, Into::into), - randomness_contract_address: p.randomness_contract_address.map(Into::into), posdao_transition: p.posdao_transition.map(Into::into), block_gas_limit_contract_transitions, + randomness_contract_address, } } } @@ -553,8 +558,6 @@ pub struct AuthorityRound { two_thirds_majority_transition: BlockNumber, maximum_empty_steps: usize, machine: EthereumMachine, - /// If set, enables random number contract integration. - randomness_contract_address: Option
, /// The block number at which the consensus engine switches from AuRa to AuRa with POSDAO /// modifications. posdao_transition: Option, @@ -562,6 +565,8 @@ pub struct AuthorityRound { block_gas_limit_contract_transitions: BTreeMap, /// History of step hashes recently received from peers. received_step_hashes: RwLock>, + /// If set, enables random number contract integration. It maps the transition block to the contract address. + randomness_contract_address: BTreeMap, } // header-chain validator. @@ -1479,7 +1484,7 @@ impl Engine for AuthorityRound { }; // Random number generation - if let Some(contract_addr) = self.randomness_contract_address { + if let Some((_, &contract_addr)) = self.randomness_contract_address.range(..=block.header.number()).last() { let contract = util::BoundContract::bind(&*client, BlockId::Latest, contract_addr); // TODO: How should these errors be handled? let phase = randomness::RandomnessPhase::load(&contract, our_addr) @@ -1917,7 +1922,7 @@ mod tests { block_reward_contract_transitions: Default::default(), strict_empty_steps_transition: 0, two_thirds_majority_transition: 0, - randomness_contract_address: None, + randomness_contract_address: BTreeMap::new(), posdao_transition: Some(0), block_gas_limit_contract_transitions: BTreeMap::new(), }; diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index 8bf45f1054c..11cd99d2d07 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -185,25 +185,8 @@ pub struct Clique { impl Clique { /// Initialize Clique engine from empty state. - pub fn new(our_params: CliqueParams, machine: EthereumMachine) -> Result, Error> { - let mut engine = Clique { - epoch_length: our_params.epoch, - period: our_params.period, - client: Default::default(), - block_state_by_hash: RwLock::new(LruCache::new(STATE_CACHE_NUM)), - proposals: Default::default(), - signer: Default::default(), - machine, - step_service: None, - }; - - let res = Arc::new(engine); - - if our_params.period > 0 { - engine.step_service = Some(StepService::start(Arc::downgrade(&res) as Weak>)); - } - - Ok(res) + pub fn new(_our_params: CliqueParams, _machine: EthereumMachine) -> Result, Error> { + unimplemented!() } #[cfg(test)] diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index 0061630077e..d2b31f36036 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -69,10 +69,8 @@ pub struct AuthorityRoundParams { pub strict_empty_steps_transition: Option, /// First block for which a 2/3 quorum (instead of 1/2) is required. pub two_thirds_majority_transition: Option, - /// If set, enables random number contract integration, and use Proof of - /// Stake (PoS) consensus. Otherwise, use Proof of Authority (PoA) - /// consensus. - pub randomness_contract_address: Option
, + /// A map of randomness contract transitions. + pub randomness_contract_address: Option>, /// The block number at which the consensus engine switches from AuRa to AuRa with POSDAO /// modifications. pub posdao_transition: Option, @@ -117,6 +115,10 @@ mod tests { "blockGasLimitContractTransitions": { "10": "0x1000000000000000000000000000000000000001", "20": "0x2000000000000000000000000000000000000002" + }, + "randomnessContractAddress": { + "10": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "20": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" } } }"#; @@ -133,5 +135,10 @@ mod tests { (Uint(20.into()), Address(H160::from_str("2000000000000000000000000000000000000002").unwrap()))]; assert_eq!(deserialized.params.block_gas_limit_contract_transitions, Some(expected_bglc.to_vec().into_iter().collect())); + assert_eq!(deserialized.params.randomness_contract_address.unwrap(), + vec![ + (Uint(10.into()), Address(H160::from_str("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap())), + (Uint(20.into()), Address(H160::from_str("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb").unwrap())), + ].into_iter().collect()); } }