Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2) #115

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 15 additions & 6 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package baseapp
import (
"context"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/job"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/server"
"github.com/berachain/offchain-sdk/telemetry"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/job"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/berachain/offchain-sdk/v2/server"
"github.com/berachain/offchain-sdk/v2/telemetry"

ethdb "github.com/ethereum/go-ethereum/ethdb"
)
Expand All @@ -25,6 +25,9 @@ type BaseApp struct {

// svr is the server for the baseapp.
svr *server.Server

// chain is the eth client for the baseapp.
chain eth.Client
}

// New creates a new baseapp.
Expand All @@ -49,7 +52,8 @@ func New(
metrics: metrics,
},
),
svr: svr,
svr: svr,
chain: ethClient,
}
}

Expand Down Expand Up @@ -86,3 +90,8 @@ func (b *BaseApp) Stop() {
b.svr.Stop()
}
}

// Chain returns the eth client for the baseapp.
func (b *BaseApp) Chain() eth.Client {
return b.chain
}
30 changes: 10 additions & 20 deletions baseapp/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package baseapp
import (
"errors"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/job"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/server"
"github.com/berachain/offchain-sdk/telemetry"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/job"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/berachain/offchain-sdk/v2/server"
"github.com/berachain/offchain-sdk/v2/telemetry"

ethdb "github.com/ethereum/go-ethereum/ethdb"
)
Expand All @@ -21,14 +20,16 @@ type AppBuilder struct {
ethClient eth.Client
svr *server.Server
metrics telemetry.Metrics
logger log.Logger
}

// NewAppBuilder creates a new app builder.
func NewAppBuilder(appName string) *AppBuilder {
func NewAppBuilder(appName string, logger log.Logger) *AppBuilder {
return &AppBuilder{
appName: appName,
jobs: []job.Basic{},
metrics: telemetry.NewNoopMetrics(),
logger: logger,
}
}

Expand Down Expand Up @@ -88,28 +89,17 @@ func (ab *AppBuilder) RegisterMiddleware(m server.Middleware) error {
return nil
}

// RegisterPrometheusTelemetry registers a Prometheus metrics HTTP server.
func (ab *AppBuilder) RegisterPrometheusTelemetry() error {
if ab.svr == nil {
return errors.New("must enable the HTTP server to register Prometheus")
}

return ab.RegisterHTTPHandler(&server.Handler{Path: "/metrics", Handler: promhttp.Handler()})
}

// RegisterEthClient registers the eth client.
// TODO: update this to connection pool on baseapp and context gets one for running
func (ab *AppBuilder) RegisterEthClient(ethClient eth.Client) {
ab.ethClient = ethClient
}

// BuildApp builds the app.
func (ab *AppBuilder) BuildApp(
logger log.Logger,
) *BaseApp {
func (ab *AppBuilder) BuildApp() *BaseApp {
return New(
ab.appName,
logger,
ab.logger,
ab.ethClient,
ab.jobs,
ab.db,
Expand Down
8 changes: 4 additions & 4 deletions baseapp/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package baseapp
import (
"context"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/telemetry"
sdk "github.com/berachain/offchain-sdk/types"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/berachain/offchain-sdk/v2/telemetry"
sdk "github.com/berachain/offchain-sdk/v2/types"

ethdb "github.com/ethereum/go-ethereum/ethdb"
)
Expand Down
8 changes: 4 additions & 4 deletions baseapp/job_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"reflect"
"sync"

"github.com/berachain/offchain-sdk/job"
"github.com/berachain/offchain-sdk/log"
sdk "github.com/berachain/offchain-sdk/types"
"github.com/berachain/offchain-sdk/worker"
"github.com/berachain/offchain-sdk/v2/job"
"github.com/berachain/offchain-sdk/v2/log"
sdk "github.com/berachain/offchain-sdk/v2/types"
"github.com/berachain/offchain-sdk/v2/worker"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions baseapp/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"errors"
"time"

"github.com/berachain/offchain-sdk/job"
workertypes "github.com/berachain/offchain-sdk/job/types"
"github.com/berachain/offchain-sdk/v2/job"
workertypes "github.com/berachain/offchain-sdk/v2/job/types"
)

// producerTask returns a execution task for the given HasProducer job.
Expand Down
2 changes: 1 addition & 1 deletion client/eth/client_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"time"

"github.com/berachain/offchain-sdk/telemetry"
"github.com/berachain/offchain-sdk/v2/telemetry"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down
6 changes: 3 additions & 3 deletions client/eth/client_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"math/big"
"testing"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/client/eth/mocks"
tmocks "github.com/berachain/offchain-sdk/telemetry/mocks"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/client/eth/mocks"
tmocks "github.com/berachain/offchain-sdk/v2/telemetry/mocks"
"github.com/stretchr/testify/mock"
)

Expand Down
2 changes: 1 addition & 1 deletion client/eth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/stretchr/testify/assert"

"github.com/ethereum/go-ethereum"
Expand Down
2 changes: 1 addition & 1 deletion client/eth/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/v2/log"
lru "github.com/hashicorp/golang-lru/v2"
)

Expand Down
4 changes: 2 additions & 2 deletions client/eth/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"testing"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions client/eth/health_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/v2/log"

"github.com/ethereum/go-ethereum/ethclient"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func (c *HealthCheckedClient) StartHealthCheck(ctx context.Context) {
c.logger.Error("eth client reporting unhealthy", "err", err, "url", c.dialurl)
} else {
c.SetHealthy(true)
c.logger.Info("eth client reporting healthy", "url", c.dialurl)
c.logger.Debug("eth client reporting healthy", "url", c.dialurl)
}
}
time.Sleep(c.healthCheckInterval)
Expand Down
2 changes: 1 addition & 1 deletion client/eth/mocks/ConnectionPool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"os"

