Skip to content

Commit

Permalink
Check round number in get round result
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Feb 19, 2024
1 parent 5b5f9bb commit 4e8133f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ export class BeaconCache {
}
}

public async get(round: number): Promise<string> {
const got = this.data.get(round);
public async get(requestRound: number): Promise<string> {
const got = this.data.get(requestRound);
if (got) {
return got;
}

const { signature } = await this.client.get(round);
this.data.set(round, signature);
const { signature, round } = await this.client.get(requestRound);
assert(typeof signature === "string", "Got unexpected signature type at runtime");
assert(typeof round === "number", "Got unexpected round type at runtime");
assert(
round === requestRound,
`Got differerent round than expected from drand client (requested: ${requestRound}, got: ${round}). This is likely a server-side error.`,
);
this.data.set(requestRound, signature);
return signature;
}

Expand Down

0 comments on commit 4e8133f

Please sign in to comment.