-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from lidofinance/develop
Merge develop to main
- Loading branch information
Showing
2 changed files
with
65 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SimpleFallbackJsonRpcBatchProvider } from '@lido-nestjs/execution'; | ||
import { Log, Filter } from '@ethersproject/abstract-provider'; | ||
import { LoggerService } from '@lido-nestjs/logger'; | ||
|
||
const DEFAULT_RETRY_COUNT = 5; | ||
|
||
// Retry needs for the case when the logs are not available in the RPC response, but they are expected to be there. | ||
export const getLogsByRetryCount = async ( | ||
provider: SimpleFallbackJsonRpcBatchProvider, | ||
filter: Filter, | ||
logger: LoggerService, | ||
eventName: string, | ||
retryCount = DEFAULT_RETRY_COUNT, | ||
): Promise<Log[]> => { | ||
let logs = await provider.getLogs(filter); | ||
|
||
while (logs.length === 0 && retryCount > 0) { | ||
logger.warn(`${eventName}: No logs found. Retrying in 200 ms...`, { service: 'rewards' }); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 200)); | ||
logs = await provider.getLogs(filter); | ||
retryCount -= 1; | ||
} | ||
|
||
return logs; | ||
}; |