Skip to content
Open
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
46 changes: 34 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/cluster"
"github.com/obolnetwork/charon/cluster/proposerconfig"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/core/aggsigdb"
"github.com/obolnetwork/charon/core/bcast"
Expand Down Expand Up @@ -104,7 +105,6 @@ type Config struct {
ConsensusProtocol string
Nickname string
BeaconNodeHeaders []string
ProposerGasLimit uint64
FallbackBeaconNodeAddrs []string
ExecutionEngineAddr string
Graffiti []string
Expand All @@ -115,10 +115,8 @@ type Config struct {
PublishAddress string
PublishTimeout time.Duration
FetchFeerecipientUpdates bool
BuilderURLs []string
BuilderMinBid uint64
BuilderBoostFactor uint64
BuilderMaxExecutionPayment uint64
ProposerConfigFile string
ProposerConfigSeed proposerconfig.Seed

TestConfig TestConfig
}
Expand Down Expand Up @@ -511,7 +509,24 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
life.RegisterStart(lifecycle.AsyncAppCtx, lifecycle.StartBuilderRegWatcher,
lifecycle.HookFuncCtx(builderRegSvc.Run))

wireProposerConfigFile(ctx, conf, lock, nodeIdx, builderRegSvc.FeeRecipient)
genesis, err := eth2wrap.FetchGenesisTime(ctx, eth2Cl)
if err != nil {
return err
}

slotDur, slotsPerEpoch, err := eth2wrap.FetchSlotsConfig(ctx, eth2Cl)
if err != nil {
return err
}

currentEpoch := currentEpochFunc(genesis, slotDur, slotsPerEpoch)

gloasActive := func() bool { return forkSchedule().Active(eth2wrap.Gloas, currentEpoch()) }

_, err = loadProposerConfig(ctx, conf, *lock, nodeIdx, builderRegSvc.FeeRecipient, gloasActive)
Comment thread
KaloyanTanev marked this conversation as resolved.
Resolved
if err != nil {
return err
}

peers, err := lock.Peers()
if err != nil {
Expand Down Expand Up @@ -636,11 +651,6 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
return err
}

_, slotsPerEpoch, err := eth2wrap.FetchSlotsConfig(ctx, eth2Cl)
if err != nil {
return err
}

builderCfg := builderConfig(conf)

hosts, err := builderHosts(conf)
Expand All @@ -664,7 +674,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,

dutyDB := dutydb.NewMemDB(retainerFunc("dutydb"))

vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, builderRegSvc.FeeRecipient, conf.BuilderAPI, conf.ProposerGasLimit,
vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, builderRegSvc.FeeRecipient, conf.BuilderAPI, conf.ProposerConfigSeed.GasLimit,
validatorapi.WithBuilderHosts(hosts))
if err != nil {
return err
Expand Down Expand Up @@ -956,6 +966,18 @@ func calculateTrackerDelay(ctx context.Context, cl eth2wrap.Client, now time.Tim
return maxDelayTimeSlot, nil
}

// currentEpochFunc returns a function returning the current epoch per the genesis time and slot config.
func currentEpochFunc(genesisTime time.Time, slotDuration time.Duration, slotsPerEpoch uint64) func() eth2p0.Epoch {
return func() eth2p0.Epoch {
elapsed := time.Since(genesisTime)
if elapsed < 0 {
return 0
}

return eth2p0.Epoch(uint64(elapsed/slotDuration) / slotsPerEpoch)
}
}

// eth2PubKeys returns a list of BLS pubkeys of validators in the cluster lock.
func eth2PubKeys(lock *cluster.Lock) []eth2p0.BLSPubKey {
var pubkeys []eth2p0.BLSPubKey
Expand Down
17 changes: 17 additions & 0 deletions app/app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ func TestCalculateTrackerDelay(t *testing.T) {
}
}

func TestCurrentEpochFunc(t *testing.T) {
const slotDuration = 12 * time.Second

for _, test := range []struct {
name string
genesis time.Time
epoch uint64
}{
{name: "after genesis", genesis: time.Now().Add(-slotDuration * (3*16 + 5)), epoch: 3},
{name: "before genesis", genesis: time.Now().Add(time.Hour), epoch: 0},
} {
t.Run(test.name, func(t *testing.T) {
require.EqualValues(t, test.epoch, currentEpochFunc(test.genesis, slotDuration, 16)())
})
}
}

func TestSetFeeRecipient(t *testing.T) {
set := beaconmock.ValidatorSetA
for i := range len(set) {
Expand Down
32 changes: 16 additions & 16 deletions app/builderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// proposer configuration output. The other builder flags are rejected without URLs,
// so they cannot be set (and silently dropped) on their own.
func builderConfigured(conf Config) bool {
return len(conf.BuilderURLs) > 0
return len(conf.ProposerConfigSeed.BuilderURLs) > 0
}

// builderConfig returns the gloas builder configuration sent as the required body of
Expand All @@ -30,29 +30,29 @@ func builderConfigured(conf Config) bool {
// proposal from the aggregated builder preferences duty, leaving out a builder whose auth
// isn't aggregated.
func builderConfig(conf Config) *gloas.BuilderConfig {
builders := make([]*gloas.BuilderEntry, 0, len(conf.BuilderURLs))
for _, url := range conf.BuilderURLs {
builders := make([]*gloas.BuilderEntry, 0, len(conf.ProposerConfigSeed.BuilderURLs))
for _, url := range conf.ProposerConfigSeed.BuilderURLs {
builders = append(builders, &gloas.BuilderEntry{
URL: []byte(url),
BuilderPubkeys: []eth2p0.BLSPubKey{},
MaxExecutionPayment: eth2p0.Gwei(conf.BuilderMaxExecutionPayment),
MinBid: eth2p0.Gwei(conf.BuilderMinBid),
BuilderBoostFactor: conf.BuilderBoostFactor,
MaxExecutionPayment: eth2p0.Gwei(conf.ProposerConfigSeed.BuilderMaxExecutionPayment),
MinBid: eth2p0.Gwei(conf.ProposerConfigSeed.BuilderMinBid),
BuilderBoostFactor: conf.ProposerConfigSeed.BuilderBoostFactor,
})
}

return &gloas.BuilderConfig{
MinBid: eth2p0.Gwei(conf.BuilderMinBid),
BuilderBoostFactor: conf.BuilderBoostFactor,
MinBid: eth2p0.Gwei(conf.ProposerConfigSeed.BuilderMinBid),
BuilderBoostFactor: conf.ProposerConfigSeed.BuilderBoostFactor,
Builders: builders,
}
}

// builderHosts returns the hosts of the configured builders, the default data of the builder
// request auths validator clients sign for them, in the configured order.
func builderHosts(conf Config) ([]string, error) {
hosts := make([]string, 0, len(conf.BuilderURLs))
for _, url := range conf.BuilderURLs {
hosts := make([]string, 0, len(conf.ProposerConfigSeed.BuilderURLs))
for _, url := range conf.ProposerConfigSeed.BuilderURLs {
host, err := eth2util.BuilderAuthData(url)
if err != nil {
return nil, err
Expand All @@ -68,7 +68,7 @@ func builderHosts(conf Config) ([]string, error) {
// It is exchanged via the peerinfo protocol so peers can detect divergent builder
// configurations, which would produce divergent (non-aggregatable) builder duties.
func builderConfigHash(conf Config) []byte {
urls := slices.Clone(conf.BuilderURLs)
urls := slices.Clone(conf.ProposerConfigSeed.BuilderURLs)
slices.Sort(urls)

h := sha256.New()
Expand All @@ -79,7 +79,7 @@ func builderConfigHash(conf Config) []byte {
}

_, _ = fmt.Fprintf(h, "min_bid:%d\nbuilder_boost_factor:%d\nmax_execution_payment:%d\n",
conf.BuilderMinBid, conf.BuilderBoostFactor, conf.BuilderMaxExecutionPayment)
conf.ProposerConfigSeed.BuilderMinBid, conf.ProposerConfigSeed.BuilderBoostFactor, conf.ProposerConfigSeed.BuilderMaxExecutionPayment)

return h.Sum(nil)
}
Expand All @@ -91,13 +91,13 @@ func initBuilderConfigMetrics(conf Config) {
return
}

for _, u := range conf.BuilderURLs {
for _, u := range conf.ProposerConfigSeed.BuilderURLs {
builderURLGauge.WithLabelValues(withoutUserInfo(u)).Set(1)
}

builderMinBidGauge.WithLabelValues().Set(float64(conf.BuilderMinBid))
builderBoostFactorGauge.WithLabelValues().Set(float64(conf.BuilderBoostFactor))
builderMaxExecutionPaymentGauge.WithLabelValues().Set(float64(conf.BuilderMaxExecutionPayment))
builderMinBidGauge.WithLabelValues().Set(float64(conf.ProposerConfigSeed.BuilderMinBid))
builderBoostFactorGauge.WithLabelValues().Set(float64(conf.ProposerConfigSeed.BuilderBoostFactor))
builderMaxExecutionPaymentGauge.WithLabelValues().Set(float64(conf.ProposerConfigSeed.BuilderMaxExecutionPayment))
}

// withoutUserInfo returns the URL without its user info. Relay URLs carry the relay's public key as the
Expand Down
32 changes: 17 additions & 15 deletions app/builderconfig_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,70 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/obolnetwork/charon/cluster/proposerconfig"
)

func TestBuilderConfig(t *testing.T) {
// Each configured builder is an entry without its auth: the fetcher adds the aggregated
// builder request auth per proposal. MinBid and BuilderBoostFactor also gate P2P bids.
conf := Config{
conf := Config{ProposerConfigSeed: proposerconfig.Seed{
BuilderURLs: []string{"https://a.example.com", "https://b.example.com"},
BuilderMinBid: 7,
BuilderBoostFactor: 120,
BuilderMaxExecutionPayment: 3,
}
}}

cfg := builderConfig(conf)
require.EqualValues(t, 7, cfg.MinBid)
require.EqualValues(t, 120, cfg.BuilderBoostFactor)
require.Len(t, cfg.Builders, 2)

for i, entry := range cfg.Builders {
require.Equal(t, []byte(conf.BuilderURLs[i]), entry.URL)
require.Equal(t, []byte(conf.ProposerConfigSeed.BuilderURLs[i]), entry.URL)
require.Nil(t, entry.Auth)
require.Empty(t, entry.BuilderPubkeys)
require.EqualValues(t, 3, entry.MaxExecutionPayment)
require.EqualValues(t, 7, entry.MinBid)
require.EqualValues(t, 120, entry.BuilderBoostFactor)
}

require.Empty(t, builderConfig(Config{BuilderMinBid: 7}).Builders)
require.Empty(t, builderConfig(Config{ProposerConfigSeed: proposerconfig.Seed{BuilderMinBid: 7}}).Builders)
}

func TestBuilderConfigured(t *testing.T) {
require.False(t, builderConfigured(Config{}))
// The other builder values only apply alongside builder URLs, the flags reject them without.
require.False(t, builderConfigured(Config{BuilderMinBid: 1, BuilderBoostFactor: 99, BuilderMaxExecutionPayment: 1}))
require.False(t, builderConfigured(Config{ProposerConfigSeed: proposerconfig.Seed{BuilderMinBid: 1, BuilderBoostFactor: 99, BuilderMaxExecutionPayment: 1}}))

require.True(t, builderConfigured(Config{BuilderURLs: []string{"https://builder.example.com"}}))
require.True(t, builderConfigured(Config{ProposerConfigSeed: proposerconfig.Seed{BuilderURLs: []string{"https://builder.example.com"}}}))
}

func TestBuilderConfigHash(t *testing.T) {
conf := Config{
conf := Config{ProposerConfigSeed: proposerconfig.Seed{
BuilderURLs: []string{"https://b.example.com", "https://a.example.com"},
BuilderMinBid: 1,
BuilderBoostFactor: 100,
BuilderMaxExecutionPayment: 2,
}
}}

hash := builderConfigHash(conf)
require.Len(t, hash, 32)

// The hash is insensitive to builder URL order.
reordered := conf
reordered.BuilderURLs = []string{"https://a.example.com", "https://b.example.com"}
reordered.ProposerConfigSeed.BuilderURLs = []string{"https://a.example.com", "https://b.example.com"}
require.Equal(t, hash, builderConfigHash(reordered))

// Each value contributes to the hash.
for _, mutate := range []func(*Config){
func(c *Config) { c.BuilderURLs = c.BuilderURLs[:1] },
func(c *Config) { c.BuilderMinBid++ },
func(c *Config) { c.BuilderBoostFactor++ },
func(c *Config) { c.BuilderMaxExecutionPayment++ },
func(c *Config) { c.ProposerConfigSeed.BuilderURLs = c.ProposerConfigSeed.BuilderURLs[:1] },
func(c *Config) { c.ProposerConfigSeed.BuilderMinBid++ },
func(c *Config) { c.ProposerConfigSeed.BuilderBoostFactor++ },
func(c *Config) { c.ProposerConfigSeed.BuilderMaxExecutionPayment++ },
} {
mutated := conf
mutated.BuilderURLs = append([]string(nil), conf.BuilderURLs...)
mutated.ProposerConfigSeed.BuilderURLs = append([]string(nil), conf.ProposerConfigSeed.BuilderURLs...)
mutate(&mutated)
require.NotEqual(t, hash, builderConfigHash(mutated))
}
Expand All @@ -77,7 +79,7 @@ func TestBuilderConfigHash(t *testing.T) {
}

func TestBuilderHosts(t *testing.T) {
hosts, err := builderHosts(Config{BuilderURLs: []string{"https://Relay-A.example.com:443/path", "http://relay-b.example.com"}})
hosts, err := builderHosts(Config{ProposerConfigSeed: proposerconfig.Seed{BuilderURLs: []string{"https://Relay-A.example.com:443/path", "http://relay-b.example.com"}}})
require.NoError(t, err)
require.Equal(t, []string{"relay-a.example.com", "relay-b.example.com"}, hosts)

Expand Down
14 changes: 14 additions & 0 deletions app/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ var (
Help: "The configured maximum execution layer payment in gwei counted when valuing a builder bid. Absent when no builder URLs are configured.",
}, nil)

proposerConfigRevisionGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "app",
Subsystem: "proposer_config",
Name: "revision",
Help: "The revision of the loaded proposer config document, 0 for an unsigned document derived locally from the lock and flags.",
})

proposerConfigInvalidGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "app",
Subsystem: "proposer_config",
Name: "invalid",
Help: "Set to 1 while the proposer config file fails validation or cannot be loaded, 0 otherwise.",
})

validatorStackParamsGauge = promauto.NewResetGaugeVec(prometheus.GaugeOpts{
Namespace: "app",
Subsystem: "validator_stack",
Expand Down
Loading
Loading