Skip to content

Commit

Permalink
fix: improve postman logging and error parsing (#622)
Browse files Browse the repository at this point in the history
* fix: improve postman logging and error parsing

* fix: remove unnecessary casting
VGau authored Jan 29, 2025
1 parent c819e31 commit 317ef4f
Showing 30 changed files with 547 additions and 338 deletions.
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import {
L2ClaimMessageTransactionSizeProcessorConfig,
} from "../../core/services/processors/IL2ClaimMessageTransactionSizeProcessor";
import { IL2ClaimTransactionSizeCalculator } from "../../core/services/processors/IL2ClaimTransactionSizeCalculator";
import { ErrorParser } from "../../utils/ErrorParser";
import { Message } from "../../core/entities/Message";

export class L2ClaimMessageTransactionSizeProcessor implements IL2ClaimMessageTransactionSizeProcessor {
/**
@@ -48,6 +50,8 @@ export class L2ClaimMessageTransactionSizeProcessor implements IL2ClaimMessageTr
* @returns {Promise<void>} A promise that resolves when the processing is complete.
*/
public async process(): Promise<void> {
let message: Message | null = null;

try {
const messages = await this.databaseService.getNFirstMessagesByStatus(
MessageStatus.ANCHORED,
@@ -57,10 +61,11 @@ export class L2ClaimMessageTransactionSizeProcessor implements IL2ClaimMessageTr
);

if (messages.length === 0) {
this.logger.info("No anchored messages found to compute transaction size.");
return;
}

const message = messages[0];
message = messages[0];

const { gasLimit, maxPriorityFeePerGas, maxFeePerGas } =
await this.l2MessageServiceClient.estimateClaimGasFees(message);
@@ -86,7 +91,32 @@ export class L2ClaimMessageTransactionSizeProcessor implements IL2ClaimMessageTr
gasLimit,
);
} catch (e) {
this.logger.error(e);
await this.handleProcessingError(e, message);
}
}

/**
* Handles error that occur during the processing.
*
* @param {unknown} e - The error that occurred.
* @param {Message | null} message - The message object being processed when the error occurred.
* @returns {Promise<void>} A promise that resolves when the error has been handled.
*/
private async handleProcessingError(e: unknown, message: Message | null): Promise<void> {
const parsedError = ErrorParser.parseErrorWithMitigation(e);

if (parsedError?.mitigation && !parsedError.mitigation.shouldRetry && message) {
message.edit({ status: MessageStatus.NON_EXECUTABLE });
await this.databaseService.updateMessage(message);
this.logger.warnOrError("Error occurred while processing message transaction size.", {
...parsedError,
messageHash: message.messageHash,
});
return;
}

this.logger.warnOrError("Error occurred while processing message transaction size.", {
parsedError,
});
}
}
8 changes: 7 additions & 1 deletion postman/src/services/processors/MessageAnchoringProcessor.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import { MessageStatus } from "../../core/enums";
import { ILogger } from "../../core/utils/logging/ILogger";
import { IMessageServiceContract } from "../../core/services/contracts/IMessageServiceContract";
import { IMessageDBService } from "../../core/persistence/IMessageDBService";
import { ErrorParser } from "../../utils/ErrorParser";

export class MessageAnchoringProcessor implements IMessageAnchoringProcessor {
private readonly maxFetchMessagesFromDb: number;
@@ -93,7 +94,12 @@ export class MessageAnchoringProcessor implements IMessageAnchoringProcessor {

await this.databaseService.saveMessages(messages);
} catch (e) {
this.logger.error(e);
const error = ErrorParser.parseErrorWithMitigation(e);
this.logger.error("An error occurred while processing messages.", {
errorCode: error?.errorCode,
errorMessage: error?.errorMessage,
...(error?.data ? { data: error.data } : {}),
});
}
}
}
10 changes: 9 additions & 1 deletion postman/src/services/processors/MessageClaimingPersister.ts
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import {
MessageClaimingPersisterConfig,
} from "../../core/services/processors/IMessageClaimingPersister";
import { IMessageDBService } from "../../core/persistence/IMessageDBService";
import { ErrorParser } from "../../utils/ErrorParser";

