Skip to content

Add Cross-domain Watcher service#306

Merged
K-Ho merged 11 commits intomasterfrom
IS-54/SNX-Frontend/WatcherService
Oct 8, 2020
Merged

Add Cross-domain Watcher service#306
K-Ho merged 11 commits intomasterfrom
IS-54/SNX-Frontend/WatcherService

Conversation

@K-Ho
Copy link
Contributor

@K-Ho K-Ho commented Oct 4, 2020

Description

This adds a cross domain watcher service. Usage is as follows:
Watcher is initialized with L1 and L2 providers + L1 and L2 messenger addresses.

User sends an L1->L2 Deposit tx. Front-end gets the L1 tx hash and calls getMessageHashesFromL1Tx which returns an array of all messageHashes of the L1->L2 txs that were sent in this tx (we would expect this to be a singleton array, but you could construct an L1 tx that sends multiple L1->L2 messages).

Front-end now calls onceL2Relay(messageHash, (l2TxHash) => {// do thing}). Once the L2 tx is relayed, then the callback will be triggered with the L2 tx hash.

The watcher service can of course be used in the reverse direction as well, using getMessageHashesFromL2Tx followed by onceL1Relay(messageHash, (l1TxHash) => {// do thing})

Questions

Best way to add tests for this other than the integration testing repo?

Metadata

Fixes

Contributing Agreement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this API. LGTM 👍

Copy link
Contributor

@smartcontracts smartcontracts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API looks good!

Copy link
Contributor

@karlfloersch karlfloersch Oct 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What were the thoughts here about using a callback vs just returning a promise? (it does seem you do return a promise in addition to accepting a callback, & just curious about that choice)

Copy link
Contributor

@karlfloersch karlfloersch Oct 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh also nit: should probably add a return value for this function.

(being more picky about this stuff because this is going to be a very externally facing API)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was trying to emulate the provider.once functionality in ethers https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/-%23-Provider-once -

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to do this that is a bit more flexible I think is to make the Watcher an EventEmitter and then update this part of the code:

    layer.provider.on(filter, (log: any) => {
      if (log.data === msgHash) {
        this.emit('relayed', log.transactionHash)
      }

Then the Watcher would have the on property and the once property as well as the rest of the highly used/tested EventEmitter properties

Copy link
Contributor

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚢🛠🚀

@K-Ho K-Ho merged commit dbab98b into master Oct 8, 2020
@gakonst gakonst deleted the IS-54/SNX-Frontend/WatcherService branch March 18, 2021 15:09
agusduha pushed a commit that referenced this pull request Mar 20, 2025
theochap pushed a commit that referenced this pull request Dec 10, 2025
* chore: Bump `superchain-registry` version

* fix: use versioned superchain primitives dep

---------

Co-authored-by: refcell <abigger87@gmail.com>
theochap pushed a commit that referenced this pull request Jan 15, 2026
### Description

Adds an example to the `op-alloy` book that walks through implementing
`L1BlockInfo` hardfork changes in `op-alloy`.

Closes #279
emhane added a commit that referenced this pull request Feb 3, 2026
Closes #296

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments