mirror of
https://github.com/farcasterxyz/hub-monorepo.git
synced 2026-04-18 03:00:22 -04:00
fix: Dedup eth events retries by block number to save api calls (#917)
This commit is contained in:
5
.changeset/kind-bugs-wave.md
Normal file
5
.changeset/kind-bugs-wave.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@farcaster/hubble': patch
|
||||
---
|
||||
|
||||
Dedupe eth events when retrying to be more efficient with api calls
|
||||
@@ -54,6 +54,7 @@ export class EthEventsProvider {
|
||||
private _idEventsByBlock: Map<number, Array<IdRegistryEvent>>;
|
||||
private _nameEventsByBlock: Map<number, Array<NameRegistryEvent>>;
|
||||
private _renewEventsByBlock: Map<number, Array<NameRegistryRenewEvent>>;
|
||||
private _retryDedupMap: Map<number, boolean>;
|
||||
|
||||
private _lastBlockNumber: number;
|
||||
|
||||
@@ -87,6 +88,7 @@ export class EthEventsProvider {
|
||||
this._nameEventsByBlock = new Map();
|
||||
this._idEventsByBlock = new Map();
|
||||
this._renewEventsByBlock = new Map();
|
||||
this._retryDedupMap = new Map();
|
||||
|
||||
// Setup IdRegistry contract
|
||||
this._idRegistryContract.on('Register', (to: string, id: bigint, _recovery, _url, event: ContractEventPayload) => {
|
||||
@@ -240,6 +242,10 @@ export class EthEventsProvider {
|
||||
* @param blockNumber
|
||||
*/
|
||||
public async retryEventsFromBlock(blockNumber: number) {
|
||||
if (this._retryDedupMap.has(blockNumber)) {
|
||||
return;
|
||||
}
|
||||
this._retryDedupMap.set(blockNumber, true);
|
||||
await this.syncHistoricalIdEvents(IdRegistryEventType.REGISTER, blockNumber, blockNumber + 1, 1);
|
||||
await this.syncHistoricalIdEvents(IdRegistryEventType.TRANSFER, blockNumber, blockNumber + 1, 1);
|
||||
|
||||
@@ -471,6 +477,8 @@ export class EthEventsProvider {
|
||||
await this._hub.submitNameRegistryEvent(updatedEvent);
|
||||
}
|
||||
}
|
||||
|
||||
this._retryDedupMap.delete(cachedBlock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ describe('Multi peer sync engine', () => {
|
||||
|
||||
// Because do it without awaiting, we need to wait for the promise to resolve
|
||||
await sleep(100);
|
||||
expect(mockRPCProvider.getLogsCount).toBeGreaterThan(0);
|
||||
expect(mockRPCProvider.getLogsCount).toEqual(3);
|
||||
});
|
||||
|
||||
test('Merge with multiple signers', async () => {
|
||||
|
||||
Reference in New Issue
Block a user