To use a pool of clients which implements the interface of the client and redirects the requests to the specific client.
Create a new struct named ClientPool, which holds an array of EVM clients implementing the client.EVM interface found in app/domain/client/evm.go. The struct will have a next index field to keep track of the next client to use.
Create a NewClientPool function to initialize the ClientPool struct. The function will accept an array of nodeURLs and create a new EVM client instance for each URL. It then appends each generated client to the clients slice.
Implement methods in ClientPool that delegate operations to the clients in the pool. Use the getClient method to determine which client to use.
Replace the existing EVM client reference in the main implementation with the new ClientPool and update the initialization as needed.
With this approach, each time we call a method on the ClientPool, it will automatically delegate the call to the next EVM client in the pool. If there are issues with any client, it will automatically switch to the next client in the pool and retry the operation until it exhausts the available clients.
This strategy ensures that your system remains operational even if multiple EVM clients become unresponsive simultaneously. It also provides a simple way to distribute requests across multiple EVM network nodes.
Notion detailed guide
To use a pool of clients which implements the interface of the client and redirects the requests to the specific client.
Create a new struct named ClientPool, which holds an array of EVM clients implementing the client.EVM interface found in app/domain/client/evm.go. The struct will have a next index field to keep track of the next client to use.
Create a NewClientPool function to initialize the ClientPool struct. The function will accept an array of nodeURLs and create a new EVM client instance for each URL. It then appends each generated client to the clients slice.
Implement methods in ClientPool that delegate operations to the clients in the pool. Use the getClient method to determine which client to use.
Replace the existing EVM client reference in the main implementation with the new ClientPool and update the initialization as needed.
With this approach, each time we call a method on the
ClientPool
, it will automatically delegate the call to the next EVM client in the pool. If there are issues with any client, it will automatically switch to the next client in the pool and retry the operation until it exhausts the available clients.This strategy ensures that your system remains operational even if multiple EVM clients become unresponsive simultaneously. It also provides a simple way to distribute requests across multiple EVM network nodes.