Merge pull request #3843 from ethcore/auth-round-seal

AuthorityRound seal and simplify Generic seal Spec
This commit is contained in:
Gav Wood 2016-12-15 13:08:50 +01:00 committed by GitHub
commit a660024eac
8 changed files with 58 additions and 37 deletions

View File

@ -21,8 +21,9 @@
}, },
"genesis": { "genesis": {
"seal": { "seal": {
"generic": { "authority_round": {
"rlp": "0xc28080" "step": "0x0",
"signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
} }
}, },
"difficulty": "0x20000", "difficulty": "0x20000",

View File

@ -17,10 +17,7 @@
}, },
"genesis": { "genesis": {
"seal": { "seal": {
"generic": { "generic": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
"fields": 1,
"rlp": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
}
}, },
"difficulty": "0x20000", "difficulty": "0x20000",
"author": "0x0000000000000000000000000000000000000000", "author": "0x0000000000000000000000000000000000000000",

View File

@ -11,9 +11,7 @@
}, },
"genesis": { "genesis": {
"seal": { "seal": {
"generic": { "generic": "0x0"
"rlp": "0x0"
}
}, },
"difficulty": "0x20000", "difficulty": "0x20000",
"author": "0x0000000000000000000000000000000000000000", "author": "0x0000000000000000000000000000000000000000",

View File

@ -17,7 +17,7 @@
//! Spec seal. //! Spec seal.
use rlp::*; use rlp::*;
use util::hash::{H64, H256}; use util::hash::{H64, H256, H520};
use ethjson; use ethjson;
/// Classic ethereum seal. /// Classic ethereum seal.
@ -32,23 +32,35 @@ impl Into<Generic> for Ethereum {
fn into(self) -> Generic { fn into(self) -> Generic {
let mut s = RlpStream::new_list(2); let mut s = RlpStream::new_list(2);
s.append(&self.mix_hash).append(&self.nonce); s.append(&self.mix_hash).append(&self.nonce);
Generic { Generic(s.out())
rlp: s.out()
}
} }
} }
/// Generic seal. /// AuthorityRound seal.
pub struct Generic { pub struct AuthorityRound {
/// Seal rlp. /// Seal step.
pub rlp: Vec<u8>, pub step: usize,
/// Seal signature.
pub signature: H520,
} }
impl Into<Generic> for AuthorityRound {
fn into(self) -> Generic {
let mut s = RlpStream::new_list(2);
s.append(&self.step).append(&self.signature);
Generic(s.out())
}
}
pub struct Generic(pub Vec<u8>);
/// Genesis seal type. /// Genesis seal type.
pub enum Seal { pub enum Seal {
/// Classic ethereum seal. /// Classic ethereum seal.
Ethereum(Ethereum), Ethereum(Ethereum),
/// Generic seal. /// AuthorityRound seal.
AuthorityRound(AuthorityRound),
/// Generic RLP seal.
Generic(Generic), Generic(Generic),
} }
@ -59,9 +71,11 @@ impl From<ethjson::spec::Seal> for Seal {
nonce: eth.nonce.into(), nonce: eth.nonce.into(),
mix_hash: eth.mix_hash.into() mix_hash: eth.mix_hash.into()
}), }),
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic { ethjson::spec::Seal::AuthorityRound(ar) => Seal::AuthorityRound(AuthorityRound {
rlp: g.rlp.into() step: ar.step.into(),
}) signature: ar.signature.into()
}),
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic(g.into())),
} }
} }
} }
@ -70,7 +84,8 @@ impl Into<Generic> for Seal {
fn into(self) -> Generic { fn into(self) -> Generic {
match self { match self {
Seal::Generic(generic) => generic, Seal::Generic(generic) => generic,
Seal::Ethereum(eth) => eth.into() Seal::Ethereum(eth) => eth.into(),
Seal::AuthorityRound(ar) => ar.into(),
} }
} }
} }

View File

