Skip to content

Commit 9b5a423

Browse files
HoOngEesgkim126
authored andcommitted
Add last_committed_validators field to the Header
Modules require information about the committed validators of last block.
1 parent 1458f23 commit 9b5a423

File tree

12 files changed

+79
-9
lines changed

12 files changed

+79
-9
lines changed

coordinator/src/header.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@ pub struct Header {
2828
number: u64,
2929
/// Block author.
3030
author: Public,
31+
/// Validators who submitted tendermint Commit for last block.
32+
last_committed_validators: Vec<Public>,
3133
/// Block extra data.
3234
extra_data: Bytes,
3335
}
3436

3537
impl Header {
36-
pub fn new(parent_hash: BlockHash, timestamp: u64, number: u64, author: Public, extra_data: Bytes) -> Self {
38+
pub fn new(
39+
parent_hash: BlockHash,
40+
timestamp: u64,
41+
number: u64,
42+
author: Public,
43+
last_committed_validators: Vec<Public>,
44+
extra_data: Bytes,
45+
) -> Self {
3746
Self {
3847
parent_hash,
3948
timestamp,
4049
number,
4150
author,
51+
last_committed_validators,
4252
extra_data,
4353
}
4454
}

core/src/encoded.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ impl Header {
6969

7070
pub fn into_simplified(self) -> coordinator::Header {
7171
let view = self.view();
72-
coordinator::Header::new(view.parent_hash(), view.timestamp(), view.number(), view.author(), view.extra_data())
72+
coordinator::Header::new(
73+
view.parent_hash(),
74+
view.timestamp(),
75+
view.number(),
76+
view.author(),
77+
view.last_committed_validators(),
78+
view.extra_data(),
79+
)
7380
}
7481
}
7582

@@ -120,6 +127,10 @@ impl Header {
120127
self.view().timestamp()
121128
}
122129

130+
pub fn last_committed_validators(&self) -> Vec<Public> {
131+
self.view().last_committed_validators()
132+
}
133+
123134
/// Block extra data.
124135
pub fn extra_data(&self) -> Vec<u8> {
125136
self.view().extra_data()

core/src/views/header.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,18 @@ impl<'a> HeaderView<'a> {
9090
self.rlp.val_at(7).unwrap()
9191
}
9292

93+
pub fn last_committed_validators(&self) -> Vec<Public> {
94+
self.rlp.list_at(8).unwrap()
95+
}
96+
9397
/// Returns block extra data.
9498
pub fn extra_data(&self) -> Bytes {
95-
self.rlp.val_at(8).unwrap()
99+
self.rlp.val_at(9).unwrap()
96100
}
97101

98102
/// Returns a vector of post-RLP-encoded seal fields.
99103
pub fn seal(&self) -> Vec<Bytes> {
100-
const SIZE_WITHOUT_SEAL: usize = 9;
104+
const SIZE_WITHOUT_SEAL: usize = 10;
101105

102106
let item_count = self.rlp.item_count().unwrap();
103107
let mut seal = Vec::with_capacity(item_count - SIZE_WITHOUT_SEAL);

test/src/e2e.long/invalidBlockPropagation.helper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async function setup(): Promise<[Header, Block, Header]> {
5757
new U256(block0.timestamp),
5858
new U256(block0.number),
5959
authorPaddress.pubkey,
60+
[], // lastCommittedValidators
6061
Buffer.from(block0.extraData),
6162
BLAKE_NULL_RLP,
6263
new H256(block0.transactionsRoot),
@@ -70,6 +71,7 @@ async function setup(): Promise<[Header, Block, Header]> {
7071
new U256(block1.timestamp),
7172
new U256(block1.number),
7273
author1.pubkey,
74+
[], // lastCommittedValidators
7375
Buffer.from(block1.extraData),
7476
BLAKE_NULL_RLP,
7577
new H256(block1.transactionsRoot),
@@ -83,6 +85,7 @@ async function setup(): Promise<[Header, Block, Header]> {
8385
new U256(block2.timestamp),
8486
new U256(block2.number),
8587
author3.pubkey,
88+
[], // lastCommittedValidators
8689
Buffer.from(block2.extraData),
8790
BLAKE_NULL_RLP,
8891
new H256(block2.transactionsRoot),
@@ -147,6 +150,7 @@ async function testBody(
147150
new U256(block1.timestamp),
148151
new U256(block1.number),
149152
author4.pubkey,
153+
[], // lastCommittedValidators
150154
Buffer.from(block1.extraData),
151155
BLAKE_NULL_RLP,
152156
new H256(block1.transactionsRoot),

test/src/e2e.long/onChainBlockValid.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe("Test onChain block communication", async function() {
6464
new U256(genesisBlock.timestamp),
6565
new U256(genesisBlock.number),
6666
author1PlatformAddr.pubkey,
67+
[], // lastCommittedValidators
6768
Buffer.from(genesisBlock.extraData),
6869
BLAKE_NULL_RLP,
6970
new H256(genesisBlock.transactionsRoot),
@@ -77,6 +78,7 @@ describe("Test onChain block communication", async function() {
7778
new U256(block1.timestamp),
7879
new U256(block1.number),
7980
author2PlatformAddr.pubkey,
81+
[], // lastCommittedValidators
8082
Buffer.from(block1.extraData),
8183
BLAKE_NULL_RLP,
8284
new H256(block1.transactionsRoot),
@@ -90,6 +92,7 @@ describe("Test onChain block communication", async function() {
9092
new U256(block2.timestamp),
9193
new U256(block2.number),
9294
author3PlatformAddr.pubkey,
95+
[], // lastCommittedValidators
9396
Buffer.from(block2.extraData),
9497
BLAKE_NULL_RLP,
9598
new H256(block2.transactionsRoot),

test/src/e2e.long/onChainHeaderValid.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describe("Test onChain header communication", async function() {
153153
new U256(genesisBlock.timestamp),
154154
new U256(genesisBlock.number),
155155
author1PlatformAddr.pubkey,
156+
[], // lastCommittedValidators
156157
Buffer.from(genesisBlock.extraData),
157158
BLAKE_NULL_RLP,
158159
new H256(genesisBlock.transactionsRoot),
@@ -166,6 +167,7 @@ describe("Test onChain header communication", async function() {
166167
new U256(block1.timestamp),
167168
new U256(block1.number),
168169
author2PlatformAddr.pubkey,
170+
[], // lastCommittedValidators
169171
Buffer.from(block1.extraData),
170172
BLAKE_NULL_RLP,
171173
new H256(block1.transactionsRoot),
@@ -179,6 +181,7 @@ describe("Test onChain header communication", async function() {
179181
new U256(block2.timestamp),
180182
new U256(block2.number),
181183
author3PlatformAddr.pubkey,
184+
[], // lastCommittedValidators
182185
Buffer.from(block2.extraData),
183186
BLAKE_NULL_RLP,
184187
new H256(block2.transactionsRoot),
@@ -192,6 +195,7 @@ describe("Test onChain header communication", async function() {
192195
new U256(block3.timestamp),
193196
new U256(block3.number),
194197
author4PlatformAddr.pubkey,
198+
[], // lastCommittedValidators
195199
Buffer.from(block3.extraData),
196200
BLAKE_NULL_RLP,
197201
new H256(block3.transactionsRoot),

test/src/helper/mock/cHeader.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ export class Header {
3232
const nextValidatorSetHash = new H256(decodedmsg[5].toString("hex"));
3333
const number = new U256(parseInt(decodedmsg[6].toString("hex"), 16));
3434
const timestamp = new U256(parseInt(decodedmsg[7].toString("hex"), 16));
35-
const extraData = decodedmsg[8];
35+
const lastCommittedValidators: string[] = decodedmsg[8];
36+
const extraData = decodedmsg[9];
3637

3738
// Be careful of the order! Three roots have same types, so mistake on the order will not be catched by typechecker.
3839
const header = new Header(
3940
parentHash,
4041
timestamp,
4142
number,
4243
author,
44+
lastCommittedValidators,
4345
extraData,
4446
evidencesRoot,
4547
transactionsRoot,
@@ -65,6 +67,7 @@ export class Header {
6567
new H256(
6668
"0000000000000000000000000000000000000000000000000000000000000000"
6769
),
70+
[],
6871
Buffer.alloc(0),
6972
BLAKE_NULL_RLP,
7073
BLAKE_NULL_RLP,
@@ -78,6 +81,7 @@ export class Header {
7881
private timestamp: U256;
7982
private number: U256;
8083
private author: H256;
84+
private lastCommittedValidators: string[];
8185
private extraData: Buffer;
8286
private evidencesRoot: H256;
8387
private transactionsRoot: H256;
@@ -92,6 +96,7 @@ export class Header {
9296
timestamp: U256,
9397
number: U256,
9498
author: H256,
99+
lastCommittedValidators: string[],
95100
extraData: Buffer,
96101
evidencesRoot: H256,
97102
transactionsRoot: H256,
@@ -105,6 +110,7 @@ export class Header {
105110
this.timestamp = timestamp;
106111
this.number = number;
107112
this.author = author;
113+
this.lastCommittedValidators = lastCommittedValidators;
108114
this.extraData = extraData;
109115
this.evidencesRoot = evidencesRoot;
110116
this.transactionsRoot = transactionsRoot;
@@ -177,6 +183,7 @@ export class Header {
177183
this.nextValidatorSetHash.toEncodeObject(),
178184
this.number.toEncodeObject(),
179185
this.timestamp.toEncodeObject(),
186+
this.lastCommittedValidators,
180187
this.extraData
181188
].concat(this.seal);
182189
}

test/src/helper/mock/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ export class Mock {
384384
const author = new H256(
385385
"0000000000000000000000000000000000000000000000000000000000000000"
386386
);
387+
const lastCommittedValidators: string[] = [];
387388
const extraData = Buffer.from([
388389
23,
389390
108,
@@ -436,6 +437,7 @@ export class Mock {
436437
timestamp,
437438
number,
438439
author,
440+
lastCommittedValidators,
439441
extraData,
440442
transactionsRoot,
441443
evidencesRoot,
@@ -454,6 +456,7 @@ export class Mock {
454456
const author = new H256(
455457
"7777777777777777777777777777777777777777777777777777777777777777"
456458
);
459+
const lastCommittedValidators: string[] = [];
457460
const extraData = Buffer.alloc(0);
458461
const transactionsRoot = new H256(
459462
"45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"
@@ -473,6 +476,7 @@ export class Mock {
473476
timestamp,
474477
number,
475478
author,
479+
lastCommittedValidators,
476480
extraData,
477481
transactionsRoot,
478482
evidencesRoot,
@@ -491,6 +495,7 @@ export class Mock {
491495
const author = new H256(
492496
"6666666666666666666666666666666666666666666666666666666666666666"
493497
);
498+
const lastCommittedValidators: string[] = [];
494499
const extraData = Buffer.alloc(0);
495500
const transactionsRoot = new H256(
496501
"45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"
@@ -510,6 +515,7 @@ export class Mock {
510515
timestamp,
511516
number,
512517
author,
518+
lastCommittedValidators,
513519
extraData,
514520
evidencesRoot,
515521
transactionsRoot,

test/src/helper/mock/test/header.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Check Header RLP encoding", function() {
1616
const header = Header.default();
1717
// Find the empty header's rlp encoded data in the unit test in header.rs file
1818
expect(header.rlpBytes().toString("hex")).deep.equal(
19-
"f8c9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0808080"
19+
"f8caa00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c08080c080"
2020
);
2121
});
2222

@@ -39,7 +39,7 @@ describe("Check Header RLP encoding", function() {
3939
header.setSeal([0, 0, [Buffer.from(signature, "hex")], bitset]);
4040
// Find the header's rlp encoded data in the unit test in the tendermint/mod.rs file
4141
expect(header.rlpBytes().toString("hex")).deep.equal(
42-
"f90175a00000000000000000000000000000000000000000000000000000000000000000a03b21399e52ae4d7582032df537c00eaa3f4611210b3305ce48ac5407cd8f91bfa045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c00480808080f842b8404752ae46a97e2e4ff11b8212b85610f81ae63c5b541cc5f1e89238150c122be650b9abc954bab919de4be9a2f1dba992e88b9aa5596d2bdf2645597163697d07b86404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
42+
"f90176a00000000000000000000000000000000000000000000000000000000000000000a03b21399e52ae4d7582032df537c00eaa3f4611210b3305ce48ac5407cd8f91bfa045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0a045b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c00480c0808080f842b8404752ae46a97e2e4ff11b8212b85610f81ae63c5b541cc5f1e89238150c122be650b9abc954bab919de4be9a2f1dba992e88b9aa5596d2bdf2645597163697d07b86404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
4343
);
4444
});
4545

test/src/sdk/core/Block.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface BlockData {
1111
timestamp: number;
1212
number: number;
1313
author: Address;
14+
lastCommittedValidators: string[];
1415
extraData: number[];
1516
transactionsRoot: H256;
1617
stateRoot: H256;
@@ -24,6 +25,7 @@ export interface BlockJSON {
2425
timestamp: number;
2526
number: number;
2627
author: string;
28+
lastCommittedValidators: string[];
2729
extraData: number[];
2830
transactionsRoot: string;
2931
stateRoot: string;
@@ -42,6 +44,7 @@ export class Block {
4244
timestamp,
4345
number,
4446
author,
47+
lastCommittedValidators,
4548
extraData,
4649
transactionsRoot,
4750
stateRoot,
@@ -55,6 +58,7 @@ export class Block {
5558
timestamp,
5659
number,
5760
author: Address.fromString(author),
61+
lastCommittedValidators,
5862
extraData,
5963
transactionsRoot: new H256(transactionsRoot),
6064
stateRoot: new H256(stateRoot),
@@ -68,6 +72,7 @@ export class Block {
6872
public timestamp: number;
6973
public number: number;
7074
public author: Address;
75+
public lastCommittedValidators: string[];
7176
public extraData: number[];
7277
public transactionsRoot: H256;
7378
public stateRoot: H256;
@@ -82,6 +87,7 @@ export class Block {
8287
timestamp,
8388
number,
8489
author,
90+
lastCommittedValidators,
8591
extraData,
8692
transactionsRoot,
8793
stateRoot,
@@ -94,6 +100,7 @@ export class Block {
94100
this.timestamp = timestamp;
95101
this.number = number;
96102
this.author = author;
103+
this.lastCommittedValidators = lastCommittedValidators;
97104
this.extraData = extraData;
98105
this.transactionsRoot = transactionsRoot;
99106
this.stateRoot = stateRoot;
@@ -109,6 +116,7 @@ export class Block {
109116
timestamp,
110117
number,
111118
author,
119+
lastCommittedValidators,
112120
extraData,
113121
transactionsRoot,
114122
stateRoot,
@@ -122,6 +130,7 @@ export class Block {
122130
timestamp,
123131
number,
124132
author: author.toString(),
133+
lastCommittedValidators: [...lastCommittedValidators],
125134
extraData: [...extraData],
126135
transactionsRoot: transactionsRoot.toJSON(),
127136
stateRoot: stateRoot.toJSON(),
@@ -138,6 +147,7 @@ export class Block {
138147
timestamp,
139148
number,
140149
author,
150+
lastCommittedValidators,
141151
extraData,
142152
transactionsRoot,
143153
stateRoot,
@@ -154,6 +164,7 @@ export class Block {
154164
blockHeader.push(nextValidatorSetHash.toEncodeObject());
155165
blockHeader.push(number);
156166
blockHeader.push(timestamp);
167+
blockHeader.push(lastCommittedValidators);
157168
blockHeader.push(`0x${Buffer.from(extraData).toString("hex")}`);
158169
blockHeader.push(
159170
...seal.map(s => `0x${Buffer.from(s).toString("hex")}`)

0 commit comments

Comments
 (0)