Skip to content
Closed
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
5fd9c03
feat: indexer service to replace etherscan dependency
tuxcanfly Jan 5, 2022
70019f9
feat: indexer - use batchsubmitter scaffold
tuxcanfly Jan 5, 2022
f079689
fix: rm unused event loop, tx mgr; cleanup
tuxcanfly Jan 5, 2022
69dd9f2
fix: rename to l1IndexingService
tuxcanfly Jan 6, 2022
f01cd72
feat: implement chainSync - check local height
tuxcanfly Jan 6, 2022
89edbc7
fix: cleanup refs to db
tuxcanfly Jan 12, 2022
1a0df4c
feat: add postgres db and data layer
tuxcanfly Jan 12, 2022
96d940a
fix: cleanup; add l1 indexer driver
tuxcanfly Jan 12, 2022
37989dc
fix: rm driver, just use service
tuxcanfly Jan 12, 2022
dac6394
fix: rewrite service as indexer
tuxcanfly Jan 12, 2022
03fc66e
fix (flags): add conf-depth, max-batch-header-size
tuxcanfly Jan 12, 2022
f21d9be
fix: log header as log15 var
tuxcanfly Jan 12, 2022
a6abe40
fix: increase default rpc timeout
tuxcanfly Jan 12, 2022
b5773fb
fix: use flag for start block number, hash
tuxcanfly Jan 12, 2022
df51738
fix: bindings
tuxcanfly Jan 12, 2022
44a6eb4
fix: pass ctc address to service config
tuxcanfly Jan 12, 2022
03c007e
changelog: update
tuxcanfly Jan 12, 2022
2386738
fix: avoid panics in db, service
tuxcanfly Jan 12, 2022
ec42fdc
fix: update env
tuxcanfly Jan 12, 2022
e2cd29a
fix (metrics): rm unused guages, add placeholder
tuxcanfly Jan 13, 2022
27aedf2
fix (indexer): avoid potentially leaking defer
tuxcanfly Jan 13, 2022
4dcc24d
fix (indexer): rm txmgr
tuxcanfly Jan 13, 2022
158cc90
fix (indexer): use log instead of fmt
tuxcanfly Jan 13, 2022
a3dbbb2
fix (indexer): add tx amount to indexed fields
tuxcanfly Jan 25, 2022
5fcc9ff
fix (minor): add tx hash to deposit log
tuxcanfly Jan 25, 2022
d48ca8d
fix (indexer): store amount as text
tuxcanfly Jan 25, 2022
cabd3cb
feat (indexer): deposits - index from address
tuxcanfly Jan 31, 2022
4702850
feat (indexer): get deposits by address API
tuxcanfly Jan 31, 2022
3585f34
feat (indexer): use TokenBridgeMessage for API
tuxcanfly Feb 1, 2022
a23f801
feat (indexer): add block number/timestamp
tuxcanfly Feb 1, 2022
12132b4
feat (indexer): add /v1/status API endpoint
tuxcanfly Feb 2, 2022
4ef8909
feat (indexer): calculate sync progress
tuxcanfly Feb 2, 2022
9d8717f
feat (indexer): split l1/l2 indexer services
tuxcanfly Feb 3, 2022
7db0dd1
feat (indexer): fix log errs
tuxcanfly Feb 7, 2022
3ab055a
feat (indexer): update withdraw schema; fix addr
tuxcanfly Feb 7, 2022
89270e7
fix (indexer): include from, amount in withdrawals
tuxcanfly Feb 7, 2022
c7baa80
feat (indexer): paginate deposits/withdrawals
tuxcanfly Feb 7, 2022
fd9f732
fix (indexer): nits
tuxcanfly Feb 7, 2022
c5061fd
fix (indexer): index all withdrawal data
tuxcanfly Feb 7, 2022
97277f4
fix (indexer): switch ctc chain to l1 bridge
tuxcanfly Feb 8, 2022
95d2e74
fix (indexer): fix l1 standard bridge bindings
tuxcanfly Feb 8, 2022
03e5197
fix (indexer): add bridge address flags; cleanup
tuxcanfly Feb 8, 2022
4b8383b
fix (indexer): flags cleanup
tuxcanfly Feb 8, 2022
b92dc04
fix (indexer): cleanup unused args
tuxcanfly Feb 8, 2022
c2c2392
fix (indexer): rename l2 bridge addr var
tuxcanfly Feb 8, 2022
518ee67
feat (indexer): add l2 genesis block hash flag
tuxcanfly Feb 8, 2022
2e71416
fix (indexer): cleanup flags
tuxcanfly Feb 9, 2022
283aede
fix (indexer): add log index to indexed fields
tuxcanfly Feb 9, 2022
2f7bb3f
Add Dockerfile
mslipper Feb 10, 2022
16e6f20
fix (flags): add log-terminal flag
tuxcanfly Feb 10, 2022
2673c59
fix (indexer): fix confirmed block number log
tuxcanfly Feb 10, 2022
49d39bf
fix (indexer): skip header validation - l1 service
tuxcanfly Feb 10, 2022
47da875
fix (indexer): update env
tuxcanfly Feb 10, 2022
84fe387
fix (indexer): fix issue with skipping in kovan
tuxcanfly Feb 10, 2022
604119f
fix (indexer): revert kovan workaround
tuxcanfly Feb 10, 2022
07072a9
fix (indexer): scan eth/erc20 l1 deposits
tuxcanfly Feb 10, 2022
fa740cc
refactor (indexer): use raw hash; don't compute
tuxcanfly Feb 10, 2022
9096019
fix (indexer): index l1 tokens by address
tuxcanfly Feb 11, 2022
7ffbf50
fix (indexer): fetch token along with deposit
tuxcanfly Feb 11, 2022
9d0ee0c
fix (indexer): upsert eth l1 token fixture
tuxcanfly Feb 11, 2022
539a447
fix (indexer): fix typo - l1 -> l2 token
tuxcanfly Feb 11, 2022
4b22e52
Update env var prefix, poll rather than using newheads
mslipper Feb 11, 2022
4539cc1
Add fast sync mode when far behind
mslipper Feb 11, 2022
4f46234
Show which service logs what
mslipper Feb 11, 2022
c858b7b
Handle empty index case
mslipper Feb 11, 2022
ec0086b
Use queryRow in l1 too
mslipper Feb 11, 2022
a6e93a7
Allow indexer to be conditionally disabled
mslipper Feb 11, 2022
b39ed4c
Add http logging
mslipper Feb 11, 2022
17c6c4a
Add healthz
mslipper Feb 12, 2022
3c354b7
Add CORS
mslipper Feb 12, 2022
34cf1cb
fix (indexer): fix erc20 vm execution err handling
tuxcanfly Feb 12, 2022
99c5d6e
fix (indexer): l2 - index withdrawal erc20 tokens
tuxcanfly Feb 12, 2022
7954aeb
fix (indexer): l2 - cleanup
tuxcanfly Feb 12, 2022
a93e59b
fix (indexer): l2 - include token data in API
tuxcanfly Feb 12, 2022
1f6fc2e
feat (indexer): init custom bridge support
tuxcanfly Feb 14, 2022
932edb4
fix (indexer): l1 - add eth filter in std bridge
tuxcanfly Feb 14, 2022
4fdf6f7
feat (indexer): add bridge addrs
tuxcanfly Feb 14, 2022
0387614
fix (indexer): l1 - use standard / eth bridges
tuxcanfly Feb 15, 2022
31a5e71
fix (indexer): l1 - use bridge instead of contract
tuxcanfly Feb 15, 2022
b7b3296
fix (indexer): l1 - restore index erc20; cleanup
tuxcanfly Feb 15, 2022
a5d404c
fix (indexer): use same docker image bss
tuxcanfly Feb 15, 2022
b49ac02
feat (indexer): l1 - support bitbtc, usx bridges
tuxcanfly Feb 15, 2022
2f77a7a
feat (indexer): l2 custom bridges
tuxcanfly Feb 15, 2022
d8d702b
fix (indexer): update l2 chainids
tuxcanfly Feb 15, 2022
8290489
fix (indexer): l2 - only use standard bridge
tuxcanfly Feb 15, 2022
0a376e7
fix (indexer): l1 fetch header - retry on err
tuxcanfly Feb 16, 2022
ddb0136
fix (indexer): l2 fetch header - retry on err
tuxcanfly Feb 16, 2022
1a9ce92
fix (indexer): add l1/l2 dai bridge
tuxcanfly Feb 17, 2022
61e3ec7
fix (indexer): bridge - handle err with retry
tuxcanfly Feb 17, 2022
a715e4e
Update DB
mslipper Feb 17, 2022
5408306
fix (indexer): API - fetch l1, l2 token details
tuxcanfly Feb 18, 2022
807104b
Add metrics
mslipper Feb 18, 2022
9c18259
Clean up, fix path
mslipper Feb 19, 2022
549bd3a
Use correct current head, add sync progress metrics
mslipper Feb 22, 2022
100999a
Add metrics namespace
mslipper Feb 22, 2022
29a2d8f
Add objectives
mslipper Feb 22, 2022
e320030
rename metric
mslipper Feb 22, 2022
dc12ac6
Log duration
mslipper Feb 22, 2022
5aac874
Record withdrawal time, add indexes to DB
mslipper Feb 22, 2022
3c0aac6
fix (indexer): fix missing tx due to invalid token
tuxcanfly Feb 24, 2022
9e3f269
fix (indexer): create index - rm concurrently
tuxcanfly Feb 24, 2022
70a574f
feat (indexer): add StateCommitmentChain bindings
tuxcanfly Mar 4, 2022
3b15930
feat (indexer): add state batch schema
tuxcanfly Mar 4, 2022
4b41c4c
feat (indexer): db - add state batch index
tuxcanfly Mar 4, 2022
42e3fb3
feat (indexer): add state batch appended filter
tuxcanfly Mar 4, 2022
438e76f
feat (indexer): scan and index state batches
tuxcanfly Mar 4, 2022
cb05e16
feat (indexer): add withdrawal batch details
tuxcanfly Mar 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions go/indexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# @eth-optimism/indexer-service

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for a changelog - instead define a package.json and our changeset system will take care of it.