@ -107,7 +107,7 @@ impl From<ethjson::spec::Spec> for Spec {
fn from(s: ethjson::spec::Spec) -> Self { fn from(s: ethjson::spec::Spec) -> Self {
let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect(); let builtins = s.accounts.builtins().into_iter().map(|p| (p.0.into(), From::from(p.1))).collect();
let g = Genesis::from(s.genesis); let g = Genesis::from(s.genesis);
let seal: GenericSeal = g.seal.into(); let GenericSeal(seal_rlp) = g.seal.into();
let params = CommonParams::from(s.params); let params = CommonParams::from(s.params);
Spec { Spec {
name: s.name.into(), name: s.name.into(),
@ -124,7 +124,7 @@ impl From<ethjson::spec::Spec> for Spec {
gas_used: g.gas_used, gas_used: g.gas_used,
timestamp: g.timestamp, timestamp: g.timestamp,
extra_data: g.extra_data, extra_data: g.extra_data,
seal_rlp: seal.rlp, seal_rlp: seal_rlp,
state_root_memo: RwLock::new(g.state_root), state_root_memo: RwLock::new(g.state_root),
genesis_state: From::from(s.accounts), genesis_state: From::from(s.accounts),
} }
@ -208,7 +208,7 @@ impl Spec {
/// Overwrite the genesis components. /// Overwrite the genesis components.
pub fn overwrite_genesis_params(&mut self, g: Genesis) { pub fn overwrite_genesis_params(&mut self, g: Genesis) {
let seal: GenericSeal = g.seal.into(); let GenericSeal(seal_rlp) = g.seal.into();
self.parent_hash = g.parent_hash; self.parent_hash = g.parent_hash;
self.transactions_root = g.transactions_root; self.transactions_root = g.transactions_root;
self.receipts_root = g.receipts_root; self.receipts_root = g.receipts_root;
@ -218,7 +218,7 @@ impl Spec {
self.gas_used = g.gas_used; self.gas_used = g.gas_used;
self.timestamp = g.timestamp; self.timestamp = g.timestamp;
self.extra_data = g.extra_data; self.extra_data = g.extra_data;
self.seal_rlp = seal.rlp; self.seal_rlp = seal_rlp;
self.state_root_memo = RwLock::new(g.state_root); self.state_root_memo = RwLock::new(g.state_root);
} }

View File

@ -20,7 +20,7 @@ use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize, Serializer, Error}; use serde::{Deserialize, Deserializer, Serialize, Serializer, Error};
use serde::de::Visitor; use serde::de::Visitor;
use rustc_serialize::hex::ToHex; use rustc_serialize::hex::ToHex;
use util::hash::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H2048 as Hash2048}; use util::hash::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H520 as Hash520, H2048 as Hash2048};
macro_rules! impl_hash { macro_rules! impl_hash {
@ -87,6 +87,7 @@ macro_rules! impl_hash {
impl_hash!(H64, Hash64); impl_hash!(H64, Hash64);
impl_hash!(Address, Hash160); impl_hash!(Address, Hash160);
impl_hash!(H256, Hash256); impl_hash!(H256, Hash256);
impl_hash!(H520, Hash520);
impl_hash!(Bloom, Hash2048); impl_hash!(Bloom, Hash2048);
#[cfg(test)] #[cfg(test)]

View File

@ -33,7 +33,7 @@ pub use self::builtin::{Builtin, Pricing, Linear};
pub use self::genesis::Genesis; pub use self::genesis::Genesis;
pub use self::params::Params; pub use self::params::Params;
pub use self::spec::Spec; pub use self::spec::Spec;
pub use self::seal::{Seal, Ethereum, Generic}; pub use self::seal::{Seal, Ethereum, AuthorityRoundSeal};
pub use self::engine::Engine; pub use self::engine::Engine;
pub use self::state::State; pub use self::state::State;
pub use self::ethash::{Ethash, EthashParams}; pub use self::ethash::{Ethash, EthashParams};

View File

@ -16,7 +16,8 @@
//! Spec seal deserialization. //! Spec seal deserialization.
use hash::{H64, H256}; use hash::*;
use uint::Uint;
use bytes::Bytes; use bytes::Bytes;
/// Ethereum seal. /// Ethereum seal.
@ -29,11 +30,13 @@ pub struct Ethereum {
pub mix_hash: H256, pub mix_hash: H256,
} }
/// Generic seal. /// AuthorityRound seal.
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
pub struct Generic { pub struct AuthorityRoundSeal {
/// Seal rlp. /// Seal step.
pub rlp: Bytes, pub step: Uint,
/// Seal signature.
pub signature: H520,
} }
/// Seal variants. /// Seal variants.
@ -42,9 +45,12 @@ pub enum Seal {
/// Ethereum seal. /// Ethereum seal.
#[serde(rename="ethereum")] #[serde(rename="ethereum")]
Ethereum(Ethereum), Ethereum(Ethereum),
/// AuthorityRound seal.
#[serde(rename="authority_round")]
AuthorityRound(AuthorityRoundSeal),
/// Generic seal. /// Generic seal.
#[serde(rename="generic")] #[serde(rename="generic")]
Generic(Generic), Generic(Bytes),
} }
#[cfg(test)] #[cfg(test)]
@ -53,15 +59,18 @@ mod tests {
use spec::Seal; use spec::Seal;
#[test] #[test]
fn builtin_deserialization() { fn seal_deserialization() {
let s = r#"[{ let s = r#"[{
"ethereum": { "ethereum": {
"nonce": "0x0000000000000042", "nonce": "0x0000000000000042",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
} }
},{ },{
"generic": { "generic": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
"rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" },{
"authority_round": {
"step": "0x0",
"signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
} }
}]"#; }]"#;
let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap(); let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();