Commit c6f6d68b authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

indexer: deduplicate l2geth and geth deps (#2859)

Remove some of the l2geth packages in place of
using geth packages directly. This begins to
remove l2geth as a dependency from the indexer,
as l2geth will become legacy code after the release
of bedrock.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent b3921408
---
'@eth-optimism/indexer': patch
---
Deduplicate some l2geth and geth utils
......@@ -7,12 +7,12 @@ 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
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
SCC_ABI_ARTIFACT = ../../packages/contracts/artifacts/contracts/L1/rollup/StateCommitmentChain.sol/StateCommitmentChain.json
SCC_ABI_ARTIFACT = ../packages/contracts/artifacts/contracts/L1/rollup/StateCommitmentChain.sol/StateCommitmentChain.json
indexer:
env GO111MODULE=on go build -v $(LDFLAGS) ./cmd/indexer
......@@ -52,7 +52,7 @@ bindings-l2bridge:
cat $(L2BRIDGE_ABI_ARTIFACT) \
| jq .abi \
| ../../l2geth/build/bin/abigen --pkg l2bridge \
| abigen --pkg l2bridge \
--abi - \
--out bindings/l2bridge/l2_standard_bridge.go \
--type L2StandardBridge \
......@@ -84,7 +84,7 @@ bindings-l2erc20:
cat $(ERC20_ABI_ARTIFACT) \
| jq .abi \
| ../../l2geth/build/bin/abigen --pkg l2erc20 \
| abigen --pkg l2erc20 \
--abi - \
--out bindings/l2erc20/l2erc20.go \
--type L2ERC20 \
......
This diff is collapsed.
......@@ -6,7 +6,6 @@ import (
"fmt"
"strings"
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common"
// NOTE: Only postgresql backend is supported at the moment.
......@@ -401,7 +400,7 @@ func (d *Database) GetDepositsByAddress(address common.Address, page PaginationP
// GetWithdrawalBatch returns the StateBatch corresponding to the given
// withdrawal transaction hash.
func (d *Database) GetWithdrawalBatch(hash l2common.Hash) (*StateBatchJSON, error) {
func (d *Database) GetWithdrawalBatch(hash common.Hash) (*StateBatchJSON, error) {
const selectWithdrawalBatchStatement = `
SELECT
state_batches.index, state_batches.root, state_batches.size, state_batches.prev_total, state_batches.extra_data, state_batches.block_hash,
......@@ -459,7 +458,7 @@ func (d *Database) GetWithdrawalBatch(hash l2common.Hash) (*StateBatchJSON, erro
// GetWithdrawalsByAddress returns the list of Withdrawals indexed for the given
// address paginated by the given params.
func (d *Database) GetWithdrawalsByAddress(address l2common.Address, page PaginationParam) (*PaginatedWithdrawals, error) {
func (d *Database) GetWithdrawalsByAddress(address common.Address, page PaginationParam) (*PaginatedWithdrawals, error) {
const selectWithdrawalsStatement = `
SELECT
withdrawals.guid, withdrawals.from_address, withdrawals.to_address,
......@@ -505,7 +504,7 @@ func (d *Database) GetWithdrawalsByAddress(address l2common.Address, page Pagina
}
for i := range withdrawals {
batch, _ := d.GetWithdrawalBatch(l2common.HexToHash(withdrawals[i].TxHash))
batch, _ := d.GetWithdrawalBatch(common.HexToHash(withdrawals[i].TxHash))
withdrawals[i].Batch = batch
}
......@@ -540,12 +539,12 @@ func (d *Database) GetWithdrawalsByAddress(address l2common.Address, page Pagina
}
// GetHighestL1Block returns the highest known L1 block.
func (d *Database) GetHighestL1Block() (*L1BlockLocator, error) {
func (d *Database) GetHighestL1Block() (*BlockLocator, error) {
const selectHighestBlockStatement = `
SELECT number, hash FROM l1_blocks ORDER BY number DESC LIMIT 1
`
var highestBlock *L1BlockLocator
var highestBlock *BlockLocator
err := txn(d.db, func(tx *sql.Tx) error {
row := tx.QueryRow(selectHighestBlockStatement)
if row.Err() != nil {
......@@ -563,7 +562,7 @@ func (d *Database) GetHighestL1Block() (*L1BlockLocator, error) {
return err
}
highestBlock = &L1BlockLocator{
highestBlock = &BlockLocator{
Number: number,
Hash: common.HexToHash(hash),
}
......@@ -578,12 +577,12 @@ func (d *Database) GetHighestL1Block() (*L1BlockLocator, error) {
}
// GetHighestL2Block returns the highest known L2 block.
func (d *Database) GetHighestL2Block() (*L2BlockLocator, error) {
func (d *Database) GetHighestL2Block() (*BlockLocator, error) {
const selectHighestBlockStatement = `
SELECT number, hash FROM l2_blocks ORDER BY number DESC LIMIT 1
`
var highestBlock *L2BlockLocator
var highestBlock *BlockLocator
err := txn(d.db, func(tx *sql.Tx) error {
row := tx.QueryRow(selectHighestBlockStatement)
if row.Err() != nil {
......@@ -601,9 +600,9 @@ func (d *Database) GetHighestL2Block() (*L2BlockLocator, error) {
return err
}
highestBlock = &L2BlockLocator{
highestBlock = &BlockLocator{
Number: number,
Hash: l2common.HexToHash(hash),
Hash: common.HexToHash(hash),
}
return nil
......
package db
import l2common "github.com/ethereum-optimism/optimism/l2geth/common"
import "github.com/ethereum/go-ethereum/common"
// ETHL1Token is a placeholder token for differentiating ETH transactions from
// ERC20 transactions on L1.
......@@ -13,7 +13,7 @@ var ETHL1Token = &Token{
// ETHL2Address is a placeholder address for differentiating ETH transactions
// from ERC20 transactions on L2.
var ETHL2Address = l2common.HexToAddress("0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000")
var ETHL2Address = common.HexToAddress("0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000")
// ETHL2Token is a placeholder token for differentiating ETH transactions from
// ERC20 transactions on L2.
......
package db
import (
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common"
)
......@@ -21,8 +20,8 @@ func (b IndexedL1Block) String() string {
// IndexedL2Block contains the L2 block including the withdrawals in it.
type IndexedL2Block struct {
Hash l2common.Hash
ParentHash l2common.Hash
Hash common.Hash
ParentHash common.Hash
Number uint64
Timestamp uint64
Withdrawals []Withdrawal
......
package db
import (
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common"
)
// L1BlockLocator contains the block locator for a L1 block.
type L1BlockLocator struct {
// BlockLocator contains the block number and hash. It can
// uniquely identify an Ethereum block
type BlockLocator struct {
Number uint64 `json:"number"`
Hash common.Hash `json:"hash"`
}
// L2BlockLocator contains the block locator for a L2 block.
type L2BlockLocator struct {
Number uint64 `json:"number"`
Hash l2common.Hash `json:"hash"`
}
......@@ -3,17 +3,17 @@ package db
import (
"math/big"
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common"
)
// Withdrawal contains transaction data for withdrawals made via the L2 to L1 bridge.
type Withdrawal struct {
GUID string
TxHash l2common.Hash
L1Token l2common.Address
L2Token l2common.Address
FromAddress l2common.Address
ToAddress l2common.Address
TxHash common.Hash
L1Token common.Address
L2Token common.Address
FromAddress common.Address
ToAddress common.Address
Amount *big.Int
Data []byte
LogIndex uint
......
......@@ -12,8 +12,6 @@ import (
"github.com/ethereum-optimism/optimism/indexer/services"
l2rpc "github.com/ethereum-optimism/optimism/l2geth/rpc"
"github.com/ethereum-optimism/optimism/indexer/metrics"
"github.com/ethereum-optimism/optimism/indexer/server"
"github.com/rs/cors"
......@@ -21,7 +19,6 @@ import (
database "github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum-optimism/optimism/indexer/services/l1"
"github.com/ethereum-optimism/optimism/indexer/services/l2"
l2ethclient "github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
......@@ -82,7 +79,7 @@ type Indexer struct {
ctx context.Context
cfg Config
l1Client *ethclient.Client
l2Client *l2ethclient.Client
l2Client *ethclient.Client
l1IndexingService *l1.Service
l2IndexingService *l2.Service
......@@ -130,12 +127,12 @@ func NewIndexer(cfg Config, gitVersion string) (*Indexer, error) {
// Connect to L1 and L2 providers. Perform these last since they are the
// most expensive.
l1Client, rawl1Client, err := dialL1EthClientWithTimeout(ctx, cfg.L1EthRpc)
l1Client, rawl1Client, err := dialEthClientWithTimeout(ctx, cfg.L1EthRpc)
if err != nil {
return nil, err
}
l2Client, l2RPC, err := dialL2EthClientWithTimeout(ctx, cfg.L2EthRpc)
l2Client, l2RPC, err := dialEthClientWithTimeout(ctx, cfg.L2EthRpc)
if err != nil {
return nil, err
}
......@@ -271,7 +268,7 @@ func (b *Indexer) Stop() {
// dialL1EthClientWithTimeout attempts to dial the L1 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// this method will return an error.
func dialL1EthClientWithTimeout(ctx context.Context, url string) (
func dialEthClientWithTimeout(ctx context.Context, url string) (
*ethclient.Client, *rpc.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
......@@ -284,23 +281,6 @@ func dialL1EthClientWithTimeout(ctx context.Context, url string) (
return ethclient.NewClient(c), c, nil
}
// dialL2EthClientWithTimeout attempts to dial the L2 provider using the
// provided URL. If the dial doesn't complete within defaultDialTimeout seconds,
// this method will return an error.
func dialL2EthClientWithTimeout(ctx context.Context, url string) (
*l2ethclient.Client, *l2rpc.Client, error) {
ctxt, cancel := context.WithTimeout(ctx, defaultDialTimeout)
defer cancel()
rpc, err := l2rpc.DialContext(ctxt, url)
if err != nil {
return nil, nil, err
}
return l2ethclient.NewClient(rpc), rpc, nil
}
// traceRateToFloat64 converts a time.Duration into a valid float64 for the
// Sentry client. The client only accepts values between 0.0 and 1.0, so this
// method clamps anything greater than 1 second to 1.0.
......
......@@ -6,7 +6,6 @@ import (
"strconv"
"time"
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
......@@ -160,7 +159,7 @@ func (m *Metrics) RecordDeposit(addr common.Address) {
m.DepositsCount.WithLabelValues(sym).Inc()
}
func (m *Metrics) RecordWithdrawal(addr l2common.Address) {
func (m *Metrics) RecordWithdrawal(addr common.Address) {
sym := m.tokenAddrs[addr.String()]
if sym == "" {
sym = "UNKNOWN"
......
......@@ -96,7 +96,7 @@ type Service struct {
type IndexerStatus struct {
Synced float64 `json:"synced"`
Highest db.L1BlockLocator `json:"highest_block"`
Highest db.BlockLocator `json:"highest_block"`
}
func NewService(cfg ServiceConfig) (*Service, error) {
......@@ -203,7 +203,7 @@ func (s *Service) Loop(ctx context.Context) {
}
func (s *Service) Update(newHeader *types.Header) error {
var lowest = db.L1BlockLocator{
var lowest = db.BlockLocator{
Number: s.cfg.StartBlockNumber,
Hash: common.HexToHash(s.cfg.StartBlockHash),
}
......
......@@ -8,8 +8,8 @@ import (
"github.com/ethereum-optimism/optimism/indexer/bindings/l2bridge"
"github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum-optimism/optimism/l2geth/accounts/abi/bind"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
)
type WithdrawalsMap map[common.Hash][]db.Withdrawal
......
......@@ -5,7 +5,7 @@ import (
"time"
"github.com/ethereum-optimism/optimism/indexer/bindings/l2bridge"
"github.com/ethereum-optimism/optimism/l2geth/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)
// clientRetryInterval is the interval to wait between retrying client API
......
......@@ -6,8 +6,8 @@ import (
"github.com/ethereum-optimism/optimism/indexer/bindings/l2bridge"
"github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum-optimism/optimism/l2geth/accounts/abi/bind"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
)
type StandardBridge struct {
......
......@@ -7,11 +7,10 @@ import (
"time"
"github.com/ethereum-optimism/optimism/indexer/services/util"
"github.com/ethereum-optimism/optimism/l2geth/rpc"
"github.com/ethereum-optimism/optimism/l2geth/core/types"
"github.com/ethereum-optimism/optimism/l2geth/log"
l2rpc "github.com/ethereum-optimism/optimism/l2geth/rpc"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
)
const (
......@@ -29,7 +28,7 @@ type ConfirmedHeaderSelector struct {
cfg HeaderSelectorConfig
}
func HeadersByRange(ctx context.Context, client *l2rpc.Client, startHeight uint64, count int) ([]*types.Header, error) {
func HeadersByRange(ctx context.Context, client *rpc.Client, startHeight uint64, count int) ([]*types.Header, error) {
height := startHeight
batchElems := make([]rpc.BatchElem, count)
for i := 0; i < count; i++ {
......@@ -63,7 +62,7 @@ func (f *ConfirmedHeaderSelector) NewHead(
ctx context.Context,
lowest uint64,
header *types.Header,
client *l2rpc.Client,
client *rpc.Client,
) ([]*types.Header, error) {
number := header.Number.Uint64()
......
......@@ -3,12 +3,13 @@ package l2
import (
"github.com/ethereum-optimism/optimism/indexer/bindings/l2erc20"
"github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum-optimism/optimism/l2geth/accounts/abi/bind"
l2common "github.com/ethereum-optimism/optimism/l2geth/common"
l2ethclient "github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func QueryERC20(address l2common.Address, client *l2ethclient.Client) (*db.Token, error) {
func QueryERC20(address common.Address, client *ethclient.Client) (*db.Token, error) {
contract, err := l2erc20.NewL2ERC20(address, client)
if err != nil {
return nil, err
......
......@@ -10,17 +10,18 @@ import (
"sync"
"time"
l2rpc "github.com/ethereum-optimism/optimism/l2geth/rpc"
"github.com/ethereum-optimism/optimism/indexer/metrics"
"github.com/ethereum-optimism/optimism/indexer/server"
"github.com/prometheus/client_golang/prometheus"
"github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum-optimism/optimism/indexer/services/l2/bridge"
"github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum-optimism/optimism/l2geth/core/types"
l2ethclient "github.com/ethereum-optimism/optimism/l2geth/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/gorilla/mux"
)
......@@ -44,7 +45,7 @@ var clientRetryInterval = 5 * time.Second
// HeaderByNumberWithRetry retries the given func until it succeeds, waiting
// for clientRetryInterval duration after every call.
func HeaderByNumberWithRetry(ctx context.Context,
client *l2ethclient.Client) (*types.Header, error) {
client *ethclient.Client) (*types.Header, error) {
for {
res, err := client.HeaderByNumber(ctx, nil)
switch err {
......@@ -60,8 +61,8 @@ func HeaderByNumberWithRetry(ctx context.Context,
type ServiceConfig struct {
Context context.Context
Metrics *metrics.Metrics
L2RPC *l2rpc.Client
L2Client *l2ethclient.Client
L2RPC *rpc.Client
L2Client *ethclient.Client
ChainID *big.Int
ConfDepth uint64
MaxHeaderBatchSize uint64
......@@ -86,7 +87,7 @@ type Service struct {
type IndexerStatus struct {
Synced float64 `json:"synced"`
Highest db.L2BlockLocator `json:"highest_block"`
Highest db.BlockLocator `json:"highest_block"`
}
func NewService(cfg ServiceConfig) (*Service, error) {
......@@ -181,7 +182,7 @@ func (s *Service) Loop(ctx context.Context) {
}
func (s *Service) Update(newHeader *types.Header) error {
var lowest = db.L2BlockLocator{
var lowest = db.BlockLocator{
Number: s.cfg.StartBlockNumber,
Hash: common.HexToHash(s.cfg.StartBlockHash),
}
......
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