Skip to content

FallbackProvider should spawn quorum/weight runners, not quorum runners #4298

@staltz

Description

@staltz

Ethers Version

6.6.2

Search Terms

FallbackProvider

Describe the Problem

For eth_getLogs requests, we would like to send requests sequentially to providers, in such a way that if the i-th request is successful, then the (i+1)-th request is NOT sent.

Our understanding is that (according to our chat last week) "it is supposed to call parallel up to quorum. So if the quorum is 2 and each provider has a weight of 1, there should be two in-flight at a time. After stallTimeout the next gets kicked off, to account for the overly common case of backends not responding and also not hanging up."

Assuming all our providers have weight 2 and the quorum is 2:

Expected: each provider ("runner") is attempted one at a time, proceeding to the next one only if the request failed.

Actual: 2 runners are simultaneously attempted.

The culprit seems to be this line of code:

for (let i = 0; i < this.quorum; i++) {
this.#addRunner(running, req);
}

Notice how this.quorum runners are started, independently of the weight of each provider runner. I believe that we should instead count the total-so-far weight of runners started and stop the for-loop if enough has been reached for the quorum.

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer), Browser (Chrome, Safari, etc), React Native/Expo/JavaScriptCore

Environment (Other)

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or improvement.fixed/completeThis Bug is fixed or Enhancement is complete and published.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions