Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions packages/relay/src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -223,7 +213,6 @@ export class DebugImpl implements Debug {
}),
);

await this.cacheService.set(cacheKey, result, DebugImpl.traceBlockByNumber, requestDetails);
return result;
}

Expand All @@ -240,7 +229,6 @@ export class DebugImpl implements Debug {
}),
);

await this.cacheService.set(cacheKey, result, DebugImpl.traceBlockByNumber, requestDetails);
return result;
}

Expand Down
11 changes: 7 additions & 4 deletions packages/relay/tests/lib/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand All @@ -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';
Expand Down Expand Up @@ -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')!,
Expand Down Expand Up @@ -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));
Expand Down
Loading