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

Fix FallbackProvider stalling behavior to allow sequential requests #4299

Closed
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
16 changes: 9 additions & 7 deletions src.ts/providers/provider-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ export class FallbackProvider extends AbstractProvider {
}

// Adds a new runner (if available) to running.
#addRunner(running: Set<RunnerState>, req: PerformActionRequest): null | RunnerState {
#addRunner(running: Set<RunnerState>, req: PerformActionRequest): number {
const config = this.#getNextConfig(running);

// No runners available
if (config == null) { return null; }
if (config == null) { return 0; }

// Create a new runner
const runner: RunnerState = {
Expand Down Expand Up @@ -524,7 +524,7 @@ export class FallbackProvider extends AbstractProvider {
})();

running.add(runner);
return runner;
return runner.config.weight;
}

// Initializes the blockNumber and network for each runner and
Expand Down Expand Up @@ -668,6 +668,9 @@ export class FallbackProvider extends AbstractProvider {
return value;
}

// Wait for someone to either complete its perform or stall out
await Promise.race(interesting);

// Add any new runners, because a staller timed out or a result
// or error response came in.
for (let i = 0; i < newRunners; i++) {
Expand All @@ -681,9 +684,6 @@ export class FallbackProvider extends AbstractProvider {
info: { request: req, results: Array.from(running).map((r) => stringify(r.result)) }
});

// Wait for someone to either complete its perform or stall out
await Promise.race(interesting);

// This is recursive, but at worst case the depth is 2x the
// number of providers (each has a perform and a staller)
return await this.#waitForQuorum(running, req);
Expand Down Expand Up @@ -716,8 +716,10 @@ export class FallbackProvider extends AbstractProvider {

// Bootstrap enough runners to meet quorum
const running: Set<RunnerState> = new Set();
let weightSoFar = 0;
for (let i = 0; i < this.quorum; i++) {
this.#addRunner(running, req);
weightSoFar += this.#addRunner(running, req);
if (weightSoFar >= this.quorum) { break; }
}

const result = await this.#waitForQuorum(running, req);
Expand Down