From 22632e63240dd65ff43d76669d1da33ee1e9e0a7 Mon Sep 17 00:00:00 2001 From: keorn Date: Mon, 5 Dec 2016 14:07:31 +0000 Subject: [PATCH] make generic seal take valid rlp --- ethcore/res/authority_round.json | 3 +-- ethcore/res/instant_seal.json | 1 - ethcore/src/spec/seal.rs | 9 ++------- ethcore/src/spec/spec.rs | 13 ++----------- json/src/spec/seal.rs | 9 +++------ 5 files changed, 8 insertions(+), 27 deletions(-) diff --git a/ethcore/res/authority_round.json b/ethcore/res/authority_round.json index 9ab782395..a0f88b85b 100644 --- a/ethcore/res/authority_round.json +++ b/ethcore/res/authority_round.json @@ -21,8 +21,7 @@ "genesis": { "seal": { "generic": { - "fields": 2, - "rlp": "0x200" + "rlp": "0xc28080" } }, "difficulty": "0x20000", diff --git a/ethcore/res/instant_seal.json b/ethcore/res/instant_seal.json index a6b24faf9..fbb650102 100644 --- a/ethcore/res/instant_seal.json +++ b/ethcore/res/instant_seal.json @@ -12,7 +12,6 @@ "genesis": { "seal": { "generic": { - "fields": 0, "rlp": "0x0" } }, diff --git a/ethcore/src/spec/seal.rs b/ethcore/src/spec/seal.rs index e25f174d2..f3e5dca95 100644 --- a/ethcore/src/spec/seal.rs +++ b/ethcore/src/spec/seal.rs @@ -30,11 +30,9 @@ pub struct Ethereum { impl Into for Ethereum { fn into(self) -> Generic { - let mut s = RlpStream::new(); - s.append(&self.mix_hash); - s.append(&self.nonce); + let mut s = RlpStream::new_list(2); + s.append(&self.mix_hash).append(&self.nonce); Generic { - fields: 2, rlp: s.out() } } @@ -42,8 +40,6 @@ impl Into for Ethereum { /// Generic seal. pub struct Generic { - /// Number of seal fields. - pub fields: usize, /// Seal rlp. pub rlp: Vec, } @@ -64,7 +60,6 @@ impl From for Seal { mix_hash: eth.mix_hash.into() }), ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic { - fields: g.fields, rlp: g.rlp.into() }) } diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 71c15bca2..63a692701 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -94,8 +94,6 @@ pub struct Spec { pub receipts_root: H256, /// The genesis block's extra data field. pub extra_data: Bytes, - /// The number of seal fields in the genesis block. - pub seal_fields: usize, /// Each seal field, expressed as RLP, concatenated. pub seal_rlp: Bytes, @@ -127,7 +125,6 @@ impl From for Spec { gas_used: g.gas_used, timestamp: g.timestamp, extra_data: g.extra_data, - seal_fields: seal.fields, seal_rlp: seal.rlp, state_root_memo: RwLock::new(g.state_root), genesis_state: From::from(s.accounts), @@ -192,13 +189,8 @@ impl Spec { header.set_gas_limit(self.gas_limit.clone()); header.set_difficulty(self.difficulty.clone()); header.set_seal({ - let seal = { - let mut s = RlpStream::new_list(self.seal_fields); - s.append_raw(&self.seal_rlp, self.seal_fields); - s.out() - }; - let r = Rlp::new(&seal); - (0..self.seal_fields).map(|i| r.at(i).as_raw().to_vec()).collect() + let r = Rlp::new(&self.seal_rlp); + r.iter().map(|f| f.as_raw().to_vec()).collect() }); trace!(target: "spec", "Header hash is {}", header.hash()); header @@ -227,7 +219,6 @@ impl Spec { self.gas_used = g.gas_used; self.timestamp = g.timestamp; self.extra_data = g.extra_data; - self.seal_fields = seal.fields; self.seal_rlp = seal.rlp; self.state_root_memo = RwLock::new(g.state_root); } diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index a1a53819a..5bff73d31 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -32,9 +32,7 @@ pub struct Ethereum { /// Generic seal. #[derive(Debug, PartialEq, Deserialize)] pub struct Generic { - /// Number of fields. - pub fields: usize, - /// Their rlp. + /// Seal rlp. pub rlp: Bytes, } @@ -63,11 +61,10 @@ mod tests { } },{ "generic": { - "fields": 1, - "rlp": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" + "rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" } }]"#; - let _deserialized: Vec = serde_json::from_str(s).unwrap(); + let deserialized: Vec = serde_json::from_str(s).unwrap(); // TODO: validate all fields } }