ethers.js/lib.commonjs/providers/provider-fallback.d.ts

115 lines
3.4 KiB
TypeScript
Raw Permalink Normal View History

2023-03-03 18:25:07 -07:00
import { AbstractProvider } from "./abstract-provider.js";
import { Network } from "./network.js";
import type { PerformActionRequest } from "./abstract-provider.js";
import type { Networkish } from "./network.js";
/**
* A configuration entry for how to use a [[Provider]].
*/
export interface FallbackProviderConfig {
2023-06-01 17:52:58 -04:00
/**
* The provider.
*/
2023-03-03 18:25:07 -07:00
provider: AbstractProvider;
2023-06-01 17:52:58 -04:00
/**
* The amount of time to wait before kicking off the next provider.
*
* Any providers that have not responded can still respond and be
* counted, but this ensures new providers start.
*/
2023-03-03 18:25:07 -07:00
stallTimeout?: number;
2023-06-01 17:52:58 -04:00
/**
* The priority. Lower priority providers are dispatched first.
*/
2023-03-03 18:25:07 -07:00
priority?: number;
2023-06-01 17:52:58 -04:00
/**
* The amount of weight a provider is given against the quorum.
*/
2023-03-03 18:25:07 -07:00
weight?: number;
}
/**
* The statistics and state maintained for a [[Provider]].
*/
export interface FallbackProviderState extends Required<FallbackProviderConfig> {
2023-06-01 17:52:58 -04:00
/**
* The most recent blockNumber this provider has reported (-2 if none).
*/
2023-03-03 18:25:07 -07:00
blockNumber: number;
2023-06-01 17:52:58 -04:00
/**
* The number of total requests ever sent to this provider.
*/
2023-03-03 18:25:07 -07:00
requests: number;
2023-06-01 17:52:58 -04:00
/**
* The number of responses that errored.
*/
2023-03-03 18:25:07 -07:00
errorResponses: number;
2023-06-01 17:52:58 -04:00
/**
* The number of responses that occured after the result resolved.
*/
2023-03-03 18:25:07 -07:00
lateResponses: number;
2023-06-01 17:52:58 -04:00
/**
* How many times syncing was required to catch up the expected block.
*/
2023-03-03 18:25:07 -07:00
outOfSync: number;
2023-06-01 17:52:58 -04:00
/**
* The number of requests which reported unsupported operation.
*/
2023-03-03 18:25:07 -07:00
unsupportedEvents: number;
2023-06-01 17:52:58 -04:00
/**
* A rolling average (5% current duration) for response time.
*/
2023-03-03 18:25:07 -07:00
rollingDuration: number;
2023-06-01 17:52:58 -04:00
/**
* The ratio of quorum-agreed results to total.
*/
2023-03-03 18:25:07 -07:00
score: number;
}
/**
* Additional options to configure a [[FallbackProvider]].
*/
export type FallbackProviderOptions = {
quorum?: number;
eventQuorum?: number;
eventWorkers?: number;
cacheTimeout?: number;
pollingInterval?: number;
2023-03-03 18:25:07 -07:00
};
/**
2023-06-01 17:52:58 -04:00
* A **FallbackProvider** manages several [[Providers]] providing
2024-02-02 03:25:03 -05:00
* resilience by switching between slow or misbehaving nodes, security
2023-06-01 17:52:58 -04:00
* by requiring multiple backends to aggree and performance by allowing
* faster backends to respond earlier.
2023-03-03 18:25:07 -07:00
*
*/
export declare class FallbackProvider extends AbstractProvider {
#private;
2023-06-01 17:52:58 -04:00
/**
* The number of backends that must agree on a value before it is
* accpeted.
*/
2023-03-03 18:25:07 -07:00
readonly quorum: number;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
readonly eventQuorum: number;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
readonly eventWorkers: number;
2023-06-01 17:52:58 -04:00
/**
* Creates a new **FallbackProvider** with %%providers%% connected to
* %%network%%.
*
* If a [[Provider]] is included in %%providers%%, defaults are used
* for the configuration.
*/
constructor(providers: Array<AbstractProvider | FallbackProviderConfig>, network?: Networkish, options?: FallbackProviderOptions);
2023-03-03 18:25:07 -07:00
get providerConfigs(): Array<FallbackProviderState>;
_detectNetwork(): Promise<Network>;
2023-06-01 17:52:58 -04:00
/**
* Transforms a %%req%% into the correct method call on %%provider%%.
*/
2023-03-03 18:25:07 -07:00
_translatePerform(provider: AbstractProvider, req: PerformActionRequest): Promise<any>;
_perform<T = any>(req: PerformActionRequest): Promise<T>;
destroy(): Promise<void>;
}
//# sourceMappingURL=provider-fallback.d.ts.map