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