From 672c620e32fa6d4c756f986e784224f164dbd9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szynwelski?= Date: Thu, 7 Dec 2023 10:07:27 +0100 Subject: [PATCH] Random sequencer selection --- src/contract/sequencer/SequencerClient.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/contract/sequencer/SequencerClient.ts b/src/contract/sequencer/SequencerClient.ts index da9a45ba..fcacf0a8 100644 --- a/src/contract/sequencer/SequencerClient.ts +++ b/src/contract/sequencer/SequencerClient.ts @@ -45,9 +45,9 @@ export interface SequencerClient { */ type SequencerAddress = { /** - * The URL address of the sequencer + * Sequencer URLs */ - url: string; + urls: [string]; /** * The type of sequencer */ @@ -68,13 +68,16 @@ export const createSequencerClient = async ( ): Promise => { const response = warpFetchWrapper.fetch(`${stripTrailingSlash(gatewayUrl)}/gateway/sequencer/address`); const address = await getJsonResponse(response); + // if there are several sequencer nodes to choose from, we randomly select one + const sequencerAddress = + address.urls.length > 1 ? address.urls[Math.floor(Math.random() * address.urls.length)] : address.urls[0]; if (address.type == 'centralized') { - return new CentralizedSequencerClient(address.url, warpFetchWrapper); + return new CentralizedSequencerClient(sequencerAddress, warpFetchWrapper); } if (address.type == 'decentralized') { - return new DecentralizedSequencerClient(address.url, gatewayUrl, warpFetchWrapper); + return new DecentralizedSequencerClient(sequencerAddress, gatewayUrl, warpFetchWrapper); } throw new Error('Unknown sequencer type: ' + address.type);