## 0.0.0
### Patch Changes

- 44a6eb4ce: Draft
100 changes: 100 additions & 0 deletions go/indexer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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)"

L1BRIDGE_ABI_ARTIFACT = ../../packages/contracts/artifacts/contracts/L1/messaging/L1StandardBridge.sol/L1StandardBridge.json
L2BRIDGE_ABI_ARTIFACT = ../../packages/contracts/artifacts/contracts/L2/messaging/L2StandardBridge.sol/L2StandardBridge.json

ERC20_ABI_ARTIFACT = ./contracts/ERC20.sol/ERC20.json

indexer:
env GO111MODULE=on go build -v $(LDFLAGS) ./cmd/indexer

clean:
rm indexer

test:
go test -v ./...

lint:
golangci-lint run ./...

bindings: bindings-l1bridge bindings-l2bridge bindings-l1erc20 bindings-l2erc20

bindings-l1bridge:
$(eval temp := $(shell mktemp))

cat $(L1BRIDGE_ABI_ARTIFACT) \
| jq -r .bytecode > $(temp)

cat $(L1BRIDGE_ABI_ARTIFACT) \
| jq .abi \
| abigen --pkg l1bridge \
--abi - \
--out bindings/l1bridge/l1_standard_bridge.go \
--type L1StandardBridge \
--bin $(temp)

