diff --git a/packages/relay/src/lib/debug.ts b/packages/relay/src/lib/debug.ts index 81f409336b..217305d335 100644 --- a/packages/relay/src/lib/debug.ts +++ b/packages/relay/src/lib/debug.ts @@ -9,10 +9,10 @@ import { MirrorNodeClient } from './clients'; import { IOpcode } from './clients/models/IOpcode'; import { IOpcodesResponse } from './clients/models/IOpcodesResponse'; import constants, { CallType, TracerType } from './constants'; -import { RPC_LAYOUT, rpcMethod, rpcParamLayoutConfig, rpcParamValidationRules } from './decorators'; +import { cache, RPC_LAYOUT, rpcMethod, rpcParamLayoutConfig, rpcParamValidationRules } from './decorators'; import { predefined } from './errors/JsonRpcError'; import { CommonService } from './services'; -import { CacheService } from './services/cacheService/cacheService'; +import { CACHE_LEVEL, CacheService } from './services/cacheService/cacheService'; import { BlockTracerConfig, CallTracerResult, @@ -109,6 +109,7 @@ export class DebugImpl implements Debug { 1: { type: ParamType.COMBINED_TRACER_TYPE, required: false }, 2: { type: ParamType.TRACER_CONFIG, required: false }, }) + @cache(CacheService.getInstance(CACHE_LEVEL.L1)) async traceTransaction( transactionIdOrHash: string, tracer: TracerType, @@ -152,6 +153,9 @@ export class DebugImpl implements Debug { 1: { type: ParamType.TRACER_CONFIG_WRAPPER, required: false }, }) @rpcParamLayoutConfig(RPC_LAYOUT.custom((params) => [params[0], params[1]])) + @cache(CacheService.getInstance(CACHE_LEVEL.L1), { + skipParams: [{ index: '0', value: constants.NON_CACHABLE_BLOCK_PARAMS }], + }) async traceBlockByNumber( blockNumber: string, tracerObject: BlockTracerConfig, @@ -171,20 +175,6 @@ export class DebugImpl implements Debug { if (blockResponse == null) throw predefined.RESOURCE_NOT_FOUND(`Block ${blockNumber} not found`); - const cacheKey = `${constants.CACHE_KEY.DEBUG_TRACE_BLOCK_BY_NUMBER}_${blockResponse.number}_${JSON.stringify( - tracerObject, - )}`; - - const cachedTracerObject = await this.cacheService.getAsync( - cacheKey, - DebugImpl.traceBlockByNumber, - requestDetails, - ); - - if (cachedTracerObject) { - return cachedTracerObject; - } - const timestampRangeParams = [`gte:${blockResponse.timestamp.from}`, `lte:${blockResponse.timestamp.to}`]; const contractResults: MirrorNodeContractResult[] = await this.mirrorNodeClient.getContractResultWithRetry( @@ -223,7 +213,6 @@ export class DebugImpl implements Debug { }), ); - await this.cacheService.set(cacheKey, result, DebugImpl.traceBlockByNumber, requestDetails); return result; } @@ -240,7 +229,6 @@ export class DebugImpl implements Debug { }), ); - await this.cacheService.set(cacheKey, result, DebugImpl.traceBlockByNumber, requestDetails); return result; } diff --git a/packages/relay/tests/lib/debug.spec.ts b/packages/relay/tests/lib/debug.spec.ts index 553088b82d..d2d8a68a78 100644 --- a/packages/relay/tests/lib/debug.spec.ts +++ b/packages/relay/tests/lib/debug.spec.ts @@ -19,12 +19,12 @@ import { HbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLi import { IPAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository'; import { DebugImpl } from '../../src/lib/debug'; import { CommonService } from '../../src/lib/services'; -import { CacheService } from '../../src/lib/services/cacheService/cacheService'; import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../src/lib/types'; import RelayAssertions from '../assertions'; import { getQueryParams, withOverriddenEnvsInMochaTest } from '../helpers'; +import { generateEthTestEnv } from './eth/eth-helpers'; chai.use(chaiAsPromised); const logger = pino({ level: 'silent' }); @@ -34,11 +34,11 @@ let restMock: MockAdapter; let web3Mock: MockAdapter; let mirrorNodeInstance: MirrorNodeClient; let debugService: DebugImpl; -let cacheService: CacheService; let hapiServiceInstance: HAPIService; + describe('Debug API Test Suite', async function () { this.timeout(10000); - + const { cacheService } = generateEthTestEnv(true); const requestDetails = new RequestDetails({ requestId: 'debugTest', ipAddress: '0.0.0.0' }); const transactionHash = '0xb7a433b014684558d4154c73de3ed360bd5867725239938c2143acb7a76bca82'; const nonExistentTransactionHash = '0xb8a433b014684558d4154c73de3ed360bd5867725239938c2143acb7a76bca82'; @@ -253,7 +253,6 @@ describe('Debug API Test Suite', async function () { }; this.beforeAll(() => { - cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( ConfigService.get('MIRROR_NODE_URL')!, @@ -285,6 +284,10 @@ describe('Debug API Test Suite', async function () { debugService = new DebugImpl(mirrorNodeInstance, logger, cacheService); }); + this.beforeEach(() => { + cacheService.clear(requestDetails); + }); + describe('debug_traceTransaction', async function () { beforeEach(() => { restMock.onGet(CONTARCTS_RESULTS_ACTIONS).reply(200, JSON.stringify(contractsResultsActionsResult));