Skip to content

Commit

Permalink
fix: disabled bytecode handler and add ignored chains for debugger (#149
Browse files Browse the repository at this point in the history
)

- Comment out bytecode handler for less specific error messages
- Added debugIgnoredChains for skipping some specifics chains
- New fallback for skipping some chains in `debugMessage`, will show
spinner until messages actually delivers or fails


![image](https://github.com/user-attachments/assets/ed2460ee-c6e1-44b0-b880-ae7c7a8826da)
  • Loading branch information
Xaroz authored Dec 12, 2024
1 parent 54b3938 commit 0585bff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/consts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export const config: Config = Object.freeze({
// Based on https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/infra/config/environments/mainnet3/agent.ts
// Based on https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/main/typescript/infra/config/environments/testnet4/agent.ts
export const unscrapedChainsInDb = ['proteustestnet', 'viction'];

export const debugIgnoredChains = ['treasure'];
50 changes: 30 additions & 20 deletions src/features/debugger/debugMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
errorToString,
formatMessage,
isValidAddress,
strip0x,
trimToLength,
} from '@hyperlane-xyz/utils';

Expand All @@ -25,11 +24,12 @@ import { logger } from '../../utils/logger';
import { getMailboxAddress } from '../chains/utils';
import { isIcaMessage, tryDecodeIcaBody, tryFetchIcaAddress } from '../messages/ica';

import { debugIgnoredChains } from '../../consts/config';
import { GasPayment, IsmModuleTypes, MessageDebugResult, MessageDebugStatus } from './types';

type Provider = providers.Provider;

const HANDLE_FUNCTION_SIG = 'handle(uint32,bytes32,bytes)';
// const HANDLE_FUNCTION_SIG = 'handle(uint32,bytes32,bytes)';
const IGP_PAYMENT_CHECK_DELAY = 30_000; // 30 seconds

export async function debugMessage(
Expand Down Expand Up @@ -84,6 +84,7 @@ export async function debugMessage(
recipient,
senderBytes,
body,
destName,
);
if (deliveryResult.status && deliveryResult.description) return deliveryResult;
else details.calldataDetails = deliveryResult.calldataDetails;
Expand Down Expand Up @@ -145,6 +146,7 @@ async function debugMessageDelivery(
recipient: Address,
senderBytes: string,
body: string,
destName: string,
) {
const recipientContract = MessageRecipientFactory.connect(recipient, destProvider);
const handleCalldata = recipientContract.interface.encodeFunctionData('handle', [
Expand Down Expand Up @@ -172,12 +174,20 @@ async function debugMessageDelivery(
const errorReason = extractReasonString(err);
logger.debug(errorReason);

const bytecodeHasHandle = await tryCheckBytecodeHandle(destProvider, recipient);
if (!bytecodeHasHandle) {
logger.info('Bytecode does not have function matching handle sig');
// const bytecodeHasHandle = await tryCheckBytecodeHandle(destProvider, recipient);
// if (!bytecodeHasHandle) {
// logger.info('Bytecode does not have function matching handle sig');
// return {
// status: MessageDebugStatus.RecipientNotHandler,
// description: `Recipient contract should have handle function of signature: ${HANDLE_FUNCTION_SIG}. Check that recipient is not a proxy. Error: ${errorReason}`,
// calldataDetails,
// };
// }

if (debugIgnoredChains.includes(destName)) {
return {
status: MessageDebugStatus.RecipientNotHandler,
description: `Recipient contract should have handle function of signature: ${HANDLE_FUNCTION_SIG}. Check that recipient is not a proxy. Error: ${errorReason}`,
status: null,
description: '',
calldataDetails,
};
}
Expand Down Expand Up @@ -328,19 +338,19 @@ async function fetchGasPaymentEvents(provider: Provider, messageId: string) {
return { contractToPayments, contractToTotalGas, numPayments, numIGPs };
}

async function tryCheckBytecodeHandle(provider: Provider, recipientAddress: string) {
try {
// scan bytecode for handle function selector
const bytecode = await provider.getCode(recipientAddress);
const msgRecipientInterface = MessageRecipientFactory.createInterface();
const handleFunction = msgRecipientInterface.functions[HANDLE_FUNCTION_SIG];
const handleSignature = msgRecipientInterface.getSighash(handleFunction);
return bytecode.includes(strip0x(handleSignature));
} catch (error) {
logger.error('Error checking bytecode for handle fn', error);
return true;
}
}
// async function tryCheckBytecodeHandle(provider: Provider, recipientAddress: string) {
// try {
// // scan bytecode for handle function selector
// const bytecode = await provider.getCode(recipientAddress);
// const msgRecipientInterface = MessageRecipientFactory.createInterface();
// const handleFunction = msgRecipientInterface.functions[HANDLE_FUNCTION_SIG];
// const handleSignature = msgRecipientInterface.getSighash(handleFunction);
// return bytecode.includes(strip0x(handleSignature));
// } catch (error) {
// logger.error('Error checking bytecode for handle fn', error);
// return true;
// }
// }

async function tryDebugIcaMsg(
sender: Address,
Expand Down

0 comments on commit 0585bff

Please sign in to comment.