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
1 change: 1 addition & 0 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class EthImpl implements Eth {
? new RedisPendingTransactionStorage(this.redisClient)
: new LocalPendingTransactionStorage();
const transactionPoolService = new TransactionPoolService(storage, logger);
transactionPoolService.resetState();
this.transactionService = new TransactionService(
cacheService,
chain,
Expand Down
6 changes: 3 additions & 3 deletions packages/relay/src/lib/precheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from 'pino';
import { prepend0x } from '../formatters';
import { MirrorNodeClient } from './clients';
import constants from './constants';
import { JsonRpcError, predefined } from './errors/JsonRpcError';
import { predefined } from './errors/JsonRpcError';
import { CommonService, TransactionPoolService } from './services';
import { RequestDetails } from './types';
import { IAccountBalance } from './types/mirrorNode';
Expand Down Expand Up @@ -80,9 +80,9 @@ export class Precheck {
this.gasLimit(parsedTx);
const mirrorAccountInfo = await this.verifyAccount(parsedTx, requestDetails);
const signerNonce =
mirrorAccountInfo.ethereum_nonce + ConfigService.get('ENABLE_TX_POOL')
mirrorAccountInfo.ethereum_nonce + (ConfigService.get('ENABLE_TX_POOL')
? await this.transactionPoolService.getPendingCount(parsedTx.from!)
: 0;
: 0);
this.nonce(parsedTx, signerNonce);
this.chainId(parsedTx);
this.value(parsedTx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ export class TransactionService implements ITransactionService {

await this.validateRawTransaction(parsedTx, networkGasPriceInWeiBars, requestDetails);

// Save the transaction to the transaction pool before submitting it to the network
if (ConfigService.get('ENABLE_TX_POOL')) {
await this.transactionPoolService.saveTransaction(parsedTx.from!, parsedTx);
}

/**
* Note: If the USE_ASYNC_TX_PROCESSING feature flag is enabled,
* the transaction hash is calculated and returned immediately after passing all prechecks.
Expand Down Expand Up @@ -491,11 +496,6 @@ export class TransactionService implements ITransactionService {

const originalCallerAddress = parsedTx.from?.toString() || '';

// Save the transaction to the transaction pool before submitting it to the network
if (ConfigService.get('ENABLE_TX_POOL')) {
await this.transactionPoolService.saveTransaction(originalCallerAddress, parsedTx);
}

this.eventEmitter.emit('eth_execution', {
method: constants.ETH_SEND_RAW_TRANSACTION,
});
Expand All @@ -507,6 +507,11 @@ export class TransactionService implements ITransactionService {
requestDetails,
);

// Remove the transaction from the transaction pool after successful submission
if (ConfigService.get('ENABLE_TX_POOL')) {
await this.transactionPoolService.removeTransaction(originalCallerAddress, parsedTx.hash!);
}

sendRawTransactionError = error;

// After the try-catch process above, the `submittedTransactionId` is potentially valid in only two scenarios:
Expand Down Expand Up @@ -551,21 +556,12 @@ export class TransactionService implements ITransactionService {
);
}

// Remove the transaction from the transaction pool after successful submission
if (ConfigService.get('ENABLE_TX_POOL')) {
await this.transactionPoolService.removeTransaction(originalCallerAddress, contractResult.hash);
}
return contractResult.hash;
} catch (e: any) {
sendRawTransactionError = e;
}
}

// Remove the transaction from the transaction pool after unsuccessful submission
if (ConfigService.get('ENABLE_TX_POOL')) {
await this.transactionPoolService.removeTransaction(originalCallerAddress, parsedTx.hash!);
}

// If this point is reached, it means that no valid transaction hash was returned. Therefore, an error must have occurred.
return await this.sendRawTransactionErrorHandler(
sendRawTransactionError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Transaction } from 'ethers';
import { Logger } from 'pino';

import { IExecuteTransactionEventPayload } from '../../types/events';
import {
PendingTransactionStorage,
TransactionPoolService as ITransactionPoolService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import chaiAsPromised from 'chai-as-promised';
import { randomBytes, uuidV4 } from 'ethers';
import pino from 'pino';
import { Registry } from 'prom-client';
import { RedisClientType } from 'redis';
import sinon from 'sinon';

import { RedisClientManager } from '../../../../src/lib/clients/redisClientManager';
Expand All @@ -30,7 +29,6 @@ describe('IPAddressHbarSpendingPlanRepository', function () {
let cacheServiceSpy: sinon.SinonSpiedInstance<CacheService>;
let repository: IPAddressHbarSpendingPlanRepository;
let redisClientManager: RedisClientManager;
let redisClient: RedisClientType | undefined;

if (isSharedCacheEnabled) {
useInMemoryRedisServer(logger, 6383);
Expand All @@ -41,9 +39,6 @@ describe('IPAddressHbarSpendingPlanRepository', function () {
if (isSharedCacheEnabled) {
redisClientManager = new RedisClientManager(logger, 'redis://127.0.0.1:6383', 1000);
await redisClientManager.connect();
redisClient = redisClientManager.getClient();
} else {
redisClient = undefined;
}
cacheService = new CacheService(logger, registry);
cacheServiceSpy = sinon.spy(cacheService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Logger, pino } from 'pino';
import * as sinon from 'sinon';

import { TransactionPoolService } from '../../../../src/lib/services/transactionPoolService/transactionPoolService';
import { IExecuteTransactionEventPayload } from '../../../../src/lib/types/events';
import { AddToListResult, PendingTransactionStorage } from '../../../../src/lib/types/transactionPool';

describe('TransactionPoolService Test Suite', function () {
Expand All @@ -18,7 +17,6 @@ describe('TransactionPoolService Test Suite', function () {

const testAddress = '0x742d35cc6629c0532c262d2d73f4c8e1a1b7b7b7';
const testTxHash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
const testTransactionId = '[email protected]';
const testTransaction: Transaction = {
hash: testTxHash,
data: '0x',
Expand All @@ -30,21 +28,6 @@ describe('TransactionPoolService Test Suite', function () {
nonce: 1,
} as Transaction;

const createTestEventPayload = (
overrides?: Partial<IExecuteTransactionEventPayload>,
): IExecuteTransactionEventPayload => ({
transactionId: testTransactionId,
transactionHash: testTxHash,
txConstructorName: 'EthereumTransaction',
operatorAccountId: '0.0.2',
requestDetails: {
requestId: 'test-request-id',
ipAddress: '127.0.0.1',
} as any,
originalCallerAddress: testAddress,
...overrides,
});

beforeEach(() => {
logger = pino({ level: 'silent' });

Expand Down
Loading
Loading