Ethereum: how can we control the logic behind ethersJs fallbackProvider’s choices

Control of logic behind the Ethersj Fallback supplier: guarantee consistency through several RPCs

When using Ethejs for the management of several RPCs, one of the main concerns is to guarantee consistency between different suppliers. The case provider is a crucial component in this sense, but its flexibility can sometimes lead to inconsistencies if they are not correctly configured. In this article we will examine how the logic behind the suppliers of Ethersj houses can control and face the joint problems that can occur.

Why is consistency important?

In connection with Etherjs, the consistency on multiple RPC is of fundamental importance to maintain a single uniform vision of the blockchain state. If a supplier has a different quorum (minimum number of signatures required to validate transactions) compared to another, this can lead to inconsistencies in the final state of the network.

Fallback Quorum Standard Provider

The Back case provider uses 4 of 6 blockchains (or chains if you want) to make a decision. This means that a supplier, if it fails or does not respond for a longer period of time, can fall on the other supplier to make a decision.

Output: event when setting a quorum

A common problem with the autumn cooking provider is that the determination of a personalized quorum can lead to inconsistent decisions on different RPCs. If you set a quorum, Ethersjs uses standard blockchain if another provider uses you. This means that a provider has a higher quorum than others, it can be selected as a fallback, even if it is not the right choice for your specific application.

Solution: Fallback provider regulation

Ethereum: how can we control the logic behind ethersJs fallbackProvider's choices

In order to control the logic behind Ethersj’s Fallback suppliers and to ensure consistency through several RPCs, they can adapt to his behavior. Here are some strategies to achieve this:

  • Overwriting the Standard quorum: it is possible to overwrite the standard of quorum 4 standard by setting a personalized quorum for each provider. For example:

`Javascript

Const FallbackPrier = New Ether.Priders.fall Backback Provider ({{{{{{{{{{{{{{{H AND

Provider: [Ethers.providers.jsonrPcPrprier (‘ // Provider a

Ethers.providers.jsonrPcPrprier (‘ // Provider B

},

Gas limit: 1000000,

MaxPriorityFeepengas: 1.5, // Set the gas edge for each provider

});

`

In this example, the provider A has a personalized quorum of 4, while provider B returns to standard 6 quorum.

  • Use a Fallback strategy based on Quora : you can use a quora -based approach in which the provider with the highest quorum is selected when making a decision. For example:

Javascript

Const FallbackPrier = New Ether.Priders.fall Backback Provider ({{{{{{{{{{{{{{{H AND

Provider: [

{

Name: ‘Provider a’,

Address: ‘ ,,

Gas limit: 1000000,

MaxPriorityFeepengas: 1.5,

},

{

Name: ‘Provider B’,

Address: ‘ ,,

Gas limit: 1000000,

MaxPriorityFeepengas: 1.5,

},

] ,,

Fallback: (event, provider) => {

If (Provider.qorum> 4) {

// Provider A is selected as Fallback

Return ‘supplier to’;

} in a different way {

// Provider B is selected as Fallback

Return ‘supplier B’;

}

},

});

`

In this example, the A supplier has a quorum of 4, so it is selected as Fallback in a decision.

  • Use an consensus saving : it is possible to use a saving consent such as the test of sharing (POS) or a delegated test of the puncture (DPO) to ensure that different suppliers agree on a quorum. For example:

Javascript

Const FallbackPrier = New Ether.Priders.fall Backback Provider ({{{{{{{{{{{{{{{H AND

Provider: [

{

Name: ‘Provider a’,

Address: ‘ ,,

Gas limit: 1000000,

MaxPriorityFeepengas: 1.

ethereum validate using javascript