Commit 7dc259c0 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2233 from cfromknecht/teleportr-service

feat: add Teleportr service
parents c1619de1 2910a3c5
---
'@eth-optimism/batch-submitter-service': patch
---
Move L2 dial logic out of bss-core to avoid l2geth dependency
......@@ -10,8 +10,8 @@ on:
- '*rc'
- 'regenesis/*'
pull_request:
paths:
- 'go/teleportr/**'
branches:
- '*'
workflow_dispatch:
defaults:
......@@ -25,8 +25,8 @@ jobs:
postgres:
image: postgres
env:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- 5432:5432
steps:
......
......@@ -20,7 +20,7 @@ packages/contracts/hardhat*
packages/data-transport-layer/db
# vim
*.swp
*.sw*
.env
.env*
......
......@@ -93,7 +93,7 @@ func Main(gitVersion string) func(ctx *cli.Context) error {
return err
}
l2Client, err := dial.L2EthClientWithTimeout(ctx, cfg.L2EthRpc, cfg.DisableHTTP2)
l2Client, err := DialL2EthClientWithTimeout(ctx, cfg.L2EthRpc, cfg.DisableHTTP2)
if err != nil {
return err
}
......
package dial
package batchsubmitter
import (
"context"
......@@ -6,18 +6,19 @@ import (
"net/http"
"strings"
"github.com/ethereum-optimism/optimism/go/bss-core/dial"
"github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum-optimism/optimism/l2geth/log"
"github.com/ethereum-optimism/optimism/l2geth/rpc"
)
// L2EthClientWithTimeout attempts to dial the L2 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// DialL2EthClientWithTimeout attempts to dial the L2 provider using the
// 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) (
*ethclient.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
ctxt, cancel := context.WithTimeout(ctx, dial.DefaultTimeout)
defer cancel()
if strings.HasPrefix(url, "http") {
......
......@@ -3,7 +3,7 @@ package dial
import "time"
const (
// defaultDialTimeout is default duration the service will wait on
// startup to make a connection to either the L1 or L2 backends.
defaultDialTimeout = 5 * time.Second
// DefaultTimeout is default duration the service will wait on startup to
// make a connection to either the L1 or L2 backends.
DefaultTimeout = 5 * time.Second
)
......@@ -12,12 +12,12 @@ import (
)
// L1EthClientWithTimeout attempts to dial the L1 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// provided URL. If the dial doesn't complete within DefaultTimeout seconds,
// this method will return an error.
func L1EthClientWithTimeout(ctx context.Context, url string, disableHTTP2 bool) (
*ethclient.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
ctxt, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()
if strings.HasPrefix(url, "http") {
......
......@@ -3,13 +3,11 @@ module github.com/ethereum-optimism/optimism/go/bss-core
go 1.16
require (
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.0.0
github.com/ethereum-optimism/optimism/l2geth v1.0.0
github.com/ethereum/go-ethereum v1.10.12
github.com/getsentry/sentry-go v0.11.0
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef
)
replace github.com/ethereum-optimism/optimism/l2geth => ../../l2geth
This diff is collapsed.
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITVERSION := $(shell cat package.json | jq .version)
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X main.GitVersion=$(GITVERSION)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"
DEPOSIT_ARTIFACT := ../../packages/contracts/artifacts/contracts/L1/teleportr/TeleportrDeposit.sol/TeleportrDeposit.json
DISBURSER_ARTIFACT := ../../packages/contracts/artifacts/contracts/L2/teleportr/TeleportrDisburser.sol/TeleportrDisburser.json
teleportr:
env GO111MODULE=on go build -v $(LDFLAGS) ./cmd/teleportr
clean:
rm teleportr
test:
go test -v ./...
lint:
golangci-lint run ./...
bindings: bindings-deposit bindings-disburser
bindings-deposit:
$(eval temp := $(shell mktemp))
cat $(DEPOSIT_ARTIFACT) | jq -r .bytecode > $(temp)
cat $(DEPOSIT_ARTIFACT) | jq .abi | \
abigen \
--pkg deposit \
--abi - \
--out bindings/deposit/teleportr_deposit.go \
--type TeleportrDeposit \
--bin $(temp)
bindings-disburser:
$(eval temp := $(shell mktemp))
cat $(DISBURSER_ARTIFACT) | jq -r .bytecode > $(temp)
cat $(DISBURSER_ARTIFACT) | jq .abi | \
abigen \
--pkg disburse \
--abi - \
--out bindings/disburse/teleportr_disburser.go \
--type TeleportrDisburser \
--bin $(temp)
.PHONY: \
teleportr \
bindings \
bindings-deposit \
bindings-disburser \
clean \
test \
lint
This diff is collapsed.
This diff is collapsed.
package main
import (
"fmt"
"os"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"
"github.com/ethereum-optimism/optimism/go/teleportr"
"github.com/ethereum-optimism/optimism/go/teleportr/flags"
)
var (
GitVersion = ""
GitCommit = ""
GitDate = ""
)
func main() {
// Set up logger with a default INFO level in case we fail to parse flags.
// Otherwise the final critical log won't show what the parsing error was.
log.Root().SetHandler(
log.LvlFilterHandler(
log.LvlInfo,
log.StreamHandler(os.Stdout, log.TerminalFormat(true)),
),
)
app := cli.NewApp()
app.Flags = flags.Flags
app.Version = fmt.Sprintf("%s-%s-%s", GitVersion, GitCommit, GitDate)
app.Name = "teleportr"
app.Usage = "Teleportr"
app.Description = "Teleportr bridge from L1 to L2"
app.Action = teleportr.Main(GitVersion)
err := app.Run(os.Args)
if err != nil {
log.Crit("Application failed", "message", err)
}
}
package teleportr
import (
"time"
"github.com/ethereum-optimism/optimism/go/teleportr/flags"
"github.com/urfave/cli"
)
type Config struct {
/* Required Params */
// BuildEnv identifies the environment this binary is intended for, i.e.
// production, development, etc.
BuildEnv string
// EthNetworkName identifies the intended Ethereum network.
EthNetworkName string
// L1EthRpc is the HTTP provider URL for L1.
L1EthRpc string
// L2EthRpc is the HTTP provider URL for L1.
L2EthRpc string
// DepositAddress is the TeleportrDeposit contract adddress.
DepositAddress string
// DepositDeployBlockNumber is the deployment block number of the
// TeleportrDeposit contract.
DepositDeployBlockNumber uint64
// FilterQueryMaxBlocks is the maximum range of a filter query in blocks.
FilterQueryMaxBlocks uint64
// DisburserAddress is the TeleportrDisburser contract address.
DisburserAddress string
// MaxL2TxSize is the maximum size in bytes of any L2 transactions generated
// for teleportr disbursements.
MaxL2TxSize uint64
// NumDepositConfirmations is the number of confirmations required before a
// deposit is considered confirmed.
NumDepositConfirmations uint64
// PollInterval is the delay between querying L2 for more transaction
// and creating a new batch.
PollInterval time.Duration
// SafeAbortNonceTooLowCount is the number of ErrNonceTooLowObservations
// required to give up on a tx at a particular nonce without receiving
// confirmation.
SafeAbortNonceTooLowCount uint64
// ResubmissionTimeout is time we will wait before resubmitting a
// transaction.
ResubmissionTimeout time.Duration
// PostgresHost is the host of the teleportr postgres instance.
PostgresHost string
// PostgresPort is the port of the teleportr postgres instance.
PostgresPort uint16
// PostgresUser is the username for the teleportr postgres instance.
PostgresUser string
// PostgresPassword is the password for the teleportr postgres instance.
PostgresPassword string
// PostgresDBName is the database name of the teleportr postgres instance.
PostgresDBName string
// PostgresEnableSSL determines whether or not to enable SSL on connections
// to the teleportr postgres instance.
PostgresEnableSSL bool
/* Optional Params */
// LogLevel is the lowest log level that will be output.
LogLevel string
// LogTerminal if true, prints to stdout in terminal format, otherwise
// prints using JSON. If SentryEnable is true this flag is ignored, and logs
// are printed using JSON.
LogTerminal bool
// DisburserPrivKey the private key of the wallet used to submit
// transactions to the TeleportrDisburser contract.
DisburserPrivKey string
// Mnemonic is the HD seed used to derive the wallet private key for
// submitting to the TeleportrDisburser. Must be used in conjunction with
// DisburserHDPath.
Mnemonic string
// DisburserHDPath is the derivation path used to obtain the private key for
// the disburser transactions.
DisburserHDPath string
// MetricsServerEnable if true, will create a metrics client and log to
// Prometheus.
MetricsServerEnable bool
// MetricsHostname is the hostname at which the metrics server is running.
MetricsHostname string
// MetricsPort is the port at which the metrics server is running.
MetricsPort uint64
// DisableHTTP2 disables HTTP2 support.
DisableHTTP2 bool
}
func NewConfig(ctx *cli.Context) (Config, error) {
return Config{
/* Required Flags */
BuildEnv: ctx.GlobalString(flags.BuildEnvFlag.Name),
EthNetworkName: ctx.GlobalString(flags.EthNetworkNameFlag.Name),
L1EthRpc: ctx.GlobalString(flags.L1EthRpcFlag.Name),
L2EthRpc: ctx.GlobalString(flags.L2EthRpcFlag.Name),
DepositAddress: ctx.GlobalString(flags.DepositAddressFlag.Name),
DepositDeployBlockNumber: ctx.GlobalUint64(flags.DepositDeployBlockNumberFlag.Name),
DisburserAddress: ctx.GlobalString(flags.DisburserAddressFlag.Name),
MaxL2TxSize: ctx.GlobalUint64(flags.MaxL2TxSizeFlag.Name),
NumDepositConfirmations: ctx.GlobalUint64(flags.NumDepositConfirmationsFlag.Name),
FilterQueryMaxBlocks: ctx.GlobalUint64(flags.FilterQueryMaxBlocksFlag.Name),
PollInterval: ctx.GlobalDuration(flags.PollIntervalFlag.Name),
SafeAbortNonceTooLowCount: ctx.GlobalUint64(flags.SafeAbortNonceTooLowCountFlag.Name),
ResubmissionTimeout: ctx.GlobalDuration(flags.ResubmissionTimeoutFlag.Name),
PostgresHost: ctx.GlobalString(flags.PostgresHostFlag.Name),
PostgresPort: uint16(ctx.GlobalUint64(flags.PostgresPortFlag.Name)),
PostgresUser: ctx.GlobalString(flags.PostgresUserFlag.Name),
PostgresPassword: ctx.GlobalString(flags.PostgresPasswordFlag.Name),
PostgresDBName: ctx.GlobalString(flags.PostgresDBNameFlag.Name),
PostgresEnableSSL: ctx.GlobalBool(flags.PostgresEnableSSLFlag.Name),
/* Optional flags */
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
DisburserPrivKey: ctx.GlobalString(flags.DisburserPrivateKeyFlag.Name),
Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name),
DisburserHDPath: ctx.GlobalString(flags.DisburserHDPathFlag.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name),
MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name),
DisableHTTP2: ctx.GlobalBool(flags.HTTP2DisableFlag.Name),
}, nil
}
......@@ -24,9 +24,9 @@ var (
// Deposit represents an event emitted from the TeleportrDeposit contract on L1,
// along with additional info about the tx that generated the event.
type Deposit struct {
ID int64
ID uint64
TxnHash common.Hash
BlockNumber int64
BlockNumber uint64
BlockTimestamp time.Time
Address common.Address
Amount *big.Int
......@@ -35,16 +35,17 @@ type Deposit struct {
// ConfirmationInfo holds metadata about a tx on either the L1 or L2 chain.
type ConfirmationInfo struct {
TxnHash common.Hash
BlockNumber int64
BlockNumber uint64
BlockTimestamp time.Time
}
// CompletedTeleport represents an L1 deposit that has been disbursed on L2. The
// struct also hold info about the L1 and L2 txns involved.
type CompletedTeleport struct {
ID int64
ID uint64
Address common.Address
Amount *big.Int
Success bool
Deposit ConfirmationInfo
Disbursement ConfirmationInfo
}
......@@ -65,13 +66,32 @@ CREATE TABLE IF NOT EXISTS disbursements (
id INT8 NOT NULL PRIMARY KEY REFERENCES deposits(id),
txn_hash VARCHAR NOT NULL,
block_number INT8 NOT NULL,
block_timestamp TIMESTAMPTZ NOT NULL
block_timestamp TIMESTAMPTZ NOT NULL,
success BOOL NOT NULL
);
`
const lastProcessedBlockTable = `
CREATE TABLE IF NOT EXISTS last_processed_block (
id BOOL PRIMARY KEY DEFAULT TRUE,
value INT8 NOT NULL,
CONSTRAINT id CHECK (id)
);
`
const pendingTxTable = `
CREATE TABLE IF NOT EXISTS pending_txs (
txn_hash VARCHAR NOT NULL PRIMARY KEY,
start_id INT8 NOT NULL,
end_id INT8 NOT NULL
);
`
var migrations = []string{
createDepositsTable,
createDisbursementsTable,
lastProcessedBlockTable,
pendingTxTable,
}
// Config houses the data required to connect to a Postgres backend.
......@@ -155,6 +175,13 @@ func (d *Database) Close() error {
return d.conn.Close()
}
const upsertLastProcessedBlock = `
INSERT INTO last_processed_block (value)
VALUES ($1)
ON CONFLICT (id) DO UPDATE
SET value = $1
`
const upsertDepositStatement = `
INSERT INTO deposits (id, txn_hash, block_number, block_timestamp, address, amount)
VALUES ($1, $2, $3, $4, $5, $6)
......@@ -164,10 +191,10 @@ SET (txn_hash, block_number, block_timestamp, address, amount) = ($2, $3, $4, $5
// UpsertDeposits inserts a list of deposits into the database, or updats an
// existing deposit in place if the same ID is found.
func (d *Database) UpsertDeposits(deposits []Deposit) error {
if len(deposits) == 0 {
return nil
}
func (d *Database) UpsertDeposits(
deposits []Deposit,
lastProcessedBlock uint64,
) error {
// Sanity check deposits.
for _, deposit := range deposits {
......@@ -185,7 +212,6 @@ func (d *Database) UpsertDeposits(deposits []Deposit) error {
}()
for _, deposit := range deposits {
_, err = tx.Exec(
upsertDepositStatement,
deposit.ID,
......@@ -200,29 +226,30 @@ func (d *Database) UpsertDeposits(deposits []Deposit) error {
}
}
_, err = tx.Exec(upsertLastProcessedBlock, lastProcessedBlock)
if err != nil {
return err
}
return tx.Commit()
}
const latestDepositQuery = `
SELECT block_number FROM deposits
ORDER BY block_number DESC
LIMIT 1
const lastProcessedBlockQuery = `
SELECT value FROM last_processed_block
`
// LatestDeposit returns the block number of the latest deposit known to the
// database.
func (d *Database) LatestDeposit() (*int64, error) {
row := d.conn.QueryRow(latestDepositQuery)
func (d *Database) LastProcessedBlock() (*uint64, error) {
row := d.conn.QueryRow(lastProcessedBlockQuery)
var latestTransfer int64
err := row.Scan(&latestTransfer)
var lastProcessedBlock uint64
err := row.Scan(&lastProcessedBlock)
if err == sql.ErrNoRows {
return nil, nil
} else if err != nil {
return nil, err
}
return &latestTransfer, nil
return &lastProcessedBlock, nil
}
const confirmedDepositsQuery = `
......@@ -235,7 +262,7 @@ ORDER BY dep.id ASC
// ConfirmedDeposits returns the set of all deposits that have sufficient
// confirmation, but do not have a recorded disbursement.
func (d *Database) ConfirmedDeposits(blockNumber, confirmations int64) ([]Deposit, error) {
func (d *Database) ConfirmedDeposits(blockNumber, confirmations uint64) ([]Deposit, error) {
rows, err := d.conn.Query(confirmedDepositsQuery, confirmations, blockNumber)
if err != nil {
return nil, err
......@@ -277,20 +304,43 @@ func (d *Database) ConfirmedDeposits(blockNumber, confirmations int64) ([]Deposi
return deposits, nil
}
const latestDisbursementIDQuery = `
SELECT id FROM disbursements
ORDER BY id DESC
LIMIT 1
`
// LatestDisbursementID returns the latest deposit id known to the database that
// has a recorded disbursement.
func (d *Database) LatestDisbursementID() (*uint64, error) {
row := d.conn.QueryRow(latestDisbursementIDQuery)
var latestDisbursementID uint64
err := row.Scan(&latestDisbursementID)
if err == sql.ErrNoRows {
return nil, nil
} else if err != nil {
return nil, err
}
return &latestDisbursementID, nil
}
const markDisbursedStatement = `
INSERT INTO disbursements (id, txn_hash, block_number, block_timestamp)
VALUES ($1, $2, $3, $4)
INSERT INTO disbursements (id, txn_hash, block_number, block_timestamp, success)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (id) DO UPDATE
SET (txn_hash, block_number, block_timestamp) = ($2, $3, $4)
SET (txn_hash, block_number, block_timestamp, success) = ($2, $3, $4, $5)
`
// UpsertDisbursement inserts a disbursement, or updates an existing record
// in-place if the ID already exists.
func (d *Database) UpsertDisbursement(
id int64,
id uint64,
txnHash common.Hash,
blockNumber int64,
blockNumber uint64,
blockTimestamp time.Time,
success bool,
) error {
if blockTimestamp.IsZero() {
return ErrZeroTimestamp
......@@ -302,6 +352,7 @@ func (d *Database) UpsertDisbursement(
txnHash.String(),
blockNumber,
blockTimestamp,
success,
)
if err != nil {
if strings.Contains(err.Error(), "violates foreign key constraint") {
......@@ -322,7 +373,7 @@ func (d *Database) UpsertDisbursement(
const completedTeleportsQuery = `
SELECT
dep.id, dep.address, dep.amount,
dep.id, dep.address, dep.amount, dis.success,
dep.txn_hash, dep.block_number, dep.block_timestamp,
dis.txn_hash, dis.block_number, dis.block_timestamp
FROM deposits AS dep, disbursements AS dis
......@@ -350,6 +401,7 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
&teleport.ID,
&addressStr,
&amountStr,
&teleport.Success,
&depTxnHashStr,
&teleport.Deposit.BlockNumber,
&teleport.Deposit.BlockTimestamp,
......@@ -379,3 +431,88 @@ func (d *Database) CompletedTeleports() ([]CompletedTeleport, error) {
return teleports, nil
}
// PendingTx encapsulates the metadata stored about published disbursement txs.
type PendingTx struct {
// Txhash is the tx hash of the disbursement tx.
TxHash common.Hash
// StartID is the deposit id of the first disbursement, inclusive.
StartID uint64
// EndID is the deposit id fo the last disbursement, exclusive.
EndID uint64
}
const upsertPendingTxStatement = `
INSERT INTO pending_txs (txn_hash, start_id, end_id)
VALUES ($1, $2, $3)
ON CONFLICT (txn_hash) DO UPDATE
SET (start_id, end_id) = ($2, $3)
`
// UpsertPendingTx inserts a disbursement, or updates the entry if the TxHash
// already exists.
func (d *Database) UpsertPendingTx(pendingTx PendingTx) error {
_, err := d.conn.Exec(
upsertPendingTxStatement,
pendingTx.TxHash.String(),
pendingTx.StartID,
pendingTx.EndID,
)
return err
}
const listPendingTxsQuery = `
SELECT txn_hash, start_id, end_id
FROM pending_txs
ORDER BY start_id DESC, end_id DESC, txn_hash ASC
`
// ListPendingTxs returns all pending txs stored in the database.
func (d *Database) ListPendingTxs() ([]PendingTx, error) {
rows, err := d.conn.Query(listPendingTxsQuery)
if err != nil {
return nil, err
}
defer rows.Close()
var pendingTxs []PendingTx
for rows.Next() {
var pendingTx PendingTx
var txHashStr string
err = rows.Scan(
&txHashStr,
&pendingTx.StartID,
&pendingTx.EndID,
)
if err != nil {
return nil, err
}
pendingTx.TxHash = common.HexToHash(txHashStr)
pendingTxs = append(pendingTxs, pendingTx)
}
if err := rows.Err(); err != nil {
return nil, err
}
return pendingTxs, nil
}
const deletePendingTxsStatement = `
DELETE FROM pending_txs
WHERE start_id = $1 AND end_id = $2
`
// DeletePendingTx removes any pending txs with matching start and end ids. This
// allows the caller to remove any logically-conflicting pending txs from the
// database after successfully processing the outcomes.
func (d *Database) DeletePendingTx(startID, endID uint64) error {
_, err := d.conn.Exec(
deletePendingTxsStatement,
startID,
endID,
)
return err
}
This diff is collapsed.
This diff is collapsed.
package disburser
// FilterStartBlockNumberParams holds the arguments passed to
// FindFilterStartBlockNumber.
type FilterStartBlockNumberParams struct {
// BlockNumber the current block height of the chain.
BlockNumber uint64
// NumConfirmations is the number of confirmations required to consider a
// block final.
NumConfirmations uint64
// DeployBlockNumber is the deployment height of the Deposit contract.
DeployBlockNumber uint64
// LastProcessedBlockNumber is the height of the last processed block.
//
// NOTE: This will be nil on the first invocation, before blocks have been
// ingested.
LastProcessedBlockNumber *uint64
}
func (p *FilterStartBlockNumberParams) unconfirmed(blockNumber uint64) bool {
return p.BlockNumber+1 < blockNumber+p.NumConfirmations
}
// FindFilterStartBlockNumber returns the block height from which to begin
// filtering logs based on the relative heights of the chain, the contract
// deployment, and the last block that was processed.
func FindFilterStartBlockNumber(params FilterStartBlockNumberParams) uint64 {
// On initilization, always start at the deploy height.
if params.LastProcessedBlockNumber == nil {
return params.DeployBlockNumber
}
// If the deployment height has not exited the confirmation window, we can
// still begin our search from the deployment height.
if params.unconfirmed(params.DeployBlockNumber) {
return params.DeployBlockNumber
}
// Otherwise, start from the block immediately following the last processed
// block. If that height is still hasn't fully confirmed, we'll use the
// height of the last confirmed block.
var filterStartBlockNumber = *params.LastProcessedBlockNumber + 1
if params.unconfirmed(filterStartBlockNumber) {
filterStartBlockNumber = params.BlockNumber + 1 - params.NumConfirmations
}
return filterStartBlockNumber
}
package disburser_test
import (
"testing"
"github.com/ethereum-optimism/optimism/go/teleportr/drivers/disburser"
"github.com/stretchr/testify/require"
)
func uint64Ptr(x uint64) *uint64 {
return &x
}
type filterStartBlockNumberTestCase struct {
name string
params disburser.FilterStartBlockNumberParams
expStartBlockNumber uint64
}
// TestFindFilterStartBlockNumber exhaustively tests the behavior of
// FindFilterStartBlockNumber and its edge cases.
func TestFindFilterStartBlockNumber(t *testing.T) {
tests := []filterStartBlockNumberTestCase{
// Deploy number should be returned if LastProcessedBlockNumber is nil.
{
name: "init returns deploy block number",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 10,
NumConfirmations: 5,
DeployBlockNumber: 42,
LastProcessedBlockNumber: nil,
},
expStartBlockNumber: 42,
},
// Deploy number should be returned if the deploy number is still in our
// confirmation window.
{
name: "conf lookback before deploy number",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 43,
NumConfirmations: 5,
DeployBlockNumber: 42,
LastProcessedBlockNumber: uint64Ptr(43),
},
expStartBlockNumber: 42,
},
// Deploy number should be returned if the deploy number is still in our
// confirmation window.
{
name: "conf lookback before deploy number",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 43,
NumConfirmations: 44,
DeployBlockNumber: 42,
LastProcessedBlockNumber: uint64Ptr(43),
},
expStartBlockNumber: 42,
},
// If our confirmation window is ahead of the last deposit + 1, expect
// last deposit + 1.
{
name: "conf lookback gt last deposit plus one",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 100,
NumConfirmations: 5,
DeployBlockNumber: 42,
LastProcessedBlockNumber: uint64Ptr(43),
},
expStartBlockNumber: 44,
},
// If our confirmation window is equal to last deposit + 1, expect last
// deposit + 1.
{
name: "conf lookback eq last deposit plus one",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 48,
NumConfirmations: 5,
DeployBlockNumber: 42,
LastProcessedBlockNumber: uint64Ptr(43),
},
expStartBlockNumber: 44,
},
// If our confirmation window starts before last deposit + 1, expect
// block number - num confs + 1.
{
name: "conf lookback lt last deposit plus one",
params: disburser.FilterStartBlockNumberParams{
BlockNumber: 47,
NumConfirmations: 5,
DeployBlockNumber: 42,
LastProcessedBlockNumber: uint64Ptr(43),
},
expStartBlockNumber: 43,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
testFindFilterStartBlockNumber(t, test)
})
}
}
func testFindFilterStartBlockNumber(
t *testing.T,
test filterStartBlockNumberTestCase,
) {
startBlockNumber := disburser.FindFilterStartBlockNumber(test.params)
require.Equal(t, test.expStartBlockNumber, startBlockNumber)
}
package disburser
import (
"github.com/ethereum-optimism/optimism/go/bss-core/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const methodLabel = "method"
var (
// DBMethodUpsertDeposits is a label for UpsertDeposits db method.
DBMethodUpsertDeposits = prometheus.Labels{methodLabel: "upsert_deposits"}
// DBMethodConfirmedDeposits is a label for ConfirmedDeposits db method.
DBMethodConfirmedDeposits = prometheus.Labels{methodLabel: "confirmed_deposits"}
// DBMethodLastProcessedBlock is a label for LastProcessedBlock db method.
DBMethodLastProcessedBlock = prometheus.Labels{methodLabel: "last_processed_block"}
// DBMethodUpsertPendingTx is a label for UpsertPendingTx db method.
DBMethodUpsertPendingTx = prometheus.Labels{methodLabel: "upsert_pending_tx"}
// DBMethodListPendingTxs is a label for ListPendingTxs db method.
DBMethodListPendingTxs = prometheus.Labels{methodLabel: "list_pending_txs"}
// DBMethodUpsertDisbursement is a label for UpsertDisbursement db method.
DBMethodUpsertDisbursement = prometheus.Labels{methodLabel: "upsert_disbursement"}
// DBMethodLatestDisbursementID is a label for LatestDisbursementID db method.
DBMethodLatestDisbursementID = prometheus.Labels{methodLabel: "latest_disbursement_id"}
// DBMethodDeletePendingTx is a label for DeletePendingTx db method.
DBMethodDeletePendingTx = prometheus.Labels{methodLabel: "delete_pending_tx"}
)
// Metrics extends the BSS core metrics with additional metrics tracked by the
// sequencer driver.
type Metrics struct {
*metrics.Base
// FailedDatabaseMethods tracks the number of database failures for each
// known database method.
FailedDatabaseMethods *prometheus.GaugeVec
// DepositIDMismatch tracks whether or not our database is in sync with the
// disrburser contract. 1 means in sync, 0 means out of sync.
DepositIDMismatch prometheus.Gauge
// MissingDisbursements tracks the number of deposits that are missing
// disbursement below our supposed next deposit id.
MissingDisbursements prometheus.Gauge
// SuccessfulDisbursements tracks the number of disbursements that emit a
// success event from a given tx.
SuccessfulDisbursements prometheus.Gauge
// FailedDisbursements tracks the number of disbursements that emit a failed
// event from a given tx.
FailedDisbursements prometheus.Gauge
// PostgresLastDisbursedID tracks the latest disbursement id in postgres.
PostgresLastDisbursedID prometheus.Gauge
// ContractNextDisbursementID tracks the next disbursement id expected by
// the disburser contract.
ContractNextDisbursementID prometheus.Gauge
}
// NewMetrics initializes a new, extended metrics object.
func NewMetrics(subsystem string) *Metrics {
base := metrics.NewBase(subsystem, "")
return &Metrics{
Base: base,
FailedDatabaseMethods: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "failed_database_operations",
Help: "Tracks the number of database failures",
Subsystem: base.SubsystemName(),
}, []string{methodLabel}),
DepositIDMismatch: promauto.NewGauge(prometheus.GaugeOpts{
Name: "deposit_id_mismatch",
Help: "Set to 1 when the postgres and the disrburser contract " +
"disagree on the next deposit id, and 0 otherwise",
Subsystem: base.SubsystemName(),
}),
MissingDisbursements: promauto.NewGauge(prometheus.GaugeOpts{
Name: "missing_disbursements",
Help: "Number of deposits that are missing disbursements in " +
"postgres below our supposed next deposit id",
Subsystem: base.SubsystemName(),
}),
SuccessfulDisbursements: promauto.NewGauge(prometheus.GaugeOpts{
Name: "successful_disbursements",
Help: "Number of disbursements that emit a success event " +
"from a given tx",
Subsystem: base.SubsystemName(),
}),
FailedDisbursements: promauto.NewGauge(prometheus.GaugeOpts{
Name: "failed_disbursements",
Help: "Number of disbursements that emit a failed event " +
"from a given tx",
Subsystem: base.SubsystemName(),
}),
PostgresLastDisbursedID: promauto.NewGauge(prometheus.GaugeOpts{
Name: "postgres_last_disbursed_id",
Help: "Latest recorded disbursement id in postgres",
Subsystem: base.SubsystemName(),
}),
ContractNextDisbursementID: promauto.NewGauge(prometheus.GaugeOpts{
Name: "contract_next_disbursement_id",
Help: "Next disbursement id expected by the disburser contract",
Subsystem: base.SubsystemName(),
}),
}
}
package flags
import "github.com/urfave/cli"
const envVarPrefix = "TELEPORTR_"
func prefixEnvVar(name string) string {
return envVarPrefix + name
}
var (
/* Required Flags */
BuildEnvFlag = cli.StringFlag{
Name: "build-env",
Usage: "Build environment for which the binary is produced, " +
"e.g. production or development",
Required: true,
EnvVar: "BUILD_ENV",
}
EthNetworkNameFlag = cli.StringFlag{
Name: "eth-network-name",
Usage: "Ethereum network name",
Required: true,
EnvVar: "ETH_NETWORK_NAME",
}
L1EthRpcFlag = cli.StringFlag{
Name: "l1-eth-rpc",
Usage: "HTTP provider URL for L1",
Required: true,
EnvVar: "L1_ETH_RPC",
}
L2EthRpcFlag = cli.StringFlag{
Name: "l2-eth-rpc",
Usage: "HTTP provider URL for L2",
Required: true,
EnvVar: "L2_ETH_RPC",
}
DepositAddressFlag = cli.StringFlag{
Name: "deposit-address",
Usage: "Address of the TeleportrDeposit contract",
Required: true,
EnvVar: prefixEnvVar("DEPOSIT_ADDRESS"),
}
DepositDeployBlockNumberFlag = cli.Uint64Flag{
Name: "deposit-deploy-block-number",
Usage: "Deployment block number of the TeleportrDeposit contract",
Required: true,
EnvVar: prefixEnvVar("DEPOSIT_DEPLOY_BLOCK_NUMBER"),
}
DisburserAddressFlag = cli.StringFlag{
Name: "disburser-address",
Usage: "Address of the TeleportrDisburser contract",
Required: true,
EnvVar: prefixEnvVar("DISBURSER_ADDRESS"),
}
MaxL2TxSizeFlag = cli.Uint64Flag{
Name: "max-l2-tx-size",
Usage: "Maximum size in bytes of any L2 transaction that gets " +
"sent for disbursement",
Required: true,
EnvVar: prefixEnvVar("MAX_L2_TX_SIZE"),
}
NumDepositConfirmationsFlag = cli.Uint64Flag{
Name: "num-deposit-confirmations",
Usage: "Number of confirmations before deposits are considered " +
"confirmed",
Required: true,
EnvVar: prefixEnvVar("NUM_DEPOSIT_CONFIRMATIONS"),
}
FilterQueryMaxBlocksFlag = cli.Uint64Flag{
Name: "filter-query-max-blocks",
Usage: "Maximum range of a filter query in blocks",
Required: true,
EnvVar: prefixEnvVar("FILTER_QUERY_MAX_BLOCKS"),
}
PollIntervalFlag = cli.DurationFlag{
Name: "poll-interval",
Usage: "Delay between querying L1 for more transactions and " +
"creating a new disbursement batch",
Required: true,
EnvVar: prefixEnvVar("POLL_INTERVAL"),
}
SafeAbortNonceTooLowCountFlag = cli.Uint64Flag{
Name: "safe-abort-nonce-too-low-count",
Usage: "Number of ErrNonceTooLow observations required to " +
"give up on a tx at a particular nonce without receiving " +
"confirmation",
Required: true,
EnvVar: prefixEnvVar("SAFE_ABORT_NONCE_TOO_LOW_COUNT"),
}
ResubmissionTimeoutFlag = cli.DurationFlag{
Name: "resubmission-timeout",
Usage: "Duration we will wait before resubmitting a " +
"transaction to L2",
Required: true,
EnvVar: prefixEnvVar("RESUBMISSION_TIMEOUT"),
}
PostgresHostFlag = cli.StringFlag{
Name: "postgres-host",
Usage: "Host of the teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_HOST"),
}
PostgresPortFlag = cli.Uint64Flag{
Name: "postgres-port",
Usage: "Port of the teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_PORT"),
}
PostgresUserFlag = cli.StringFlag{
Name: "postgres-user",
Usage: "Username of the teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_USER"),
}
PostgresPasswordFlag = cli.StringFlag{
Name: "postgres-password",
Usage: "Password of the teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_PASSWORD"),
}
PostgresDBNameFlag = cli.StringFlag{
Name: "postgres-db-name",
Usage: "Database name of the teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_DB_NAME"),
}
PostgresEnableSSLFlag = cli.BoolFlag{
Name: "postgres-enable-ssl",
Usage: "Whether or not to enable SSL on connections to " +
"teleportr postgres instance",
Required: true,
EnvVar: prefixEnvVar("POSTGRES_ENABLE_SSL"),
}
/* Optional Flags */
LogLevelFlag = cli.StringFlag{
Name: "log-level",
Usage: "The lowest log level that will be output",
Value: "info",
EnvVar: prefixEnvVar("LOG_LEVEL"),
}
LogTerminalFlag = cli.BoolFlag{
Name: "log-terminal",
Usage: "If true, outputs logs in terminal format, otherwise prints " +
"in JSON format. If SENTRY_ENABLE is set to true, this flag is " +
"ignored and logs are printed using JSON",
EnvVar: prefixEnvVar("LOG_TERMINAL"),
}
DisburserPrivateKeyFlag = cli.StringFlag{
Name: "disburser-private-key",
Usage: "The private key to use for sending to the disburser contract",
EnvVar: prefixEnvVar("DISBURSER_PRIVATE_KEY"),
}
MnemonicFlag = cli.StringFlag{
Name: "mnemonic",
Usage: "The mnemonic used to derive the wallet for the disburser",
EnvVar: prefixEnvVar("MNEMONIC"),
}
DisburserHDPathFlag = cli.StringFlag{
Name: "disburser-hd-path",
Usage: "The HD path used to derive the disburser wallet from the " +
"mnemonic. The mnemonic flag must also be set.",
EnvVar: prefixEnvVar("DISBURSER_HD_PATH"),
}
MetricsServerEnableFlag = cli.BoolFlag{
Name: "metrics-server-enable",
Usage: "Whether or not to run the embedded metrics server",
EnvVar: prefixEnvVar("METRICS_SERVER_ENABLE"),
}
MetricsHostnameFlag = cli.StringFlag{
Name: "metrics-hostname",
Usage: "The hostname of the metrics server",
Value: "127.0.0.1",
EnvVar: prefixEnvVar("METRICS_HOSTNAME"),
}
MetricsPortFlag = cli.Uint64Flag{
Name: "metrics-port",
Usage: "The port of the metrics server",
Value: 7300,
EnvVar: prefixEnvVar("METRICS_PORT"),
}
HTTP2DisableFlag = cli.BoolFlag{
Name: "http2-disable",
Usage: "Whether or not to disable HTTP/2 support.",
EnvVar: prefixEnvVar("HTTP2_DISABLE"),
}
)
var requiredFlags = []cli.Flag{
BuildEnvFlag,
EthNetworkNameFlag,
L1EthRpcFlag,
L2EthRpcFlag,
DepositAddressFlag,
DepositDeployBlockNumberFlag,
DisburserAddressFlag,
MaxL2TxSizeFlag,
NumDepositConfirmationsFlag,
FilterQueryMaxBlocksFlag,
PollIntervalFlag,
SafeAbortNonceTooLowCountFlag,
ResubmissionTimeoutFlag,
PostgresHostFlag,
PostgresPortFlag,
PostgresUserFlag,
PostgresPasswordFlag,
PostgresDBNameFlag,
PostgresEnableSSLFlag,
}
var optionalFlags = []cli.Flag{
LogLevelFlag,
LogTerminalFlag,
DisburserPrivateKeyFlag,
MnemonicFlag,
DisburserHDPathFlag,
MetricsServerEnableFlag,
MetricsHostnameFlag,
MetricsPortFlag,
HTTP2DisableFlag,
}
// Flags contains the list of configuration options available to the binary.
var Flags = append(requiredFlags, optionalFlags...)
package flags
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/urfave/cli"
)
// TestRequiredFlagsSetRequired asserts that all flags deemed required properly
// have the Required field set to true.
func TestRequiredFlagsSetRequired(t *testing.T) {
for _, flag := range requiredFlags {
reqFlag, ok := flag.(cli.RequiredFlag)
require.True(t, ok)
require.True(t, reqFlag.IsRequired())
}
}
// TestOptionalFlagsDontSetRequired asserts that all flags deemed optional set
// the Required field to false.
func TestOptionalFlagsDontSetRequired(t *testing.T) {
for _, flag := range optionalFlags {
reqFlag, ok := flag.(cli.RequiredFlag)
require.True(t, ok)
require.False(t, reqFlag.IsRequired())
}
}
......@@ -3,16 +3,60 @@ module github.com/ethereum-optimism/optimism/go/teleportr
go 1.17
require (
github.com/ethereum-optimism/optimism/go/bss-core v0.0.0-20220218171106-67a0414d7606
github.com/ethereum/go-ethereum v1.10.15
github.com/google/uuid v1.3.0
github.com/lib/pq v1.10.4
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.5
)
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect
github.com/decred/base58 v1.0.3 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/crypto/ripemd160 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0 // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.0.0 // indirect
github.com/getsentry/sentry-go v0.11.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
replace github.com/ethereum-optimism/optimism/go/bss-core => ../bss-core
This diff is collapsed.
{
"name": "@eth-optimism/teleportr",
"version": "0.0.0",
"private": true,
"devDependencies": {}
}
package teleportr
import (
"context"
"os"
"os/signal"
"syscall"
"time"
bsscore "github.com/ethereum-optimism/optimism/go/bss-core"
"github.com/ethereum-optimism/optimism/go/bss-core/dial"
"github.com/ethereum-optimism/optimism/go/bss-core/metrics"
"github.com/ethereum-optimism/optimism/go/bss-core/txmgr"
"github.com/ethereum-optimism/optimism/go/teleportr/db"
"github.com/ethereum-optimism/optimism/go/teleportr/drivers/disburser"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"
)
func Main(gitVersion string) func(ctx *cli.Context) error {
return func(cliCtx *cli.Context) error {
cfg, err := NewConfig(cliCtx)
if err != nil {
return err
}
log.Info("Initializing teleportr")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var logHandler log.Handler
if cfg.LogTerminal {
logHandler = log.StreamHandler(os.Stdout, log.TerminalFormat(true))
} else {
logHandler = log.StreamHandler(os.Stdout, log.JSONFormat())
}
logLevel, err := log.LvlFromString(cfg.LogLevel)
if err != nil {
return err
}
log.Root().SetHandler(log.LvlFilterHandler(logLevel, logHandler))
disburserPrivKey, disburserAddr, err := bsscore.ParseWalletPrivKeyAndContractAddr(
"Teleportr", cfg.Mnemonic, cfg.DisburserHDPath,
cfg.DisburserPrivKey, cfg.DisburserAddress,
)
if err != nil {
return err
}
depositAddr, err := bsscore.ParseAddress(cfg.DepositAddress)
if err != nil {
return err
}
l1Client, err := dial.L1EthClientWithTimeout(ctx, cfg.L1EthRpc, cfg.DisableHTTP2)
if err != nil {
return err
}
defer l1Client.Close()
l2Client, err := dial.L1EthClientWithTimeout(ctx, cfg.L2EthRpc, cfg.DisableHTTP2)
if err != nil {
return err
}
defer l2Client.Close()
database, err := db.Open(db.Config{
Host: cfg.PostgresHost,
Port: uint16(cfg.PostgresPort),
User: cfg.PostgresUser,
Password: cfg.PostgresPassword,
DBName: cfg.PostgresDBName,
EnableSSL: cfg.PostgresEnableSSL,
})
if err != nil {
return err
}
defer database.Close()
if cfg.MetricsServerEnable {
go metrics.RunServer(cfg.MetricsHostname, cfg.MetricsPort)
}
chainID, err := l1Client.ChainID(ctx)
if err != nil {
return err
}
txManagerConfig := txmgr.Config{
ResubmissionTimeout: cfg.ResubmissionTimeout,
ReceiptQueryInterval: time.Second,
NumConfirmations: 1, // L2 insta confs
SafeAbortNonceTooLowCount: cfg.SafeAbortNonceTooLowCount,
}
teleportrDriver, err := disburser.NewDriver(disburser.Config{
Name: "Teleportr",
L1Client: l1Client,
L2Client: l2Client,
Database: database,
MaxTxSize: cfg.MaxL2TxSize,
NumConfirmations: cfg.NumDepositConfirmations,
DeployBlockNumber: cfg.DepositDeployBlockNumber,
FilterQueryMaxBlocks: cfg.FilterQueryMaxBlocks,
DepositAddr: depositAddr,
DisburserAddr: disburserAddr,
ChainID: chainID,
PrivKey: disburserPrivKey,
})
if err != nil {
return err
}
teleportrService := bsscore.NewService(bsscore.ServiceConfig{
Context: ctx,
Driver: teleportrDriver,
PollInterval: cfg.PollInterval,
ClearPendingTx: false,
L1Client: l1Client,
TxManagerConfig: txManagerConfig,
})
services := []*bsscore.Service{teleportrService}
teleportr, err := bsscore.NewBatchSubmitter(ctx, cancel, services)
if err != nil {
return err
}
log.Info("Starting teleportr")
err = teleportr.Start()
if err != nil {
return err
}
defer teleportr.Stop()
log.Info("Teleportr started")
interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, []os.Signal{
os.Interrupt,
os.Kill,
syscall.SIGTERM,
syscall.SIGQUIT,
}...)
<-interruptChannel
return nil
}
}
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