Skip to content

Commit

Permalink
feat: oracle dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Apr 17, 2024
1 parent fb27389 commit 55164bb
Show file tree
Hide file tree
Showing 5 changed files with 575 additions and 39 deletions.
48 changes: 33 additions & 15 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ var (
//Value: contracts.TestnetContracts.BlockTracker,
})

optionBidderRegistryContractAddr = altsrc.NewStringFlag(&cli.StringFlag{
Name: "bidder-registry-contract-addr",
Usage: "address of the bidder registry contract",
EnvVars: []string{"MEV_ORACLE_BIDDERREGISTRY_CONTRACT_ADDR"},
Value: contracts.TestnetContracts.BidderRegistry,
})

optionProviderRegistryContractAddr = altsrc.NewStringFlag(&cli.StringFlag{
Name: "provider-registry-contract-addr",
Usage: "address of the provider registry contract",
EnvVars: []string{"MEV_ORACLE_PROVIDERREGISTRY_CONTRACT_ADDR"},
Value: contracts.TestnetContracts.ProviderRegistry,
})

optionPgHost = altsrc.NewStringFlag(&cli.StringFlag{
Name: "pg-host",
Usage: "PostgreSQL host",
Expand Down Expand Up @@ -204,6 +218,8 @@ func main() {
optionOracleContractAddr,
optionPreconfContractAddr,
optionBlockTrackerContractAddr,
optionBidderRegistryContractAddr,
optionProviderRegistryContractAddr,
optionPgHost,
optionPgPort,
optionPgUser,
Expand Down Expand Up @@ -272,21 +288,23 @@ func launchOracleWithConfig(c *cli.Context) error {
logger.Info("key signer account", "address", keySigner.GetAddress().Hex(), "url", keySigner.String())

nd, err := node.NewNode(&node.Options{
Logger: logger,
KeySigner: keySigner,
HTTPPort: c.Int(optionHTTPPort.Name),
L1RPCUrl: c.String(optionL1RPCUrl.Name),
SettlementRPCUrl: c.String(optionSettlementRPCUrl.Name),
OracleContractAddr: common.HexToAddress(c.String(optionOracleContractAddr.Name)),
PreconfContractAddr: common.HexToAddress(c.String(optionPreconfContractAddr.Name)),
BlockTrackerContractAddr: common.HexToAddress(c.String(optionBlockTrackerContractAddr.Name)),
PgHost: c.String(optionPgHost.Name),
PgPort: c.Int(optionPgPort.Name),
PgUser: c.String(optionPgUser.Name),
PgPassword: c.String(optionPgPassword.Name),
PgDbname: c.String(optionPgDbname.Name),
LaggerdMode: c.Int(optionLaggerdMode.Name),
OverrideWinners: c.StringSlice(optionOverrideWinners.Name),
Logger: logger,
KeySigner: keySigner,
HTTPPort: c.Int(optionHTTPPort.Name),
L1RPCUrl: c.String(optionL1RPCUrl.Name),
SettlementRPCUrl: c.String(optionSettlementRPCUrl.Name),
OracleContractAddr: common.HexToAddress(c.String(optionOracleContractAddr.Name)),
PreconfContractAddr: common.HexToAddress(c.String(optionPreconfContractAddr.Name)),
BlockTrackerContractAddr: common.HexToAddress(c.String(optionBlockTrackerContractAddr.Name)),
ProviderRegistryContractAddr: common.HexToAddress(c.String(optionProviderRegistryContractAddr.Name)),
BidderRegistryContractAddr: common.HexToAddress(c.String(optionBidderRegistryContractAddr.Name)),
PgHost: c.String(optionPgHost.Name),
PgPort: c.Int(optionPgPort.Name),
PgUser: c.String(optionPgUser.Name),
PgPassword: c.String(optionPgPassword.Name),
PgDbname: c.String(optionPgDbname.Name),
LaggerdMode: c.Int(optionLaggerdMode.Name),
OverrideWinners: c.StringSlice(optionOverrideWinners.Name),
})
if err != nil {
return fmt.Errorf("failed starting node: %w", err)
Expand Down
52 changes: 44 additions & 8 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import (
"net"
"net/http"
"net/http/pprof"
"sync"
"time"

lru "github.com/hashicorp/golang-lru/v2"
"github.com/primevprotocol/mev-oracle/pkg/events"
"github.com/primevprotocol/mev-oracle/pkg/settler"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -19,21 +23,52 @@ const (
defaultNamespace = "mev_commit_oracle"
)

type Store interface {
Settlement(context.Context, []byte) (settler.Settlement, error)
}

// Service wraps http.Server with additional functionality for metrics and
// other common middlewares.
type Service struct {
logger *slog.Logger
metricsRegistry *prometheus.Registry
router *http.ServeMux
srv *http.Server
logger *slog.Logger
metricsRegistry *prometheus.Registry
router *http.ServeMux
srv *http.Server
evtMgr events.EventManager
store Store
statMu sync.RWMutex
blockStats *lru.Cache[uint64, *BlockStats]
providerStakes *lru.Cache[string, *ProviderBalances]
bidderAllowances *lru.Cache[uint64, []*BidderAllowance]
lastBlock uint64
shutdown chan struct{}
}

// New creates a new Service.
func New(logger *slog.Logger) *Service {
func New(
logger *slog.Logger,
evm events.EventManager,
store Store,
) *Service {
blockStats, _ := lru.New[uint64, *BlockStats](10000)
providerStakes, _ := lru.New[string, *ProviderBalances](1000)
bidderAllowances, _ := lru.New[uint64, []*BidderAllowance](1000)

srv := &Service{
logger: logger,
router: http.NewServeMux(),
metricsRegistry: newMetrics(),
logger: logger,
router: http.NewServeMux(),
metricsRegistry: newMetrics(),
evtMgr: evm,
store: store,
shutdown: make(chan struct{}),
blockStats: blockStats,
providerStakes: providerStakes,
bidderAllowances: bidderAllowances,
}

err := srv.configureDashboard()
if err != nil {
logger.Error("failed to configure dashboard", "error", err)
}

srv.registerDebugEndpoints()
Expand Down Expand Up @@ -115,6 +150,7 @@ func (s *Service) Stop() error {
if s.srv == nil {
return nil
}
defer close(s.shutdown)
return s.srv.Shutdown(context.Background())
}

Expand Down
Loading

0 comments on commit 55164bb

Please sign in to comment.