rm $(temp)

bindings-l2bridge:
$(eval temp := $(shell mktemp))

cat $(L2BRIDGE_ABI_ARTIFACT) \
| jq -r .bytecode > $(temp)

cat $(L2BRIDGE_ABI_ARTIFACT) \
| jq .abi \
| ../../l2geth/build/bin/abigen --pkg l2bridge \
--abi - \
--out bindings/l2bridge/l2_standard_bridge.go \
--type L2StandardBridge \
--bin $(temp)

rm $(temp)

bindings-l1erc20:
$(eval temp := $(shell mktemp))

cat $(ERC20_ABI_ARTIFACT) \
| jq -r .bytecode > $(temp)

cat $(ERC20_ABI_ARTIFACT) \
| jq .abi \
| abigen --pkg l1erc20 \
--abi - \
--out bindings/l1erc20/l1erc20.go \
--type L1ERC20 \
--bin $(temp)

rm $(temp)

bindings-l2erc20:
$(eval temp := $(shell mktemp))

cat $(ERC20_ABI_ARTIFACT) \
| jq -r .bytecode > $(temp)

cat $(ERC20_ABI_ARTIFACT) \
| jq .abi \
| ../../l2geth/build/bin/abigen --pkg l2erc20 \
--abi - \
--out bindings/l2erc20/l2erc20.go \
--type L2ERC20 \
--bin $(temp)

