Skip to content

Commit

Permalink
Random sequencer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
szynwelski committed Dec 7, 2023
1 parent 0f5c58c commit 672c620
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/contract/sequencer/SequencerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -68,13 +68,16 @@ export const createSequencerClient = async (
): Promise<SequencerClient> => {
const response = warpFetchWrapper.fetch(`${stripTrailingSlash(gatewayUrl)}/gateway/sequencer/address`);
const address = await getJsonResponse<SequencerAddress>(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);
Expand Down

0 comments on commit 672c620

Please sign in to comment.