Commit b80fc6e6 authored by Will Cory's avatar Will Cory

messageIndex

parent 28ad99fe
...@@ -333,11 +333,11 @@ export class CrossChainMessenger { ...@@ -333,11 +333,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<CrossChainMessage> { ): Promise<CrossChainMessage> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
// Bedrock messages are already in the correct format. // Bedrock messages are already in the correct format.
...@@ -405,11 +405,11 @@ export class CrossChainMessenger { ...@@ -405,11 +405,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<LowLevelMessage> { ): Promise<LowLevelMessage> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only convert L2 to L1 messages to low level`) throw new Error(`can only convert L2 to L1 messages to low level`)
...@@ -421,7 +421,7 @@ export class CrossChainMessenger { ...@@ -421,7 +421,7 @@ export class CrossChainMessenger {
if (version.eq(0)) { if (version.eq(0)) {
updated = await this.toBedrockCrossChainMessage( updated = await this.toBedrockCrossChainMessage(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
} else { } else {
updated = resolved updated = resolved
...@@ -454,10 +454,10 @@ export class CrossChainMessenger { ...@@ -454,10 +454,10 @@ export class CrossChainMessenger {
throw new Error(`no withdrawals found in receipt`) throw new Error(`no withdrawals found in receipt`)
} }
const withdrawal = withdrawals[multiWithdrawalIndex] const withdrawal = withdrawals[messageIndex]
if (!withdrawal) { if (!withdrawal) {
throw new Error( throw new Error(
`withdrawal index ${multiWithdrawalIndex} out of bounds there are ${withdrawals.length} withdrawals` `withdrawal index ${messageIndex} out of bounds there are ${withdrawals.length} withdrawals`
) )
} }
messageNonce = withdrawal.nonce messageNonce = withdrawal.nonce
...@@ -604,7 +604,7 @@ export class CrossChainMessenger { ...@@ -604,7 +604,7 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<CrossChainMessage> { ): Promise<CrossChainMessage> {
if (!message) { if (!message) {
throw new Error('message is undefined') throw new Error('message is undefined')
...@@ -648,10 +648,10 @@ export class CrossChainMessenger { ...@@ -648,10 +648,10 @@ export class CrossChainMessenger {
message as TransactionLike message as TransactionLike
) )
const out = messages[multiWithdrawalIndex] const out = messages[messageIndex]
if (!out) { if (!out) {
throw new Error( throw new Error(
`withdrawal index ${multiWithdrawalIndex} out of bounds. There are ${messages.length} withdrawals` `withdrawal index ${messageIndex} out of bounds. There are ${messages.length} withdrawals`
) )
} }
return out return out
...@@ -670,13 +670,13 @@ export class CrossChainMessenger { ...@@ -670,13 +670,13 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<MessageStatus> { ): Promise<MessageStatus> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
const receipt = await this.getMessageReceipt(resolved, multiWithdrawalIndex) const receipt = await this.getMessageReceipt(resolved, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
if (receipt === null) { if (receipt === null) {
...@@ -694,7 +694,7 @@ export class CrossChainMessenger { ...@@ -694,7 +694,7 @@ export class CrossChainMessenger {
if (this.bedrock) { if (this.bedrock) {
const output = await this.getMessageBedrockOutput( const output = await this.getMessageBedrockOutput(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
if (output === null) { if (output === null) {
return MessageStatus.STATE_ROOT_NOT_PUBLISHED return MessageStatus.STATE_ROOT_NOT_PUBLISHED
...@@ -703,7 +703,7 @@ export class CrossChainMessenger { ...@@ -703,7 +703,7 @@ export class CrossChainMessenger {
// Convert the message to the low level message that was proven. // Convert the message to the low level message that was proven.
const withdrawal = await this.toLowLevelMessage( const withdrawal = await this.toLowLevelMessage(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
// Attempt to fetch the proven withdrawal. // Attempt to fetch the proven withdrawal.
...@@ -723,7 +723,7 @@ export class CrossChainMessenger { ...@@ -723,7 +723,7 @@ export class CrossChainMessenger {
} else { } else {
const stateRoot = await this.getMessageStateRoot( const stateRoot = await this.getMessageStateRoot(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
if (stateRoot === null) { if (stateRoot === null) {
return MessageStatus.STATE_ROOT_NOT_PUBLISHED return MessageStatus.STATE_ROOT_NOT_PUBLISHED
...@@ -765,11 +765,11 @@ export class CrossChainMessenger { ...@@ -765,11 +765,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<MessageReceipt> { ): Promise<MessageReceipt> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
// legacy withdrawals relayed prebedrock are v1 // legacy withdrawals relayed prebedrock are v1
const messageHashV0 = hashCrossDomainMessagev0( const messageHashV0 = hashCrossDomainMessagev0(
...@@ -877,12 +877,12 @@ export class CrossChainMessenger { ...@@ -877,12 +877,12 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<MessageReceipt> { ): Promise<MessageReceipt> {
// Resolving once up-front is slightly more efficient. // Resolving once up-front is slightly more efficient.
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
let totalTimeMs = 0 let totalTimeMs = 0
...@@ -890,7 +890,7 @@ export class CrossChainMessenger { ...@@ -890,7 +890,7 @@ export class CrossChainMessenger {
const tick = Date.now() const tick = Date.now()
const receipt = await this.getMessageReceipt( const receipt = await this.getMessageReceipt(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
if (receipt !== null) { if (receipt !== null) {
return receipt return receipt
...@@ -926,12 +926,12 @@ export class CrossChainMessenger { ...@@ -926,12 +926,12 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<void> { ): Promise<void> {
// Resolving once up-front is slightly more efficient. // Resolving once up-front is slightly more efficient.
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
let totalTimeMs = 0 let totalTimeMs = 0
...@@ -939,7 +939,7 @@ export class CrossChainMessenger { ...@@ -939,7 +939,7 @@ export class CrossChainMessenger {
const tick = Date.now() const tick = Date.now()
const currentStatus = await this.getMessageStatus( const currentStatus = await this.getMessageStatus(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
// Handle special cases for L1 to L2 messages. // Handle special cases for L1 to L2 messages.
...@@ -1009,7 +1009,7 @@ export class CrossChainMessenger { ...@@ -1009,7 +1009,7 @@ export class CrossChainMessenger {
bufferPercent?: number bufferPercent?: number
from?: string from?: string
}, },
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<BigNumber> { ): Promise<BigNumber> {
let resolved: CrossChainMessage | CrossChainMessageRequest let resolved: CrossChainMessage | CrossChainMessageRequest
let from: string let from: string
...@@ -1019,7 +1019,7 @@ export class CrossChainMessenger { ...@@ -1019,7 +1019,7 @@ export class CrossChainMessenger {
} else { } else {
resolved = await this.toCrossChainMessage( resolved = await this.toCrossChainMessage(
message as MessageLike, message as MessageLike,
multiWithdrawalIndex messageIndex
) )
from = opts?.from || (resolved as CrossChainMessage).sender from = opts?.from || (resolved as CrossChainMessage).sender
} }
...@@ -1055,13 +1055,13 @@ export class CrossChainMessenger { ...@@ -1055,13 +1055,13 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<number> { ): Promise<number> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
const status = await this.getMessageStatus(resolved, multiWithdrawalIndex) const status = await this.getMessageStatus(resolved, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
if ( if (
status === MessageStatus.RELAYED || status === MessageStatus.RELAYED ||
...@@ -1101,7 +1101,7 @@ export class CrossChainMessenger { ...@@ -1101,7 +1101,7 @@ export class CrossChainMessenger {
// when the state root is published. // when the state root is published.
const stateRoot = await this.getMessageStateRoot( const stateRoot = await this.getMessageStateRoot(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
const challengePeriod = await this.getChallengePeriodSeconds() const challengePeriod = await this.getChallengePeriodSeconds()
const targetBlock = await this.l1Provider.getBlock( const targetBlock = await this.l1Provider.getBlock(
...@@ -1135,13 +1135,13 @@ export class CrossChainMessenger { ...@@ -1135,13 +1135,13 @@ export class CrossChainMessenger {
const challengePeriod = const challengePeriod =
oracleVersion === '1.0.0' oracleVersion === '1.0.0'
? // The ABI in the SDK does not contain FINALIZATION_PERIOD_SECONDS ? // The ABI in the SDK does not contain FINALIZATION_PERIOD_SECONDS
// in OptimismPortal, so making an explicit call instead. // in OptimismPortal, so making an explicit call instead.
BigNumber.from( BigNumber.from(
await this.contracts.l1.OptimismPortal.provider.call({ await this.contracts.l1.OptimismPortal.provider.call({
to: this.contracts.l1.OptimismPortal.address, to: this.contracts.l1.OptimismPortal.address,
data: '0xf4daa291', // FINALIZATION_PERIOD_SECONDS data: '0xf4daa291', // FINALIZATION_PERIOD_SECONDS
}) })
) )
: await this.contracts.l1.L2OutputOracle.FINALIZATION_PERIOD_SECONDS() : await this.contracts.l1.L2OutputOracle.FINALIZATION_PERIOD_SECONDS()
return challengePeriod.toNumber() return challengePeriod.toNumber()
} }
...@@ -1177,11 +1177,11 @@ export class CrossChainMessenger { ...@@ -1177,11 +1177,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<BedrockOutputData | null> { ): Promise<BedrockOutputData | null> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
// Outputs are only a thing for L2 to L1 messages. // Outputs are only a thing for L2 to L1 messages.
...@@ -1236,11 +1236,11 @@ export class CrossChainMessenger { ...@@ -1236,11 +1236,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<StateRoot | null> { ): Promise<StateRoot | null> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
// State roots are only a thing for L2 to L1 messages. // State roots are only a thing for L2 to L1 messages.
...@@ -1429,11 +1429,11 @@ export class CrossChainMessenger { ...@@ -1429,11 +1429,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<CrossChainMessageProof> { ): Promise<CrossChainMessageProof> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only generate proofs for L2 to L1 messages`) throw new Error(`can only generate proofs for L2 to L1 messages`)
...@@ -1441,7 +1441,7 @@ export class CrossChainMessenger { ...@@ -1441,7 +1441,7 @@ export class CrossChainMessenger {
const stateRoot = await this.getMessageStateRoot( const stateRoot = await this.getMessageStateRoot(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
if (stateRoot === null) { if (stateRoot === null) {
throw new Error(`state root for message not yet published`) throw new Error(`state root for message not yet published`)
...@@ -1498,11 +1498,11 @@ export class CrossChainMessenger { ...@@ -1498,11 +1498,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<BedrockCrossChainMessageProof> { ): Promise<BedrockCrossChainMessageProof> {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only generate proofs for L2 to L1 messages`) throw new Error(`can only generate proofs for L2 to L1 messages`)
...@@ -1510,7 +1510,7 @@ export class CrossChainMessenger { ...@@ -1510,7 +1510,7 @@ export class CrossChainMessenger {
const output = await this.getMessageBedrockOutput( const output = await this.getMessageBedrockOutput(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
if (output === null) { if (output === null) {
throw new Error(`state root for message not yet published`) throw new Error(`state root for message not yet published`)
...@@ -1518,7 +1518,7 @@ export class CrossChainMessenger { ...@@ -1518,7 +1518,7 @@ export class CrossChainMessenger {
const withdrawal = await this.toLowLevelMessage( const withdrawal = await this.toLowLevelMessage(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
const hash = hashLowLevelMessage(withdrawal) const hash = hashLowLevelMessage(withdrawal)
const messageSlot = hashMessageHash(hash) const messageSlot = hashMessageHash(hash)
...@@ -1870,11 +1870,11 @@ export class CrossChainMessenger { ...@@ -1870,11 +1870,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<TransactionRequest> => { ): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L2_TO_L1) { if (resolved.direction === MessageDirection.L2_TO_L1) {
throw new Error(`cannot resend L2 to L1 message`) throw new Error(`cannot resend L2 to L1 message`)
...@@ -1924,11 +1924,11 @@ export class CrossChainMessenger { ...@@ -1924,11 +1924,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<TransactionRequest> => { ): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error('cannot finalize L1 to L2 message') throw new Error('cannot finalize L1 to L2 message')
...@@ -1942,11 +1942,11 @@ export class CrossChainMessenger { ...@@ -1942,11 +1942,11 @@ export class CrossChainMessenger {
const withdrawal = await this.toLowLevelMessage( const withdrawal = await this.toLowLevelMessage(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
const proof = await this.getBedrockMessageProof( const proof = await this.getBedrockMessageProof(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
const args = [ const args = [
...@@ -1993,11 +1993,11 @@ export class CrossChainMessenger { ...@@ -1993,11 +1993,11 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<TransactionRequest> => { ): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage( const resolved = await this.toCrossChainMessage(
message, message,
multiWithdrawalIndex messageIndex
) )
if (resolved.direction === MessageDirection.L1_TO_L2) { if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`cannot finalize L1 to L2 message`) throw new Error(`cannot finalize L1 to L2 message`)
...@@ -2006,7 +2006,7 @@ export class CrossChainMessenger { ...@@ -2006,7 +2006,7 @@ export class CrossChainMessenger {
if (this.bedrock) { if (this.bedrock) {
const withdrawal = await this.toLowLevelMessage( const withdrawal = await this.toLowLevelMessage(
resolved, resolved,
multiWithdrawalIndex messageIndex
) )
return this.contracts.l1.OptimismPortal.populateTransaction.finalizeWithdrawalTransaction( return this.contracts.l1.OptimismPortal.populateTransaction.finalizeWithdrawalTransaction(
[ [
...@@ -2023,7 +2023,7 @@ export class CrossChainMessenger { ...@@ -2023,7 +2023,7 @@ export class CrossChainMessenger {
// L1CrossDomainMessenger relayMessage is the only method that isn't fully backwards // L1CrossDomainMessenger relayMessage is the only method that isn't fully backwards
// compatible, so we need to use the legacy interface. When we fully upgrade to Bedrock we // compatible, so we need to use the legacy interface. When we fully upgrade to Bedrock we
// should be able to remove this code. // should be able to remove this code.
const proof = await this.getMessageProof(resolved, multiWithdrawalIndex) const proof = await this.getMessageProof(resolved, messageIndex)
const legacyL1XDM = new ethers.Contract( const legacyL1XDM = new ethers.Contract(
this.contracts.l1.L1CrossDomainMessenger.address, this.contracts.l1.L1CrossDomainMessenger.address,
getContractInterface('L1CrossDomainMessenger'), getContractInterface('L1CrossDomainMessenger'),
...@@ -2284,13 +2284,13 @@ export class CrossChainMessenger { ...@@ -2284,13 +2284,13 @@ export class CrossChainMessenger {
/** /**
* The index of the withdrawal if multiple are made with multicall * The index of the withdrawal if multiple are made with multicall
*/ */
multiWithdrawalIndex = 0 messageIndex = 0
): Promise<BigNumber> => { ): Promise<BigNumber> => {
return this.l1Provider.estimateGas( return this.l1Provider.estimateGas(
await this.populateTransaction.proveMessage( await this.populateTransaction.proveMessage(
message, message,
opts, opts,
multiWithdrawalIndex messageIndex
) )
) )
}, },
......
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