rm $(temp)

.PHONY: \
indexer \
bindings \
bindings-l1bridge \
bindings-l2bridge \
clean \
test \
lint
1,124 changes: 1,124 additions & 0 deletions go/indexer/bindings/l1bridge/l1_standard_bridge.go

Large diffs are not rendered by default.

842 changes: 842 additions & 0 deletions go/indexer/bindings/l1erc20/l1erc20.go

Large diffs are not rendered by default.

797 changes: 797 additions & 0 deletions go/indexer/bindings/l2bridge/l2_standard_bridge.go

Large diffs are not rendered by default.

788 changes: 788 additions & 0 deletions go/indexer/bindings/l2erc20/l2erc20.go

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions go/indexer/cmd/indexer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"os"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli"

"github.com/ethereum-optimism/optimism/go/indexer"
"github.com/ethereum-optimism/optimism/go/indexer/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 crtiical log won't show what the parsing error was.
log.Root().SetHandler(
log.LvlFilterHandler(
log.LvlInfo,
log.StreamHandler(os.Stdout, log.TerminalFormat(true)),
Comment thread
tuxcanfly marked this conversation as resolved.
),
)

app := cli.NewApp()
app.Flags = flags.Flags
app.Version = fmt.Sprintf("%s-%s", GitVersion, params.VersionWithCommit(GitCommit, GitDate))
app.Name = "indexer"
app.Usage = "Indexer Service"
app.Description = "Service for indexing deposits and withdrawals " +
"by account on L1 and L2"

app.Action = indexer.Main(GitVersion)
err := app.Run(os.Args)
if err != nil {
log.Crit("Application failed", "message", err)
}
}
173 changes: 173 additions & 0 deletions go/indexer/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package indexer

import (
"errors"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli"

"github.com/ethereum-optimism/optimism/go/indexer/flags"
)

var (
// ErrSentryDSNNotSet signals that not Data Source Name was provided
// with which to configure Sentry logging.
ErrSentryDSNNotSet = errors.New("sentry-dsn must be set if use-sentry " +
"is true")
)

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

// L1StandardBridgeAddress is the l1 standard bridge contract address.
L1StandardBridgeAddress string

// L2StandardBridgeAddress is the l2 standard bridge contract address.
L2StandardBridgeAddress string

// L2GenesisBlockHash is the l2 genesis block hash.
L2GenesisBlockHash string

// PollInterval is the delay between querying L2 for more transaction
// and creating a new batch.
PollInterval time.Duration

// Hostname of the database connection.
DBHost string

// Port of the database connection.
DBPort uint64

// Username of the database connection.
DBUser string

// Password of the database connection.
DBPassword string

// Database name of the database connection.
DBName string

