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;
|
|
|
|
};
|
|
|
|
/**
|
2023-06-01 17:52:58 -04: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-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.
|
|
|
|
*/
|
2023-03-03 18:25:07 -07:00
|
|
|
constructor(providers: Array<AbstractProvider | FallbackProviderConfig>, network?: Networkish);
|
|
|
|
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>;
|
|
|
|
}
|
2023-04-27 21:19:55 +09:00
|
|
|
//# sourceMappingURL=provider-fallback.d.ts.map
|