Skip to content

Commit

Permalink
fix: added cache refreshing after subsequent getFilterLogs calls for …
Browse files Browse the repository at this point in the history
…the same filter (#3308)

fix: we now refresh the cache after getFilterLogs calls as well

Signed-off-by: Simeon Nakov <[email protected]>
  • Loading branch information
simzzz authored Dec 6, 2024
1 parent 20d242a commit cbcc55d
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
*
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { Logger } from 'pino';

import { generateRandomHex } from '../../../../formatters';
import { MirrorNodeClient } from '../../../clients';
import constants from '../../../constants';
import { IFilterService } from './IFilterService';
import { CommonService } from '../ethCommonService';
import { generateRandomHex } from '../../../../formatters';
import { JsonRpcError, predefined } from '../../../errors/JsonRpcError';
import { Log } from '../../../model';
import { CacheService } from '../../cacheService/cacheService';
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { RequestDetails } from '../../../types';
import { CacheService } from '../../cacheService/cacheService';
import { CommonService } from '../ethCommonService';
import { IFilterService } from './IFilterService';

/**
* Create a new Filter Service implementation.
Expand Down Expand Up @@ -208,14 +209,29 @@ export class FilterService implements IFilterService {
throw predefined.FILTER_NOT_FOUND;
}

return await this.common.getLogs(
const logs = await this.common.getLogs(
null,
filter?.params.fromBlock,
filter?.params.toBlock,
filter?.params.address,
filter?.params.topics,
requestDetails,
);

// update filter to refresh TTL
await this.cacheService.set(
cacheKey,
{
type: filter.type,
params: filter.params,
lastQueried: filter.lastQueried,
},
this.ethGetFilterChanges,
requestDetails,
constants.FILTER.TTL,
);

return logs;
}

public async getFilterChanges(filterId: string, requestDetails: RequestDetails): Promise<string[] | Log[]> {
Expand Down

0 comments on commit cbcc55d

Please sign in to comment.