export class MessageClaimingPersister implements IMessageClaimingPersister {
private messageBeingRetry: { message: Message | null; retries: number };
@@ -79,6 +80,7 @@ export class MessageClaimingPersister implements IMessageClaimingPersister {
try {
firstPendingMessage = await this.databaseService.getFirstPendingMessage(this.config.direction);
if (!firstPendingMessage?.claimTxHash) {
this.logger.info("No pending message status to update.");
return;
}

@@ -111,7 +113,13 @@ export class MessageClaimingPersister implements IMessageClaimingPersister {

await this.updateReceiptStatus(firstPendingMessage, receipt);
} catch (e) {
this.logger.error(e);
const error = ErrorParser.parseErrorWithMitigation(e);
this.logger.error("Error processing message.", {
...(firstPendingMessage ? { messageHash: firstPendingMessage.messageHash } : {}),
...(error?.errorCode ? { errorCode: error.errorCode } : {}),
...(error?.errorMessage ? { errorMessage: error.errorMessage } : {}),
...(error?.data ? { data: error.data } : {}),
});
}
}

5 changes: 3 additions & 2 deletions postman/src/services/processors/MessageClaimingProcessor.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ import {
Overrides,
TransactionResponse,
ContractTransactionResponse,
EthersError,
TransactionReceipt,
Signer,
ErrorDescription,
@@ -74,6 +73,7 @@ export class MessageClaimingProcessor implements IMessageClaimingProcessor {
);

if (!nextMessageToClaim) {
this.logger.info("No message to claim found");
return;
}

@@ -265,7 +265,7 @@ export class MessageClaimingProcessor implements IMessageClaimingProcessor {
* @returns {Promise<void>} A promise that resolves when the error has been handled.
*/
private async handleProcessingError(e: unknown, message: Message | null): Promise<void> {
const parsedError = ErrorParser.parseErrorWithMitigation(e as EthersError);
const parsedError = ErrorParser.parseErrorWithMitigation(e);

if (parsedError?.mitigation && !parsedError.mitigation.shouldRetry && message) {
message.edit({ status: MessageStatus.NON_EXECUTABLE });
@@ -274,6 +274,7 @@ export class MessageClaimingProcessor implements IMessageClaimingProcessor {

this.logger.warnOrError(e, {
parsedError,
...(message ? { messageHash: message.messageHash } : {}),
});
}
}
Original file line number Diff line number Diff line change
@@ -3,12 +3,13 @@ import { mock } from "jest-mock-extended";
import {
ContractTransactionResponse,
ErrorDescription,
makeError,
Overrides,
Signer,
TransactionReceipt,
TransactionResponse,
} from "ethers";
import { Direction } from "@consensys/linea-sdk";
import { Direction, makeBaseError } from "@consensys/linea-sdk";
import { TestLogger } from "../../../utils/testing/helpers";
import { MessageStatus } from "../../../core/enums";
import { testL1NetworkConfig, testMessage, DEFAULT_MAX_FEE_PER_GAS } from "../../../utils/testing/constants";
@@ -67,7 +68,7 @@ describe("L2ClaimMessageTransactionSizeProcessor", () => {
it("Should log as error when calculateTransactionSize failed", async () => {
const testGasLimit = 50_000n;

const loggerErrorSpy = jest.spyOn(logger, "error");
const loggerErrorSpy = jest.spyOn(logger, "warnOrError");
jest.spyOn(databaseService, "getNFirstMessagesByStatus").mockResolvedValue([testMessage]);
jest.spyOn(l2ContractClientMock, "estimateClaimGasFees").mockResolvedValue({
gasLimit: testGasLimit,
@@ -81,7 +82,53 @@ describe("L2ClaimMessageTransactionSizeProcessor", () => {
await transactionSizeProcessor.process();

expect(loggerErrorSpy).toHaveBeenCalledTimes(1);
expect(loggerErrorSpy).toHaveBeenCalledWith(new Error("calculation failed."));
expect(loggerErrorSpy).toHaveBeenCalledWith("Error occurred while processing message transaction size.", {
errorCode: "UNKNOWN_ERROR",
errorMessage: "calculation failed.",
messageHash: testMessage.messageHash,
mitigation: { shouldRetry: false },
});
});

it("Should log as error when estimateClaimGasFees failed", async () => {
const loggerErrorSpy = jest.spyOn(logger, "warnOrError");
jest.spyOn(databaseService, "getNFirstMessagesByStatus").mockResolvedValue([testMessage]);
jest.spyOn(l2ContractClientMock, "estimateClaimGasFees").mockRejectedValue(
makeBaseError(
makeError("could not coalesce error", "UNKNOWN_ERROR", {
error: {
code: -32000,
data: "0x5461344300000000000000000000000034be5b8c30ee4fde069dc878989686abe9884470",
message: "Execution reverted",
},
payload: {
id: 1,
jsonrpc: "2.0",
method: "linea_estimateGas",
params: [
{
data: "0x491e09360000000000000000000000004420ce157f2c39edaae6cc107a42c8e527d6e02800000000000000000000000034be5b8c30ee4fde069dc878989686abe988447000000000000000000000000000000000000000000000000000006182ba2f0b400000000000000000000000000000000000000000000000000001c6bf52634000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000052b130000000000000000000000000000000000000000000000000000000000000000",
from: "0x46eA7a855DA88FBC09cc59de93468E6bFbf0d81b",
to: "0x508Ca82Df566dCD1B0DE8296e70a96332cD644ec",
value: "0",
},
],
},
}),
testMessage,
),
);

await transactionSizeProcessor.process();

expect(loggerErrorSpy).toHaveBeenCalledTimes(1);
expect(loggerErrorSpy).toHaveBeenCalledWith("Error occurred while processing message transaction size.", {
data: "0x5461344300000000000000000000000034be5b8c30ee4fde069dc878989686abe9884470",
errorCode: "UNKNOWN_ERROR",
errorMessage: "Execution reverted",
messageHash: testMessage.messageHash,
mitigation: { shouldRetry: false },
});
});

it("Should log as info and call updateMessage if the transaction size calculation succeed", async () => {
Original file line number Diff line number Diff line change
@@ -129,7 +129,10 @@ describe("TestMessageAnchoringProcessor", () => {
await anchoringProcessor.process();

expect(loggerErrorSpy).toHaveBeenCalledTimes(1);
expect(loggerErrorSpy).toHaveBeenCalledWith(error);
expect(loggerErrorSpy).toHaveBeenCalledWith("An error occurred while processing messages.", {
errorCode: "UNKNOWN_ERROR",
errorMessage: error.message,
});
expect(messageRepositoryMockSaveSpy).toHaveBeenCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
@@ -82,7 +82,11 @@ describe("TestMessageClaimingPersister ", () => {
await messageClaimingPersister.process();

expect(loggerErrorSpy).toHaveBeenCalledTimes(1);
expect(loggerErrorSpy).toHaveBeenCalledWith(getTxReceiptError);
expect(loggerErrorSpy).toHaveBeenCalledWith("Error processing message.", {
messageHash: testPendingMessage.messageHash,
errorCode: "UNKNOWN_ERROR",
errorMessage: getTxReceiptError.message,
});
});

it("Should log as info and update message as claimed success if successful", async () => {
Original file line number Diff line number Diff line change
@@ -370,6 +370,7 @@ describe("TestMessageClaimingProcessor", () => {
expect(loggerWarnOrErrorSpy).toHaveBeenCalledTimes(1);
expect(loggerWarnOrErrorSpy).toHaveBeenCalledWith(actionRejectedError, {
parsedError: ErrorParser.parseErrorWithMitigation(actionRejectedError as EthersError),
messageHash: expectedLoggingMessage.messageHash,
});
});
});
Loading

0 comments on commit 317ef4f

Please sign in to comment.