-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathfetchDeliveryStatus.ts
More file actions
106 lines (101 loc) · 3.99 KB
/
Copy pathfetchDeliveryStatus.ts
File metadata and controls
106 lines (101 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { IRegistry } from '@hyperlane-xyz/registry';
import { ChainMap, ChainMetadata, MultiProtocolProvider } from '@hyperlane-xyz/sdk';
import { constants } from 'ethers';
import { Message, MessageStatus } from '../../types';
import { logger } from '../../utils/logger';
import { toDecimalNumber } from '../../utils/number';
import { getMailboxAddress } from '../chains/utils';
import { debugMessage } from '../debugger/debugMessage';
import { MessageDebugStatus } from '../debugger/types';
import { checkIsMessageDelivered } from '../messages/utils';
import {
MessageDeliveryFailingResult,
MessageDeliveryPendingResult,
MessageDeliveryStatusResponse,
MessageDeliverySuccessResult,
} from './types';
export async function fetchDeliveryStatus(
multiProvider: MultiProtocolProvider,
registry: IRegistry,
overrideChainMetadata: ChainMap<Partial<ChainMetadata>>,
message: Message,
): Promise<MessageDeliveryStatusResponse> {
const destName = multiProvider.tryGetChainName(message.destinationDomainId);
if (!destName)
throw new Error(
`Cannot check delivery status, no chain name provided for domain ${message.destinationDomainId}`,
);
const destMailboxAddr = await getMailboxAddress(destName, overrideChainMetadata, registry);
if (!destMailboxAddr)
throw new Error(
`Cannot check delivery status, no mailbox address provided for chain ${destName}`,
);
const { isDelivered, blockNumber, transactionHash } = await checkIsMessageDelivered(
message.msgId,
message.destinationDomainId,
destMailboxAddr,
multiProvider,
);
if (isDelivered) {
const txDetails = await fetchTransactionDetails(
multiProvider,
message.destinationDomainId,
transactionHash,
);
// If a delivery (aka process) tx is found, mark as success
const result: MessageDeliverySuccessResult = {
status: MessageStatus.Delivered,
deliveryTransaction: {
timestamp: toDecimalNumber(txDetails?.timestamp || 0) * 1000,
hash: transactionHash || constants.HashZero,
from: txDetails?.from || constants.AddressZero,
to: txDetails?.to || constants.AddressZero,
blockHash: txDetails?.blockHash || constants.HashZero,
blockNumber: toDecimalNumber(blockNumber || 0),
mailbox: constants.AddressZero,
nonce: txDetails?.nonce || 0,
gasLimit: toDecimalNumber(txDetails?.gasLimit || 0),
gasPrice: toDecimalNumber(txDetails?.gasPrice || 0),
effectiveGasPrice: toDecimalNumber(txDetails?.gasPrice || 0),
gasUsed: toDecimalNumber(txDetails?.gasLimit || 0),
cumulativeGasUsed: toDecimalNumber(txDetails?.gasLimit || 0),
maxFeePerGas: toDecimalNumber(txDetails?.maxFeePerGas || 0),
maxPriorityPerGas: toDecimalNumber(txDetails?.maxPriorityFeePerGas || 0),
},
};
return result;
} else {
// Tip/raw rows may lack full finalized fields (e.g. message body), so avoid
// deep debug that can generate false negatives.
if (message.isProvisional) {
const result: MessageDeliveryPendingResult = {
status: MessageStatus.Pending,
debugResult: {
status: MessageDebugStatus.NoErrorsFound,
description: 'Provisional tip-stage message; debug deferred until finalized.',
},
};
return result;
}
const debugResult = await debugMessage(multiProvider, registry, overrideChainMetadata, message);
const messageStatus =
debugResult.status === MessageDebugStatus.NoErrorsFound
? MessageStatus.Pending
: MessageStatus.Failing;
const result: MessageDeliveryPendingResult | MessageDeliveryFailingResult = {
status: messageStatus,
debugResult,
};
return result;
}
}
function fetchTransactionDetails(
multiProvider: MultiProtocolProvider,
domainId: DomainId,
txHash?: string,
) {
if (!txHash) return null;
logger.debug(`Searching for transaction details for ${txHash}`);
const provider = multiProvider.getEthersV5Provider(domainId);
return provider.getTransaction(txHash);
}