/* 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

// SentryEnable if true, logs any error messages to sentry. SentryDsn
// must also be set if SentryEnable is true.
SentryEnable bool

// SentryDsn is the sentry Data Source Name.
SentryDsn string

// SentryTraceRate the frequency with which Sentry should flush buffered
// events.
SentryTraceRate time.Duration

// StartBlockNumber is the block number to start indexing from.
StartBlockNumber uint64

// StartBlockHash is the block hash to start indexing from.
StartBlockHash string

// ConfDepth is the number of confirmations after which headers are
// considered confirmed.
ConfDepth uint64

// MaxHeaderBatchSize is the maximum number of headers to request as a
// batch.
MaxHeaderBatchSize uint64

// 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

// DisableIndexer enables/disables the indexer.
DisableIndexer bool
}

// NewConfig parses the Config from the provided flags or environment variables.
// This method fails if ValidateConfig deems the configuration to be malformed.
func NewConfig(ctx *cli.Context) (Config, error) {
cfg := 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),
L1StandardBridgeAddress: ctx.GlobalString(flags.L1StandardBridgeAddressFlag.Name),
L2StandardBridgeAddress: ctx.GlobalString(flags.L2StandardBridgeAddressFlag.Name),
L2GenesisBlockHash: ctx.GlobalString(flags.L2GenesisBlockHashFlag.Name),
DBHost: ctx.GlobalString(flags.DBHostFlag.Name),
DBPort: ctx.GlobalUint64(flags.DBPortFlag.Name),
DBUser: ctx.GlobalString(flags.DBUserFlag.Name),
DBPassword: ctx.GlobalString(flags.DBPasswordFlag.Name),
DBName: ctx.GlobalString(flags.DBNameFlag.Name),
/* Optional Flags */
DisableIndexer: ctx.GlobalBool(flags.DisableIndexer.Name),
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
SentryEnable: ctx.GlobalBool(flags.SentryEnableFlag.Name),
SentryDsn: ctx.GlobalString(flags.SentryDsnFlag.Name),
SentryTraceRate: ctx.GlobalDuration(flags.SentryTraceRateFlag.Name),
StartBlockNumber: ctx.GlobalUint64(flags.StartBlockNumberFlag.Name),
StartBlockHash: ctx.GlobalString(flags.StartBlockHashFlag.Name),
ConfDepth: ctx.GlobalUint64(flags.ConfDepthFlag.Name),
MaxHeaderBatchSize: ctx.GlobalUint64(flags.MaxHeaderBatchSizeFlag.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
MetricsHostname: ctx.GlobalString(flags.MetricsHostnameFlag.Name),
MetricsPort: ctx.GlobalUint64(flags.MetricsPortFlag.Name),
}

err := ValidateConfig(&cfg)
if err != nil {
return Config{}, err
}

return cfg, nil
}

// ValidateConfig ensures additional constraints on the parsed configuration to
// ensure that it is well-formed.
func ValidateConfig(cfg *Config) error {
// Sanity check log level.
if cfg.LogLevel == "" {
cfg.LogLevel = "debug"
}

_, err := log.LvlFromString(cfg.LogLevel)
if err != nil {
return err
}

// Ensure the Sentry Data Source Name is set when using Sentry.
if cfg.SentryEnable && cfg.SentryDsn == "" {
return ErrSentryDSNNotSet
}

return nil
}
34 changes: 34 additions & 0 deletions go/indexer/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package indexer_test

import (
"fmt"
"testing"

indexer "github.com/ethereum-optimism/optimism/go/indexer"
"github.com/stretchr/testify/require"
)

var validateConfigTests = []struct {
name string
cfg indexer.Config
expErr error
}{
{
name: "bad log level",
cfg: indexer.Config{
LogLevel: "unknown",
},
expErr: fmt.Errorf("unknown level: unknown"),
},
}

// TestValidateConfig asserts the behavior of ValidateConfig by testing expected
// error and success configurations.
func TestValidateConfig(t *testing.T) {
for _, test := range validateConfigTests {
t.Run(test.name, func(t *testing.T) {
err := indexer.ValidateConfig(&test.cfg)
require.Equal(t, err, test.expErr)
})
}
}
4 changes: 4 additions & 0 deletions go/indexer/contracts/ERC20.sol/ERC20.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/d8a0f286587dfbd9a9d1e4f1e98e7119.json"
}
Loading