Skip to content

Commit 8767752

Browse files
committed
Add a seed info field to the genesis header seal
1 parent faa067c commit 8767752

File tree

5 files changed

+85
-13
lines changed

5 files changed

+85
-13
lines changed

core/res/tendermint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"cur_view": "0x0",
5555
"precommits": [
5656
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
57-
]
57+
],
58+
"precommit_bitset": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
5859
}
5960
},
6061
"score": "0x20000",

core/src/scheme/seal.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Kodebox, Inc.
1+
// Copyright 2018-2019 Kodebox, Inc.
22
// This file is part of CodeChain.
33
//
44
// This program is free software: you can redistribute it and/or modify
@@ -15,9 +15,18 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use cjson;
18-
use primitives::H520;
18+
use primitives::{H256, H520};
1919
use rlp::RlpStream;
2020

21+
pub struct SeedInfo {
22+
/// Seed signer index in the validator set
23+
pub seed_signer_idx: usize,
24+
/// Seed hash generated from the vrf
25+
pub seed: H256,
26+
/// Seed proof
27+
pub proof: Vec<u8>,
28+
}
29+
2130
/// Tendermint seal.
2231
pub struct Tendermint {
2332
/// Parent block's view
@@ -26,6 +35,10 @@ pub struct Tendermint {
2635
pub cur_view: usize,
2736
/// Precommit seal signatures.
2837
pub precommits: Vec<H520>,
38+
/// Precommit signatures' bitset
39+
pub precommit_bitset: Vec<u8>,
40+
/// Seed information for randomized leader election
41+
pub vrf_seed_info: SeedInfo,
2942
}
3043

3144
impl From<Tendermint> for Generic {
@@ -53,6 +66,12 @@ impl From<cjson::scheme::Seal> for Seal {
5366
prev_view: tender.prev_view.into(),
5467
cur_view: tender.cur_view.into(),
5568
precommits: tender.precommits.into_iter().map(Into::into).collect(),
69+
precommit_bitset: tender.precommit_bitset.into(),
70+
vrf_seed_info: SeedInfo {
71+
seed_signer_idx: tender.vrf_seed_info.seed_signer_idx.into(),
72+
seed: tender.vrf_seed_info.seed.into(),
73+
proof: tender.vrf_seed_info.proof.into(),
74+
}
5675
}),
5776
cjson::scheme::Seal::Generic(g) => Seal::Generic(Generic(g.into())),
5877
}

json/src/scheme/genesis.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod tests {
5252
use primitives::{H256 as Core256, H520 as Core520};
5353
use serde_json;
5454

55-
use super::super::{Seal, TendermintSeal};
55+
use super::super::{Seal, SeedInfo, TendermintSeal};
5656
use super::Genesis;
5757
use crate::bytes::Bytes;
5858
use crate::hash::{H256, H520};
@@ -67,7 +67,13 @@ mod tests {
6767
"cur_view": "0x0",
6868
"precommits": [
6969
"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
70-
]
70+
],
71+
"precommit_bitset": "0x0000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000001",
72+
"vrf_seed_info": {
73+
"seed_signer_idx": "0x0",
74+
"seed": "0x0000000000000000000000000000000000000000000000000000000000000001",
75+
"proof": "0x0000001000000000000000000000000000000000000000000000000000000001"
76+
}
7177
}
7278
},
7379
"author": "tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhn9p3",
@@ -83,7 +89,20 @@ mod tests {
8389
cur_view: 0x0.into(),
8490
precommits: vec![
8591
H520(Core520::from("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
86-
]
92+
],
93+
precommit_bitset: Bytes::new(vec![
94+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95+
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
97+
]),
98+
vrf_seed_info: SeedInfo {
99+
seed_signer_idx: 0x0.into(),
100+
seed: H256(Core256::from("0x0000000000000000000000000000000000000000000000000000000000000001")),
101+
proof: Bytes::new(vec![
102+
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
104+
])
105+
},
87106
}),
88107
score: 0x0004_0000_0000u64.into(),
89108
author: Some(PlatformAddress::from_str("tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhn9p3").unwrap()),

json/src/scheme/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use self::genesis::Genesis;
3838
pub use self::null_engine::{NullEngine, NullEngineParams};
3939
pub use self::params::Params;
4040
pub use self::scheme::Scheme;
41-
pub use self::seal::{Seal, TendermintSeal};
41+
pub use self::seal::{Seal, SeedInfo, TendermintSeal};
4242
pub use self::shard::Shard;
4343
pub use self::simple_poa::{SimplePoA, SimplePoAParams};
4444
pub use self::solo::{Solo, SoloParams};

json/src/scheme/seal.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use crate::bytes::Bytes;
18-
use crate::hash::H520;
18+
use crate::hash::{H256, H520};
1919
use crate::uint::Uint;
2020

21+
#[derive(Debug, PartialEq, Deserialize)]
22+
pub struct SeedInfo {
23+
/// Seed signer index in the validator set
24+
pub seed_signer_idx: Uint,
25+
/// Seed hash generated from the vrf
26+
pub seed: H256,
27+
/// Seed proof
28+
pub proof: Bytes,
29+
}
30+
2131
/// Tendermint seal.
2232
#[derive(Debug, PartialEq, Deserialize)]
2333
pub struct TendermintSeal {
@@ -27,6 +37,10 @@ pub struct TendermintSeal {
2737
pub cur_view: Uint,
2838
/// Proposal seal signature.
2939
pub precommits: Vec<H520>,
40+
/// Precommit signatures' bitset
41+
pub precommit_bitset: Bytes,
42+
/// Seed information for randomized leader election
43+
pub vrf_seed_info: SeedInfo,
3044
}
3145

3246
/// Seal variants.
@@ -41,12 +55,12 @@ pub enum Seal {
4155

4256
#[cfg(test)]
4357
mod tests {
44-
use primitives::H520 as Core520;
58+
use primitives::{H256 as Core256, H520 as Core520};
4559
use serde_json;
4660

47-
use super::{Seal, TendermintSeal};
61+
use super::{Seal, SeedInfo, TendermintSeal};
4862
use crate::bytes::Bytes;
49-
use crate::hash::H520;
63+
use crate::hash::{H256, H520};
5064

5165
#[test]
5266
fn seal_deserialization() {
@@ -58,7 +72,13 @@ mod tests {
5872
"cur_view": "0x4",
5973
"precommits": [
6074
"0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"
61-
]
75+
],
76+
"precommit_bitset": "0x0000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000001",
77+
"vrf_seed_info": {
78+
"seed_signer_idx": "0x0",
79+
"seed": "0x0000000000000000000000000000000000000000000000000000000000000001",
80+
"proof": "0x0000001000000000000000000000000000000000000000000000000000000001"
81+
}
6282
}
6383
}]"#;
6484

@@ -71,7 +91,20 @@ mod tests {
7191
Seal::Tendermint(TendermintSeal {
7292
prev_view: 0x3.into(),
7393
cur_view: 0x4.into(),
74-
precommits: vec![H520(Core520::from("0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"))]
94+
precommits: vec![H520(Core520::from("0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"))],
95+
precommit_bitset: Bytes::new(vec![
96+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
97+
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
99+
]),
100+
vrf_seed_info: SeedInfo {
101+
seed_signer_idx: 0x0.into(),
102+
seed: H256(Core256::from("0x0000000000000000000000000000000000000000000000000000000000000001")),
103+
proof: Bytes::new(vec![
104+
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
106+
])
107+
},
75108
}),
76109
]);
77110
}

0 commit comments

Comments
 (0)