From 4e8133ffcae631269ab636c8fc01ad13a16f4b8a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 19 Feb 2024 20:24:48 +0100 Subject: [PATCH] Check round number in get round result --- cache.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cache.ts b/cache.ts index 062bf18..9265e66 100644 --- a/cache.ts +++ b/cache.ts @@ -22,14 +22,20 @@ export class BeaconCache { } } - public async get(round: number): Promise { - const got = this.data.get(round); + public async get(requestRound: number): Promise { + 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; }