make generic seal take valid rlp
This commit is contained in:
parent
cf796d3ea4
commit
22632e6324
@ -21,8 +21,7 @@
|
||||
"genesis": {
|
||||
"seal": {
|
||||
"generic": {
|
||||
"fields": 2,
|
||||
"rlp": "0x200"
|
||||
"rlp": "0xc28080"
|
||||
}
|
||||
},
|
||||
"difficulty": "0x20000",
|
||||
|
@ -12,7 +12,6 @@
|
||||
"genesis": {
|
||||
"seal": {
|
||||
"generic": {
|
||||
"fields": 0,
|
||||
"rlp": "0x0"
|
||||
}
|
||||
},
|
||||
|
@ -30,11 +30,9 @@ pub struct Ethereum {
|
||||
|
||||
impl Into<Generic> 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<Generic> for Ethereum {
|
||||
|
||||
/// Generic seal.
|
||||
pub struct Generic {
|
||||
/// Number of seal fields.
|
||||
pub fields: usize,
|
||||
/// Seal rlp.
|
||||
pub rlp: Vec<u8>,
|
||||
}
|
||||
@ -64,7 +60,6 @@ impl From<ethjson::spec::Seal> for Seal {
|
||||
mix_hash: eth.mix_hash.into()
|
||||
}),
|
||||
ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic {
|
||||
fields: g.fields,
|
||||
rlp: g.rlp.into()
|
||||
})
|
||||
}
|
||||
|
@ -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<ethjson::spec::Spec> 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);
|
||||
}
|
||||
|
@ -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<Seal> = serde_json::from_str(s).unwrap();
|
||||
let deserialized: Vec<Seal> = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user