Add registrar fields (#4716)
* add registrar field * use constructor for dev registrar * fix test
This commit is contained in:
		
							parent
							
								
									5dd406a19a
								
							
						
					
					
						commit
						ade5a13f5b
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @ -47,6 +47,8 @@ pub struct AuthorityRoundParams { | ||||
| 	pub step_duration: Duration, | ||||
| 	/// Block reward.
 | ||||
| 	pub block_reward: U256, | ||||
| 	/// Namereg contract address.
 | ||||
| 	pub registrar: Address, | ||||
| 	/// Starting step,
 | ||||
| 	pub start_step: Option<u64>, | ||||
| 	/// Valid validators.
 | ||||
| @ -60,6 +62,7 @@ impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams { | ||||
| 			step_duration: Duration::from_secs(p.step_duration.into()), | ||||
| 			validators: p.validators, | ||||
| 			block_reward: p.block_reward.map_or_else(U256::zero, Into::into), | ||||
| 			registrar: p.registrar.map_or_else(Address::new, Into::into), | ||||
| 			start_step: p.start_step.map(Into::into), | ||||
| 		} | ||||
| 	} | ||||
| @ -71,6 +74,7 @@ pub struct AuthorityRound { | ||||
| 	params: CommonParams, | ||||
| 	gas_limit_bound_divisor: U256, | ||||
| 	block_reward: U256, | ||||
| 	registrar: Address, | ||||
| 	step_duration: Duration, | ||||
| 	builtins: BTreeMap<Address, Builtin>, | ||||
| 	transition_service: IoService<()>, | ||||
| @ -109,6 +113,7 @@ impl AuthorityRound { | ||||
| 				params: params, | ||||
| 				gas_limit_bound_divisor: our_params.gas_limit_bound_divisor, | ||||
| 				block_reward: our_params.block_reward, | ||||
| 				registrar: our_params.registrar, | ||||
| 				step_duration: our_params.step_duration, | ||||
| 				builtins: builtins, | ||||
| 				transition_service: IoService::<()>::start()?, | ||||
| @ -176,11 +181,16 @@ impl IoHandler<()> for TransitionHandler { | ||||
| 
 | ||||
| impl Engine for AuthorityRound { | ||||
| 	fn name(&self) -> &str { "AuthorityRound" } | ||||
| 
 | ||||
| 	fn version(&self) -> SemanticVersion { SemanticVersion::new(1, 0, 0) } | ||||
| 
 | ||||
| 	/// Two fields - consensus step and the corresponding proposer signature.
 | ||||
| 	fn seal_fields(&self) -> usize { 2 } | ||||
| 
 | ||||
| 	fn params(&self) -> &CommonParams { &self.params } | ||||
| 
 | ||||
| 	fn additional_params(&self) -> HashMap<String, String> { hash_map!["registrar".to_owned() => self.registrar.hex()] } | ||||
| 
 | ||||
| 	fn builtins(&self) -> &BTreeMap<Address, Builtin> { &self.builtins } | ||||
| 
 | ||||
| 	fn step(&self) { | ||||
|  | ||||
| @ -15,7 +15,7 @@ | ||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| 
 | ||||
| use std::collections::BTreeMap; | ||||
| use util::Address; | ||||
| use util::{Address, HashMap}; | ||||
| use builtin::Builtin; | ||||
| use engines::{Engine, Seal}; | ||||
| use env_info::EnvInfo; | ||||
| @ -26,14 +26,16 @@ use block::ExecutedBlock; | ||||
| /// An engine which does not provide any consensus mechanism, just seals blocks internally.
 | ||||
| pub struct InstantSeal { | ||||
| 	params: CommonParams, | ||||
| 	registrar: Address, | ||||
| 	builtins: BTreeMap<Address, Builtin>, | ||||
| } | ||||
| 
 | ||||
| impl InstantSeal { | ||||
| 	/// Returns new instance of InstantSeal with default VM Factory
 | ||||
| 	pub fn new(params: CommonParams, builtins: BTreeMap<Address, Builtin>) -> Self { | ||||
| 	pub fn new(params: CommonParams, registrar: Address, builtins: BTreeMap<Address, Builtin>) -> Self { | ||||
| 		InstantSeal { | ||||
| 			params: params, | ||||
| 			registrar: registrar, | ||||
| 			builtins: builtins, | ||||
| 		} | ||||
| 	} | ||||
| @ -48,6 +50,10 @@ impl Engine for InstantSeal { | ||||
| 		&self.params | ||||
| 	} | ||||
| 
 | ||||
| 	fn additional_params(&self) -> HashMap<String, String> { | ||||
| 		hash_map!["registrar".to_owned() => self.registrar.hex()] | ||||
| 	} | ||||
| 
 | ||||
| 	fn builtins(&self) -> &BTreeMap<Address, Builtin> { | ||||
| 		&self.builtins | ||||
| 	} | ||||
| @ -76,9 +82,9 @@ mod tests { | ||||
| 	fn instant_can_seal() { | ||||
| 		let spec = Spec::new_instant(); | ||||
| 		let engine = &*spec.engine; | ||||
| 		let genesis_header = spec.genesis_header(); | ||||
| 		let mut db_result = get_temp_state_db(); | ||||
| 		let db = spec.ensure_db_good(db_result.take(), &Default::default()).unwrap(); | ||||
| 		let genesis_header = spec.genesis_header(); | ||||
| 		let last_hashes = Arc::new(vec![genesis_header.hash()]); | ||||
| 		let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::default(), (3141562.into(), 31415620.into()), vec![]).unwrap(); | ||||
| 		let b = b.close_and_lock(); | ||||
|  | ||||
| @ -78,6 +78,7 @@ pub struct Tendermint { | ||||
| 	step_service: IoService<Step>, | ||||
| 	client: RwLock<Option<Weak<EngineClient>>>, | ||||
| 	block_reward: U256, | ||||
| 	registrar: Address, | ||||
| 	/// Blockchain height.
 | ||||
| 	height: AtomicUsize, | ||||
| 	/// Consensus view.
 | ||||
| @ -109,6 +110,7 @@ impl Tendermint { | ||||
| 				client: RwLock::new(None), | ||||
| 				step_service: IoService::<Step>::start()?, | ||||
| 				block_reward: our_params.block_reward, | ||||
| 				registrar: our_params.registrar, | ||||
| 				height: AtomicUsize::new(1), | ||||
| 				view: AtomicUsize::new(0), | ||||
| 				step: RwLock::new(Step::Propose), | ||||
| @ -369,14 +371,20 @@ impl Tendermint { | ||||
| 
 | ||||
| impl Engine for Tendermint { | ||||
| 	fn name(&self) -> &str { "Tendermint" } | ||||
| 
 | ||||
| 	fn version(&self) -> SemanticVersion { SemanticVersion::new(1, 0, 0) } | ||||
| 
 | ||||
| 	/// (consensus view, proposal signature, authority signatures)
 | ||||
| 	fn seal_fields(&self) -> usize { 3 } | ||||
| 
 | ||||
| 	fn params(&self) -> &CommonParams { &self.params } | ||||
| 
 | ||||
| 	fn additional_params(&self) -> HashMap<String, String> { hash_map!["registrar".to_owned() => self.registrar.hex()] } | ||||
| 
 | ||||
| 	fn builtins(&self) -> &BTreeMap<Address, Builtin> { &self.builtins } | ||||
| 
 | ||||
| 	fn maximum_uncle_count(&self) -> usize { 0 } | ||||
| 
 | ||||
| 	fn maximum_uncle_age(&self) -> usize { 0 } | ||||
| 
 | ||||
| 	/// Additional engine-specific information for the user/developer concerning `header`.
 | ||||
|  | ||||
| @ -17,7 +17,7 @@ | ||||
| //! Tendermint specific parameters.
 | ||||
| 
 | ||||
| use ethjson; | ||||
| use util::{U256, Uint}; | ||||
| use util::{U256, Uint, Address, FixedHash}; | ||||
| use time::Duration; | ||||
| use super::super::transition::Timeouts; | ||||
| use super::Step; | ||||
| @ -33,6 +33,8 @@ pub struct TendermintParams { | ||||
| 	pub timeouts: TendermintTimeouts, | ||||
| 	/// Block reward.
 | ||||
| 	pub block_reward: U256, | ||||
| 	/// Namereg contract address.
 | ||||
| 	pub registrar: Address, | ||||
| } | ||||
| 
 | ||||
| /// Base timeout of each step in ms.
 | ||||
| @ -88,6 +90,7 @@ impl From<ethjson::spec::TendermintParams> for TendermintParams { | ||||
| 				commit: p.timeout_commit.map_or(dt.commit, to_duration), | ||||
| 			}, | ||||
| 			block_reward: p.block_reward.map_or_else(U256::zero, Into::into), | ||||
| 			registrar: p.registrar.map_or_else(Address::new, Into::into), | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -160,7 +160,7 @@ impl Spec { | ||||
| 	fn engine(engine_spec: ethjson::spec::Engine, params: CommonParams, builtins: BTreeMap<Address, Builtin>) -> Arc<Engine> { | ||||
| 		match engine_spec { | ||||
| 			ethjson::spec::Engine::Null => Arc::new(NullEngine::new(params, builtins)), | ||||
| 			ethjson::spec::Engine::InstantSeal => Arc::new(InstantSeal::new(params, builtins)), | ||||
| 			ethjson::spec::Engine::InstantSeal(instant) => Arc::new(InstantSeal::new(params, instant.params.registrar.map_or_else(Address::new, Into::into), builtins)), | ||||
| 			ethjson::spec::Engine::Ethash(ethash) => Arc::new(ethereum::Ethash::new(params, From::from(ethash.params), builtins)), | ||||
| 			ethjson::spec::Engine::BasicAuthority(basic_authority) => Arc::new(BasicAuthority::new(params, From::from(basic_authority.params), builtins)), | ||||
| 			ethjson::spec::Engine::AuthorityRound(authority_round) => AuthorityRound::new(params, From::from(authority_round.params), builtins).expect("Failed to start AuthorityRound consensus engine."), | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
| //! Authority params deserialization.
 | ||||
| 
 | ||||
| use uint::Uint; | ||||
| use hash::Address; | ||||
| use super::ValidatorSet; | ||||
| 
 | ||||
| /// Authority params deserialization.
 | ||||
| @ -33,6 +34,8 @@ pub struct AuthorityRoundParams { | ||||
| 	/// Block reward.
 | ||||
| 	#[serde(rename="blockReward")] | ||||
| 	pub block_reward: Option<Uint>, | ||||
| 	/// Address of the registrar contract.
 | ||||
| 	pub registrar: Option<Address>, | ||||
| 	/// Starting step. Determined automatically if not specified.
 | ||||
| 	/// To be used for testing only.
 | ||||
| 	#[serde(rename="startStep")] | ||||
|  | ||||
| @ -16,7 +16,7 @@ | ||||
| 
 | ||||
| //! Engine deserialization.
 | ||||
| 
 | ||||
| use super::{Ethash, BasicAuthority, AuthorityRound, Tendermint}; | ||||
| use super::{Ethash, InstantSeal, BasicAuthority, AuthorityRound, Tendermint}; | ||||
| 
 | ||||
| /// Engine deserialization.
 | ||||
| #[derive(Debug, PartialEq, Deserialize)] | ||||
| @ -26,7 +26,7 @@ pub enum Engine { | ||||
| 	Null, | ||||
| 	/// Instantly sealing engine.
 | ||||
| 	#[serde(rename="instantSeal")] | ||||
| 	InstantSeal, | ||||
| 	InstantSeal(InstantSeal), | ||||
| 	/// Ethash engine.
 | ||||
| 	Ethash(Ethash), | ||||
| 	/// BasicAuthority engine.
 | ||||
| @ -55,12 +55,10 @@ mod tests { | ||||
| 		assert_eq!(Engine::Null, deserialized); | ||||
| 
 | ||||
| 		let s = r#"{
 | ||||
| 			"instantSeal": null | ||||
| 			"instantSeal": { "params": {} } | ||||
| 		}"#;
 | ||||
| 
 | ||||
| 		let deserialized: Engine = serde_json::from_str(s).unwrap(); | ||||
| 		assert_eq!(Engine::InstantSeal, deserialized); | ||||
| 
 | ||||
| 		let _deserialized: Engine = serde_json::from_str(s).unwrap(); | ||||
| 
 | ||||
| 		let s = r#"{
 | ||||
| 			"Ethash": { | ||||
|  | ||||
							
								
								
									
										50
									
								
								json/src/spec/instant_seal.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								json/src/spec/instant_seal.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,50 @@ | ||||
| // Copyright 2015-2017 Parity Technologies (UK) Ltd.
 | ||||
| // This file is part of Parity.
 | ||||
| 
 | ||||
| // Parity is free software: you can redistribute it and/or modify
 | ||||
| // it under the terms of the GNU General Public License as published by
 | ||||
| // the Free Software Foundation, either version 3 of the License, or
 | ||||
| // (at your option) any later version.
 | ||||
| 
 | ||||
| // Parity is distributed in the hope that it will be useful,
 | ||||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | ||||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | ||||
| // GNU General Public License for more details.
 | ||||
| 
 | ||||
| // You should have received a copy of the GNU General Public License
 | ||||
| // along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| 
 | ||||
| //! Instant params deserialization.
 | ||||
| 
 | ||||
| use hash::Address; | ||||
| 
 | ||||
| /// Instant params deserialization.
 | ||||
| #[derive(Debug, PartialEq, Deserialize)] | ||||
| pub struct InstantSealParams { | ||||
| 	/// Address of the registrar contract.
 | ||||
| 	pub registrar: Option<Address>, | ||||
| } | ||||
| 
 | ||||
| /// Instant engine deserialization.
 | ||||
| #[derive(Debug, PartialEq, Deserialize)] | ||||
| pub struct InstantSeal { | ||||
| 	/// Instant Seal params.
 | ||||
| 	pub params: InstantSealParams, | ||||
| } | ||||
| 
 | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
| 	use serde_json; | ||||
| 	use spec::instant_seal::InstantSeal; | ||||
| 
 | ||||
| 	#[test] | ||||
| 	fn instant_seal_deserialization() { | ||||
| 		let s = r#"{
 | ||||
| 			"params": { | ||||
| 				"registrar": "0xc6d9d2cd449a754c494264e1809c50e34d64562b" | ||||
| 			} | ||||
| 		}"#;
 | ||||
| 
 | ||||
| 		let _deserialized: InstantSeal = serde_json::from_str(s).unwrap(); | ||||
| 	} | ||||
| } | ||||
| @ -26,6 +26,7 @@ pub mod engine; | ||||
| pub mod state; | ||||
| pub mod ethash; | ||||
| pub mod validator_set; | ||||
| pub mod instant_seal; | ||||
| pub mod basic_authority; | ||||
| pub mod authority_round; | ||||
| pub mod tendermint; | ||||
| @ -40,6 +41,7 @@ pub use self::engine::Engine; | ||||
| pub use self::state::State; | ||||
| pub use self::ethash::{Ethash, EthashParams}; | ||||
| pub use self::validator_set::ValidatorSet; | ||||
| pub use self::instant_seal::{InstantSeal, InstantSealParams}; | ||||
| pub use self::basic_authority::{BasicAuthority, BasicAuthorityParams}; | ||||
| pub use self::authority_round::{AuthorityRound, AuthorityRoundParams}; | ||||
| pub use self::tendermint::{Tendermint, TendermintParams}; | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
| //! Tendermint params deserialization.
 | ||||
| 
 | ||||
| use uint::Uint; | ||||
| use hash::Address; | ||||
| use super::ValidatorSet; | ||||
| 
 | ||||
| /// Tendermint params deserialization.
 | ||||
| @ -42,6 +43,8 @@ pub struct TendermintParams { | ||||
| 	/// Block reward.
 | ||||
| 	#[serde(rename="blockReward")] | ||||
| 	pub block_reward: Option<Uint>, | ||||
| 	/// Address of the registrar contract.
 | ||||
| 	pub registrar: Option<Address>, | ||||
| } | ||||
| 
 | ||||
| /// Tendermint engine deserialization.
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user