Skip to content

feat: add Teleportr service#2233

Merged
mslipper merged 12 commits intoethereum-optimism:developfrom
cfromknecht:teleportr-service
Mar 2, 2022
Merged

feat: add Teleportr service#2233
mslipper merged 12 commits intoethereum-optimism:developfrom
cfromknecht:teleportr-service

Conversation

@cfromknecht
Copy link
Contributor

@cfromknecht cfromknecht commented Feb 25, 2022

Description
This PR adds the Teleportr service implemented as a bss-core driver. The general principal is the same the batch submitter, except here we are pulling data from L1 and posting to L2. There are however some notable differences:

  • The teleportr driver is backed by a Postgres instance for ingesting Deposit events and holding metadata about the progression of the deposit until it is disbursed. The ingestion happens inside each call to Driver.GetBatchBlockRange, and overwrites deposits with the same deposit ID to handle reorgs up to the NumDepositConfirmations window.
  • L2 doesn't support EIP-1559, so when submitting batch transactions we rely on a call to EstimateGas inside the Driver.UpdateGasPrice callback to set a proper L2 fee rate. Note that this also differs from the prior approach where the fees were linearly scaled between a min and max configuration. This eliminates the need for adding the additional configuration arguments and needing to further modify the bss-core interface to support the old methodology, seeing as we can start using EIP-1559 for Teleportr L2 txs in the near future.
  • There is no need to support ClearPendingTxs since L2Geth doesn't have a mempool where prior transactions can be stuck.

TODO:

  • Record disbursement success/fail by inspecting receipt in Postgres
  • Figure out how to deploy Teleportr contracts on itests and address manager (bumped to follow up)
  • Add itests (bumped to followup)

Blocked by:

Metadata

  • Fixes ENG-1932

@changeset-bot
Copy link

changeset-bot bot commented Feb 25, 2022

🦋 Changeset detected

Latest commit: 2910a3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@eth-optimism/batch-submitter-service Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2022

Codecov Report

Merging #2233 (1480c92) into develop (c1619de) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2233   +/-   ##
========================================
  Coverage    73.04%   73.04%           
========================================
  Files           86       86           
  Lines         2846     2846           
  Branches       486      486           
========================================
  Hits          2079     2079           
  Misses         767      767           
Flag Coverage Δ
batch-submitter 62.63% <ø> (ø)
contracts 90.88% <ø> (ø)
core-utils 87.80% <ø> (ø)
data-transport-layer 36.89% <ø> (ø)
sdk 57.71% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1619de...1480c92. Read the comment docs.

"blockNumber", receipt.BlockNumber,
"blockTimestamp", blockTimestamp)

err = d.cfg.Database.UpsertDisbursement(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a disbursement fails to be marked as successful, what happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would show up in the db as confirmed but not disbursed, and would require manual intervention to add the disbursement. the best way to get around this IMO is to add a database that tracks txhash => (startId, endId) and then we can recover after startups or in GetBatchBlockRange. this is a little more involved though, as we would need a call back from within the txmgr before it publishes, but it's definitely the safer route

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, actually we can just do the tracking in the SendTransaction iface method 😎

// are missing a disbursement for this deposit even though the contract
// beleves it was disbursed.
case deposit.ID < startID:
log.Warn("Filtering deposit with missing disbursement",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should have a metric for this as well.

// provided URL. If the dial doesn't complete within dial.DefaultTimeout seconds,
// this method will return an error.
func L2EthClientWithTimeout(ctx context.Context, url string, disableHTTP2 bool) (
func DialL2EthClientWithTimeout(ctx context.Context, url string, disableHTTP2 bool) (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason as to why we are using the l2geth deps here? I feel like we could use the upstream stuff for things like rpc or utils, especially now that the http2 fix is in: 6f2ea19

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fwiw we do use upstream for L2 in this driver since we don't need to access any non-standard info

// stateRootSize is the size in bytes of a state root.
const stateRootSize = 32

var bigOne = new(big.Int).SetUint64(1) //nolint:unused
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to leave this even though its unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, was left over from copying in from the BSS driver as a template.

BlockNumber: event.Raw.BlockNumber,
BlockTimestamp: time.Unix(int64(header.Time), 0),
Address: event.Emitter,
Amount: event.Amount,
Copy link
Contributor

Choose a reason for hiding this comment

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

There have been hacks in the past where a bridge uses tx.Value instead of a value emitted from an event which could cause problems if the tx calls a loop, it would count the value multiple times. I believe we are safe from this kind of attack but perhaps its good to add a unit test to the contract tests before this goes into production

ENABLE_GAS_REPORT: 1
NO_NETWORK: 1

teleportr_postgres:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning on adding integration tests for teleportr? Eventually the docker compose setup will become unwieldy for local development using too many resources and we don't have a good way to define sets of integration tests that bring up parts of the stack to specifically test. I think adding teleportr is fine now fwiw

Copy link
Contributor

@tynes tynes Feb 25, 2022

Choose a reason for hiding this comment

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

Oh I see that teleportr has replicas: 0 but the postgres does not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, yes i'm planning to add itests but will do so in a follow up. this pr will just have the bulk of the teleportr service

@github-actions github-actions bot added the M-ci Meta: ci related work label Mar 2, 2022
This avoids having l2geth as a dependency for other projects building on
bss-core. Speicifically this avoids having to copy l2geth into docker
builds.
Currently the teleportr database supports a LatestDeposit method,
which returns the highest block number observed, if any. The intent was
to use this as the starting point for syncing, however, this isn't super
useful as there may be long periods of inactivity that we have already
scanned.

Instead, we now store the last processed block in a separate table, and
pass the end of the ingestion block range as argument to UpsertDeposits.
The list of deposits and last processed block are written atomically to
avoid consistency issues. The value can be retrieved using the
LastProcessedBlock getter.
@github-actions github-actions bot removed 2-reviewers M-ci Meta: ci related work A-ops Area: ops labels Mar 2, 2022
@cfromknecht
Copy link
Contributor Author

Pushed a small change to record success/failures for every database operation

@cfromknecht cfromknecht requested a review from tynes March 2, 2022 21:29
@cfromknecht cfromknecht requested a review from mslipper March 2, 2022 21:29
@github-actions github-actions bot added 2-reviewers M-ci Meta: ci related work labels Mar 2, 2022
@mslipper mslipper merged commit 7dc259c into ethereum-optimism:develop Mar 2, 2022
@cfromknecht cfromknecht deleted the teleportr-service branch March 2, 2022 23:20
theochap pushed a commit that referenced this pull request Dec 10, 2025
## Overview

Small cleanup to the `RollupNodeService::start` function.

---------

Co-authored-by: refcell <abigger87@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-ci Meta: ci related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants