From 6b286a5dee845afb34dbc6cf89afa35a1b8277f1 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 4 Oct 2018 14:08:20 +0100 Subject: [PATCH] make instantSeal engine backwards compatible, closes #9696 (#9700) --- ethcore/src/engines/instant_seal.rs | 2 +- ethcore/src/engines/mod.rs | 2 +- ethcore/src/spec/spec.rs | 8 ++++++-- json/src/spec/engine.rs | 13 ++++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 80e9ea451..c1b5de4ab 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -18,7 +18,7 @@ use engines::{Engine, Seal}; use parity_machine::{Machine, Transactions, TotalScoredHeader}; /// `InstantSeal` params. -#[derive(Debug, PartialEq)] +#[derive(Default, Debug, PartialEq)] pub struct InstantSealParams { /// Whether to use millisecond timestamp pub millisecond_timestamp: bool, diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 11507c206..0f5a9f4cc 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -32,7 +32,7 @@ pub mod epoch; pub use self::authority_round::AuthorityRound; pub use self::basic_authority::BasicAuthority; pub use self::epoch::{EpochVerifier, Transition as EpochTransition}; -pub use self::instant_seal::InstantSeal; +pub use self::instant_seal::{InstantSeal, InstantSealParams}; pub use self::null_engine::NullEngine; pub use self::tendermint::Tendermint; diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index aa5d9cd9b..c76b610e9 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -33,7 +33,10 @@ use vm::{EnvInfo, CallType, ActionValue, ActionParams, ParamsType}; use builtin::Builtin; use encoded; -use engines::{EthEngine, NullEngine, InstantSeal, BasicAuthority, AuthorityRound, Tendermint, DEFAULT_BLOCKHASH_CONTRACT}; +use engines::{ + EthEngine, NullEngine, InstantSeal, InstantSealParams, BasicAuthority, + AuthorityRound, Tendermint, DEFAULT_BLOCKHASH_CONTRACT +}; use error::Error; use executive::Executive; use factory::Factories; @@ -596,7 +599,8 @@ impl Spec { match engine_spec { ethjson::spec::Engine::Null(null) => Arc::new(NullEngine::new(null.params.into(), machine)), ethjson::spec::Engine::Ethash(ethash) => Arc::new(::ethereum::Ethash::new(spec_params.cache_dir, ethash.params.into(), machine, spec_params.optimization_setting)), - ethjson::spec::Engine::InstantSeal(instant_seal) => Arc::new(InstantSeal::new(instant_seal.params.into(), machine)), + ethjson::spec::Engine::InstantSeal(Some(instant_seal)) => Arc::new(InstantSeal::new(instant_seal.params.into(), machine)), + ethjson::spec::Engine::InstantSeal(None) => Arc::new(InstantSeal::new(InstantSealParams::default(), machine)), ethjson::spec::Engine::BasicAuthority(basic_authority) => Arc::new(BasicAuthority::new(basic_authority.params.into(), machine)), ethjson::spec::Engine::AuthorityRound(authority_round) => AuthorityRound::new(authority_round.params.into(), machine) .expect("Failed to start AuthorityRound consensus engine."), diff --git a/json/src/spec/engine.rs b/json/src/spec/engine.rs index f8476757c..020cc1fd0 100644 --- a/json/src/spec/engine.rs +++ b/json/src/spec/engine.rs @@ -26,7 +26,7 @@ pub enum Engine { Null(NullEngine), /// Instantly sealing engine. #[serde(rename="instantSeal")] - InstantSeal(InstantSeal), + InstantSeal(Option), /// Ethash engine. Ethash(Ethash), /// BasicAuthority engine. @@ -71,6 +71,17 @@ mod tests { _ => panic!(), }; + let s = r#"{ + "instantSeal": null + }"#; + + let deserialized: Engine = serde_json::from_str(s).unwrap(); + match deserialized { + Engine::InstantSeal(_) => {}, // instant seal is unit tested in its own file. + _ => panic!(), + }; + + let s = r#"{ "Ethash": { "params": {