Skip to content

Commit 590fcae

Browse files
author
SeungMin Lee
committed
Change totalScore in the BlockSyncMessage to seq
In the past, the work of removing the totalScore from the BodySyncMessage and introducing the seq, the test was not modified at that time. Therefore, we removed the remaining totalScore and changed it to the seq.
1 parent d1834b6 commit 590fcae

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ async function testBody(
172172
}
173173

174174
const genesis = mock.genesisHash;
175-
await mock.sendStatus(bestScore, bestHash, genesis);
175+
const seq = new U256(0);
176+
await mock.sendStatus(seq, bestHash, genesis);
176177
await mock.sendBlockHeaderResponse([
177178
header0.toEncodeObject(),
178179
header.toEncodeObject(),

test/src/helper/mock/blockSyncMessage.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type BlockSyncMessageBody = IStatus | IRequest | IResponse;
3939

4040
interface IStatus {
4141
type: "status";
42-
totalScore: U256;
42+
seq: U256;
4343
bestHash: H256;
4444
genesisHash: H256;
4545
}
@@ -64,14 +64,12 @@ export class BlockSyncMessage {
6464
if (msgId === MessageType.MESSAGE_ID_STATUS) {
6565
Emitter.emit("status");
6666
const msg = decodedmsg[1];
67-
const totalScore = new U256(
68-
parseInt(msg[0].toString("hex"), 16) || 0
69-
);
67+
const seq = new U256(parseInt(msg[0].toString("hex"), 16) || 0);
7068
const bestHash = new H256(msg[1].toString("hex"));
7169
const genesisHash = new H256(msg[2].toString("hex"));
7270
return new BlockSyncMessage({
7371
type: "status",
74-
totalScore,
72+
seq,
7573
bestHash,
7674
genesisHash
7775
});
@@ -123,7 +121,7 @@ export class BlockSyncMessage {
123121
return [
124122
MessageType.MESSAGE_ID_STATUS,
125123
[
126-
this.body.totalScore.toEncodeObject(),
124+
this.body.seq.toEncodeObject(),
127125
this.body.bestHash.toEncodeObject(),
128126
this.body.genesisHash.toEncodeObject()
129127
]

test/src/helper/mock/index.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Mock {
6868
this.p2psocket.enableLog();
6969
}
7070

71-
public async establish(bestHash?: H256, bestScore?: U256) {
71+
public async establish(bestHash?: H256) {
7272
await this.p2psocket.connect();
7373

7474
let isStatusArrived;
@@ -84,17 +84,15 @@ export class Mock {
8484
await this.waitStatusMessage();
8585
}
8686

87-
const score =
88-
bestScore == undefined ? new U256("99999999999999999") : bestScore;
8987
const best =
9088
bestHash == undefined
9189
? new H256(
9290
"0x649fb35c0e304eb601ae71fe330729a2c1a27687ae7e2b0170866b86047a7bb9"
9391
)
9492
: bestHash;
9593
const genesis = this.p2psocket.getGenesisHash();
96-
this.sendStatus(score, best, genesis);
97-
94+
const seq = new U256(0);
95+
this.sendStatus(seq, best, genesis);
9896
await this.waitHeaderRequest();
9997

10098
if (this.log) {
@@ -192,10 +190,10 @@ export class Mock {
192190
return null;
193191
}
194192

195-
public async sendStatus(score: U256, bestHash: H256, genesisHash: H256) {
193+
public async sendStatus(seq: U256, bestHash: H256, genesisHash: H256) {
196194
const msg = new BlockSyncMessage({
195+
seq,
197196
type: "status",
198-
totalScore: score,
199197
bestHash,
200198
genesisHash
201199
});
@@ -257,17 +255,15 @@ export class Mock {
257255
public async sendEncodedBlock(
258256
header: EncodedHeaders,
259257
body: EncodedBodies,
260-
bestBlockHash: H256,
261-
bestBlockScore: U256
258+
bestBlockHash: H256
262259
) {
263260
if (this.log) {
264261
console.log("Send blocks");
265262
}
266-
const score = bestBlockScore;
267263
const best = bestBlockHash;
268264
const genesis = this.p2psocket.getGenesisHash();
269-
await this.sendStatus(score, best, genesis);
270-
265+
const seq = new U256(0);
266+
this.sendStatus(seq, best, genesis);
271267
await this.sendBlockHeaderResponse(header);
272268
if (this.log) {
273269
console.log("Send header response");
@@ -288,11 +284,10 @@ export class Mock {
288284
console.log("Send blocks");
289285
}
290286
const bestBlock = header[header.length - 1];
291-
const score = bestBlock.getScore();
292287
const best = bestBlock.hashing();
293288
const genesis = this.p2psocket.getGenesisHash();
294-
await this.sendStatus(score, best, genesis);
295-
289+
const seq = new U256(0);
290+
await this.sendStatus(seq, best, genesis);
296291
await this.sendBlockHeaderResponse(header.map(h => h.toEncodeObject()));
297292
if (this.log) {
298293
console.log("Send header response");

0 commit comments

Comments
 (0)