Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to not shuffle providers #588

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/providers/src.ts/fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ let nextRid = 1;
export class FallbackProvider extends BaseProvider {
readonly providers: Array<BaseProvider>;
readonly weights: Array<number>;
readonly shuffle: boolean;
readonly quorum: number;

constructor(providers: Array<BaseProvider>, quorum?: number, weights?: Array<number>) {
constructor(providers: Array<BaseProvider>, quorum?: number, weights?: Array<number>, shuffle?: boolean) {
logger.checkNew(new.target, FallbackProvider);

if (providers.length === 0) {
Expand Down Expand Up @@ -116,6 +117,7 @@ export class FallbackProvider extends BaseProvider {
}
}

shuffle = shuffle === false ? false : true

// All networks are ready, we can know the network for certain
let ready = checkNetworks(providers.map((p) => p.network));
Expand All @@ -138,6 +140,7 @@ export class FallbackProvider extends BaseProvider {
defineReadOnly(this, "providers", Object.freeze(providers.slice()));
defineReadOnly(this, "quorum", quorum);
defineReadOnly(this, "weights", Object.freeze(weights.slice()));
defineReadOnly(this, "shuffle", shuffle);
}

static doPerform(provider: BaseProvider, method: string, params: { [ name: string ]: any }): Promise<any> {
Expand Down Expand Up @@ -173,7 +176,8 @@ export class FallbackProvider extends BaseProvider {

perform(method: string, params: { [name: string]: any }): any {
let T0 = now();
let runners: Array<Runner> = (<Array<BaseProvider>>(shuffled(this.providers))).map((provider, i) => {
let providers: Array<BaseProvider> = this.shuffle ? shuffled(this.providers) : this.providers
let runners: Array<Runner> = providers.map((provider, i) => {
let weight = this.weights[i];
let rid = nextRid++;
return {
Expand Down