coreapp "github.com/berachain/offchain-sdk/core/app"
coreapp "github.com/berachain/offchain-sdk/v2/core/app"
"github.com/spf13/cobra"
)

Expand Down
26 changes: 14 additions & 12 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"os/signal"
"syscall"

"github.com/berachain/offchain-sdk/baseapp"
"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/cmd/flags"
"github.com/berachain/offchain-sdk/config"
"github.com/berachain/offchain-sdk/config/toml"
coreapp "github.com/berachain/offchain-sdk/core/app"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/server"
"github.com/berachain/offchain-sdk/v2/baseapp"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/cmd/flags"
"github.com/berachain/offchain-sdk/v2/config"
"github.com/berachain/offchain-sdk/v2/config/toml"
coreapp "github.com/berachain/offchain-sdk/v2/core/app"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/berachain/offchain-sdk/v2/server"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +27,7 @@ func StartCmd[C any](app coreapp.App[C], defaultAppHome string) *cobra.Command {
}

// StartCmdWithOptions runs the service passed in.
func StartCmdWithOptions[C any](
func StartCmdWithOptions[C any]( //nolint:gocognit // TODO: refactor
app coreapp.App[C], defaultAppHome string, _ StartCmdOptions,
) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -64,9 +64,9 @@ func StartCmdWithOptions[C any](
return err
}

ab := baseapp.NewAppBuilder(app.Name())

logger := log.NewWithCfg(cmd.OutOrStdout(), app.Name(), cfg.Log)

ab := baseapp.NewAppBuilder(app.Name(), logger)
// // Maybe move this to BuildApp?
// ethClient := eth.NewHealthCheckedClient(&cfg.Eth)
// ab.RegisterEthClient(ethClient)
Expand Down Expand Up @@ -95,7 +95,9 @@ func StartCmdWithOptions[C any](
}

// Build the application, then start it.
app.Setup(ab, cfg.App, logger)
if err = app.Setup(ab, cfg.App, logger); err != nil {
return err
}
if err = app.Start(ctx); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package config

import (
"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/server"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/log"
"github.com/berachain/offchain-sdk/v2/server"
)

// Reader defines an interface for reading in configuration data.
Expand Down
4 changes: 2 additions & 2 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package app
import (
"context"

"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/v2/log"
)

type App[C any] interface {
Name() string
Setup(ab Builder, config C, logger log.Logger)
Setup(ab Builder, config C, logger log.Logger) error
Start(context.Context) error
Stop()
}
12 changes: 5 additions & 7 deletions core/app/builder.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package app

import (
"github.com/berachain/offchain-sdk/baseapp"
"github.com/berachain/offchain-sdk/job"
"github.com/berachain/offchain-sdk/log"
"github.com/berachain/offchain-sdk/server"
"github.com/berachain/offchain-sdk/telemetry"
"github.com/berachain/offchain-sdk/v2/baseapp"
"github.com/berachain/offchain-sdk/v2/job"
"github.com/berachain/offchain-sdk/v2/server"
"github.com/berachain/offchain-sdk/v2/telemetry"

"github.com/ethereum/go-ethereum/ethdb"
)

// Builder is a builder for an app. It follows a basic factory pattern.
type Builder interface {
AppName() string
BuildApp(log.Logger) *baseapp.BaseApp
BuildApp() *baseapp.BaseApp
RegisterJob(job.Basic)
RegisterMetrics(cfg *telemetry.Config) error
RegisterDB(db ethdb.KeyValueStore)
RegisterHTTPHandler(handler *server.Handler) error
RegisterMiddleware(m server.Middleware) error
RegisterPrometheusTelemetry() error
}
2 changes: 1 addition & 1 deletion core/transactor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package transactor
import (
"time"

"github.com/berachain/offchain-sdk/types/queue/sqs"
"github.com/berachain/offchain-sdk/v2/types/queue/sqs"
)

type Config struct {
Expand Down
6 changes: 3 additions & 3 deletions core/transactor/factory/batcher/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

"github.com/berachain/offchain-sdk/client/eth"
"github.com/berachain/offchain-sdk/log"
sdk "github.com/berachain/offchain-sdk/types"
"github.com/berachain/offchain-sdk/v2/client/eth"
"github.com/berachain/offchain-sdk/v2/log"
sdk "github.com/berachain/offchain-sdk/v2/types"
"github.com/stretchr/testify/assert"

"github.com/ethereum/go-ethereum/common"
Expand Down
8 changes: 4 additions & 4 deletions core/transactor/factory/batcher/multicall3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"math/big"
"strings"

"github.com/berachain/offchain-sdk/contracts/bindings"
"github.com/berachain/offchain-sdk/core/transactor/factory"
"github.com/berachain/offchain-sdk/core/transactor/types"
sdk "github.com/berachain/offchain-sdk/types"
"github.com/berachain/offchain-sdk/v2/contracts/bindings"
"github.com/berachain/offchain-sdk/v2/core/transactor/factory"
"github.com/berachain/offchain-sdk/v2/core/transactor/types"
sdk "github.com/berachain/offchain-sdk/v2/types"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down
Loading
Loading