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
0aea323d
Unverified
Commit
0aea323d
authored
Sep 22, 2021
by
Mark Tyneway
Committed by
GitHub
Sep 22, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1404 from ethereum-optimism/matt/watcher-l1-l2-blocksToFetch
Watcher: l1 vs l2 blocksToFetch
parents
08d1c86a
8da04505
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
9 deletions
+33
-9
yellow-windows-scream.md
.changeset/yellow-windows-scream.md
+5
-0
watcher.ts
packages/core-utils/src/watcher.ts
+28
-9
No files found.
.changeset/yellow-windows-scream.md
0 → 100644
View file @
0aea323d
---
'
@eth-optimism/core-utils'
:
minor
---
Allow a configurable L1 and L2 blocks to fetch in the watcher
packages/core-utils/src/watcher.ts
View file @
0aea323d
...
...
@@ -2,9 +2,14 @@
import
{
ethers
}
from
'
ethers
'
import
{
Provider
,
TransactionReceipt
}
from
'
@ethersproject/abstract-provider
'
const
SENT_MESSAGE
=
ethers
.
utils
.
id
(
'
SentMessage(bytes)
'
)
const
RELAYED_MESSAGE
=
ethers
.
utils
.
id
(
`RelayedMessage(bytes32)`
)
const
FAILED_RELAYED_MESSAGE
=
ethers
.
utils
.
id
(
`FailedRelayedMessage(bytes32)`
)
export
interface
Layer
{
provider
:
Provider
messengerAddress
:
string
blocksToFetch
?:
number
}
export
interface
WatcherOptions
{
...
...
@@ -12,6 +17,7 @@ export interface WatcherOptions {
l2
:
Layer
pollInterval
?:
number
blocksToFetch
?:
number
pollForPending
?:
boolean
}
export
class
Watcher
{
...
...
@@ -19,16 +25,20 @@ export class Watcher {
public
l2
:
Layer
public
pollInterval
=
3000
public
blocksToFetch
=
1500
public
pollForPending
=
true
constructor
(
opts
:
WatcherOptions
)
{
this
.
l1
=
opts
.
l1
this
.
l2
=
opts
.
l2
if
(
opts
.
pollInterval
)
{
if
(
typeof
opts
.
pollInterval
===
'
number
'
)
{
this
.
pollInterval
=
opts
.
pollInterval
}
if
(
opts
.
blocksToFetch
)
{
if
(
typeof
opts
.
blocksToFetch
===
'
number
'
)
{
this
.
blocksToFetch
=
opts
.
blocksToFetch
}
if
(
typeof
opts
.
pollForPending
===
'
boolean
'
)
{
this
.
pollForPending
=
opts
.
pollForPending
}
}
public
async
getMessageHashesFromL1Tx
(
l1TxHash
:
string
):
Promise
<
string
[]
>
{
...
...
@@ -40,14 +50,14 @@ export class Watcher {
public
async
getL1TransactionReceipt
(
l2ToL1MsgHash
:
string
,
pollForPending
=
true
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
return
this
.
getTransactionReceipt
(
this
.
l1
,
l2ToL1MsgHash
,
pollForPending
)
}
public
async
getL2TransactionReceipt
(
l1ToL2MsgHash
:
string
,
pollForPending
=
true
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
return
this
.
getTransactionReceipt
(
this
.
l2
,
l1ToL2MsgHash
,
pollForPending
)
}
...
...
@@ -65,7 +75,7 @@ export class Watcher {
for
(
const
log
of
receipt
.
logs
)
{
if
(
log
.
address
===
layer
.
messengerAddress
&&
log
.
topics
[
0
]
===
ethers
.
utils
.
id
(
'
SentMessage(bytes)
'
)
log
.
topics
[
0
]
===
SENT_MESSAGE
)
{
const
[
message
]
=
ethers
.
utils
.
defaultAbiCoder
.
decode
(
[
'
bytes
'
],
...
...
@@ -80,22 +90,31 @@ export class Watcher {
public
async
getTransactionReceipt
(
layer
:
Layer
,
msgHash
:
string
,
pollForPending
=
true
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
if
(
typeof
pollForPending
!==
'
boolean
'
)
{
pollForPending
=
this
.
pollForPending
}
let
matches
:
ethers
.
providers
.
Log
[]
=
[]
let
blocksToFetch
=
layer
.
blocksToFetch
if
(
typeof
blocksToFetch
!==
'
number
'
)
{
blocksToFetch
=
this
.
blocksToFetch
}
// scan for transaction with specified message
while
(
matches
.
length
===
0
)
{
const
blockNumber
=
await
layer
.
provider
.
getBlockNumber
()
const
startingBlock
=
Math
.
max
(
blockNumber
-
this
.
blocksToFetch
,
0
)
const
startingBlock
=
Math
.
max
(
blockNumber
-
blocksToFetch
,
0
)
const
successFilter
:
ethers
.
providers
.
Filter
=
{
address
:
layer
.
messengerAddress
,
topics
:
[
ethers
.
utils
.
id
(
`RelayedMessage(bytes32)`
)
],
topics
:
[
RELAYED_MESSAGE
],
fromBlock
:
startingBlock
,
}
const
failureFilter
:
ethers
.
providers
.
Filter
=
{
address
:
layer
.
messengerAddress
,
topics
:
[
ethers
.
utils
.
id
(
`FailedRelayedMessage(bytes32)`
)
],
topics
:
[
FAILED_RELAYED_MESSAGE
],
fromBlock
:
startingBlock
,
}
const
successLogs
=
await
layer
.
provider
.
getLogs
(
successFilter
)
...
...
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