Skip to content

Commit

Permalink
chore(relayer): delete duplicate DB interface (#17698)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Jul 1, 2024
1 parent a3e1cf7 commit c28c984
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/relayer/indexer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Config struct {
BackOffMaxRetries uint64
MinFeeToIndex uint64
OpenQueueFunc func() (queue.Queue, error)
OpenDBFunc func() (DB, error)
OpenDBFunc func() (db.DB, error)
}

// NewConfigFromCliContext creates a new config instance from command line flags.
Expand Down Expand Up @@ -94,7 +94,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
}
return nil
}(),
OpenDBFunc: func() (DB, error) {
OpenDBFunc: func() (db.DB, error) {
return db.OpenDBConnection(db.DBConnectionOpts{
Name: c.String(flags.DatabaseUsername.Name),
Password: c.String(flags.DatabasePassword.Name),
Expand Down
6 changes: 4 additions & 2 deletions packages/relayer/indexer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/db"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/mock"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -69,7 +71,7 @@ func TestNewConfigFromCliContext(t *testing.T) {
assert.Equal(t, WatchMode(watchMode), c.WatchMode)
assert.Equal(t, eventName, c.EventName)

c.OpenDBFunc = func() (DB, error) {
c.OpenDBFunc = func() (db.DB, error) {
return &mock.DB{}, nil
}

Expand Down
13 changes: 3 additions & 10 deletions packages/relayer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package indexer

import (
"context"
"database/sql"
"fmt"
"log/slog"
"math/big"
Expand All @@ -17,16 +16,16 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"

"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/signalservice"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/taikol1"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/repo"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/utils"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"
)

var (
Expand Down Expand Up @@ -74,12 +73,6 @@ type ethClient interface {
TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error)
}

// DB is a local interface that lets us narrow down a database type for testing.
type DB interface {
DB() (*sql.DB, error)
GormDB() *gorm.DB
}

// Indexer is the main struct of this package, containing all dependencies necessary for indexing
// relayer-related chain data. All database repositories, contract implementations,
// and configurations will be injected here.
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
ErrNoDB = errors.Validation.NewWithKeyAndDetail("ERR_NO_DB", "no db")
)

// DB is a local interface that lets us narrow down a database type for testing.
type DB interface {
DB() (*sql.DB, error)
GormDB() *gorm.DB
Expand Down
13 changes: 7 additions & 6 deletions packages/relayer/processor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/urfave/cli/v2"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"

"github.com/taikoxyz/taiko-mono/packages/relayer/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/db"
pkgFlags "github.com/taikoxyz/taiko-mono/packages/relayer/pkg/flags"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue/rabbitmq"
"github.com/urfave/cli/v2"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

// hopConfig is a config struct that must be provided for an individual
Expand Down Expand Up @@ -76,7 +77,7 @@ type Config struct {
DestRPCUrl string
ETHClientTimeout uint64
OpenQueueFunc func() (queue.Queue, error)
OpenDBFunc func() (DB, error)
OpenDBFunc func() (db.DB, error)

hopConfigs []hopConfig

Expand Down Expand Up @@ -178,7 +179,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
),
MaxMessageRetries: c.Uint64(flags.MaxMessageRetries.Name),
MinFeeToProcess: c.Uint64(flags.MinFeeToProcess.Name),
OpenDBFunc: func() (DB, error) {
OpenDBFunc: func() (db.DB, error) {
return db.OpenDBConnection(db.DBConnectionOpts{
Name: c.String(flags.DatabaseUsername.Name),
Password: c.String(flags.DatabasePassword.Name),
Expand Down
6 changes: 4 additions & 2 deletions packages/relayer/processor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-mono/packages/relayer/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/db"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/mock"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -71,7 +73,7 @@ func TestNewConfigFromCliContext(t *testing.T) {
assert.Equal(t, uint64(100), c.QueuePrefetch)
assert.Equal(t, true, c.EnableTaikoL2)

c.OpenDBFunc = func() (DB, error) {
c.OpenDBFunc = func() (db.DB, error) {
return &mock.DB{}, nil
}

Expand Down
11 changes: 2 additions & 9 deletions packages/relayer/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package processor
import (
"context"
"crypto/ecdsa"
"database/sql"
"encoding/json"
"errors"
"fmt"
Expand All @@ -15,6 +14,8 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand All @@ -23,10 +24,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2"
"gorm.io/gorm"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/erc1155vault"
Expand All @@ -41,11 +39,6 @@ import (
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/utils"
)

type DB interface {
DB() (*sql.DB, error)
GormDB() *gorm.DB
}

// ethClient is a slimmed down interface of a go-ethereum ethclient.Client
// we can use for mocking and testing
type ethClient interface {
Expand Down
4 changes: 2 additions & 2 deletions packages/relayer/watchdog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Config struct {
DestRPCUrl string
ETHClientTimeout uint64
OpenQueueFunc func() (queue.Queue, error)
OpenDBFunc func() (DB, error)
OpenDBFunc func() (db.DB, error)

SrcTxmgrConfigs *txmgr.CLIConfig
DestTxmgrConfigs *txmgr.CLIConfig
Expand Down Expand Up @@ -94,7 +94,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
BackoffRetryInterval: c.Uint64(flags.BackOffRetryInterval.Name),
BackOffMaxRetrys: c.Uint64(flags.BackOffMaxRetrys.Name),
ETHClientTimeout: c.Uint64(flags.ETHClientTimeout.Name),
OpenDBFunc: func() (DB, error) {
OpenDBFunc: func() (db.DB, error) {
return db.OpenDBConnection(db.DBConnectionOpts{
Name: c.String(flags.DatabaseUsername.Name),
Password: c.String(flags.DatabasePassword.Name),
Expand Down
6 changes: 4 additions & 2 deletions packages/relayer/watchdog/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"

"github.com/taikoxyz/taiko-mono/packages/relayer/cmd/flags"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/db"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/mock"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -64,7 +66,7 @@ func TestNewConfigFromCliContext(t *testing.T) {
assert.Equal(t, uint64(10), c.ETHClientTimeout)
assert.Equal(t, uint64(100), c.QueuePrefetch)

c.OpenDBFunc = func() (DB, error) {
c.OpenDBFunc = func() (db.DB, error) {
return &mock.DB{}, nil
}

Expand Down
12 changes: 2 additions & 10 deletions packages/relayer/watchdog/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package watchdog
import (
"context"
"crypto/ecdsa"
"database/sql"
"encoding/json"
"fmt"
"log/slog"
Expand All @@ -14,30 +13,23 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/cyberhorsey/errors"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"
"gorm.io/gorm"

txmgrMetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/taikoxyz/taiko-mono/packages/relayer"
"github.com/taikoxyz/taiko-mono/packages/relayer/bindings/bridge"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/encoding"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/queue"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/repo"
"github.com/taikoxyz/taiko-mono/packages/relayer/pkg/utils"
"github.com/urfave/cli/v2"
)

type DB interface {
DB() (*sql.DB, error)
GormDB() *gorm.DB
}

type ethClient interface {
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
Expand Down

0 comments on commit c28c984

Please sign in to comment.