From b6ff0e85c352a9bba40a73e138ba0cf1181a5cb1 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Thu, 21 Nov 2024 11:34:42 -0500 Subject: [PATCH 1/3] sdk: slotSubscriber skip extra calls to getSlot --- sdk/src/slot/SlotSubscriber.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/slot/SlotSubscriber.ts b/sdk/src/slot/SlotSubscriber.ts index 0288ae0c75..6fb4c2fe9d 100644 --- a/sdk/src/slot/SlotSubscriber.ts +++ b/sdk/src/slot/SlotSubscriber.ts @@ -40,7 +40,9 @@ export class SlotSubscriber { return; } - this.currentSlot = await this.connection.getSlot('confirmed'); + if (this.currentSlot === undefined) { + this.currentSlot = await this.connection.getSlot('confirmed'); + } this.subscriptionId = this.connection.onSlotChange((slotInfo) => { if (!this.currentSlot || this.currentSlot < slotInfo.slot) { From 00a756cf81d1a2b247dffe789997ad24ffbd7f50 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Thu, 21 Nov 2024 11:48:24 -0500 Subject: [PATCH 2/3] make sure only one fetch happens --- sdk/src/slot/SlotSubscriber.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/slot/SlotSubscriber.ts b/sdk/src/slot/SlotSubscriber.ts index 6fb4c2fe9d..de07513b69 100644 --- a/sdk/src/slot/SlotSubscriber.ts +++ b/sdk/src/slot/SlotSubscriber.ts @@ -21,6 +21,7 @@ export class SlotSubscriber { resubTimeoutMs?: number; isUnsubscribing = false; receivingData = false; + initialSubDone = false; public constructor( private connection: Connection, @@ -40,7 +41,8 @@ export class SlotSubscriber { return; } - if (this.currentSlot === undefined) { + if (!this.initialSubDone) { + this.initialSubDone = true; this.currentSlot = await this.connection.getSlot('confirmed'); } From b5c33394cae794e17f18a4c61048f91f42d714c8 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Thu, 21 Nov 2024 12:18:41 -0500 Subject: [PATCH 3/3] sdk: throw err if resub too smol --- sdk/src/slot/SlotSubscriber.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/slot/SlotSubscriber.ts b/sdk/src/slot/SlotSubscriber.ts index de07513b69..00c4785695 100644 --- a/sdk/src/slot/SlotSubscriber.ts +++ b/sdk/src/slot/SlotSubscriber.ts @@ -30,7 +30,7 @@ export class SlotSubscriber { this.eventEmitter = new EventEmitter(); this.resubTimeoutMs = config?.resubTimeoutMs; if (this.resubTimeoutMs < 1000) { - console.log( + throw new Error( 'resubTimeoutMs should be at least 1000ms to avoid spamming resub' ); }