Skip to content

Commit

Permalink
fix: Apply transaction fees in the createFile to the HBar rate limiter.
Browse files Browse the repository at this point in the history
Signed-off-by: ebadiere <ebadiere@gmail.com>
  • Loading branch information
ebadiere committed Jun 28, 2024
1 parent 01b8b2c commit 231c8c3
Show file tree
Hide file tree
Showing 2 changed files with 1,829 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/relay/src/lib/clients/sdkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,12 @@ export class SDKClient {

const fileCreateTxResponse = await fileCreateTx.execute(client);
const { fileId } = await fileCreateTxResponse.getReceipt(client);
createFileId = fileId;

// get transaction fee and add expense to limiter
const createFileRecord = await fileCreateTxResponse.getRecord(this.clientMain);
let transactionFee = createFileRecord.transactionFee;
this.hbarLimiter.addExpense(transactionFee.toTinybars().toNumber(), currentDateNow);

this.captureMetrics(
SDKClient.transactionMode,
fileCreateTx.constructor.name,
Expand All @@ -686,6 +689,13 @@ export class SDKClient {
.setMaxChunks(this.maxChunks);
await fileAppendTx.execute(client);

const fileAppendTxResponse = await fileAppendTx.execute(client);

// get transaction fee and add expense to limiter
const appendFileRecord = await fileAppendTxResponse.getRecord(this.clientMain);
transactionFee = appendFileRecord.transactionFee;
this.hbarLimiter.addExpense(transactionFee.toTinybars().toNumber(), currentDateNow);

this.captureMetrics(
SDKClient.transactionMode,
fileAppendTx.constructor.name,
Expand Down Expand Up @@ -748,6 +758,10 @@ export class SDKClient {
callerName,
interactingEntity,
);

this.logger.info(
`${requestIdPrefix} ${fileCreateTx.transactionId} ${callerName} ${fileCreateTx.constructor.name} status: ${sdkClientError.status} (${sdkClientError.status._code}), cost: ${transactionFee}`,
);
} catch (err: any) {
const recordQueryError = new SDKClientError(err, err.message);
this.logger.error(
Expand All @@ -757,9 +771,8 @@ export class SDKClient {
}
}

this.logger.trace(
`${requestIdPrefix} ${fileCreateTx.transactionId} ${callerName} ${fileCreateTx.constructor.name} status: ${sdkClientError.status} (${sdkClientError.status._code}), cost: ${transactionFee}`,
);
this.logger.info(`${requestIdPrefix} HBAR_RATE_LIMIT_EXCEEDED cost: ${transactionFee}`);

if (error instanceof JsonRpcError) {
throw predefined.HBAR_RATE_LIMIT_EXCEEDED;
}
Expand Down
Loading

0 comments on commit 231c8c3

Please sign in to comment.