Commit dd0e4698 authored by Kelvin Fichter's avatar Kelvin Fichter

fix(sdk): have getMessageStatus call messenger

getMessageStatus was previously using event queries to figure out the
status of the given message. We can do the same thing by making requests
directly to the messenger contracts which is more reliable because most
RPC endpoints won't allow massive block ranges.
parent ed2668a5
---
'@eth-optimism/sdk': patch
---
Simplifies getMessageStatus to use an O(1) lookup instead of an event query
...@@ -667,25 +667,54 @@ export class CrossChainMessenger { ...@@ -667,25 +667,54 @@ export class CrossChainMessenger {
toBlockOrBlockHash?: BlockTag toBlockOrBlockHash?: BlockTag
): Promise<MessageStatus> { ): Promise<MessageStatus> {
const resolved = await this.toCrossChainMessage(message, messageIndex) const resolved = await this.toCrossChainMessage(message, messageIndex)
const receipt = await this.getMessageReceipt( // legacy withdrawals relayed prebedrock are v1
resolved, const messageHashV0 = hashCrossDomainMessagev0(
messageIndex, resolved.target,
fromBlockOrBlockHash, resolved.sender,
toBlockOrBlockHash resolved.message,
resolved.messageNonce
) )
// bedrock withdrawals are v1
// legacy withdrawals relayed postbedrock are v1
// there is no good way to differentiate between the two types of legacy
// so what we will check for both
const messageHashV1 = hashCrossDomainMessagev1(
resolved.messageNonce,
resolved.sender,
resolved.target,
resolved.value,
resolved.minGasLimit,
resolved.message
)
// Here we want the messenger that will receive the message, not the one that sent it.
const messenger =
resolved.direction === MessageDirection.L1_TO_L2
? this.contracts.l2.L2CrossDomainMessenger
: this.contracts.l1.L1CrossDomainMessenger
const success =
(await messenger.successfulMessages(messageHashV0)) ||
(await messenger.successfulMessages(messageHashV1))
const failure =
(await messenger.failedMessages(messageHashV0)) ||
(await messenger.failedMessages(messageHashV1))
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
if (receipt === null) { if (success) {
return MessageStatus.UNCONFIRMED_L1_TO_L2_MESSAGE return MessageStatus.RELAYED
} else if (failure) {
return MessageStatus.FAILED_L1_TO_L2_MESSAGE
} else { } else {
if (receipt.receiptStatus === MessageReceiptStatus.RELAYED_SUCCEEDED) { return MessageStatus.UNCONFIRMED_L1_TO_L2_MESSAGE
return MessageStatus.RELAYED
} else {
return MessageStatus.FAILED_L1_TO_L2_MESSAGE
}
} }
} else { } else {
if (receipt === null) { if (success) {
return MessageStatus.RELAYED
} else if (failure) {
return MessageStatus.READY_FOR_RELAY
} else {
let timestamp: number let timestamp: number
if (this.bedrock) { if (this.bedrock) {
const output = await this.getMessageBedrockOutput( const output = await this.getMessageBedrockOutput(
...@@ -737,12 +766,6 @@ export class CrossChainMessenger { ...@@ -737,12 +766,6 @@ export class CrossChainMessenger {
} else { } else {
return MessageStatus.READY_FOR_RELAY return MessageStatus.READY_FOR_RELAY
} }
} else {
if (receipt.receiptStatus === MessageReceiptStatus.RELAYED_SUCCEEDED) {
return MessageStatus.RELAYED
} else {
return MessageStatus.READY_FOR_RELAY
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment