Skip to content

Commit

Permalink
chore(core-p2p): verify peer claimed state
Browse files Browse the repository at this point in the history
  • Loading branch information
air1one committed Sep 9, 2020
1 parent 4f9ea3c commit 24a8b04
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core-p2p/src/peer-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class PeerVerifier {
claimedState: P2P.IPeerState,
deadline: number,
): Promise<PeerVerificationResult | undefined> {
if (!this.checkStateHeader(claimedState)) {
if (!(await this.checkStateHeader(claimedState))) {
return undefined;
}

Expand All @@ -102,7 +102,7 @@ export class PeerVerifier {
return new PeerVerificationResult(ourHeight, claimedHeight, highestCommonBlockHeight);
}

private checkStateHeader(claimedState: P2P.IPeerState): boolean {
private async checkStateHeader(claimedState: P2P.IPeerState): Promise<boolean> {
const blockHeader: Interfaces.IBlockData = claimedState.header as Interfaces.IBlockData;
const claimedHeight: number = Number(blockHeader.height);
if (claimedHeight !== claimedState.height) {
Expand All @@ -126,8 +126,9 @@ export class PeerVerifier {
return true;
}

const claimedBlock: Interfaces.IBlock = Blocks.BlockFactory.fromData(blockHeader);
if (claimedBlock.verifySignature()) {
const roundInfo = roundCalculator.calculateRound(claimedHeight);
const delegates = await this.getDelegatesByRound(roundInfo);
if (await this.verifyPeerBlock(blockHeader, claimedHeight, delegates)) {
return true;
}

Expand Down

0 comments on commit 24a8b04

Please sign in to comment.