Despite decentralization being one of the core principles of web3, most dApps currently rely on centralized RPC providers to read/write data to the blockchain. This not only means that they have a single point of failure but also that they are susceptible to censorship and reliability issues.
BetteRPC aims to accelerate the future of Web3 Infrastructure decentralization by providing an open and configurable decentralized RPC gateway. BetteRPC is able to achieve efficient, reliable, and anonymous RPC calls by leveraging a peer-to-peer network powered by fluence ♥.
BetterRPC project is built with fluence, a decentralized serverless platform and computing marketplace powered by blockchain economics.
BetteRPC works by using multiple RPC providers and tracking a score for each of them by looking at metrics like latency and reliability.
In order to measure these metrics a quorum
algorithm is used. When receiving an RPC call, it is executed in parallel on all the providers and then a quorum is executed by checking if a given threshold of providers returned the same value. Providers' scores are then updated in the following way:
- The provider with the fastest response will get points
- If the quorum passed, the providers whose response was aligned with the quorum will get point
- If a call fails, the provider will lose points. This only applies if not all of the calls failed since this would probably mean that the request was bad.
The points obtained/lost for each of these factors are configurable, in order to make it easy for every dApp to adapt the system to their needs.
The quorum algorithm is implemented in the quorum
function in rpc.aqua
and with two main services:
QuorumChecker
: executes the quorumScoreTracker
: updates the providers score
BetteRPC provides a way to execute an optimized RPC calls. This works by using the providers ordered by score and handling failover. Basically, the call will be first tried with the provider with the highest score. If it fails, the second provider will be used, and so on.
Optimized calls make sense only if the scores have been updated a considerable number of times. The system will then use the quorum
algorithm for the first calls, and after that optimized calls will become available.
This feature is implemented in the optimized
function in rpc.aqua
.
BetteRPC can be configured by editing /fluence/gateway/config.json
.
The main available options are:
providers
: array of provider urls to uselatencyPoints
: points obtained by the fastest providerquorumPoints
: points obtained by providers aligned with quorumfailedCallPoints
: points lost when a call fails (should be negative)quorumNumber
: threshold for quorumminimumScoreUpdates
: number of times that provider scores need to be updated before using optimized calls
- Install Docker on your machine: https://www.docker.com/get-started.
- Having fluence setup:
npm -g i @fluencelabs/cli@latest
Clone the repo
git clone git@github.com:TalentLayer-Labs/betterpc.git
Launch the whole setup and follow the instructions:
make install
Now you can access to:
- Frontend: http://localhost:5173
- Backend Gateway: http://localhost:8080