Skip to content

Commit

Permalink
small config changes in main (removal of unused) (#115)
Browse files Browse the repository at this point in the history
* small config changes in main (removal of unused)

* typo

* Add builder pubkey to logs
  • Loading branch information
lukanus authored Mar 24, 2023
1 parent 2fb7086 commit ac93531
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 128 deletions.
80 changes: 1 addition & 79 deletions cmd/dreamboat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ package config

import (
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
"strings"

"github.com/blocknative/dreamboat/structs"
)

const (
Expand All @@ -35,30 +30,14 @@ const (

// Config provides all available options for the default BeaconClient and Relay
type Config struct {
builders map[structs.PubKey]*builder

GenesisForkVersion string
BellatrixForkVersion string
CapellaForkVersion string
GenesisValidatorsRoot string
}

func NewConfig() *Config {
return &Config{
builders: make(map[structs.PubKey]*builder),
}
}

func (c *Config) LoadBuilders(builderURLs []string) (err error) {
var entry *builder
for _, b := range builderURLs {
if entry, err = newBuilderEntry(b); err != nil {
break
}

c.builders[entry.PubKey] = entry
}
return err
return &Config{}
}

func (c *Config) LoadNetwork(network string) {
Expand Down Expand Up @@ -116,60 +95,3 @@ func (c *Config) ReadNetworkConfig(datadir, network string) (err error) {

return nil
}

// builder represents a builder that the relay service connects to.
type builder struct {
PubKey structs.PubKey
URL *url.URL
}

func (b builder) Loggable() map[string]any {
return map[string]any{
"pubkey": b.PubKey,
"url": b.URL,
}
}

// NewRelayEntry creates a new instance based on an input string
// relayURL can be IP@PORT, PUBKEY@IP:PORT, https://IP, etc.
func newBuilderEntry(relayURL string) (*builder, error) {
u, err := url.ParseRequestURI(ensureScheme(relayURL))
if err != nil {
return nil, err
}

// Extract the relay's public key from the parsed URL.
if !hasPubKey(u) {
return nil, errors.New("missing relay public key")
}

var pk structs.PubKey
if err = pk.UnmarshalText([]byte(u.User.Username())); err != nil {
return nil, err
}

return &builder{
PubKey: pk,
URL: u,
}, nil
}

// GetURI returns the full request URI with scheme, host, path and args.
func (b builder) GetURI(path string) string {
u := *b.URL
u.User = nil
u.Path = path
return u.String()
}

func ensureScheme(url string) string {
if strings.HasPrefix(url, "http") {
return url
}

return fmt.Sprintf("http://%s", url)
}

func hasPubKey(u *url.URL) bool {
return u.User.Username() != ""
}
36 changes: 6 additions & 30 deletions cmd/dreamboat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ var flags = []cli.Flag{
Value: "text",
EnvVars: []string{"LOGFMT"},
},
&cli.BoolFlag{
Name: "profile",
Usage: "activates profiling http endpoint",
Value: false,
},
&cli.StringFlag{
Name: "addr",
Usage: "server listen address",
Expand All @@ -95,12 +90,7 @@ var flags = []cli.Flag{
Usage: "`url` for beacon endpoint",
EnvVars: []string{"RELAY_BEACON"},
},
&cli.BoolFlag{
Name: "check-builders",
Usage: "check builder blocks",
EnvVars: []string{"RELAY_CHECK_BUILDERS"},
},
&cli.StringSliceFlag{
&cli.StringSliceFlag{ // TODO: Remove
Name: "builder",
Usage: "`url` formatted as schema://pubkey@host",
EnvVars: []string{"BN_RELAY_BUILDER_URLS"},
Expand Down Expand Up @@ -165,18 +155,6 @@ var flags = []cli.Flag{
Value: 200,
EnvVars: []string{"RELAY_HEADER_MEMORY_SLOT_LAG"},
},
&cli.DurationFlag{
Name: "relay-header-memory-slot-time-lag",
Usage: "how log should it take for lagged slot to be eligible fot purge",
Value: time.Minute * 5,
EnvVars: []string{"RELAY_HEADER_MEMORY_SLOT_TIME_LAG"},
},
&cli.DurationFlag{
Name: "relay-header-memory-purge-interval",
Usage: "how often memory should be purged",
Value: time.Minute * 10,
EnvVars: []string{"RELAY_HEADER_MEMORY_PURGE_INTERVAL"},
},
&cli.IntFlag{
Name: "relay-payload-cache-size",
Usage: "number of payloads to cache for fast in-memory reads",
Expand Down Expand Up @@ -213,7 +191,7 @@ var flags = []cli.Flag{
Value: "",
EnvVars: []string{"RELAY_DATAAPI_DATABASE_URL"},
},
&cli.BoolFlag{
&cli.BoolFlag{ // TODO: Remove
Name: "relay-fast-boot",
Usage: "speed up booting up of relay, adding temporary inconsistency on the builder_blocks_received endpoint",
Value: false,
Expand Down Expand Up @@ -295,12 +273,8 @@ func run() cli.ActionFunc {
}
}

if err := cfg.LoadBuilders(c.StringSlice("builder")); err != nil {
return err
}

TTL := c.Duration("ttl")
logger := logger(c).WithField("fast-boot", c.Bool("relay-fast-boot"))
logger := logger(c)

timeDataStoreStart := time.Now()
m := metrics.NewMetrics()
Expand Down Expand Up @@ -401,7 +375,9 @@ func run() cli.ActionFunc {

validatorStoreManager := validators.NewStoreManager(logger, validatorCache, valDS, int(math.Floor(TTL.Seconds()/2)), c.Uint("relay-store-queue-size"))
validatorStoreManager.AttachMetrics(m)
validatorStoreManager.RunStore(c.Uint("relay-workers-store-validator"))
if c.Uint("relay-workers-store-validator") > 0 {
validatorStoreManager.RunStore(c.Uint("relay-workers-store-validator"))
}

domainBuilder, err := ComputeDomain(types.DomainTypeAppBuilder, cfg.GenesisForkVersion, types.Root{}.String())
if err != nil {
Expand Down
37 changes: 21 additions & 16 deletions relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (rs *Relay) GetPayload(ctx context.Context, m *structs.MetricGroup, payload
"blockHash": payloadRequest.BlockHash(),
"pubkey": pk,
})
logger.Info("payload requested")
logger.WithField("event", "payload_requested").Info("payload requested")

forkv := rs.beaconState.ForkVersion(structs.Slot(payloadRequest.Slot()))

Expand All @@ -337,13 +337,13 @@ func (rs *Relay) GetPayload(ctx context.Context, m *structs.MetricGroup, payload

key, err := payloadRequest.ToPayloadKey(pk)
if err != nil {
logger.WithError(err).Warn("error getting payload")
logger.WithField("event", "invalid_payload_key").WithError(err).Warn("error getting payload")
return nil, ErrNoPayloadFound
}

payload, fromCache, err := rs.d.GetPayload(ctx, forkv, key)
if err != nil || payload == nil {
logger.WithError(err).Warn("error getting payload")
logger.WithField("event", "storage_error").WithError(err).Warn("error getting payload")
return nil, ErrNoPayloadFound
}
m.AppendSince(tGet, "getPayload", "get")
Expand All @@ -352,46 +352,49 @@ func (rs *Relay) GetPayload(ctx context.Context, m *structs.MetricGroup, payload
rs.lastDeliveredSlot.Store(payloadRequest.Slot())
}

logger = logger.With(log.F{
"from_cache": fromCache,
"builder": payload.BuilderPubkey().String(),
"processingTimeMs": time.Since(tStart).Milliseconds(),
})

// defer put delivered datastore write
go func(rs *Relay, slot structs.Slot, payloadRequest structs.SignedBlindedBeaconBlock) {
go func(l log.Logger, rs *Relay, slot structs.Slot, payloadRequest structs.SignedBlindedBeaconBlock) {
if rs.config.PublishBlock {
beaconBlock, err := payloadRequest.ToBeaconBlock(payload.ExecutionPayload())
if err != nil {
logger.WithError(err).Warn("fail to create block for publication")
l.WithField("event", "wrong_publish_payload").WithError(err).Warn("fail to create block for publication")
} else {
if err = rs.beacon.PublishBlock(beaconBlock); err != nil {
logger.With(log.F{
l.With(log.F{
"slot": slot,
"block_number": payloadRequest.BlockNumber(),
}).WithError(err).Warn("fail to publish block to beacon node")
}).WithField("event", "publish_error").WithError(err).Warn("fail to publish block to beacon node")
} else {
logger.Info("published block to beacon node")
l.WithField("event", "published").Info("published block to beacon node")
}
}
}

trace, err := payload.ToDeliveredTrace(payloadRequest.Slot())
if err != nil {
logger.WithError(err).Warn("failed to generate delivered payload")
l.WithField("event", "wrong_evidence_payload").WithError(err).Warn("failed to generate delivered payload")
return
}

if err := rs.das.PutDelivered(context.Background(), slot, trace, rs.config.TTL); err != nil {
logger.WithError(err).Warn("failed to set payload after delivery")
l.WithField("event", "evidence_failure").WithError(err).Warn("failed to set payload after delivery")
}
}(rs, structs.Slot(payloadRequest.Slot()), payloadRequest)
}(logger, rs, structs.Slot(payloadRequest.Slot()), payloadRequest)

exp := payload.ExecutionPayload()

logger = logger.With(log.F{
"slot": payloadRequest.Slot(),
"from_cache": fromCache,
"processingTimeMs": time.Since(tStart).Milliseconds(),
})
switch forkv {
case structs.ForkBellatrix:
bep := exp.(*bellatrix.ExecutionPayload)
logger.With(log.F{
"fork": "bellatrix",
"event": "payload_sent",
"blockHash": bep.EpBlockHash,
"blockNumber": bep.EpBlockNumber,
"stateRoot": bep.EpStateRoot,
Expand All @@ -407,6 +410,7 @@ func (rs *Relay) GetPayload(ctx context.Context, m *structs.MetricGroup, payload
cep := exp.(*capella.ExecutionPayload)
logger.With(log.F{
"fork": "capella",
"event": "payload_sent",
"blockHash": cep.EpBlockHash,
"blockNumber": cep.EpBlockNumber,
"stateRoot": cep.EpStateRoot,
Expand All @@ -419,6 +423,7 @@ func (rs *Relay) GetPayload(ctx context.Context, m *structs.MetricGroup, payload
CapellaData: *cep,
}, nil
}
logger.Error("unknown fork failure")
return nil, errors.New("unknown fork")

}
9 changes: 8 additions & 1 deletion structs/forks/bellatrix/bellatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,15 @@ func (bbat *BlockBidAndTrace) ExecutionPayload() structs.ExecutionPayload {
return &bbat.Payload.BellatrixData
}

func (bbat *BlockBidAndTrace) BuilderPubkey() (pub types.PublicKey) {
if bbat.Trace == nil || bbat.Trace.Message == nil {
return pub
}
return bbat.Trace.Message.BuilderPubkey
}

func (bbat *BlockBidAndTrace) ToDeliveredTrace(slot uint64) (dt structs.DeliveredTrace, err error) {
if bbat.Trace.Message == nil {
if bbat.Trace == nil || bbat.Trace.Message == nil {
return dt, errors.New("empty trace contents")
}
return structs.DeliveredTrace{
Expand Down
9 changes: 8 additions & 1 deletion structs/forks/capella/capella.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,15 @@ func (bbat *BlockBidAndTrace) ExecutionPayload() structs.ExecutionPayload {
return &bbat.Payload.CapellaData
}

func (bbat *BlockBidAndTrace) BuilderPubkey() (pub types.PublicKey) {
if bbat.Trace == nil || bbat.Trace.Message == nil {
return pub
}
return bbat.Trace.Message.BuilderPubkey
}

func (bbat *BlockBidAndTrace) ToDeliveredTrace(slot uint64) (dt structs.DeliveredTrace, err error) {
if bbat.Trace.Message == nil {
if bbat.Trace == nil || bbat.Trace.Message == nil {
return dt, errors.New("empty message")
}
return structs.DeliveredTrace{
Expand Down
1 change: 1 addition & 0 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type ExecutionPayloadHeader interface {

type BlockBidAndTrace interface {
BidValue() types.U256Str
BuilderPubkey() (pub types.PublicKey)

ExecutionPayload() ExecutionPayload
ToDeliveredTrace(slot uint64) (DeliveredTrace, error)
Expand Down
2 changes: 1 addition & 1 deletion verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Request struct {
Response *StoreResp
}

// Resp respone structure
// Resp response structure
// - potential candidate for structure pool
// as it's almost constant size
type Resp struct {
Expand Down

0 comments on commit ac93531

Please sign in to comment.