Merge pull request #3717 from ethcore/spec-rlp-loading
Use valid RLP in generic genesis seal spec
This commit is contained in:
commit
84c923ff6d
@ -21,8 +21,7 @@
|
|||||||
"genesis": {
|
"genesis": {
|
||||||
"seal": {
|
"seal": {
|
||||||
"generic": {
|
"generic": {
|
||||||
"fields": 2,
|
"rlp": "0xc28080"
|
||||||
"rlp": "0x200"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"difficulty": "0x20000",
|
"difficulty": "0x20000",
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"genesis": {
|
"genesis": {
|
||||||
"seal": {
|
"seal": {
|
||||||
"generic": {
|
"generic": {
|
||||||
"fields": 0,
|
|
||||||
"rlp": "0x0"
|
"rlp": "0x0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -30,11 +30,9 @@ pub struct Ethereum {
|
|||||||
|
|
||||||
impl Into<Generic> for Ethereum {
|
impl Into<Generic> for Ethereum {
|
||||||
fn into(self) -> Generic {
|
fn into(self) -> Generic {
|
||||||
let mut s = RlpStream::new();
|
let mut s = RlpStream::new_list(2);
|
||||||
s.append(&self.mix_hash);
|
s.append(&self.mix_hash).append(&self.nonce);
|
||||||
s.append(&self.nonce);
|
|
||||||
Generic {
|
Generic {
|
||||||
fields: 2,
|
|
||||||
rlp: s.out()
|
rlp: s.out()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,8 +40,6 @@ impl Into<Generic> for Ethereum {
|
|||||||
|
|
||||||
/// Generic seal.
|
/// Generic seal.
|
||||||
pub struct Generic {
|
pub struct Generic {
|
||||||
/// Number of seal fields.
|
|
||||||
pub fields: usize,
|
|
||||||
/// Seal rlp.
|
/// Seal rlp.
|
||||||
pub rlp: Vec<u8>,
|
pub rlp: Vec<u8>,
|
||||||
}
|
}
|
||||||
@ -64,7 +60,6 @@ impl From<ethjson::spec::Seal> for Seal {
|
|||||||
mix_hash: eth.mix_hash.into()
|
mix_hash: eth.mix_hash.into()
|
||||||
}),
|
}),
|
||||||
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic {
|
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic {
|
||||||
fields: g.fields,
|
|
||||||
rlp: g.rlp.into()
|
rlp: g.rlp.into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,6 @@ pub struct Spec {
|
|||||||
pub receipts_root: H256,
|
pub receipts_root: H256,
|
||||||
/// The genesis block's extra data field.
|
/// The genesis block's extra data field.
|
||||||
pub extra_data: Bytes,
|
pub extra_data: Bytes,
|
||||||
/// The number of seal fields in the genesis block.
|
|
||||||
pub seal_fields: usize,
|
|
||||||
/// Each seal field, expressed as RLP, concatenated.
|
/// Each seal field, expressed as RLP, concatenated.
|
||||||
pub seal_rlp: Bytes,
|
pub seal_rlp: Bytes,
|
||||||
|
|
||||||
@ -127,7 +125,6 @@ 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_fields: seal.fields,
|
|
||||||
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),
|
||||||
@ -192,13 +189,8 @@ impl Spec {
|
|||||||
header.set_gas_limit(self.gas_limit.clone());
|
header.set_gas_limit(self.gas_limit.clone());
|
||||||
header.set_difficulty(self.difficulty.clone());
|
header.set_difficulty(self.difficulty.clone());
|
||||||
header.set_seal({
|
header.set_seal({
|
||||||
let seal = {
|
let r = Rlp::new(&self.seal_rlp);
|
||||||
let mut s = RlpStream::new_list(self.seal_fields);
|
r.iter().map(|f| f.as_raw().to_vec()).collect()
|
||||||
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()
|
|
||||||
});
|
});
|
||||||
trace!(target: "spec", "Header hash is {}", header.hash());
|
trace!(target: "spec", "Header hash is {}", header.hash());
|
||||||
header
|
header
|
||||||
@ -227,7 +219,6 @@ 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_fields = seal.fields;
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,7 @@ pub struct Ethereum {
|
|||||||
/// Generic seal.
|
/// Generic seal.
|
||||||
#[derive(Debug, PartialEq, Deserialize)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct Generic {
|
pub struct Generic {
|
||||||
/// Number of fields.
|
/// Seal rlp.
|
||||||
pub fields: usize,
|
|
||||||
/// Their rlp.
|
|
||||||
pub rlp: Bytes,
|
pub rlp: Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +61,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
"generic": {
|
"generic": {
|
||||||
"fields": 1,
|
"rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
|
||||||
"rlp": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"
|
|
||||||
}
|
}
|
||||||
}]"#;
|
}]"#;
|
||||||
let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
|
let _deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user