Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
14b7c164
Unverified
Commit
14b7c164
authored
Mar 03, 2022
by
Matthew Slipper
Committed by
GitHub
Mar 03, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2252 from ethereum-optimism/sc/wait-for-status
feat(sdk): add fn to wait for message status
parents
1efebf14
b66e3131
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
117 additions
and
33 deletions
+117
-33
moody-lobsters-lay.md
.changeset/moody-lobsters-lay.md
+5
-0
basic-l1-l2-communication.spec.ts
integration-tests/test/basic-l1-l2-communication.spec.ts
+4
-5
bridged-tokens.spec.ts
integration-tests/test/bridged-tokens.spec.ts
+12
-19
env.ts
integration-tests/test/shared/env.ts
+4
-8
cross-chain-messenger.ts
packages/sdk/src/cross-chain-messenger.ts
+71
-1
cross-chain-messenger.ts
packages/sdk/src/interfaces/cross-chain-messenger.ts
+21
-0
No files found.
.changeset/moody-lobsters-lay.md
0 → 100644
View file @
14b7c164
---
'
@eth-optimism/sdk'
:
patch
---
Add a function for waiting for a particular message status
integration-tests/test/basic-l1-l2-communication.spec.ts
View file @
14b7c164
...
@@ -74,11 +74,10 @@ describe('Basic L1<>L2 Communication', async () => {
...
@@ -74,11 +74,10 @@ describe('Basic L1<>L2 Communication', async () => {
}
}
)
)
let
status
:
MessageStatus
await
env
.
messenger
.
waitForMessageStatus
(
while
(
status
!==
MessageStatus
.
READY_FOR_RELAY
)
{
transaction
,
status
=
await
env
.
messenger
.
getMessageStatus
(
transaction
)
MessageStatus
.
READY_FOR_RELAY
await
sleep
(
1000
)
)
}
await
env
.
messenger
.
finalizeMessage
(
transaction
)
await
env
.
messenger
.
finalizeMessage
(
transaction
)
await
env
.
messenger
.
waitForMessageReceipt
(
transaction
)
await
env
.
messenger
.
waitForMessageReceipt
(
transaction
)
...
...
integration-tests/test/bridged-tokens.spec.ts
View file @
14b7c164
...
@@ -3,7 +3,6 @@ import { BigNumber, Contract, ContractFactory, utils, Wallet } from 'ethers'
...
@@ -3,7 +3,6 @@ import { BigNumber, Contract, ContractFactory, utils, Wallet } from 'ethers'
import
{
ethers
}
from
'
hardhat
'
import
{
ethers
}
from
'
hardhat
'
import
{
getContractFactory
}
from
'
@eth-optimism/contracts
'
import
{
getContractFactory
}
from
'
@eth-optimism/contracts
'
import
{
MessageStatus
}
from
'
@eth-optimism/sdk
'
import
{
MessageStatus
}
from
'
@eth-optimism/sdk
'
import
{
sleep
}
from
'
@eth-optimism/core-utils
'
/* Imports: Internal */
/* Imports: Internal */
import
{
expect
}
from
'
./shared/setup
'
import
{
expect
}
from
'
./shared/setup
'
...
@@ -108,12 +107,10 @@ describe('Bridged tokens', () => {
...
@@ -108,12 +107,10 @@ describe('Bridged tokens', () => {
500
500
)
)
// TODO: Maybe this should be built into the SDK
await
env
.
messenger
.
waitForMessageStatus
(
let
status
:
MessageStatus
tx
,
while
(
status
!==
MessageStatus
.
READY_FOR_RELAY
)
{
MessageStatus
.
READY_FOR_RELAY
status
=
await
env
.
messenger
.
getMessageStatus
(
tx
)
)
await
sleep
(
1000
)
}
await
env
.
messenger
.
finalizeMessage
(
tx
)
await
env
.
messenger
.
finalizeMessage
(
tx
)
await
env
.
messenger
.
waitForMessageReceipt
(
tx
)
await
env
.
messenger
.
waitForMessageReceipt
(
tx
)
...
@@ -139,12 +136,10 @@ describe('Bridged tokens', () => {
...
@@ -139,12 +136,10 @@ describe('Bridged tokens', () => {
}
}
)
)
// TODO: Maybe this should be built into the SDK
await
env
.
messenger
.
waitForMessageStatus
(
let
status
:
MessageStatus
tx
,
while
(
status
!==
MessageStatus
.
READY_FOR_RELAY
)
{
MessageStatus
.
READY_FOR_RELAY
status
=
await
env
.
messenger
.
getMessageStatus
(
tx
)
)
await
sleep
(
1000
)
}
await
env
.
messenger
.
finalizeMessage
(
tx
)
await
env
.
messenger
.
finalizeMessage
(
tx
)
await
env
.
messenger
.
waitForMessageReceipt
(
tx
)
await
env
.
messenger
.
waitForMessageReceipt
(
tx
)
...
@@ -201,12 +196,10 @@ describe('Bridged tokens', () => {
...
@@ -201,12 +196,10 @@ describe('Bridged tokens', () => {
}
}
)
)
// TODO: Maybe this should be built into the SDK
await
env
.
messenger
.
waitForMessageStatus
(
let
status
:
MessageStatus
withdrawalTx
,
while
(
status
!==
MessageStatus
.
READY_FOR_RELAY
)
{
MessageStatus
.
READY_FOR_RELAY
status
=
await
env
.
messenger
.
getMessageStatus
(
withdrawalTx
)
)
await
sleep
(
1000
)
}
await
env
.
messenger
.
finalizeMessage
(
withdrawalTx
)
await
env
.
messenger
.
finalizeMessage
(
withdrawalTx
)
await
env
.
messenger
.
waitForMessageReceipt
(
withdrawalTx
)
await
env
.
messenger
.
waitForMessageReceipt
(
withdrawalTx
)
...
...
integration-tests/test/shared/env.ts
View file @
14b7c164
...
@@ -129,14 +129,10 @@ export class OptimismEnv {
...
@@ -129,14 +129,10 @@ export class OptimismEnv {
}
}
for
(
const
message
of
messages
)
{
for
(
const
message
of
messages
)
{
let
status
:
MessageStatus
await
this
.
messenger
.
waitForMessageStatus
(
while
(
message
,
status
!==
MessageStatus
.
READY_FOR_RELAY
&&
MessageStatus
.
READY_FOR_RELAY
status
!==
MessageStatus
.
RELAYED
)
)
{
status
=
await
this
.
messenger
.
getMessageStatus
(
message
)
await
sleep
(
1000
)
}
let
relayed
=
false
let
relayed
=
false
while
(
!
relayed
)
{
while
(
!
relayed
)
{
...
...
packages/sdk/src/cross-chain-messenger.ts
View file @
14b7c164
...
@@ -453,10 +453,13 @@ export class CrossChainMessenger implements ICrossChainMessenger {
...
@@ -453,10 +453,13 @@ export class CrossChainMessenger implements ICrossChainMessenger {
timeoutMs
?:
number
timeoutMs
?:
number
}
=
{}
}
=
{}
):
Promise
<
MessageReceipt
>
{
):
Promise
<
MessageReceipt
>
{
// Resolving once up-front is slightly more efficient.
const
resolved
=
await
this
.
toCrossChainMessage
(
message
)
let
totalTimeMs
=
0
let
totalTimeMs
=
0
while
(
totalTimeMs
<
(
opts
.
timeoutMs
||
Infinity
))
{
while
(
totalTimeMs
<
(
opts
.
timeoutMs
||
Infinity
))
{
const
tick
=
Date
.
now
()
const
tick
=
Date
.
now
()
const
receipt
=
await
this
.
getMessageReceipt
(
message
)
const
receipt
=
await
this
.
getMessageReceipt
(
resolved
)
if
(
receipt
!==
null
)
{
if
(
receipt
!==
null
)
{
return
receipt
return
receipt
}
else
{
}
else
{
...
@@ -468,6 +471,73 @@ export class CrossChainMessenger implements ICrossChainMessenger {
...
@@ -468,6 +471,73 @@ export class CrossChainMessenger implements ICrossChainMessenger {
throw
new
Error
(
`timed out waiting for message receipt`
)
throw
new
Error
(
`timed out waiting for message receipt`
)
}
}
public
async
waitForMessageStatus
(
message
:
MessageLike
,
status
:
MessageStatus
,
opts
:
{
pollIntervalMs
?:
number
timeoutMs
?:
number
}
=
{}
):
Promise
<
void
>
{
// Resolving once up-front is slightly more efficient.
const
resolved
=
await
this
.
toCrossChainMessage
(
message
)
let
totalTimeMs
=
0
while
(
totalTimeMs
<
(
opts
.
timeoutMs
||
Infinity
))
{
const
tick
=
Date
.
now
()
const
currentStatus
=
await
this
.
getMessageStatus
(
resolved
)
// Handle special cases for L1 to L2 messages.
if
(
resolved
.
direction
===
MessageDirection
.
L1_TO_L2
)
{
// If we're at the expected status, we're done.
if
(
currentStatus
===
status
)
{
return
}
if
(
status
===
MessageStatus
.
UNCONFIRMED_L1_TO_L2_MESSAGE
&&
currentStatus
>
status
)
{
// Anything other than UNCONFIRMED_L1_TO_L2_MESSAGE implies that the message was at one
// point "unconfirmed", so we can stop waiting.
return
}
if
(
status
===
MessageStatus
.
FAILED_L1_TO_L2_MESSAGE
&&
currentStatus
===
MessageStatus
.
RELAYED
)
{
throw
new
Error
(
`incompatible message status, expected FAILED_L1_TO_L2_MESSAGE got RELAYED`
)
}
if
(
status
===
MessageStatus
.
RELAYED
&&
currentStatus
===
MessageStatus
.
FAILED_L1_TO_L2_MESSAGE
)
{
throw
new
Error
(
`incompatible message status, expected RELAYED got FAILED_L1_TO_L2_MESSAGE`
)
}
}
// Handle special cases for L2 to L1 messages.
if
(
resolved
.
direction
===
MessageDirection
.
L2_TO_L1
)
{
if
(
currentStatus
>=
status
)
{
// For L2 to L1 messages, anything after the expected status implies the previous status,
// so we can safely return if the current status enum is larger than the expected one.
return
}
}
await
sleep
(
opts
.
pollIntervalMs
||
4000
)
totalTimeMs
+=
Date
.
now
()
-
tick
}
throw
new
Error
(
`timed out waiting for message status change`
)
}
public
async
estimateL2MessageGasLimit
(
public
async
estimateL2MessageGasLimit
(
message
:
MessageRequestLike
,
message
:
MessageRequestLike
,
opts
?:
{
opts
?:
{
...
...
packages/sdk/src/interfaces/cross-chain-messenger.ts
View file @
14b7c164
...
@@ -226,6 +226,27 @@ export interface ICrossChainMessenger {
...
@@ -226,6 +226,27 @@ export interface ICrossChainMessenger {
}
}
):
Promise
<
MessageReceipt
>
):
Promise
<
MessageReceipt
>
/**
* Waits until the status of a given message changes to the expected status. Note that if the
* status of the given message changes to a status that implies the expected status, this will
* still return. If the status of the message changes to a status that exclues the expected
* status, this will throw an error.
*
* @param message Message to wait for.
* @param status Expected status of the message.
* @param opts Options to pass to the waiting function.
* @param opts.pollIntervalMs Number of milliseconds to wait when polling.
* @param opts.timeoutMs Milliseconds to wait before timing out.
*/
waitForMessageStatus
(
message
:
MessageLike
,
status
:
MessageStatus
,
opts
?:
{
pollIntervalMs
?:
number
timeoutMs
?:
number
}
):
Promise
<
void
>
/**
/**
* Estimates the amount of gas required to fully execute a given message on L2. Only applies to
* Estimates the amount of gas required to fully execute a given message on L2. Only applies to
* L1 => L2 messages. You would supply this gas limit when sending the message to L2.
* L1 => L2 messages. You would supply this gas limit when sending the message to L2.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment