`GetLatestBlockWithRetry` and `GetStakerId` contract call is called repeatedly
Yashk767 opened this issue · 0 comments
Yashk767 commented
Description
The RPC usage metrics revealed that calls to eth_getBlockByNumber
were excessively high. This function is being invoked repeatedly within a for loop during our voting process. To prevent reaching the free tier limit of RPC usage, there's a necessity to optimize this implementation.
Staker Id remains the same for a staker throughout but we still call getStakerId for an address every time inside HandleBlock
.
Solution
We do use GetLatestBlockWithRetry
in functions GetBufferedState
and GetEpoch
to get the latest block number, rather we can use the existing latest block number provided in
HandleBlock(client *ethclient.Client, account types.Account, blockNumber *big.Int, config types.Configurations, rogueData types.Rogue, backupNodeActionsToIgnore []string)
For stakerId
we can just call GetStakerId(address)
only once outside the voting for loop and use the same when required.