Skip to content

Commit

Permalink
Merge pull request #29 from noislabs/check-round-resuklt
Browse files Browse the repository at this point in the history
Check round number in get round result
  • Loading branch information
webmaster128 authored Feb 19, 2024
2 parents 5b5f9bb + 4e8133f commit e3a21a2
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 e3a21a2

Please sign in to comment.