diff --git a/app/app.go b/app/app.go index 8f992634f8..7c568cbeef 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -104,7 +105,6 @@ type Config struct { ConsensusProtocol string Nickname string BeaconNodeHeaders []string - ProposerGasLimit uint64 FallbackBeaconNodeAddrs []string ExecutionEngineAddr string Graffiti []string @@ -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 } @@ -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) + if err != nil { + return err + } peers, err := lock.Peers() if err != nil { @@ -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) @@ -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 @@ -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 diff --git a/app/app_internal_test.go b/app/app_internal_test.go index 842ff88dc1..fc2e247165 100644 --- a/app/app_internal_test.go +++ b/app/app_internal_test.go @@ -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) { diff --git a/app/builderconfig.go b/app/builderconfig.go index ecf536c52f..1329a60f88 100644 --- a/app/builderconfig.go +++ b/app/builderconfig.go @@ -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 @@ -30,20 +30,20 @@ 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, } } @@ -51,8 +51,8 @@ func builderConfig(conf Config) *gloas.BuilderConfig { // 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 @@ -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() @@ -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) } @@ -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 diff --git a/app/builderconfig_internal_test.go b/app/builderconfig_internal_test.go index 414204576e..28344a5fbf 100644 --- a/app/builderconfig_internal_test.go +++ b/app/builderconfig_internal_test.go @@ -6,17 +6,19 @@ 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) @@ -24,7 +26,7 @@ func TestBuilderConfig(t *testing.T) { 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) @@ -32,42 +34,42 @@ func TestBuilderConfig(t *testing.T) { 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)) } @@ -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) diff --git a/app/metrics.go b/app/metrics.go index 5c4e222059..c036e90a71 100644 --- a/app/metrics.go +++ b/app/metrics.go @@ -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", diff --git a/app/proposerconfig.go b/app/proposerconfig.go index 8ed9365c62..7e5cda508c 100644 --- a/app/proposerconfig.go +++ b/app/proposerconfig.go @@ -4,295 +4,235 @@ package app import ( "context" - "encoding/json" - "fmt" - "os" - "path/filepath" "slices" "strconv" + "strings" "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/core" ) -// proposerConfigDir and proposerConfigFilename locate the generated validator client -// proposer configuration file in a dedicated directory next to the cluster lock file, -// keeping validator client facing configuration separate from charon's own files. -const ( - proposerConfigDir = "vc-config" - proposerConfigFilename = "proposer-config.json" +// proposerConfigEditCmd is the command changing the proposer config cluster-wide. +const proposerConfigEditCmd = "charon alpha edit proposer-config" - // proposerConfigVersion is the charon proposer configuration schema version, - // bumped on backwards incompatible schema changes. - proposerConfigVersion = 1 -) - -// proposerConfigJSON is charon's canonical proposer configuration schema, closely -// modelled on the Prysm/Teku proposer settings format minus its pre-gloas legacy -// fields. It is consumed by per validator client adapters (the CDVN wrapper scripts) -// which render each client's native format from it. -// -// The consumer contract: a validator absent from proposer_config uses default_config; -// entries are only emitted for validators diverging from it and only carry the -// diverging fields. Any absent field falls back to the corresponding field one level -// up, ultimately default_config. Since jq's // operator swallows false, the schema -// must never make a boolean field optional. -type proposerConfigJSON struct { - // Version is the charon proposer configuration schema version. - Version uint32 `json:"version"` - // ProposerConfig maps this node's validator public shares (the identities the - // validator client manages) to their proposer settings. Only validators whose - // settings diverge from default_config have an entry. - ProposerConfig map[string]proposerSettingsJSON `json:"proposer_config"` - // DefaultConfig applies to validators without an explicit entry, holding the - // majority settings across this node's validators. - DefaultConfig proposerSettingsJSON `json:"default_config"` -} - -// proposerSettingsJSON holds one validator's proposer settings. All fields are set -// on default_config; a proposer_config entry only carries the fields diverging from -// it, the rest fall back to default_config. -type proposerSettingsJSON struct { - FeeRecipient string `json:"fee_recipient,omitempty"` - // GasLimit is the preferred target gas limit for the execution payload. - GasLimit string `json:"gas_limit,omitempty"` - // Builder holds the gloas builder configuration, only emitted on default_config - // and only when builder URLs are configured. Per-validator overrides may be - // emitted additively in the future. - Builder *builderSettingsJSON `json:"builder,omitempty"` -} - -// builderSettingsJSON holds the builder configuration defaults; each entry in -// Builders may override them (mirroring how proposer_config entries override -// default_config), falling back to these values for absent fields. -type builderSettingsJSON struct { - // MinBid is the minimum bid value in gwei, applying to p2p gossip bids as well. - MinBid string `json:"min_bid"` - // BuilderBoostFactor is the percentage multiplier applied to builder bid values. - BuilderBoostFactor string `json:"builder_boost_factor"` - // MaxExecutionPayment is the maximum execution layer payment in gwei counted - // when valuing a builder bid. - MaxExecutionPayment string `json:"max_execution_payment"` - // Builders lists the builders to request execution payload bids from directly. - Builders []builderEntryJSON `json:"builders"` -} - -// builderEntryJSON is one builder to request bids from directly. The override -// fields are part of the schema for consumers but charon does not emit them yet, -// all builders currently share the enclosing defaults. -type builderEntryJSON struct { - URL string `json:"url"` - // The fields below optionally override the enclosing builderSettingsJSON values - // for this builder; if missing, use the enclosing value. - MinBid string `json:"min_bid,omitempty"` - BuilderBoostFactor string `json:"builder_boost_factor,omitempty"` - MaxExecutionPayment string `json:"max_execution_payment,omitempty"` -} - -// writeProposerConfigFile generates the validator client proposer configuration file -// if it doesn't already exist. Fee recipients mirror what charon registers with builders: -// the effective builder registrations including operator overrides, falling back to the -// cluster lock. The gas limit is the configured proposer gas limit. An existing file is -// never modified. -func writeProposerConfigFile(conf Config, lock *cluster.Lock, nodeIdx cluster.NodeIdx, - feeRecipientFunc func(core.PubKey) string, -) (bool, error) { - dir := filepath.Join(filepath.Dir(conf.LockFile), proposerConfigDir) - if err := os.MkdirAll(dir, 0o755); err != nil { - return false, errors.Wrap(err, "create proposer config directory", z.Str("dir", dir)) +// loadProposerConfig loads the validator client proposer config file on start, writing the initial one if it is +// absent and verifying it. Only a file of another +// cluster and an initial config needed but underivable return errors; other failures are logged and a document returned. +func loadProposerConfig(ctx context.Context, conf Config, lock cluster.Lock, nodeIdx cluster.NodeIdx, + feeRecipientFunc func(core.PubKey) string, gloasActive func() bool, +) (proposerconfig.Document, error) { + // The initial config is only derived when needed, a valid signed file never depends on it. + initial := func() (proposerconfig.Document, error) { + return InitialProposerConfig(lock, conf.ProposerConfigSeed, feeRecipientFunc) } - path := filepath.Join(dir, proposerConfigFilename) - - if info, err := os.Stat(path); err == nil { - if info.IsDir() { - return false, errors.New("proposer config file path is a directory", z.Str("path", path)) - } - - return false, nil // Never modify an existing file. - } else if !os.IsNotExist(err) { - return false, errors.Wrap(err, "stat proposer config file", z.Str("path", path)) + if conf.TestConfig.Lock != nil { + // In-memory test lock, there is no cluster directory holding the file. + return initial() } - feeRecipients := lock.FeeRecipientAddresses() - - // Resolve each validator's settings, counting identical ones to determine the - // majority default below. - type valSettings struct { - pubshareHex string - feeRecipient string - } + path := conf.ProposerConfigFile + ctx = log.WithCtx(ctx, z.Str("path", path)) - var ( - all []valSettings - feeCounts = make(map[string]int) - ) + doc, err := proposerconfig.Load(path, lock, nodeIdx) + if errors.Is(err, proposerconfig.ErrLockHashMismatch) { + return proposerconfig.Document{}, errors.Wrap(err, "proposer config file belongs to another cluster (after a lock-changing edit, use vc-config/ from its output directory)") + } else if errors.Is(err, proposerconfig.ErrNotFound) { + return writeInitialProposerConfig(ctx, path, lock, nodeIdx, initial, gloasActive) + } else if err != nil { + // Leave the file untouched for the operator to inspect, charon uses the initial config meanwhile. + log.Error(ctx, "Failed loading proposer config file, using one derived from the lock and flags; fix it or delete it to regenerate", err) - for vi, val := range lock.Validators { - pubshare, err := val.PublicShare(nodeIdx.PeerIdx) + doc, err = initial() if err != nil { - return false, errors.Wrap(err, "public share", z.Int("validator", vi)) + return proposerconfig.Document{}, err } - corePubkey, err := core.PubKeyFromBytes(val.PubKey) - if err != nil { - return false, errors.Wrap(err, "core pubkey", z.Int("validator", vi)) - } + setProposerConfigGauges(doc, false) - feeRecipient := feeRecipientFunc(corePubkey) - if feeRecipient == "" { - feeRecipient = feeRecipients[vi] - } + return doc, nil + } - vs := valSettings{ - pubshareHex: fmt.Sprintf("%#x", pubshare), - feeRecipient: feeRecipient, - } + err = proposerconfig.Verify(doc, lock) + valid := err == nil + setProposerConfigGauges(doc, valid) - all = append(all, vs) - feeCounts[vs.feeRecipient]++ + if valid { + log.Info(ctx, "Loaded proposer config file", revisionFields(doc)...) + } else { + // The validator client uses the file regardless, so charon does too. + log.Error(ctx, "Invalid proposer config file, using it anyway", err, z.U64("revision", doc.Revision)) } - // The default config holds the majority fee recipient, ties broken by the first - // validator holding it, so the common uniform cluster emits no entries. - var defaultFee string - - for _, vs := range all { - if feeCounts[vs.feeRecipient] > feeCounts[defaultFee] { - defaultFee = vs.feeRecipient - } + // Unsigned, the flags seeded it: report where it differs from them. + if doc.Revision == 0 { + warnUnsignedProposerConfigDiffers(ctx, lock, doc, initial) + warnUnsignedProposerConfigAfterGloas(ctx, gloasActive) } - config := proposerConfigJSON{ - Version: proposerConfigVersion, - ProposerConfig: make(map[string]proposerSettingsJSON), - DefaultConfig: proposerSettingsJSON{ - FeeRecipient: defaultFee, - GasLimit: strconv.FormatUint(conf.ProposerGasLimit, 10), - Builder: builderSettings(conf), - }, + // Signed and verified: report the seeding flags it overrides. + if doc.Revision > 0 && valid { + warnSignedProposerConfigOverridesFlags(ctx, doc, conf.ProposerConfigSeed) } - // Entries only carry the fields diverging from the default config. - for _, vs := range all { - if vs.feeRecipient == defaultFee { - continue // Covered by the default config. - } + return doc, nil +} - config.ProposerConfig[vs.pubshareHex] = proposerSettingsJSON{FeeRecipient: vs.feeRecipient} +// writeInitialProposerConfig writes the initial config to the absent file, returning it even if the write fails. +func writeInitialProposerConfig(ctx context.Context, path string, lock cluster.Lock, nodeIdx cluster.NodeIdx, + initial func() (proposerconfig.Document, error), gloasActive func() bool, +) (proposerconfig.Document, error) { + doc, err := initial() + if err != nil { + return proposerconfig.Document{}, err } - b, err := json.Marshal(config) + err = proposerconfig.Write(path, doc, lock, nodeIdx) if err != nil { - return false, errors.Wrap(err, "marshal proposer config") - } + log.Error(ctx, "Failed writing proposer config file", err) + setProposerConfigGauges(doc, false) - //nolint:gosec // Configuration file without secrets, needs to be readable by validator clients. - if err := os.WriteFile(path, append(b, '\n'), 0o644); err != nil { - return false, errors.Wrap(err, "write proposer config file", z.Str("path", path)) + return doc, nil } - return true, nil + setProposerConfigGauges(doc, true) + log.Info(ctx, "Generated proposer config file for validator clients", revisionFields(doc)...) + warnUnsignedProposerConfigAfterGloas(ctx, gloasActive) + + return doc, nil } -// builderSettings returns the builder settings of the proposer config, nil if no builder -// URLs are configured. -func builderSettings(conf Config) *builderSettingsJSON { - if !builderConfigured(conf) { - return nil +// warnUnsignedProposerConfigDiffers warns once if the unsigned (revision 0) file differs from the initial config +// derived from the lock and flags; the file wins since the flags only seed it. +func warnUnsignedProposerConfigDiffers(ctx context.Context, lock cluster.Lock, doc proposerconfig.Document, initial func() (proposerconfig.Document, error)) { + want, err := initial() + if err != nil { + log.Warn(ctx, "Skipped checking the proposer config file against the lock and flags", err) + return } - builderEntries := make([]builderEntryJSON, 0, len(conf.BuilderURLs)) - for _, u := range conf.BuilderURLs { - builderEntries = append(builderEntries, builderEntryJSON{URL: u}) + lines := proposerconfig.Diff(lock, doc.Config, want.Config) + if len(lines) == 0 { + return } - return &builderSettingsJSON{ - MinBid: strconv.FormatUint(conf.BuilderMinBid, 10), - BuilderBoostFactor: strconv.FormatUint(conf.BuilderBoostFactor, 10), - MaxExecutionPayment: strconv.FormatUint(conf.BuilderMaxExecutionPayment, 10), - Builders: builderEntries, - } + log.Warn(ctx, "Proposer config file differs from the lock and flags, using the file; change it with "+proposerConfigEditCmd, nil, + DiffSummaryFields(lines)...) } -// proposerConfigMatches returns whether the builder settings and the gas limits of the -// existing proposer config file match the configured builder and proposer gas limit flags. -func proposerConfigMatches(conf Config, path string) (builderMatches bool, gasMatches bool, err error) { - b, err := os.ReadFile(path) - if err != nil { - return false, false, errors.Wrap(err, "read proposer config file", z.Str("path", path)) - } +// DiffSummaryFields returns the log fields summarising diff lines: their count and the first few. +func DiffSummaryFields(lines []string) []z.Field { + const maxExamples = 3 - var config proposerConfigJSON - if err := json.Unmarshal(b, &config); err != nil { - return false, false, errors.Wrap(err, "decode proposer config file", z.Str("path", path)) + return []z.Field{ + z.Int("differences", len(lines)), + z.Str("examples", strings.Join(lines[:min(len(lines), maxExamples)], "; ")), } +} + +// InitialProposerConfig returns the unsigned revision 0 document: fee recipients from the effective builder +// registrations falling back to the lock, gas limit and builder from the seed flags. +func InitialProposerConfig(lock cluster.Lock, seed proposerconfig.Seed, feeRecipientFunc func(core.PubKey) string) (proposerconfig.Document, error) { + lockFees := lock.FeeRecipientAddresses() + fees := make([]string, 0, len(lock.Validators)) - gasLimit := strconv.FormatUint(conf.ProposerGasLimit, 10) + for i, val := range lock.Validators { + pubkey, err := core.PubKeyFromBytes(val.PubKey) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "core pubkey", z.Int("validator", i)) + } - gasMatches = config.DefaultConfig.GasLimit == gasLimit - for _, entry := range config.ProposerConfig { - if entry.GasLimit != "" && entry.GasLimit != gasLimit { - gasMatches = false + fee := feeRecipientFunc(pubkey) + if fee == "" { + fee = lockFees[i] } + + fees = append(fees, fee) + } + + cfg, err := proposerconfig.NewConfig(lock, fees, seed.GasLimit, seed.Builder()) + if err != nil { + return proposerconfig.Document{}, errors.Wrap(err, "initial proposer config") } - return builderSettingsEqual(config.DefaultConfig.Builder, builderSettings(conf)), gasMatches, nil + return proposerconfig.Document{ + Version: proposerconfig.Version, + LockHash: lock.LockHash, + Config: cfg, + }, nil } -// builderSettingsEqual returns whether both builder settings are absent, or equal. -func builderSettingsEqual(a, b *builderSettingsJSON) bool { - if a == nil || b == nil { - return a == b +// warnSignedProposerConfigOverridesFlags warns once if seeding flags the operator set differ from the signed file's +// defaults, logging both values; the signed file wins. +func warnSignedProposerConfigOverridesFlags(ctx context.Context, doc proposerconfig.Document, seed proposerconfig.Seed) { + fileVals := proposerconfig.FlagValues(doc.Config.DefaultConfig) + flagVals := proposerconfig.FlagValues(proposerconfig.Settings{GasLimit: strconv.FormatUint(seed.GasLimit, 10), Builder: seed.Builder()}) + + show := func(flag string, vals []string) string { + val := strings.Join(vals, ",") + if flag == "proposer-config-builder-urls" { + // Builder URLs may carry credentials, shown redacted as the URL flags are logged. + val = proposerconfig.RedactURLs(vals) + } + + if val == "" { + return "none" + } + + return val } - return a.MinBid == b.MinBid && - a.BuilderBoostFactor == b.BuilderBoostFactor && - a.MaxExecutionPayment == b.MaxExecutionPayment && - slices.Equal(a.Builders, b.Builders) -} + var ignored []string -// wireProposerConfigFile generates the proposer config file, or warns if the builder settings or -// gas limits of an existing one differ from the flags, logging failures instead of returning them -// so generation never prevents duties. -func wireProposerConfigFile(ctx context.Context, conf Config, lock *cluster.Lock, nodeIdx cluster.NodeIdx, - feeRecipientFunc func(core.PubKey) string, -) { - if conf.TestConfig.Lock != nil { - // In-memory test lock, there is no cluster directory to write the file into. - return + for _, flag := range seed.NonDefault { + if !slices.Equal(fileVals[flag], flagVals[flag]) { + ignored = append(ignored, flag+": file "+show(flag, fileVals[flag])+", flag "+show(flag, flagVals[flag])) + } } - created, err := writeProposerConfigFile(conf, lock, nodeIdx, feeRecipientFunc) - if err != nil { - log.Error(ctx, "Failed generating proposer config file, VC proposer settings must be configured manually", err) + if len(ignored) == 0 { return } - path := filepath.Join(filepath.Dir(conf.LockFile), proposerConfigDir, proposerConfigFilename) + log.Warn(ctx, "Proposer config flags ignored, the cluster agreed on different values with "+proposerConfigEditCmd, nil, + z.Str("flags", strings.Join(ignored, "; "))) +} - if created { - log.Info(ctx, "Generated proposer config file for validator clients", z.Str("path", path)) +// warnUnsignedProposerConfigAfterGloas warns post-gloas that the file is still unsigned. +func warnUnsignedProposerConfigAfterGloas(ctx context.Context, gloasActive func() bool) { + if !gloasActive() { return } - // The flags only seed a new file, the cluster changes builders and gas limits together. - builderMatches, gasMatches, err := proposerConfigMatches(conf, path) - if err != nil { - log.Warn(ctx, "Failed checking the proposer config file against the flags", err) - return + log.Warn(ctx, "Proposer config file is unsigned, agree on it cluster-wide with "+proposerConfigEditCmd, nil) +} + +// revisionFields returns the log fields identifying the document's revision. +func revisionFields(doc proposerconfig.Document) []z.Field { + fields := []z.Field{z.U64("revision", doc.Revision)} + if len(doc.Signatures) > 0 { + fields = append(fields, z.Any("signers", doc.SignerIndexes())) } - if !builderMatches { - log.Warn(ctx, "Builder flags differ from the proposer config file and only apply to a new file, "+ - "change its builders with `charon proposerconfig edit` in sync with the other peers", nil, z.Str("path", path)) + hash, err := doc.Hash() + if err == nil { + fields = append(fields, z.Hex("revision_hash", hash[:])) } - if !gasMatches { - log.Warn(ctx, "Proposer gas limit flag differs from the proposer config file and only applies to a new file, "+ - "change its gas limits in sync with the other peers", nil, z.Str("path", path), z.U64("proposer_gas_limit", conf.ProposerGasLimit)) + return fields +} + +// setProposerConfigGauges sets the revision and invalid gauges for the loaded document. +func setProposerConfigGauges(doc proposerconfig.Document, valid bool) { + proposerConfigRevisionGauge.Set(float64(doc.Revision)) + + if valid { + proposerConfigInvalidGauge.Set(0) + } else { + proposerConfigInvalidGauge.Set(1) } } diff --git a/app/proposerconfig_internal_test.go b/app/proposerconfig_internal_test.go index daea267914..7ce5c6422d 100644 --- a/app/proposerconfig_internal_test.go +++ b/app/proposerconfig_internal_test.go @@ -3,255 +3,488 @@ package app import ( - "encoding/json" - "fmt" + "bytes" + "context" "math/rand" "os" "path/filepath" + "slices" + "strings" "testing" + k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" + promtestutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" + "go.uber.org/zap/zaptest" + "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/core" ) -func TestWriteProposerConfigFile(t *testing.T) { - const ( - dv = 4 - nodes = 4 - peerIdx = 2 - ) +const editCmd = "charon alpha edit proposer-config" - lock, _, _ := cluster.NewForT(t, dv, nodes, nodes, 0, rand.New(rand.NewSource(0))) +// pcFixture is a 3 of 4 cluster with 3 validators, loaded as node 2. +type pcFixture struct { + lock cluster.Lock + keys []*k1.PrivateKey + conf Config + nodeIdx cluster.NodeIdx + path string + logs *zaptest.Buffer +} - dir := t.TempDir() - conf := Config{ - LockFile: filepath.Join(dir, "cluster-lock.json"), - BuilderAPI: true, - ProposerGasLimit: 200_000_000, +func newPCFixture(t *testing.T) pcFixture { + t.Helper() + + lock, keys, _ := cluster.NewForT(t, 3, 3, 4, 0, rand.New(rand.NewSource(0))) + path := filepath.Join(t.TempDir(), "vc-config", "proposer-config.json") + + logs := new(zaptest.Buffer) + log.InitLogfmtForT(t, logs) + + return pcFixture{ + lock: lock, + keys: keys, + conf: Config{ + ProposerConfigFile: path, + ProposerConfigSeed: proposerconfig.Seed{GasLimit: proposerconfig.DefaultGasLimit, BuilderBoostFactor: proposerconfig.DefaultBuilderBoostFactor}, + }, + nodeIdx: cluster.NodeIdx{PeerIdx: 2, ShareIdx: 3}, + path: path, + logs: logs, } - nodeIdx := cluster.NodeIdx{PeerIdx: peerIdx, ShareIdx: peerIdx + 1} +} - path := filepath.Join(dir, proposerConfigDir, proposerConfigFilename) +func (f pcFixture) load(t *testing.T, gloasActive bool) (proposerconfig.Document, error) { + t.Helper() - // Override the first validator's fee recipient (mimicking builder registration - // overrides), let the second fall back to its lock address, and give the - // remaining two identical fee recipients so they form the majority. - overridePubkey, err := core.PubKeyFromBytes(lock.Validators[0].PubKey) - require.NoError(t, err) + noOverrides := func(core.PubKey) string { return "" } + + return loadProposerConfig(context.Background(), f.conf, f.lock, f.nodeIdx, noOverrides, func() bool { return gloasActive }) +} - lockFallbackPubkey, err := core.PubKeyFromBytes(lock.Validators[1].PubKey) +// loadBadInitial loads with an override fee recipient that fails deriving the initial config. +func (f pcFixture) loadBadInitial(t *testing.T) (proposerconfig.Document, error) { + t.Helper() + + badOverride := func(core.PubKey) string { return "0xnot-an-address" } + + return loadProposerConfig(context.Background(), f.conf, f.lock, f.nodeIdx, badOverride, func() bool { return false }) +} + +// doc returns a document with the lock's fee recipients, the given gas limit and builder, signed by signers. +func (f pcFixture) doc(t *testing.T, revision uint64, gasLimit uint64, builder *proposerconfig.Builder, signers ...int) proposerconfig.Document { + t.Helper() + + cfg, err := proposerconfig.NewConfig(f.lock, f.lock.FeeRecipientAddresses(), gasLimit, builder) require.NoError(t, err) - const ( - overrideAddr = "0xcccccccccccccccccccccccccccccccccccccccc" - majorityAddr = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - ) + doc := proposerconfig.Document{ + Version: proposerconfig.Version, + LockHash: f.lock.LockHash, + Revision: revision, + Config: cfg, + } + + for _, idx := range signers { + sig, err := proposerconfig.Sign(doc, f.keys[idx]) + require.NoError(t, err) - feeRecipientFunc := func(pubkey core.PubKey) string { - switch pubkey { - case overridePubkey: - return overrideAddr - case lockFallbackPubkey: - return "" // Exercise the lock fallback. - default: - return majorityAddr - } + doc.Signatures = append(doc.Signatures, proposerconfig.Signature{Operator: idx, Signature: sig}) } - created, err := writeProposerConfigFile(conf, &lock, nodeIdx, feeRecipientFunc) + return doc +} + +func (f pcFixture) write(t *testing.T, doc proposerconfig.Document) []byte { + t.Helper() + + require.NoError(t, proposerconfig.Write(f.path, doc, f.lock, f.nodeIdx)) + + b, err := os.ReadFile(f.path) require.NoError(t, err) - require.True(t, created) + + return b +} + +func requireGauges(t *testing.T, revision, invalid float64) { + t.Helper() + + require.InDelta(t, revision, promtestutil.ToFloat64(proposerConfigRevisionGauge), 0) + require.InDelta(t, invalid, promtestutil.ToFloat64(proposerConfigInvalidGauge), 0) +} + +func requireFile(t *testing.T, path string, want []byte) { + t.Helper() b, err := os.ReadFile(path) require.NoError(t, err) + require.Equal(t, string(want), string(b)) +} - var config proposerConfigJSON +func TestLoadInitialProposerConfig(t *testing.T) { + f := newPCFixture(t) + require.EqualValues(t, 30_000_000, f.lock.TargetGasLimit) - require.NoError(t, json.Unmarshal(b, &config)) - require.EqualValues(t, 1, config.Version) + overridePubkey, err := core.PubKeyFromBytes(f.lock.Validators[0].PubKey) + require.NoError(t, err) - feeRecipients := lock.FeeRecipientAddresses() + const overrideAddr = "0xcccccccccccccccccccccccccccccccccccccccc" - pubshare := func(vi int) string { - share, err := lock.Validators[vi].PublicShare(peerIdx) - require.NoError(t, err) + feeRecipientFunc := func(pubkey core.PubKey) string { + if pubkey == overridePubkey { + return overrideAddr + } - return fmt.Sprintf("%#x", share) + return "" // Falls back to the lock. } - // The default config holds the majority fee recipient (validators 2 and 3) and the - // configured proposer gas limit. - require.Equal(t, majorityAddr, config.DefaultConfig.FeeRecipient) - require.Equal(t, "200000000", config.DefaultConfig.GasLimit) - require.Nil(t, config.DefaultConfig.Builder) // No builder URLs configured. - - // The two diverging validators get entries carrying only their fee recipient. - require.Len(t, config.ProposerConfig, 2) - require.Equal(t, proposerSettingsJSON{FeeRecipient: overrideAddr}, config.ProposerConfig[pubshare(0)]) - require.Equal(t, proposerSettingsJSON{FeeRecipient: feeRecipients[1]}, config.ProposerConfig[pubshare(1)]) + doc, err := loadProposerConfig(context.Background(), f.conf, f.lock, f.nodeIdx, feeRecipientFunc, func() bool { return false }) + require.NoError(t, err) - // No pre-gloas legacy fields in the charon schema. - require.NotContains(t, string(b), "enabled") - require.NotContains(t, string(b), "min_bid") + lockFees := f.lock.FeeRecipientAddresses() + wantFees := []string{overrideAddr, strings.ToLower(lockFees[1]), strings.ToLower(lockFees[2])} - // An existing file is never modified. - require.NoError(t, os.WriteFile(path, []byte("operator managed"), 0o644)) + require.Equal(t, proposerconfig.Version, doc.Version) + require.Equal(t, f.lock.LockHash, doc.LockHash) + require.Zero(t, doc.Revision) + require.Empty(t, doc.Signatures) + require.Equal(t, "200000000", doc.Config.DefaultConfig.GasLimit) + require.Nil(t, doc.Config.DefaultConfig.Builder) + require.Equal(t, wantFees, doc.Config.FeeRecipients(f.lock)) - created, err = writeProposerConfigFile(conf, &lock, nodeIdx, feeRecipientFunc) + loaded, err := proposerconfig.Load(f.path, f.lock, f.nodeIdx) require.NoError(t, err) - require.False(t, created) + require.Equal(t, doc.Config, loaded.Config) + require.NoError(t, proposerconfig.Verify(loaded, f.lock)) - b, err = os.ReadFile(path) - require.NoError(t, err) - require.Equal(t, "operator managed", string(b)) + requireGauges(t, 0, 0) + require.NotContains(t, f.logs.String(), editCmd) - // A directory occupying the file path is an error. - require.NoError(t, os.Remove(path)) - require.NoError(t, os.Mkdir(path, 0o755)) + t.Run("post gloas warns unsigned", func(t *testing.T) { + require.NoError(t, os.Remove(f.path)) + f.logs.Reset() - _, err = writeProposerConfigFile(conf, &lock, nodeIdx, feeRecipientFunc) - require.ErrorContains(t, err, "is a directory") + _, err := f.load(t, true) + require.NoError(t, err) + require.Contains(t, f.logs.String(), editCmd) + }) } -func TestWriteProposerConfigFileBuilder(t *testing.T) { - lock, _, _ := cluster.NewForT(t, 1, 4, 4, 0, rand.New(rand.NewSource(0))) +func TestLoadProposerConfigRevision0Drift(t *testing.T) { + f := newPCFixture(t) + f.conf.ProposerConfigSeed.BuilderURLs = []string{"https://a.example.com"} - nodeIdx := cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1} - noOverrides := func(core.PubKey) string { return "" } + fileBuilder := proposerconfig.Seed{BuilderURLs: []string{"https://b.example.com"}, BuilderBoostFactor: 100}.Builder() + want := f.doc(t, 0, proposerconfig.DefaultGasLimit, fileBuilder) + written := f.write(t, want) - t.Run("builder urls", func(t *testing.T) { - dir := t.TempDir() - conf := Config{ - LockFile: filepath.Join(dir, "cluster-lock.json"), - BuilderAPI: true, - BuilderURLs: []string{"https://builder1.example.com", "https://builder2.example.com"}, - BuilderMinBid: 1_000_000_000, - BuilderBoostFactor: 90, - BuilderMaxExecutionPayment: 2_000_000_000, - ProposerGasLimit: 200_000_000, + doc, err := f.load(t, false) + require.NoError(t, err) + require.Equal(t, want.Config, doc.Config) + requireFile(t, f.path, written) + + logs := f.logs.String() + require.Contains(t, logs, editCmd) + require.Contains(t, logs, "default.builder.urls") + require.NotContains(t, logs, "default.gas_limit") + requireGauges(t, 0, 0) + + t.Run("many differences log one warning", func(t *testing.T) { + fees := []string{ + "0x00000000000000000000000000000000000000c1", + "0x00000000000000000000000000000000000000c2", + "0x00000000000000000000000000000000000000c3", } + cfg, err := proposerconfig.NewConfig(f.lock, fees, proposerconfig.DefaultGasLimit, fileBuilder) + require.NoError(t, err) + f.write(t, proposerconfig.Document{Version: proposerconfig.Version, LockHash: f.lock.LockHash, Config: cfg}) + f.logs.Reset() - created, err := writeProposerConfigFile(conf, &lock, nodeIdx, noOverrides) + _, err = f.load(t, false) require.NoError(t, err) - require.True(t, created) - b, err := os.ReadFile(filepath.Join(dir, proposerConfigDir, proposerConfigFilename)) + logs := f.logs.String() + require.Equal(t, 1, strings.Count(logs, "level=warn"), logs) + require.Contains(t, logs, "differences=4") + require.Contains(t, logs, "default.builder.urls") + }) +} + +func TestLoadProposerConfigSigned(t *testing.T) { + f := newPCFixture(t) + f.conf.ProposerConfigSeed.BuilderURLs = []string{"https://user:secret@a.example.com", "https://user:pa,ss@b.example.com"} + f.conf.ProposerConfigSeed.BuilderMinBid = 0 // Set to its default, equal to nothing in a signed file without builders. + f.conf.ProposerConfigSeed.NonDefault = []string{"proposer-config-builder-urls", "proposer-config-builder-min-bid"} + + want := f.doc(t, 1, 60_000_000, nil, 0, 1, 3) + written := f.write(t, want) + + doc, err := f.load(t, true) + require.NoError(t, err) + require.Equal(t, want.Config, doc.Config) + require.EqualValues(t, 1, doc.Revision) + require.Equal(t, []int{0, 1, 3}, doc.SignerIndexes()) + requireFile(t, f.path, written) + + // Only explicitly set flags are compared: the default gas limit differs from the file but is not reported. + logs := f.logs.String() + require.Equal(t, 1, strings.Count(logs, "level=warn"), logs) + require.Contains(t, logs, `flags="proposer-config-builder-urls: file none, flag https://user:xxxxx@a.example.com,https://user:xxxxx@b.example.com; proposer-config-builder-min-bid: file none, flag 0"`) + require.NotContains(t, logs, "secret") + require.NotContains(t, logs, "pa,ss") + require.NotContains(t, logs, "proposer-config-gas-limit") + require.Contains(t, logs, editCmd) + require.NotContains(t, logs, "level=error") + requireGauges(t, 1, 0) + + t.Run("explicit gas limit differing warns", func(t *testing.T) { + f.conf.ProposerConfigSeed.BuilderURLs = nil + f.conf.ProposerConfigSeed.NonDefault = []string{"proposer-config-gas-limit"} + f.logs.Reset() + + _, err := f.load(t, true) require.NoError(t, err) + require.Contains(t, f.logs.String(), `flags="proposer-config-gas-limit: file 60000000, flag 200000000"`) + }) + + t.Run("flags left at their defaults do not warn", func(t *testing.T) { + f.conf.ProposerConfigSeed.BuilderURLs = nil + f.conf.ProposerConfigSeed.GasLimit = proposerconfig.DefaultGasLimit + f.conf.ProposerConfigSeed.NonDefault = nil + f.logs.Reset() - var config proposerConfigJSON - - require.NoError(t, json.Unmarshal(b, &config)) - require.EqualValues(t, 1, config.Version) - - // A uniform cluster emits no per-validator entries, the default covers all. - require.Empty(t, config.ProposerConfig) - require.Equal(t, "200000000", config.DefaultConfig.GasLimit) - - // The builder configuration is only emitted on the default config, with the - // shared values at the builder level and entries carrying no overrides. - require.NotNil(t, config.DefaultConfig.Builder) - require.Equal(t, "1000000000", config.DefaultConfig.Builder.MinBid) - require.Equal(t, "90", config.DefaultConfig.Builder.BuilderBoostFactor) - require.Equal(t, "2000000000", config.DefaultConfig.Builder.MaxExecutionPayment) - require.Equal(t, []builderEntryJSON{ - {URL: "https://builder1.example.com"}, - {URL: "https://builder2.example.com"}, - }, config.DefaultConfig.Builder.Builders) + _, err := f.load(t, true) + require.NoError(t, err) + require.NotContains(t, f.logs.String(), "level=warn") }) - t.Run("no builder urls", func(t *testing.T) { - dir := t.TempDir() - conf := Config{ - LockFile: filepath.Join(dir, "cluster-lock.json"), - BuilderMinBid: 1, // Inert without builder URLs (the flags reject this combination). - } + t.Run("matching flags do not warn", func(t *testing.T) { + f.conf.ProposerConfigSeed.BuilderURLs = nil + f.conf.ProposerConfigSeed.GasLimit = 60_000_000 + f.conf.ProposerConfigSeed.NonDefault = []string{"proposer-config-gas-limit"} + f.logs.Reset() - created, err := writeProposerConfigFile(conf, &lock, nodeIdx, noOverrides) + _, err := f.load(t, true) require.NoError(t, err) - require.True(t, created) + require.NotContains(t, f.logs.String(), "level=warn") + }) +} + +func TestLoadProposerConfigInvalidSigned(t *testing.T) { + f := newPCFixture(t) + + want := f.doc(t, 1, proposerconfig.DefaultGasLimit, nil, 0, 1) // Below threshold 3. + written := f.write(t, want) + + doc, err := f.load(t, false) + require.NoError(t, err) + require.Equal(t, want.Config, doc.Config) + require.EqualValues(t, 1, doc.Revision) + require.Contains(t, f.logs.String(), "level=error") + requireFile(t, f.path, written) + requireGauges(t, 1, 1) +} + +func TestLoadProposerConfigWrongLock(t *testing.T) { + t.Run("lock hash only", func(t *testing.T) { + f := newPCFixture(t) - b, err := os.ReadFile(filepath.Join(dir, proposerConfigDir, proposerConfigFilename)) + other := f.doc(t, 0, proposerconfig.DefaultGasLimit, nil) + other.LockHash = bytes.Repeat([]byte{0x01}, 32) + written := f.write(t, other) + + _, err := f.load(t, false) + require.ErrorIs(t, err, proposerconfig.ErrLockHashMismatch) + require.ErrorContains(t, err, "after a lock-changing edit, use vc-config/ from its output directory") + requireFile(t, f.path, written) + }) + + t.Run("other cluster's file", func(t *testing.T) { + f := newPCFixture(t) + otherLock, _, _ := cluster.NewForT(t, 3, 3, 4, 1, rand.New(rand.NewSource(1))) + + // Diverging fee recipients give entries keyed by the other cluster's pubshares. + cfg, err := proposerconfig.NewConfig(otherLock, otherLock.FeeRecipientAddresses(), proposerconfig.DefaultGasLimit, nil) require.NoError(t, err) + require.NotEmpty(t, cfg.ProposerConfig) + + doc := proposerconfig.Document{Version: proposerconfig.Version, LockHash: otherLock.LockHash, Config: cfg} + require.NoError(t, proposerconfig.Write(f.path, doc, otherLock, f.nodeIdx)) - var config proposerConfigJSON + before, err := os.ReadFile(f.path) + require.NoError(t, err) - require.NoError(t, json.Unmarshal(b, &config)) - require.EqualValues(t, 1, config.Version) - require.Nil(t, config.DefaultConfig.Builder) - require.NotContains(t, string(b), "min_bid") + _, err = f.load(t, false) + require.ErrorIs(t, err, proposerconfig.ErrLockHashMismatch) + requireFile(t, f.path, before) }) } -func TestProposerConfigMatches(t *testing.T) { - lock, _, _ := cluster.NewForT(t, 1, 4, 4, 0, rand.New(rand.NewSource(0))) +func TestLoadInitialProposerConfigFailure(t *testing.T) { + t.Run("valid signed file never derives the initial config", func(t *testing.T) { + f := newPCFixture(t) + want := f.doc(t, 1, proposerconfig.DefaultGasLimit, nil, 0, 1, 2) + f.write(t, want) - nodeIdx := cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1} - noOverrides := func(core.PubKey) string { return "" } + doc, err := f.loadBadInitial(t) + require.NoError(t, err) + require.Equal(t, want.Config, doc.Config) + requireGauges(t, 1, 0) + }) - dir := t.TempDir() - path := filepath.Join(dir, proposerConfigDir, proposerConfigFilename) + t.Run("revision 0 file skips the drift check", func(t *testing.T) { + f := newPCFixture(t) + want := f.doc(t, 0, proposerconfig.DefaultGasLimit, nil) + f.write(t, want) - newConf := func(builderURLs ...string) Config { - return Config{ - LockFile: filepath.Join(dir, "cluster-lock.json"), - BuilderAPI: true, - BuilderURLs: builderURLs, - BuilderBoostFactor: 90, - ProposerGasLimit: 200_000_000, - } + doc, err := f.loadBadInitial(t) + require.NoError(t, err) + require.Equal(t, want.Config, doc.Config) + require.Contains(t, f.logs.String(), "level=warn") + requireGauges(t, 0, 0) + }) + + t.Run("no file", func(t *testing.T) { + f := newPCFixture(t) + + _, err := f.loadBadInitial(t) + require.Error(t, err) + + _, err = os.Stat(f.path) + require.ErrorIs(t, err, os.ErrNotExist) + }) + + t.Run("unloadable file", func(t *testing.T) { + f := newPCFixture(t) + require.NoError(t, os.MkdirAll(filepath.Dir(f.path), 0o755)) + require.NoError(t, os.WriteFile(f.path, []byte("{"), 0o644)) + + _, err := f.loadBadInitial(t) + require.Error(t, err) + }) +} + +func TestLoadProposerConfigWriteFailure(t *testing.T) { + if os.Geteuid() == 0 { + t.Skip("root ignores directory permissions") } - conf := newConf("https://builder1.example.com") + f := newPCFixture(t) + dir := filepath.Dir(f.path) + require.NoError(t, os.MkdirAll(dir, 0o755)) + require.NoError(t, os.Chmod(dir, 0o555)) + t.Cleanup(func() { _ = os.Chmod(dir, 0o755) }) - created, err := writeProposerConfigFile(conf, &lock, nodeIdx, noOverrides) + doc, err := f.load(t, false) require.NoError(t, err) - require.True(t, created) + require.Zero(t, doc.Revision) + require.Equal(t, "200000000", doc.Config.DefaultConfig.GasLimit) + require.Contains(t, f.logs.String(), "level=error") + requireGauges(t, 0, 1) +} - b, err := os.ReadFile(path) - require.NoError(t, err) +func TestLoadProposerConfigUndecodable(t *testing.T) { + tests := []struct { + name string + setup func(t *testing.T, f pcFixture) + }{ + { + name: "corrupt json", + setup: func(t *testing.T, f pcFixture) { + t.Helper() + require.NoError(t, os.MkdirAll(filepath.Dir(f.path), 0o755)) + require.NoError(t, os.WriteFile(f.path, []byte(`{"version": "v1.0.0", `), 0o644)) + }, + }, + { + name: "integer version", + setup: func(t *testing.T, f pcFixture) { + t.Helper() + require.NoError(t, os.MkdirAll(filepath.Dir(f.path), 0o755)) + require.NoError(t, os.WriteFile(f.path, []byte(`{"version": 1, "proposer_config": {}, "default_config": {"gas_limit": "30000000"}}`), 0o644)) + }, + }, + { + name: "other node's pubshares", + setup: func(t *testing.T, f pcFixture) { + t.Helper() + + doc := f.doc(t, 0, proposerconfig.DefaultGasLimit, nil) + require.NotEmpty(t, doc.Config.ProposerConfig) + require.NoError(t, proposerconfig.Write(f.path, doc, f.lock, cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1})) + }, + }, + } - builderMatches, gasMatches, err := proposerConfigMatches(conf, path) - require.NoError(t, err) - require.True(t, builderMatches) - require.True(t, gasMatches) + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + f := newPCFixture(t) + f.conf.ProposerConfigSeed.GasLimit = 60_000_000 + test.setup(t, f) + + before, err := os.ReadFile(f.path) + require.NoError(t, err) + + doc, err := f.load(t, false) + require.NoError(t, err) + require.Zero(t, doc.Revision) + require.Empty(t, doc.Signatures) + require.Equal(t, "60000000", doc.Config.DefaultConfig.GasLimit) + require.Contains(t, f.logs.String(), "level=error") + require.Contains(t, f.logs.String(), "delete it to regenerate") + requireFile(t, f.path, before) + requireGauges(t, 0, 1) + }) + } - // Changed builder URLs, builder flags or no builder URLs differ, and leave the file as it is. - changedBoost := conf - changedBoost.BuilderBoostFactor = 100 + t.Run("path is a directory", func(t *testing.T) { + f := newPCFixture(t) + require.NoError(t, os.MkdirAll(f.path, 0o755)) - for _, changed := range []Config{newConf("https://builder2.example.com"), changedBoost, newConf()} { - created, err = writeProposerConfigFile(changed, &lock, nodeIdx, noOverrides) + doc, err := f.load(t, false) require.NoError(t, err) - require.False(t, created) + require.Zero(t, doc.Revision) + require.Contains(t, f.logs.String(), "level=error") - builderMatches, gasMatches, err = proposerConfigMatches(changed, path) + info, err := os.Stat(f.path) require.NoError(t, err) - require.False(t, builderMatches) - require.True(t, gasMatches) - } + require.True(t, info.IsDir()) + requireGauges(t, 0, 1) + }) +} - // A changed proposer gas limit differs, and leaves the file as it is. - changedGas := conf - changedGas.ProposerGasLimit = 60_000_000 +func TestLoadProposerConfigLockWithoutFeeRecipients(t *testing.T) { + f := newPCFixture(t) - created, err = writeProposerConfigFile(changedGas, &lock, nodeIdx, noOverrides) - require.NoError(t, err) - require.False(t, created) + // v1.0 and v1.1 locks may have no fee recipients. + f.lock.ValidatorAddresses = slices.Clone(f.lock.ValidatorAddresses) + for i := range f.lock.ValidatorAddresses { + f.lock.ValidatorAddresses[i].FeeRecipientAddress = "" + } - builderMatches, gasMatches, err = proposerConfigMatches(changedGas, path) + doc, err := f.load(t, false) require.NoError(t, err) - require.True(t, builderMatches) - require.False(t, gasMatches) + require.Empty(t, doc.Config.DefaultConfig.FeeRecipient) + require.Empty(t, doc.Config.ProposerConfig) + requireGauges(t, 0, 0) - unchanged, err := os.ReadFile(path) + loaded, err := proposerconfig.Load(f.path, f.lock, f.nodeIdx) require.NoError(t, err) - require.Equal(t, b, unchanged) + require.NoError(t, proposerconfig.Verify(loaded, f.lock)) +} - // A file that isn't a proposer config is an error. - require.NoError(t, os.WriteFile(path, []byte("operator managed"), 0o644)) +func TestLoadProposerConfigTestLock(t *testing.T) { + f := newPCFixture(t) + f.conf.TestConfig.Lock = &f.lock + + doc, err := f.load(t, false) + require.NoError(t, err) + require.Zero(t, doc.Revision) + require.Equal(t, "200000000", doc.Config.DefaultConfig.GasLimit) - _, _, err = proposerConfigMatches(conf, path) - require.ErrorContains(t, err, "decode proposer config file") + _, err = os.Stat(f.path) + require.ErrorIs(t, err, os.ErrNotExist) } diff --git a/app/vmock.go b/app/vmock.go index 5e597ee00c..98aff3474c 100644 --- a/app/vmock.go +++ b/app/vmock.go @@ -47,7 +47,7 @@ func wireValidatorMock(ctx context.Context, conf Config, eth2Cl eth2wrap.Client, return err } - vmock := validatormock.New(ctx, newVMockEth2Provider(conf, forkSchedule, pubshares), signer, pubshares, genesisTime, slotDuration, slotsPerEpoch, slotOffsetFunc, conf.BuilderAPI, conf.BuilderURLs) + vmock := validatormock.New(ctx, newVMockEth2Provider(conf, forkSchedule, pubshares), signer, pubshares, genesisTime, slotDuration, slotsPerEpoch, slotOffsetFunc, conf.BuilderAPI, conf.ProposerConfigSeed.BuilderURLs) sched.SubscribeSlots(vmock.SlotTicked) return nil diff --git a/cluster/proposerconfig/delta.go b/cluster/proposerconfig/delta.go new file mode 100644 index 0000000000..8dcf19e1f5 --- /dev/null +++ b/cluster/proposerconfig/delta.go @@ -0,0 +1,189 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "slices" + "strconv" + "strings" + + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/cluster" +) + +// ErrNoChange is returned by Apply when the delta leaves the config unchanged. +var ErrNoChange = errors.New("delta does not change the proposer config") + +// Delta is a set of changes to a Config. Zero values mean "not set": an empty FeeRecipient, a zero +// GasLimit, nil BuilderURLs and builder pointers, and a false NoBuilders. FeeRecipientValidators holds DV +// pubkeys; empty applies the fee recipient to all validators. +type Delta struct { + FeeRecipient string + FeeRecipientValidators []string + GasLimit uint64 + BuilderURLs []string + BuilderMinBid *uint64 + BuilderBoostFactor *uint64 + BuilderMaxExecutionPayment *uint64 + NoBuilders bool +} + +// Apply returns the config with the delta applied, or ErrNoChange if the result equals c. +func Apply(lock cluster.Lock, c Config, d Delta) (Config, error) { + fees := c.FeeRecipients(lock) + + if d.FeeRecipient != "" { + var err error + + fees, err = applyFeeRecipient(lock, fees, d) + if err != nil { + return Config{}, err + } + } + + gasLimit, err := c.GasLimit() + if err != nil { + return Config{}, err + } + + if d.GasLimit != 0 { + gasLimit = d.GasLimit + } + + if d.NoBuilders && (d.BuilderURLs != nil || d.BuilderMinBid != nil || d.BuilderBoostFactor != nil || d.BuilderMaxExecutionPayment != nil) { + return Config{}, errors.New("no builders excludes the other builder fields") + } + + if d.BuilderURLs != nil && len(d.BuilderURLs) == 0 { + return Config{}, errors.New("builder urls must not be empty, set no builders to remove the builders") + } + + var builder *Builder + + switch { + case d.NoBuilders: + case c.DefaultConfig.Builder == nil && d.BuilderURLs == nil: + if d.BuilderMinBid != nil || d.BuilderBoostFactor != nil || d.BuilderMaxExecutionPayment != nil { + return Config{}, errors.New("builder min bid, boost factor and max execution payment require builder urls") + } + default: + builder, err = applyBuilder(c.DefaultConfig.Builder, d) + if err != nil { + return Config{}, err + } + } + + res, err := NewConfig(lock, fees, gasLimit, builder) + if err != nil { + return Config{}, err + } + + equal, err := sameConfig(c, res) + if err != nil { + return Config{}, err + } + + if equal { + return Config{}, ErrNoChange + } + + return res, nil +} + +// applyFeeRecipient returns a copy of fees with the delta's fee recipient set on the selected validators. +func applyFeeRecipient(lock cluster.Lock, fees []string, d Delta) ([]string, error) { + fee, err := normaliseAddress(d.FeeRecipient) + if err != nil { + return nil, err + } + + res := slices.Clone(fees) + + if len(d.FeeRecipientValidators) == 0 { + for i := range res { + res[i] = fee + } + + return res, nil + } + + for _, pubkey := range d.FeeRecipientValidators { + pubkey = strings.ToLower(pubkey) + if !strings.HasPrefix(pubkey, "0x") { + pubkey = "0x" + pubkey + } + + idx := slices.IndexFunc(lock.Validators, func(v cluster.DistValidator) bool { + return pubkeyHex(v.PubKey) == pubkey + }) + if idx < 0 { + return nil, errors.New("validator not in lock", z.Str("pubkey", pubkey)) + } + + res[idx] = fee + } + + return res, nil +} + +// applyBuilder returns the builder with the delta applied without mutating b; a nil b starts from the defaults. +func applyBuilder(b *Builder, d Delta) (*Builder, error) { + var res Builder + + if b != nil { + res = *b + res.Builders = slices.Clone(b.Builders) + } else { + res = Builder{ + MinBid: "0", + BuilderBoostFactor: strconv.FormatUint(DefaultBuilderBoostFactor, 10), + MaxExecutionPayment: "0", + } + } + + if d.BuilderURLs != nil { + err := validateBuilderURLs("builder-urls", d.BuilderURLs) + if err != nil { + return nil, err + } + + res.Builders = make([]BuilderEntry, 0, len(d.BuilderURLs)) + for _, u := range d.BuilderURLs { + res.Builders = append(res.Builders, BuilderEntry{URL: u}) + } + } + + if d.BuilderMinBid != nil { + res.MinBid = strconv.FormatUint(*d.BuilderMinBid, 10) + } + + if d.BuilderBoostFactor != nil { + if *d.BuilderBoostFactor == 0 { + return nil, errors.New("builder boost factor must be greater than 0") + } + + res.BuilderBoostFactor = strconv.FormatUint(*d.BuilderBoostFactor, 10) + } + + if d.BuilderMaxExecutionPayment != nil { + res.MaxExecutionPayment = strconv.FormatUint(*d.BuilderMaxExecutionPayment, 10) + } + + return &res, nil +} + +// sameConfig returns whether a and b have the same canonical form. +func sameConfig(a, b Config) (bool, error) { + ha, err := Document{Config: a}.Hash() + if err != nil { + return false, err + } + + hb, err := Document{Config: b}.Hash() + if err != nil { + return false, err + } + + return ha == hb, nil +} diff --git a/cluster/proposerconfig/delta_internal_test.go b/cluster/proposerconfig/delta_internal_test.go new file mode 100644 index 0000000000..2817e99e4c --- /dev/null +++ b/cluster/proposerconfig/delta_internal_test.go @@ -0,0 +1,220 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +const addrC = "0x000000000000000000000000000000000000000c" + +func testBuilder() *Builder { + return &Builder{ + MinBid: "5", + BuilderBoostFactor: "110", + MaxExecutionPayment: "7", + Builders: []BuilderEntry{{URL: "https://b1.example"}}, + } +} + +func TestApplyFeeRecipientAll(t *testing.T) { + lock := testLock(t, 3) + c, err := NewConfig(lock, []string{addrA, addrA, addrB}, DefaultGasLimit, nil) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{FeeRecipient: "0x" + strings.ToUpper(addrC[2:])}) + require.NoError(t, err) + require.Equal(t, []string{addrC, addrC, addrC}, res.FeeRecipients(lock)) + require.Empty(t, res.ProposerConfig) + // The input is untouched. + require.Equal(t, []string{addrA, addrA, addrB}, c.FeeRecipients(lock)) +} + +func TestApplyFeeRecipientSubset(t *testing.T) { + lock := testLock(t, 3) + c, err := NewConfig(lock, []string{addrA, addrA, addrB}, DefaultGasLimit, nil) + require.NoError(t, err) + + // Flips the majority: validators 0 and 1 move to B, validator 2 stays on B. + v0 := pubkeyHex(lock.Validators[0].PubKey) + v1 := strings.ToUpper(pubkeyHex(lock.Validators[1].PubKey)[2:]) + + res, err := Apply(lock, c, Delta{FeeRecipient: addrB, FeeRecipientValidators: []string{v0, "0x" + v1}}) + require.NoError(t, err) + require.Equal(t, []string{addrB, addrB, addrB}, res.FeeRecipients(lock)) + require.Empty(t, res.ProposerConfig) + + // Only touched validators are listed even though the default flipped. + require.Equal(t, []string{ + "validator " + v0 + ".fee_recipient: " + addrA + " -> " + addrB, + "validator " + pubkeyHex(lock.Validators[1].PubKey) + ".fee_recipient: " + addrA + " -> " + addrB, + }, Diff(lock, c, res)) +} + +func TestApplyGasLimit(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{GasLimit: 60_000_000}) + require.NoError(t, err) + require.Equal(t, "60000000", res.DefaultConfig.GasLimit) +} + +func TestApplyBuilderURLsCreatesBlock(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{BuilderURLs: []string{"https://b2.example", "https://b1.example"}}) + require.NoError(t, err) + require.Equal(t, &Builder{ + MinBid: "0", + BuilderBoostFactor: "100", + MaxExecutionPayment: "0", + Builders: []BuilderEntry{{URL: "https://b2.example"}, {URL: "https://b1.example"}}, + }, res.DefaultConfig.Builder) + + // The edit command's flag is bare, unlike the run seeding flag. + _, err = Apply(lock, c, Delta{BuilderURLs: []string{"ftp://nope"}}) + require.ErrorContains(t, err, "builder-urls entry is not a valid http(s) URL") + require.NotContains(t, err.Error(), "proposer-config-") +} + +func TestApplyBuilderFieldDelta(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{BuilderMinBid: new(uint64(9))}) + require.NoError(t, err) + require.Equal(t, &Builder{ + MinBid: "9", + BuilderBoostFactor: "110", + MaxExecutionPayment: "7", + Builders: []BuilderEntry{{URL: "https://b1.example"}}, + }, res.DefaultConfig.Builder) + require.Equal(t, "5", c.DefaultConfig.Builder.MinBid) + + // URLs replace the list and keep the fields. + res, err = Apply(lock, c, Delta{BuilderURLs: []string{"https://b3.example"}}) + require.NoError(t, err) + require.Equal(t, "110", res.DefaultConfig.Builder.BuilderBoostFactor) + require.Equal(t, []BuilderEntry{{URL: "https://b3.example"}}, res.DefaultConfig.Builder.Builders) +} + +func TestApplyBuilderFieldWithoutBlock(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + for _, d := range []Delta{ + {BuilderMinBid: new(uint64(1))}, + {BuilderBoostFactor: new(uint64(1))}, + {BuilderMaxExecutionPayment: new(uint64(1))}, + } { + _, err = Apply(lock, c, d) + require.ErrorContains(t, err, "require builder urls") + } + + // With URLs in the same delta they apply on top of the defaults. + res, err := Apply(lock, c, Delta{BuilderURLs: []string{"https://b1.example"}, BuilderBoostFactor: new(uint64(50))}) + require.NoError(t, err) + require.Equal(t, "50", res.DefaultConfig.Builder.BuilderBoostFactor) + + _, err = Apply(lock, c, Delta{BuilderURLs: []string{"https://b1.example"}, BuilderBoostFactor: new(uint64(0))}) + require.ErrorContains(t, err, "boost factor") +} + +func TestApplyNoBuilders(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{NoBuilders: true}) + require.NoError(t, err) + require.Nil(t, res.DefaultConfig.Builder) + require.NotNil(t, c.DefaultConfig.Builder) +} + +func TestApplyCombined(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + res, err := Apply(lock, c, Delta{GasLimit: 1, BuilderURLs: []string{"https://b1.example"}}) + require.NoError(t, err) + require.Equal(t, "1", res.DefaultConfig.GasLimit) + require.Len(t, res.DefaultConfig.Builder.Builders, 1) +} + +func TestApplyNoChange(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrB}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + for _, d := range []Delta{ + {}, + {GasLimit: DefaultGasLimit}, + {BuilderURLs: []string{"https://b1.example"}, BuilderMinBid: new(uint64(5))}, + {FeeRecipient: addrB, FeeRecipientValidators: []string{pubkeyHex(lock.Validators[1].PubKey)}}, + } { + _, err = Apply(lock, c, d) + require.ErrorIs(t, err, ErrNoChange) + } + + // NoBuilders on config without builders is a no-op next to a real change. + nb, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + _, err = Apply(lock, nb, Delta{NoBuilders: true}) + require.ErrorIs(t, err, ErrNoChange) + + res, err := Apply(lock, nb, Delta{NoBuilders: true, GasLimit: 5}) + require.NoError(t, err) + require.Equal(t, "5", res.DefaultConfig.GasLimit) +} + +func TestApplyInvalidBuilderDelta(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + _, err = Apply(lock, c, Delta{BuilderURLs: []string{}}) + require.ErrorContains(t, err, "builder urls must not be empty") + + _, err = Apply(lock, c, Delta{NoBuilders: true, BuilderMinBid: new(uint64(5))}) + require.ErrorContains(t, err, "no builders excludes") +} + +func TestApplyUnknownValidator(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + unknown := "0x" + strings.Repeat("ab", 48) + + _, err = Apply(lock, c, Delta{FeeRecipient: addrB, FeeRecipientValidators: []string{unknown}}) + require.ErrorContains(t, err, "validator not in lock") +} + +func TestApplyInvalidFeeRecipient(t *testing.T) { + lock := testLock(t, 2) + c, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + _, err = Apply(lock, c, Delta{FeeRecipient: "0x123"}) + require.Error(t, err) +} + +func TestApplyDuplicateBuilderURLs(t *testing.T) { + lock := testLock(t, 1) + c, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + _, err = Apply(lock, c, Delta{BuilderURLs: []string{"https://a.example", "https://a.example"}}) + require.ErrorContains(t, err, "builder-urls entry is duplicated") +} diff --git a/cluster/proposerconfig/diff.go b/cluster/proposerconfig/diff.go new file mode 100644 index 0000000000..7b0fbd9eca --- /dev/null +++ b/cluster/proposerconfig/diff.go @@ -0,0 +1,79 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "slices" + "strings" + + "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/cluster" +) + +// Diff returns the fields that differ between a and b as "field: old -> new" lines, empty values as "none": the +// default gas limit and builder fields first, then each lock validator whose effective fee recipient differs, in +// lock order. +func Diff(lock cluster.Lock, a, b Config) []string { + orNone := func(s string) string { + if s == "" { + return "none" + } + + return s + } + + var lines []string + + add := func(field, oldVal, newVal string) { + if oldVal != newVal { + lines = append(lines, field+": "+orNone(oldVal)+" -> "+orNone(newVal)) + } + } + + add("default.gas_limit", a.DefaultConfig.GasLimit, b.DefaultConfig.GasLimit) + + oldB, newB := flattenBuilder(a.DefaultConfig.Builder), flattenBuilder(b.DefaultConfig.Builder) + if !slices.Equal(oldB.urls, newB.urls) { + // Compared raw, shown redacted: builder URLs may carry credentials. + lines = append(lines, "default.builder.urls: "+orNone(RedactURLs(oldB.urls))+" -> "+orNone(RedactURLs(newB.urls))) + } + + add("default.builder.min_bid", oldB.minBid, newB.minBid) + add("default.builder.boost_factor", oldB.boostFactor, newB.boostFactor) + add("default.builder.max_execution_payment", oldB.maxExecutionPayment, newB.maxExecutionPayment) + + oldFees, newFees := a.FeeRecipients(lock), b.FeeRecipients(lock) + for i, val := range lock.Validators { + add("validator "+pubkeyHex(val.PubKey)+".fee_recipient", oldFees[i], newFees[i]) + } + + return lines +} + +// RedactURLs returns the URLs redacted as the URL flags are logged, comma-joined for display. The URLs are +// redacted one by one: a URL may itself contain a comma. +func RedactURLs(urls []string) string { + return strings.Join(log.RedactURLs(urls, true), ",") +} + +// builderValues are a builder's settings as strings, all empty for a nil builder. +type builderValues struct { + urls []string + minBid string + boostFactor string + maxExecutionPayment string +} + +// flattenBuilder returns the builder's values. +func flattenBuilder(b *Builder) builderValues { + if b == nil { + return builderValues{} + } + + urls := make([]string, 0, len(b.Builders)) + for _, e := range b.Builders { + urls = append(urls, e.URL) + } + + return builderValues{urls: urls, minBid: b.MinBid, boostFactor: b.BuilderBoostFactor, maxExecutionPayment: b.MaxExecutionPayment} +} diff --git a/cluster/proposerconfig/diff_internal_test.go b/cluster/proposerconfig/diff_internal_test.go new file mode 100644 index 0000000000..447b3433f1 --- /dev/null +++ b/cluster/proposerconfig/diff_internal_test.go @@ -0,0 +1,98 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "encoding/binary" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/obolnetwork/charon/cluster" +) + +func TestDiff(t *testing.T) { + lock := testLock(t, 2) + a, err := NewConfig(lock, []string{addrA, addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + b, err := NewConfig(lock, []string{addrA, addrB}, 5, nil) + require.NoError(t, err) + + require.Equal(t, []string{ + "default.gas_limit: 200000000 -> 5", + "validator " + pubkeyHex(lock.Validators[1].PubKey) + ".fee_recipient: " + addrA + " -> " + addrB, + }, Diff(lock, a, b)) + + require.Empty(t, Diff(lock, a, a)) +} + +func TestDiffBuilder(t *testing.T) { + lock := testLock(t, 1) + a, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + b, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + require.Equal(t, []string{ + "default.builder.urls: none -> https://b1.example", + "default.builder.min_bid: none -> 5", + "default.builder.boost_factor: none -> 110", + "default.builder.max_execution_payment: none -> 7", + }, Diff(lock, a, b)) +} + +func TestDiffRedactsBuilderURLs(t *testing.T) { + lock := testLock(t, 1) + a, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, testBuilder()) + require.NoError(t, err) + + builder := testBuilder() + builder.Builders = []BuilderEntry{{URL: "https://user:secret@b2.example"}, {URL: "https://b3.example/key?token=secret"}, {URL: "https://user:pa,ss@b4.example"}} + b, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, builder) + require.NoError(t, err) + + // A comma in a URL does not split it before redaction. + require.Equal(t, []string{ + "default.builder.urls: https://b1.example -> https://user:xxxxx@b2.example,https://b3.example/xxxxx?token=xxxxx,https://user:xxxxx@b4.example", + }, Diff(lock, a, b)) + + // URLs differing only in redacted parts still differ. + builder = testBuilder() + builder.Builders = []BuilderEntry{{URL: "https://user:other@b2.example"}} + c, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, builder) + require.NoError(t, err) + require.Len(t, Diff(lock, b, c), 1) +} + +func TestDiffLargeLock(t *testing.T) { + const n = 5000 + + var lock cluster.Lock + + feesA := make([]string, n) + feesB := make([]string, n) + + for i := range n { + pubkey := make([]byte, 48) + binary.BigEndian.PutUint32(pubkey, uint32(i)) + lock.Validators = append(lock.Validators, cluster.DistValidator{PubKey: pubkey}) + + // Alternating fee recipients give half the validators an entry in both configs. + feesA[i], feesB[i] = addrA, addrB + if i%2 == 0 { + feesA[i], feesB[i] = addrB, addrC + } + } + + a, err := NewConfig(lock, feesA, DefaultGasLimit, nil) + require.NoError(t, err) + b, err := NewConfig(lock, feesB, DefaultGasLimit, nil) + require.NoError(t, err) + + start := time.Now() + diffs := Diff(lock, a, b) + + require.Less(t, time.Since(start), time.Second) + require.Len(t, diffs, n) +} diff --git a/cluster/proposerconfig/file.go b/cluster/proposerconfig/file.go new file mode 100644 index 0000000000..ecef56ee5c --- /dev/null +++ b/cluster/proposerconfig/file.go @@ -0,0 +1,324 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "bytes" + "cmp" + "encoding/hex" + "encoding/json" + "fmt" + "os" + "path/filepath" + "slices" + "strings" + + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/cluster" +) + +// ErrNotFound is returned by Load if the proposer config file does not exist. +var ErrNotFound = errors.Wrap(os.ErrNotExist, "proposer config file not found") + +// documentJSON is the JSON form of a Document, field order is the file's field order. +type documentJSON struct { + Version string `json:"version"` + LockHash string `json:"lock_hash"` + Revision uint64 `json:"revision"` + RevisionHash string `json:"revision_hash"` + ProposerConfig map[string]Settings `json:"proposer_config"` + DefaultConfig Settings `json:"default_config"` + Signatures []signatureJSON `json:"signatures"` +} + +type signatureJSON struct { + Operator int `json:"operator"` + Signature string `json:"signature"` +} + +// Marshal returns the JSON form of the document keyed by DV pubkeys, as exchanged between operators. +// The revision hash is recomputed from the config. +func Marshal(doc Document) ([]byte, error) { + hash, err := doc.Hash() + if err != nil { + return nil, err + } + + return marshal(doc, hash) +} + +// Unmarshal parses the JSON form, keeping its keys as they are and its revision hash as StoredHash. +func Unmarshal(b []byte) (Document, error) { + var w documentJSON + if err := json.Unmarshal(b, &w); err != nil { + return Document{}, errors.Wrap(err, "unmarshal proposer config") + } + + lockHash, err := decodeHex(w.LockHash) + if err != nil { + return Document{}, errors.Wrap(err, "decode lock hash") + } + + storedHash, err := decodeHex(w.RevisionHash) + if err != nil { + return Document{}, errors.Wrap(err, "decode revision hash") + } + + var sigs []Signature + + for _, s := range w.Signatures { + sig, err := decodeHex(s.Signature) + if err != nil { + return Document{}, errors.Wrap(err, "decode signature", z.Int("operator", s.Operator)) + } + + sigs = append(sigs, Signature{Operator: s.Operator, Signature: sig}) + } + + return Document{ + Version: w.Version, + LockHash: lockHash, + Revision: w.Revision, + Config: Config{ + DefaultConfig: w.DefaultConfig, + ProposerConfig: w.ProposerConfig, + }, + Signatures: sigs, + StoredHash: storedHash, + }, nil +} + +// marshal returns the JSON form of the document with the given revision hash, keeping its keys as they are. +func marshal(doc Document, hash [32]byte) ([]byte, error) { + proposerConfig := make(map[string]Settings, len(doc.Config.ProposerConfig)) + for k, v := range doc.Config.ProposerConfig { + proposerConfig[k] = canonicalSettings(v) + } + + sigs := make([]signatureJSON, 0, len(doc.Signatures)) + for _, s := range doc.Signatures { + sigs = append(sigs, signatureJSON{Operator: s.Operator, Signature: "0x" + hex.EncodeToString(s.Signature)}) + } + + slices.SortStableFunc(sigs, func(a, b signatureJSON) int { return cmp.Compare(a.Operator, b.Operator) }) + + b, err := json.MarshalIndent(documentJSON{ + Version: doc.Version, + LockHash: "0x" + hex.EncodeToString(doc.LockHash), + Revision: doc.Revision, + RevisionHash: "0x" + hex.EncodeToString(hash[:]), + ProposerConfig: proposerConfig, + DefaultConfig: canonicalSettings(doc.Config.DefaultConfig), + Signatures: sigs, + }, "", " ") + if err != nil { + return nil, errors.Wrap(err, "marshal proposer config") + } + + return append(b, '\n'), nil +} + +func decodeHex(s string) ([]byte, error) { + b, err := hex.DecodeString(strings.TrimPrefix(s, "0x")) + if err != nil { + return nil, errors.Wrap(err, "decode hex") + } + + return b, nil +} + +// pubshareMaps returns DV pubkey to this node's pubshare (and the reverse), both lowercase 0x hex. +func pubshareMaps(lock cluster.Lock, nodeIdx cluster.NodeIdx) (toShare, toPubkey map[string]string, err error) { + toShare = make(map[string]string, len(lock.Validators)) + toPubkey = make(map[string]string, len(lock.Validators)) + + for i, val := range lock.Validators { + share, err := val.PublicShare(nodeIdx.PeerIdx) + if err != nil { + return nil, nil, errors.Wrap(err, "pubshare", z.Int("validator", i)) + } + + pubkey := pubkeyHex(val.PubKey) + pubshare := fmt.Sprintf("%#x", share) + + toShare[pubkey] = pubshare + toPubkey[pubshare] = pubkey + } + + return toShare, toPubkey, nil +} + +// rekey returns the proposer_config with each key replaced by keys[key], erroring on a key not in keys. +// keyName names the input keys in the error. +func rekey(in map[string]Settings, keys map[string]string, keyName string) (map[string]Settings, error) { + out := make(map[string]Settings, len(in)) + + for k, v := range in { + renamed, ok := keys[strings.ToLower(k)] + if !ok { + return nil, errors.New("unknown "+keyName, z.Str(keyName, k)) + } + + out[renamed] = v + } + + return out, nil +} + +// Load reads the proposer config file, keyed by this node's pubshares, and returns it keyed by DV pubkeys. +// A file of another lock returns ErrLockHashMismatch. +func Load(path string, lock cluster.Lock, nodeIdx cluster.NodeIdx) (Document, error) { + b, err := os.ReadFile(path) + if errors.Is(err, os.ErrNotExist) { + return Document{}, errors.Wrap(ErrNotFound, "load proposer config", z.Str("path", path)) + } else if err != nil { + return Document{}, errors.Wrap(err, "read proposer config", z.Str("path", path)) + } + + _, toPubkey, err := pubshareMaps(lock, nodeIdx) + if err != nil { + return Document{}, err + } + + doc, err := Unmarshal(b) + if err != nil { + return Document{}, errors.Wrap(err, "load proposer config", z.Str("path", path)) + } + + if len(doc.LockHash) != len(lock.LockHash) { + return Document{}, errors.Wrap(invalid("malformed lock hash", z.Int("bytes", len(doc.LockHash))), "load proposer config", z.Str("path", path)) + } + + // Checked before re-keying, another cluster's pubshares would otherwise fail as unknown. + if !bytes.Equal(doc.LockHash, lock.LockHash) { + return Document{}, errors.Wrap(ErrLockHashMismatch, "proposer config file lock hash differs from lock", z.Str("path", path)) + } + + // The file is keyed by this node's pubshares, the document by DV pubkeys. + doc.Config.ProposerConfig, err = rekey(doc.Config.ProposerConfig, toPubkey, "pubshare") + if err != nil { + return Document{}, err + } + + return doc, nil +} + +// render returns the file contents of the document, keyed by this node's pubshares instead of DV pubkeys. +func render(doc Document, lock cluster.Lock, nodeIdx cluster.NodeIdx) ([]byte, error) { + // Hashed before re-keying: the revision hash covers the DV pubkeys, the same on every node. + hash, err := doc.Hash() + if err != nil { + return nil, err + } + + toShare, _, err := pubshareMaps(lock, nodeIdx) + if err != nil { + return nil, err + } + + doc.Config.ProposerConfig, err = rekey(doc.Config.ProposerConfig, toShare, "pubkey") + if err != nil { + return nil, err + } + + return marshal(doc, hash) +} + +// Write atomically writes the document, keyed by DV pubkeys, to path keyed by this node's pubshares, creating +// the directory. +func Write(path string, doc Document, lock cluster.Lock, nodeIdx cluster.NodeIdx) error { + b, err := render(doc, lock, nodeIdx) + if err != nil { + return err + } + + return writeAtomic(path, b) +} + +// writeAtomic writes data to a temp file in the same directory and renames it to path, mode 0644. +func writeAtomic(path string, data []byte) error { + dir := filepath.Dir(path) + + if err := os.MkdirAll(dir, 0o755); err != nil { + return errors.Wrap(err, "create directory", z.Str("path", dir)) + } + + tmp, err := os.CreateTemp(dir, filepath.Base(path)+".*.tmp") + if err != nil { + return errors.Wrap(err, "create temp file", z.Str("path", dir)) + } + + cleanup := func(err error, msg string) error { + _ = tmp.Close() + _ = os.Remove(tmp.Name()) + + return errors.Wrap(err, msg, z.Str("path", path)) + } + + if _, err := tmp.Write(data); err != nil { + return cleanup(err, "write temp file") + } + + if err := tmp.Chmod(0o644); err != nil { + return cleanup(err, "chmod temp file") + } + + if err := tmp.Sync(); err != nil { + return cleanup(err, "sync temp file") + } + + if err := tmp.Close(); err != nil { + return cleanup(err, "close temp file") + } + + if err := os.Rename(tmp.Name(), path); err != nil { + return cleanup(err, "rename temp file") + } + + return nil +} + +// ArchivePath returns the archive path of a revision, next to the file at path. +func ArchivePath(path string, revision uint64) string { + return filepath.Join(filepath.Dir(path), fmt.Sprintf("proposer-config-revision-%d.json", revision)) +} + +// CheckArchive returns an error if the revision's archive exists and differs from the file at path. +func CheckArchive(path string, revision uint64) error { + _, err := checkArchive(path, revision) + return err +} + +// checkArchive returns the current file's contents and whether the archive already holds them. +func checkArchive(path string, revision uint64) (current []byte, err error) { + current, err = os.ReadFile(path) + if err != nil { + return nil, errors.Wrap(err, "read proposer config", z.Str("path", path)) + } + + archive := ArchivePath(path, revision) + + existing, err := os.ReadFile(archive) + if errors.Is(err, os.ErrNotExist) { + return current, nil + } else if err != nil { + return nil, errors.Wrap(err, "read archive", z.Str("path", archive)) + } + + if !bytes.Equal(existing, current) { + return nil, errors.New("proposer config archive exists and differs, move it away first", z.Str("path", archive)) + } + + return current, nil +} + +// Archive copies the file at path byte for byte to the revision's archive; it is a no-op if an identical one exists. +func Archive(path string, revision uint64) error { + current, err := checkArchive(path, revision) + if err != nil { + return err + } + + return writeAtomic(ArchivePath(path, revision), current) +} diff --git a/cluster/proposerconfig/file_internal_test.go b/cluster/proposerconfig/file_internal_test.go new file mode 100644 index 0000000000..bfd2cce159 --- /dev/null +++ b/cluster/proposerconfig/file_internal_test.go @@ -0,0 +1,209 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "encoding/json" + "fmt" + "math/rand" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/testutil" +) + +func testDoc(t *testing.T, lock cluster.Lock) Document { + t.Helper() + + builder := &Builder{ + MinBid: "0", + BuilderBoostFactor: "100", + MaxExecutionPayment: "0", + Builders: []BuilderEntry{{URL: "https://b1.example"}}, + } + + cfg, err := NewConfig(lock, []string{addrA, addrB}, DefaultGasLimit, builder) + require.NoError(t, err) + + doc := Document{ + Version: Version, + LockHash: lock.LockHash, + Revision: 2, + Config: cfg, + Signatures: []Signature{ + {Operator: 2, Signature: []byte{0xbb, 0xbb}}, + {Operator: 0, Signature: []byte{0xaa}}, + }, + } + + hash, err := doc.Hash() + require.NoError(t, err) + + doc.StoredHash = hash[:] + + return doc +} + +func TestWriteLoadRoundTrip(t *testing.T) { + lock := testLock(t, 2) + nodeIdx := cluster.NodeIdx{PeerIdx: 1, ShareIdx: 2} + doc := testDoc(t, lock) + path := filepath.Join(t.TempDir(), "vc-config", "proposer-config.json") + + require.NoError(t, Write(path, doc, lock, nodeIdx)) + + loaded, err := Load(path, lock, nodeIdx) + require.NoError(t, err) + + // Signatures are written sorted by operator. + doc.Signatures = []Signature{doc.Signatures[1], doc.Signatures[0]} + require.Equal(t, doc, loaded) + + b, err := os.ReadFile(path) + require.NoError(t, err) + testutil.RequireGoldenBytes(t, b) + + var raw struct { + RevisionHash string `json:"revision_hash"` + } + require.NoError(t, json.Unmarshal(b, &raw)) + + hash, err := doc.Hash() + require.NoError(t, err) + require.Equal(t, fmt.Sprintf("%#x", hash), raw.RevisionHash) + + // Field order. + s := string(b) + last := -1 + + for _, k := range []string{"version", "lock_hash", "revision", "revision_hash", "proposer_config", "default_config", "signatures"} { + idx := strings.Index(s, `"`+k+`"`) + require.Greater(t, idx, last, k) + + last = idx + } + + info, err := os.Stat(path) + require.NoError(t, err) + require.EqualValues(t, 0o644, info.Mode().Perm()) +} + +func TestMarshalRoundTrip(t *testing.T) { + lock := testLock(t, 2) + doc := testDoc(t, lock) + + b, err := Marshal(doc) + require.NoError(t, err) + testutil.RequireGoldenBytes(t, b) + + got, err := Unmarshal(b) + require.NoError(t, err) + + doc.Signatures = []Signature{doc.Signatures[1], doc.Signatures[0]} + require.Equal(t, doc, got) + + // Nil and empty builders marshal identically. + doc.Config.DefaultConfig.Builder.Builders = nil + b2, err := Marshal(doc) + require.NoError(t, err) + + doc.Config.DefaultConfig.Builder.Builders = []BuilderEntry{} + b3, err := Marshal(doc) + require.NoError(t, err) + require.Equal(t, b2, b3) +} + +func TestLoadIntegerVersion(t *testing.T) { + lock := testLock(t, 1) + path := filepath.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, os.WriteFile(path, []byte(`{"version":1,"proposer_config":{},"default_config":{"gas_limit":"30000000"}}`), 0o644)) + + // A pre-release file with an integer version does not decode. + _, err := Load(path, lock, cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1}) + require.ErrorContains(t, err, "load proposer config") + require.NotErrorIs(t, err, ErrNotFound) +} + +func TestLoadMissingLockHash(t *testing.T) { + lock := testLock(t, 1) + path := filepath.Join(t.TempDir(), "proposer-config.json") + require.NoError(t, os.WriteFile(path, []byte(`{"version":"v1.0.0","proposer_config":{},"default_config":{"gas_limit":"30000000"}}`), 0o644)) + + // A hand-written file without a lock hash is invalid, not another cluster's. + _, err := Load(path, lock, cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1}) + require.ErrorIs(t, err, ErrInvalid) + require.NotErrorIs(t, err, ErrLockHashMismatch) +} + +func TestLoadForeignPubshares(t *testing.T) { + lock := testLock(t, 2) + path := filepath.Join(t.TempDir(), "proposer-config.json") + + require.NoError(t, Write(path, testDoc(t, lock), lock, cluster.NodeIdx{PeerIdx: 1, ShareIdx: 2})) + + _, err := Load(path, lock, cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1}) + require.ErrorContains(t, err, "unknown pubshare") +} + +func TestLoadLockHashMismatch(t *testing.T) { + lock := testLock(t, 2) + other, _, _ := cluster.NewForT(t, 2, 3, 4, 8, rand.New(rand.NewSource(8))) + path := filepath.Join(t.TempDir(), "proposer-config.json") + nodeIdx := cluster.NodeIdx{PeerIdx: 1, ShareIdx: 2} + + // The other cluster's file has entries keyed by pubshares unknown to this lock. + doc := testDoc(t, other) + require.NotEmpty(t, doc.Config.ProposerConfig) + require.NoError(t, Write(path, doc, other, nodeIdx)) + + _, err := Load(path, lock, nodeIdx) + require.ErrorIs(t, err, ErrLockHashMismatch) +} + +func TestLoadMissing(t *testing.T) { + lock := testLock(t, 1) + + _, err := Load(filepath.Join(t.TempDir(), "nope.json"), lock, cluster.NodeIdx{}) + require.ErrorIs(t, err, ErrNotFound) + require.ErrorIs(t, err, os.ErrNotExist) +} + +func TestWriteAtomic(t *testing.T) { + lock := testLock(t, 2) + dir := filepath.Join(t.TempDir(), "a", "b") + + require.NoError(t, Write(filepath.Join(dir, "p.json"), testDoc(t, lock), lock, cluster.NodeIdx{PeerIdx: 0, ShareIdx: 1})) + + entries, err := os.ReadDir(dir) + require.NoError(t, err) + require.Len(t, entries, 1) + require.Equal(t, "p.json", entries[0].Name()) +} + +func TestArchiveIdempotent(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "proposer-config.json") + archive := filepath.Join(dir, "proposer-config-revision-0.json") + + require.Equal(t, archive, ArchivePath(path, 0)) + require.NoError(t, os.WriteFile(path, []byte("current"), 0o644)) + + require.NoError(t, CheckArchive(path, 0)) + require.NoError(t, Archive(path, 0)) + + b, err := os.ReadFile(archive) + require.NoError(t, err) + require.Equal(t, "current", string(b)) + + require.NoError(t, CheckArchive(path, 0)) + require.NoError(t, Archive(path, 0)) + + require.NoError(t, os.WriteFile(path, []byte("changed"), 0o644)) + require.ErrorContains(t, CheckArchive(path, 0), "move it away first") + require.ErrorContains(t, Archive(path, 0), "move it away first") +} diff --git a/cluster/proposerconfig/proposerconfig.go b/cluster/proposerconfig/proposerconfig.go new file mode 100644 index 0000000000..23a1affab9 --- /dev/null +++ b/cluster/proposerconfig/proposerconfig.go @@ -0,0 +1,225 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +// Package proposerconfig defines the revisioned, operator-signed proposer configuration document +// consumed by validator clients, and its canonical revision hash. +// +// A Document's proposer_config is keyed by DV pubkeys everywhere in charon: in memory, in the revision hash, +// in Marshal's JSON exchanged between operators and in diffs. Only the file on disk is keyed by this node's +// pubshares, which its validator client knows its validators by; Load and Write translate between the two. +package proposerconfig + +import ( + "crypto/sha256" + "encoding/hex" + "encoding/json" + "strconv" + "strings" + + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/eth2util" +) + +const ( + // Version is the proposer config file schema version. + Version = "v1.0.0" + // DefaultGasLimit is the default proposer gas limit. + DefaultGasLimit uint64 = 200_000_000 + // DefaultBuilderBoostFactor is the default builder bid boost factor percentage. + DefaultBuilderBoostFactor uint64 = 100 +) + +// Settings holds one validator's proposer settings. All fields are set on default_config; +// a proposer_config entry only carries the fields diverging from it. +type Settings struct { + FeeRecipient string `json:"fee_recipient,omitempty"` + GasLimit string `json:"gas_limit,omitempty"` + Builder *Builder `json:"builder,omitempty"` +} + +// Builder holds the builder configuration defaults; each entry in Builders may override them. +type Builder struct { + // MinBid is the minimum bid value in gwei. + MinBid string `json:"min_bid"` + // BuilderBoostFactor is the percentage multiplier applied to builder bid values. + BuilderBoostFactor string `json:"builder_boost_factor"` + // MaxExecutionPayment is the maximum execution layer payment in gwei counted when valuing a bid. + MaxExecutionPayment string `json:"max_execution_payment"` + // Builders lists the builders to request execution payload bids from directly. + Builders []BuilderEntry `json:"builders"` +} + +// BuilderEntry is one builder; the optional fields override the enclosing Builder values. +type BuilderEntry struct { + URL string `json:"url"` + MinBid string `json:"min_bid,omitempty"` + BuilderBoostFactor string `json:"builder_boost_factor,omitempty"` + MaxExecutionPayment string `json:"max_execution_payment,omitempty"` +} + +// Config is the signed part of the document. ProposerConfig is keyed by lowercase 0x DV pubkey, never by +// pubshare, and only holds validators diverging from DefaultConfig. +type Config struct { + DefaultConfig Settings `json:"default_config"` + ProposerConfig map[string]Settings `json:"proposer_config"` +} + +// Signature is an operator's signature of the revision hash. +type Signature struct { + Operator int + Signature []byte +} + +// Document is a revisioned proposer config. Signatures and StoredHash are not part of the revision hash. +type Document struct { + Version string + LockHash []byte + Revision uint64 + Config Config + Signatures []Signature + StoredHash []byte +} + +// signingData is the canonical hashed form of a Document, keyed by DV pubkeys so every node hashes the same +// bytes; field order is part of the format. +type signingData struct { + Version string `json:"version"` + LockHash string `json:"lock_hash"` + Revision string `json:"revision"` + DefaultConfig Settings `json:"default_config"` + ProposerConfig map[string]Settings `json:"proposer_config"` +} + +func newSigningData(d Document) signingData { + proposerConfig := make(map[string]Settings, len(d.Config.ProposerConfig)) + for k, v := range d.Config.ProposerConfig { + proposerConfig[k] = canonicalSettings(v) + } + + return signingData{ + Version: d.Version, + LockHash: "0x" + hex.EncodeToString(d.LockHash), + Revision: strconv.FormatUint(d.Revision, 10), + DefaultConfig: canonicalSettings(d.Config.DefaultConfig), + ProposerConfig: proposerConfig, + } +} + +// canonicalSettings returns a copy with a nil builders list as an empty one, so nil and empty hash equal. +func canonicalSettings(s Settings) Settings { + if s.Builder != nil && s.Builder.Builders == nil { + b := *s.Builder + b.Builders = []BuilderEntry{} + s.Builder = &b + } + + return s +} + +// Hash returns the revision hash: sha256 over the canonical JSON of the hashed fields. +func (d Document) Hash() ([32]byte, error) { + b, err := json.Marshal(newSigningData(d)) + if err != nil { + return [32]byte{}, errors.Wrap(err, "marshal proposer config signing data") + } + + return sha256.Sum256(b), nil +} + +// NewConfig returns the config for the lock with one fee recipient per lock validator. The default +// config holds the majority fee recipient (ties go to the first validator holding it) and the gas limit +// and builder; entries only exist for validators diverging from the majority. An empty fee recipient, +// as in v1.0 and v1.1 locks, means none: it emits no entry. +func NewConfig(lock cluster.Lock, feeRecipients []string, gasLimit uint64, builder *Builder) (Config, error) { + if len(feeRecipients) != len(lock.Validators) { + return Config{}, errors.New("fee recipient count mismatch", z.Int("fee_recipients", len(feeRecipients)), z.Int("validators", len(lock.Validators))) + } + + fees := make([]string, len(feeRecipients)) + counts := make(map[string]int) + + for i, addr := range feeRecipients { + if addr == "" { + counts[""]++ + continue + } + + fee, err := normaliseAddress(addr) + if err != nil { + return Config{}, errors.Wrap(err, "fee recipient", z.Int("validator", i)) + } + + fees[i] = fee + counts[fee]++ + } + + var defaultFee string + + for _, fee := range fees { + if counts[fee] > counts[defaultFee] { + defaultFee = fee + } + } + + cfg := Config{ + DefaultConfig: Settings{ + FeeRecipient: defaultFee, + GasLimit: strconv.FormatUint(gasLimit, 10), + Builder: builder, + }, + ProposerConfig: make(map[string]Settings), + } + + for i, val := range lock.Validators { + if fees[i] != "" && fees[i] != defaultFee { + cfg.ProposerConfig[pubkeyHex(val.PubKey)] = Settings{FeeRecipient: fees[i]} + } + } + + return cfg, nil +} + +// FeeRecipient returns the fee recipient of the validator with the given DV pubkey, falling back to the +// default config. +func (c Config) FeeRecipient(pubkey string) string { + if s, ok := c.ProposerConfig[strings.ToLower(pubkey)]; ok && s.FeeRecipient != "" { + return s.FeeRecipient + } + + return c.DefaultConfig.FeeRecipient +} + +// FeeRecipients returns the fee recipient of each lock validator, in lock order. +func (c Config) FeeRecipients(lock cluster.Lock) []string { + res := make([]string, 0, len(lock.Validators)) + for _, val := range lock.Validators { + res = append(res, c.FeeRecipient(pubkeyHex(val.PubKey))) + } + + return res +} + +// GasLimit returns the default config's gas limit. +func (c Config) GasLimit() (uint64, error) { + gas, err := strconv.ParseUint(c.DefaultConfig.GasLimit, 10, 64) + if err != nil { + return 0, errors.Wrap(err, "parse gas limit", z.Str("gas_limit", c.DefaultConfig.GasLimit)) + } + + return gas, nil +} + +func pubkeyHex(pubkey []byte) string { + return "0x" + hex.EncodeToString(pubkey) +} + +// normaliseAddress validates an Ethereum address (EIP-55 checksum when mixed case) and returns it lowercased. +func normaliseAddress(addr string) (string, error) { + checksummed, err := eth2util.ValidateChecksumAddress(addr) + if err != nil { + return "", errors.Wrap(err, "validate address", z.Str("address", addr)) + } + + return strings.ToLower(checksummed), nil +} diff --git a/cluster/proposerconfig/proposerconfig_internal_test.go b/cluster/proposerconfig/proposerconfig_internal_test.go new file mode 100644 index 0000000000..4262c6c2cf --- /dev/null +++ b/cluster/proposerconfig/proposerconfig_internal_test.go @@ -0,0 +1,220 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "encoding/hex" + "encoding/json" + "math/rand" + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/testutil" +) + +const ( + addrA = "0x000000000000000000000000000000000000000a" + addrB = "0x000000000000000000000000000000000000000b" +) + +func testLock(t *testing.T, vals int) cluster.Lock { + t.Helper() + + lock, _, _ := cluster.NewForT(t, vals, 3, 4, 7, rand.New(rand.NewSource(7)), func(d *cluster.Definition) { + d.Timestamp = "2026-01-01T00:00:00Z" + }) + + return lock +} + +func TestHashGolden(t *testing.T) { + lock := testLock(t, 2) + + builder := &Builder{ + MinBid: "0", + BuilderBoostFactor: "100", + MaxExecutionPayment: "0", + Builders: []BuilderEntry{{URL: "https://b1.example"}, {URL: "https://b2.example"}}, + } + + cfg, err := NewConfig(lock, []string{addrA, addrB}, DefaultGasLimit, builder) + require.NoError(t, err) + + doc := Document{Version: Version, LockHash: lock.LockHash, Revision: 1, Config: cfg} + + hash, err := doc.Hash() + require.NoError(t, err) + testutil.RequireGoldenJSON(t, "0x"+hex.EncodeToString(hash[:])) + + // The signing data has the five hashed fields in order and no whitespace. + b, err := json.Marshal(newSigningData(doc)) + require.NoError(t, err) + testutil.RequireGoldenBytes(t, b, testutil.WithFilename("TestHashGolden_signing_data.golden")) + + s := string(b) + last := -1 + + for _, k := range []string{"version", "lock_hash", "revision", "default_config", "proposer_config"} { + idx := strings.Index(s, `"`+k+`":`) + require.Greater(t, idx, last, k) + last = idx + } + + require.NotContains(t, s, " ") +} + +func TestHashIgnoresSignatures(t *testing.T) { + lock := testLock(t, 1) + cfg, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + + doc := Document{Version: Version, LockHash: lock.LockHash, Revision: 1, Config: cfg} + h1, err := doc.Hash() + require.NoError(t, err) + + doc.Signatures = []Signature{{Operator: 1, Signature: []byte{1}}} + doc.StoredHash = []byte{2} + h2, err := doc.Hash() + require.NoError(t, err) + require.Equal(t, h1, h2) +} + +func TestHashCaseInsensitiveInputs(t *testing.T) { + lock := testLock(t, 1) + checksummed := "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed" + + c1, err := NewConfig(lock, []string{checksummed}, DefaultGasLimit, nil) + require.NoError(t, err) + c2, err := NewConfig(lock, []string{strings.ToLower(checksummed)}, DefaultGasLimit, nil) + require.NoError(t, err) + + h1, err := Document{Version: Version, LockHash: lock.LockHash, Revision: 1, Config: c1}.Hash() + require.NoError(t, err) + h2, err := Document{Version: Version, LockHash: lock.LockHash, Revision: 1, Config: c2}.Hash() + require.NoError(t, err) + require.Equal(t, h1, h2) +} + +func TestNewConfigMajority(t *testing.T) { + lock := testLock(t, 3) + pk := func(i int) string { return "0x" + hex.EncodeToString(lock.Validators[i].PubKey) } + + c, err := NewConfig(lock, []string{addrA, addrB, addrB}, DefaultGasLimit, nil) + require.NoError(t, err) + require.Equal(t, addrB, c.DefaultConfig.FeeRecipient) + require.Equal(t, "200000000", c.DefaultConfig.GasLimit) + require.Len(t, c.ProposerConfig, 1) + require.Equal(t, Settings{FeeRecipient: addrA}, c.ProposerConfig[pk(0)]) + require.Equal(t, []string{addrA, addrB, addrB}, c.FeeRecipients(lock)) + require.Equal(t, addrA, c.FeeRecipient(pk(0))) + require.Equal(t, addrB, c.FeeRecipient(pk(1))) + + gas, err := c.GasLimit() + require.NoError(t, err) + require.Equal(t, DefaultGasLimit, gas) + + // Tie: the first validator wins. + lock2 := testLock(t, 2) + c, err = NewConfig(lock2, []string{addrA, addrB}, DefaultGasLimit, nil) + require.NoError(t, err) + require.Equal(t, addrA, c.DefaultConfig.FeeRecipient) + require.Len(t, c.ProposerConfig, 1) +} + +func TestNewConfigErrors(t *testing.T) { + lock := testLock(t, 2) + + _, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, nil) + require.Error(t, err) + + _, err = NewConfig(lock, []string{addrA, "0x1234"}, DefaultGasLimit, nil) + require.Error(t, err) + + _, err = NewConfig(lock, []string{addrA, "nothex"}, DefaultGasLimit, nil) + require.Error(t, err) +} + +func TestNewConfigEmptyLockFeeRecipients(t *testing.T) { + lock := testLock(t, 3) + pk := func(i int) string { return "0x" + hex.EncodeToString(lock.Validators[i].PubKey) } + + // A v1.0/v1.1 lock may have no fee recipients, empty means none. + c, err := NewConfig(lock, []string{"", "", addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + require.Empty(t, c.DefaultConfig.FeeRecipient) + require.Equal(t, map[string]Settings{pk(2): {FeeRecipient: addrA}}, c.ProposerConfig) + require.Equal(t, []string{"", "", addrA}, c.FeeRecipients(lock)) + + // A minority empty fee recipient emits no entry and falls back to the default. + c, err = NewConfig(lock, []string{addrA, "", addrA}, DefaultGasLimit, nil) + require.NoError(t, err) + require.Equal(t, addrA, c.DefaultConfig.FeeRecipient) + require.Empty(t, c.ProposerConfig) +} + +func TestNewConfigAddressValidation(t *testing.T) { + lock := testLock(t, 1) + good := "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed" + + for _, addr := range []string{ + "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAeD", // Wrong checksum. + "0X" + good[2:], + good[2:], + } { + _, err := NewConfig(lock, []string{addr}, DefaultGasLimit, nil) + require.Error(t, err, addr) + } + + var hashes [][32]byte + + for _, addr := range []string{good, strings.ToLower(good)} { + c, err := NewConfig(lock, []string{addr}, DefaultGasLimit, nil) + require.NoError(t, err) + + h, err := Document{Version: Version, LockHash: lock.LockHash, Config: c}.Hash() + require.NoError(t, err) + + hashes = append(hashes, h) + } + + require.Equal(t, hashes[0], hashes[1]) +} + +func TestHashNilEmptyBuilders(t *testing.T) { + lock := testLock(t, 1) + + hash := func(builders []BuilderEntry) [32]byte { + c, err := NewConfig(lock, []string{addrA}, DefaultGasLimit, &Builder{MinBid: "0", BuilderBoostFactor: "100", MaxExecutionPayment: "0", Builders: builders}) + require.NoError(t, err) + + h, err := Document{Version: Version, LockHash: lock.LockHash, Config: c}.Hash() + require.NoError(t, err) + + return h + } + + require.Equal(t, hash(nil), hash([]BuilderEntry{})) +} + +func TestHashNilEmptyBuildersInEntry(t *testing.T) { + lock := testLock(t, 1) + + hash := func(builders []BuilderEntry) [32]byte { + c := Config{ + DefaultConfig: Settings{FeeRecipient: addrA}, + ProposerConfig: map[string]Settings{ + "0xaa": {Builder: &Builder{MinBid: "0", BuilderBoostFactor: "100", MaxExecutionPayment: "0", Builders: builders}}, + }, + } + + h, err := Document{Version: Version, LockHash: lock.LockHash, Config: c}.Hash() + require.NoError(t, err) + + return h + } + + require.Equal(t, hash(nil), hash([]BuilderEntry{})) +} diff --git a/cluster/proposerconfig/seed.go b/cluster/proposerconfig/seed.go new file mode 100644 index 0000000000..d1fdff13d8 --- /dev/null +++ b/cluster/proposerconfig/seed.go @@ -0,0 +1,112 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "net/url" + "slices" + "strconv" + + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/core" +) + +// Seed holds the flags seeding the initial (revision 0) proposer config. +type Seed struct { + GasLimit uint64 + BuilderURLs []string + BuilderMinBid uint64 + BuilderBoostFactor uint64 + BuilderMaxExecutionPayment uint64 + // NonDefault names the seed flags set explicitly rather than left at their defaults. + NonDefault []string +} + +// Validate checks the seed flags. +func (s Seed) Validate() error { + err := validateBuilderURLs("proposer-config-builder-urls", s.BuilderURLs) + if err != nil { + return err + } + + if s.GasLimit == 0 { + return errors.New("proposer-config-gas-limit must be greater than 0") + } + + if s.BuilderBoostFactor == 0 { + return errors.New("proposer-config-builder-boost-factor must be greater than 0") + } + + boostFactorSet := slices.Contains(s.NonDefault, "proposer-config-builder-boost-factor") + if len(s.BuilderURLs) == 0 && (s.BuilderMinBid != 0 || boostFactorSet || s.BuilderMaxExecutionPayment != 0) { + return errors.New("proposer-config-builder-min-bid, proposer-config-builder-boost-factor and " + + "proposer-config-builder-max-execution-payment require proposer-config-builder-urls") + } + + return nil +} + +// validateBuilderURLs checks each builder URL is a unique http(s) URL with a host that fits a proposal; +// flag names the URLs' flag in errors. +func validateBuilderURLs(flag string, urls []string) error { + seen := make(map[string]bool) + + for i, u := range urls { + parsed, err := url.Parse(u) + if err != nil || parsed.Scheme != "http" && parsed.Scheme != "https" || parsed.Host == "" { + // The URL is left out: one that doesn't parse cannot be redacted. + return errors.New(flag+" entry is not a valid http(s) URL", z.Int("index", i)) + } + + if seen[u] { + return errors.New(flag+" entry is duplicated", z.Str("url", log.RedactURL(u, true))) + } + + seen[u] = true + + // A builder's URL is agreed with the proposals of its bids, which can't carry a longer one. + if len(u) > core.MaxBuilderURLSize { + return errors.New(flag+" entry is longer than the maximum", z.Int("max", core.MaxBuilderURLSize)) + } + } + + return nil +} + +// FlagValues returns the settings' gas limit and builder values keyed by the seeding flag setting them: the +// builder URLs as a list, the other values as one element, the builder flags absent without a builder. +func FlagValues(s Settings) map[string][]string { + vals := map[string][]string{"proposer-config-gas-limit": {s.GasLimit}} + if s.Builder == nil { + return vals + } + + b := flattenBuilder(s.Builder) + vals["proposer-config-builder-urls"] = b.urls + vals["proposer-config-builder-min-bid"] = []string{b.minBid} + vals["proposer-config-builder-boost-factor"] = []string{b.boostFactor} + vals["proposer-config-builder-max-execution-payment"] = []string{b.maxExecutionPayment} + + return vals +} + +// Builder returns the builder settings, or nil if no builder URLs are configured. +func (s Seed) Builder() *Builder { + if len(s.BuilderURLs) == 0 { + return nil + } + + entries := make([]BuilderEntry, 0, len(s.BuilderURLs)) + for _, u := range s.BuilderURLs { + entries = append(entries, BuilderEntry{URL: u}) + } + + return &Builder{ + MinBid: strconv.FormatUint(s.BuilderMinBid, 10), + BuilderBoostFactor: strconv.FormatUint(s.BuilderBoostFactor, 10), + MaxExecutionPayment: strconv.FormatUint(s.BuilderMaxExecutionPayment, 10), + Builders: entries, + } +} diff --git a/cluster/proposerconfig/seed_internal_test.go b/cluster/proposerconfig/seed_internal_test.go new file mode 100644 index 0000000000..6469efd9b9 --- /dev/null +++ b/cluster/proposerconfig/seed_internal_test.go @@ -0,0 +1,61 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/obolnetwork/charon/core" +) + +func TestSeedValidate(t *testing.T) { + valid := Seed{GasLimit: DefaultGasLimit, BuilderBoostFactor: DefaultBuilderBoostFactor} + withURL := func(s Seed) Seed { + s.BuilderURLs = []string{"https://builder.example"} + return s + } + + boostSet := func(s Seed) Seed { + s.NonDefault = []string{"proposer-config-builder-boost-factor"} + return s + } + + require.NoError(t, valid.Validate()) + require.NoError(t, boostSet(withURL(valid)).Validate()) + + const withoutURLs = "proposer-config-builder-min-bid, proposer-config-builder-boost-factor and " + + "proposer-config-builder-max-execution-payment require proposer-config-builder-urls" + + tests := []struct { + name string + seed Seed + errMsg string + }{ + {"zero gas limit", Seed{BuilderBoostFactor: 100}, "proposer-config-gas-limit must be greater than 0"}, + {"zero boost factor", Seed{GasLimit: 1}, "proposer-config-builder-boost-factor must be greater than 0"}, + {"min bid without urls", Seed{GasLimit: 1, BuilderBoostFactor: 100, BuilderMinBid: 1}, withoutURLs}, + {"max payment without urls", Seed{GasLimit: 1, BuilderBoostFactor: 100, BuilderMaxExecutionPayment: 1}, withoutURLs}, + {"boost set without urls", boostSet(valid), withoutURLs}, + {"non-http url", Seed{GasLimit: 1, BuilderBoostFactor: 100, BuilderURLs: []string{"ftp://x"}}, "proposer-config-builder-urls entry is not a valid http(s) URL"}, + {"duplicate url", Seed{GasLimit: 1, BuilderBoostFactor: 100, BuilderURLs: []string{"https://a.example", "https://b.example", "https://a.example"}}, "proposer-config-builder-urls entry is duplicated"}, + {"long url", Seed{GasLimit: 1, BuilderBoostFactor: 100, BuilderURLs: []string{"https://" + strings.Repeat("a", core.MaxBuilderURLSize)}}, "proposer-config-builder-urls entry is longer than the maximum"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.ErrorContains(t, tt.seed.Validate(), tt.errMsg) + }) + } +} + +func TestSeedBuilder(t *testing.T) { + require.Nil(t, Seed{GasLimit: 1}.Builder()) + + b := Seed{BuilderURLs: []string{"https://a.example"}, BuilderMinBid: 2, BuilderBoostFactor: 110, BuilderMaxExecutionPayment: 3}.Builder() + require.Equal(t, &Builder{ + MinBid: "2", BuilderBoostFactor: "110", MaxExecutionPayment: "3", + Builders: []BuilderEntry{{URL: "https://a.example"}}, + }, b) +} diff --git a/cluster/proposerconfig/testdata/TestHashGolden.golden b/cluster/proposerconfig/testdata/TestHashGolden.golden new file mode 100644 index 0000000000..ec77e4d343 --- /dev/null +++ b/cluster/proposerconfig/testdata/TestHashGolden.golden @@ -0,0 +1 @@ +"0x272e75bfcea751fd76dd97eef33736617c81146ab43bdba30397bb86003427e8" \ No newline at end of file diff --git a/cluster/proposerconfig/testdata/TestHashGolden_signing_data.golden b/cluster/proposerconfig/testdata/TestHashGolden_signing_data.golden new file mode 100644 index 0000000000..c2196bf05e --- /dev/null +++ b/cluster/proposerconfig/testdata/TestHashGolden_signing_data.golden @@ -0,0 +1 @@ +{"version":"v1.0.0","lock_hash":"0xb8dc5d81fa56c6d893e752f04e313b9f63dcd44a84ff19008530449362e6ea51","revision":"1","default_config":{"fee_recipient":"0x000000000000000000000000000000000000000a","gas_limit":"200000000","builder":{"min_bid":"0","builder_boost_factor":"100","max_execution_payment":"0","builders":[{"url":"https://b1.example"},{"url":"https://b2.example"}]}},"proposer_config":{"0xb853c49d5e924260c31b3e1dc1e8a14b1d2ad4039e70a9d123fce46fcff208aac61b7fbf7a67839b8d6f14c80b8ebe06":{"fee_recipient":"0x000000000000000000000000000000000000000b"}}} \ No newline at end of file diff --git a/cluster/proposerconfig/testdata/TestMarshalRoundTrip.golden b/cluster/proposerconfig/testdata/TestMarshalRoundTrip.golden new file mode 100644 index 0000000000..4c609c3ef3 --- /dev/null +++ b/cluster/proposerconfig/testdata/TestMarshalRoundTrip.golden @@ -0,0 +1,35 @@ +{ + "version": "v1.0.0", + "lock_hash": "0xb8dc5d81fa56c6d893e752f04e313b9f63dcd44a84ff19008530449362e6ea51", + "revision": 2, + "revision_hash": "0xbd99c58116d0f003bb0ad300b07eb660bd72fcc3fcf3e1e57c7ce952776c13cd", + "proposer_config": { + "0xb853c49d5e924260c31b3e1dc1e8a14b1d2ad4039e70a9d123fce46fcff208aac61b7fbf7a67839b8d6f14c80b8ebe06": { + "fee_recipient": "0x000000000000000000000000000000000000000b" + } + }, + "default_config": { + "fee_recipient": "0x000000000000000000000000000000000000000a", + "gas_limit": "200000000", + "builder": { + "min_bid": "0", + "builder_boost_factor": "100", + "max_execution_payment": "0", + "builders": [ + { + "url": "https://b1.example" + } + ] + } + }, + "signatures": [ + { + "operator": 0, + "signature": "0xaa" + }, + { + "operator": 2, + "signature": "0xbbbb" + } + ] +} diff --git a/cluster/proposerconfig/testdata/TestWriteLoadRoundTrip.golden b/cluster/proposerconfig/testdata/TestWriteLoadRoundTrip.golden new file mode 100644 index 0000000000..89854c08a4 --- /dev/null +++ b/cluster/proposerconfig/testdata/TestWriteLoadRoundTrip.golden @@ -0,0 +1,35 @@ +{ + "version": "v1.0.0", + "lock_hash": "0xb8dc5d81fa56c6d893e752f04e313b9f63dcd44a84ff19008530449362e6ea51", + "revision": 2, + "revision_hash": "0xbd99c58116d0f003bb0ad300b07eb660bd72fcc3fcf3e1e57c7ce952776c13cd", + "proposer_config": { + "0xb44958c07ba41e9a135435682bbac2507c3651f13600a2b313eb2c335cc8924f54504e471c954bf029aaf7277f8c4e3d": { + "fee_recipient": "0x000000000000000000000000000000000000000b" + } + }, + "default_config": { + "fee_recipient": "0x000000000000000000000000000000000000000a", + "gas_limit": "200000000", + "builder": { + "min_bid": "0", + "builder_boost_factor": "100", + "max_execution_payment": "0", + "builders": [ + { + "url": "https://b1.example" + } + ] + } + }, + "signatures": [ + { + "operator": 0, + "signature": "0xaa" + }, + { + "operator": 2, + "signature": "0xbbbb" + } + ] +} diff --git a/cluster/proposerconfig/verify.go b/cluster/proposerconfig/verify.go new file mode 100644 index 0000000000..e4b1db4d42 --- /dev/null +++ b/cluster/proposerconfig/verify.go @@ -0,0 +1,188 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "bytes" + "slices" + "strings" + + k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" + + "github.com/obolnetwork/charon/app/errors" + "github.com/obolnetwork/charon/app/k1util" + "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/cluster" + "github.com/obolnetwork/charon/eth2util/enr" +) + +var ( + // ErrLockHashMismatch is returned when the document belongs to a different cluster lock. + ErrLockHashMismatch = errors.NewSentinel("proposer config lock hash mismatch") + // ErrInvalid is returned when the document violates the validity rules. + ErrInvalid = errors.NewSentinel("proposer config invalid") +) + +// invalid returns an error wrapping ErrInvalid with the reason. +func invalid(reason string, fields ...z.Field) error { + return errors.Wrap(ErrInvalid, reason, fields...) +} + +// Verify checks the document against the lock: lock hash, version, stored hash, editable fields and signatures. +// Any version with the same major as Version is accepted. Revision 0 must be unsigned; later revisions need +// threshold distinct valid operator signatures. +func Verify(doc Document, lock cluster.Lock) error { + if len(doc.LockHash) != len(lock.LockHash) { + return invalid("malformed lock hash", z.Int("bytes", len(doc.LockHash))) + } + + if !bytes.Equal(doc.LockHash, lock.LockHash) { + return errors.Wrap(ErrLockHashMismatch, "document lock hash differs from lock") + } + + if major(doc.Version) != major(Version) { + return invalid("unsupported version", z.Str("version", doc.Version), z.Str("supported", Version)) + } + + hash, err := doc.Hash() + if err != nil { + return err + } + + if len(doc.StoredHash) > 0 && !bytes.Equal(doc.StoredHash, hash[:]) { + return invalid("content was modified, revision hash mismatch") + } + + err = checkEditableFields(doc.Config, lock) + if err != nil { + return err + } + + if doc.Revision == 0 { + if len(doc.Signatures) != 0 { + return invalid("revision 0 must have no signatures", z.Int("signatures", len(doc.Signatures))) + } + + return nil + } + + if len(doc.Signatures) < lock.Threshold { + return invalid("not enough signatures", z.Int("signatures", len(doc.Signatures)), z.Int("threshold", lock.Threshold)) + } + + seen := make(map[int]bool) + + for _, sig := range doc.Signatures { + if seen[sig.Operator] { + return invalid("duplicate operator signature", z.Int("operator", sig.Operator)) + } + + seen[sig.Operator] = true + + err := verifySignature(hash, lock, sig.Operator, sig.Signature) + if err != nil { + return err + } + } + + return nil +} + +// Sign returns the operator's signature of the document's revision hash. +func Sign(doc Document, key *k1.PrivateKey) ([]byte, error) { + hash, err := doc.Hash() + if err != nil { + return nil, err + } + + sig, err := k1util.Sign(key, hash[:]) + if err != nil { + return nil, errors.Wrap(err, "sign proposer config") + } + + return sig, nil +} + +// VerifySignature checks that sig is the given operator's signature of the document's revision hash. +func VerifySignature(doc Document, lock cluster.Lock, operator int, sig []byte) error { + hash, err := doc.Hash() + if err != nil { + return err + } + + return verifySignature(hash, lock, operator, sig) +} + +func verifySignature(hash [32]byte, lock cluster.Lock, operator int, sig []byte) error { + if operator < 0 || operator >= len(lock.Operators) { + return invalid("operator index out of range", z.Int("operator", operator)) + } + + record, err := enr.Parse(lock.Operators[operator].ENR) + if err != nil { + return errors.Wrap(err, "parse operator enr", z.Int("operator", operator)) + } + + ok, err := k1util.Verify65(record.PubKey, hash[:], sig) + if err != nil { + return invalid("malformed signature", z.Int("operator", operator)) + } + + if !ok { + return invalid("signature does not verify", z.Int("operator", operator)) + } + + return nil +} + +// major returns the major of a vX.Y.Z version. +func major(version string) string { + m, _, _ := strings.Cut(version, ".") + + return m +} + +// checkEditableFields rejects what the edit command cannot write: proposer_config keys other than the lock's +// validator pubkeys in lowercase, per-validator gas limits and builders, and per-builder overrides. The proposer +// config is only changed through the CLI. +func checkEditableFields(c Config, lock cluster.Lock) error { + pubkeys := make(map[string]bool, len(lock.Validators)) + for _, val := range lock.Validators { + pubkeys[pubkeyHex(val.PubKey)] = true + } + + for pubkey, s := range c.ProposerConfig { + if !pubkeys[pubkey] { + return invalid("proposer_config key is not a lowercase lock validator pubkey", z.Str("key", pubkey)) + } + + if s.GasLimit != "" || s.Builder != nil { + return invalid("proposer_config entry sets more than fee_recipient", z.Str("pubkey", pubkey)) + } + } + + if c.DefaultConfig.Builder == nil { + return nil + } + + for _, e := range c.DefaultConfig.Builder.Builders { + if e.MinBid != "" || e.BuilderBoostFactor != "" || e.MaxExecutionPayment != "" { + return invalid("builder entry sets more than url", z.Str("url", log.RedactURL(e.URL, true))) + } + } + + return nil +} + +// SignerIndexes returns the operator indexes that signed the document, ascending. +func (d Document) SignerIndexes() []int { + idxs := make([]int, 0, len(d.Signatures)) + for _, sig := range d.Signatures { + idxs = append(idxs, sig.Operator) + } + + slices.Sort(idxs) + + return idxs +} diff --git a/cluster/proposerconfig/verify_internal_test.go b/cluster/proposerconfig/verify_internal_test.go new file mode 100644 index 0000000000..f6f266d6fa --- /dev/null +++ b/cluster/proposerconfig/verify_internal_test.go @@ -0,0 +1,275 @@ +// Copyright © 2022-2026 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 + +package proposerconfig + +import ( + "math/rand" + "strings" + "testing" + + k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" + "github.com/stretchr/testify/require" + + "github.com/obolnetwork/charon/cluster" +) + +func TestVerify(t *testing.T) { + lock, keys, _ := cluster.NewForT(t, 1, 3, 4, 7, rand.New(rand.NewSource(7))) + require.Equal(t, 3, lock.Threshold) + + newDoc := func(revision uint64, signers ...int) Document { + doc := Document{ + Version: Version, + LockHash: lock.LockHash, + Revision: revision, + Config: Config{ + DefaultConfig: Settings{FeeRecipient: addrA, GasLimit: "200000000"}, + ProposerConfig: map[string]Settings{}, + }, + } + + for _, idx := range signers { + sig, err := Sign(doc, keys[idx]) + require.NoError(t, err) + + doc.Signatures = append(doc.Signatures, Signature{Operator: idx, Signature: sig}) + } + + return doc + } + + other, err := k1.GeneratePrivateKey() + require.NoError(t, err) + + v0 := pubkeyHex(lock.Validators[0].PubKey) + + tests := []struct { + name string + doc func() Document + errIs error + errMsg string + }{ + {name: "revision 0 no signatures", doc: func() Document { return newDoc(0) }}, + {name: "revision 0 one signature", doc: func() Document { return newDoc(0, 0) }, errIs: ErrInvalid}, + {name: "revision 1 threshold", doc: func() Document { return newDoc(1, 0, 1, 2) }}, + {name: "revision 1 below threshold", doc: func() Document { return newDoc(1, 0, 1) }, errIs: ErrInvalid}, + {name: "revision 1 duplicate operator", doc: func() Document { return newDoc(1, 0, 1, 1) }, errIs: ErrInvalid}, + { + name: "revision 1 index out of range", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + doc.Signatures[2].Operator = 9 + + return doc + }, + errIs: ErrInvalid, + }, + { + name: "revision 1 negative operator index", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + doc.Signatures[2].Operator = -1 + + return doc + }, + errIs: ErrInvalid, + errMsg: "operator index out of range", + }, + { + name: "revision 1 truncated signature", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + doc.Signatures[2].Signature = doc.Signatures[2].Signature[:64] + + return doc + }, + errIs: ErrInvalid, + errMsg: "malformed signature", + }, + { + name: "revision 1 nil signature", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + doc.Signatures[2].Signature = nil + + return doc + }, + errIs: ErrInvalid, + errMsg: "malformed signature", + }, + { + name: "revision 1 signature filed under another operator", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + doc.Signatures[2].Operator = 3 + + return doc + }, + errIs: ErrInvalid, + errMsg: "signature does not verify", + }, + { + name: "revision 1 non-operator key", + doc: func() Document { + doc := newDoc(1, 0, 1, 2) + sig, err := Sign(doc, other) + require.NoError(t, err) + + doc.Signatures[2].Signature = sig + + return doc + }, + errIs: ErrInvalid, + }, + { + name: "stored hash differs", + doc: func() Document { + doc := newDoc(0) + doc.StoredHash = make([]byte, 32) + + return doc + }, + errIs: ErrInvalid, + errMsg: "content was modified", + }, + { + name: "stored hash matches", + doc: func() Document { + doc := newDoc(0) + h, err := doc.Hash() + require.NoError(t, err) + + doc.StoredHash = h[:] + + return doc + }, + }, + { + name: "other lock hash", + doc: func() Document { + doc := newDoc(0) + doc.LockHash = make([]byte, 32) + + return doc + }, + errIs: ErrLockHashMismatch, + }, + { + name: "entry gas limit", + doc: func() Document { + doc := newDoc(0) + doc.Config.ProposerConfig[v0] = Settings{GasLimit: "1"} + + return doc + }, + errIs: ErrInvalid, + errMsg: "proposer_config entry sets more than fee_recipient", + }, + { + name: "entry builder", + doc: func() Document { + doc := newDoc(0) + doc.Config.ProposerConfig[v0] = Settings{Builder: &Builder{}} + + return doc + }, + errIs: ErrInvalid, + errMsg: "proposer_config entry sets more than fee_recipient", + }, + { + name: "entry fee recipient", + doc: func() Document { + doc := newDoc(0) + doc.Config.ProposerConfig[v0] = Settings{FeeRecipient: addrB} + + return doc + }, + }, + { + name: "unknown key", + doc: func() Document { + doc := newDoc(0) + doc.Config.ProposerConfig["0xabcd"] = Settings{FeeRecipient: addrB} + + return doc + }, + errIs: ErrInvalid, + errMsg: "not a lowercase lock validator pubkey", + }, + { + name: "uppercase key", + doc: func() Document { + doc := newDoc(0) + doc.Config.ProposerConfig["0x"+strings.ToUpper(v0[2:])] = Settings{FeeRecipient: addrB} + + return doc + }, + errIs: ErrInvalid, + errMsg: "not a lowercase lock validator pubkey", + }, + { + name: "builder entry override", + doc: func() Document { + doc := newDoc(0) + doc.Config.DefaultConfig.Builder = &Builder{ + MinBid: "0", BuilderBoostFactor: "100", MaxExecutionPayment: "0", + Builders: []BuilderEntry{{URL: "https://b1.example"}, {URL: "https://b2.example", MinBid: "5"}}, + } + + return doc + }, + errIs: ErrInvalid, + errMsg: "builder entry sets more than url", + }, + { + name: "other major version", + doc: func() Document { + doc := newDoc(0) + doc.Version = "v3.0.0" + + return doc + }, + errIs: ErrInvalid, + errMsg: "unsupported version", + }, + { + name: "same major version", + doc: func() Document { + doc := newDoc(0) + doc.Version = "v1.1.0" + + return doc + }, + }, + { + name: "empty lock hash", + doc: func() Document { + doc := newDoc(0) + doc.LockHash = nil + + return doc + }, + errIs: ErrInvalid, + errMsg: "malformed lock hash", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := Verify(tt.doc(), lock) + if tt.errIs == nil { + require.NoError(t, err) + return + } + + require.ErrorIs(t, err, tt.errIs) + require.ErrorContains(t, err, tt.errMsg) + }) + } +} + +func TestSignerIndexes(t *testing.T) { + doc := Document{Signatures: []Signature{{Operator: 2}, {Operator: 0}}} + require.Equal(t, []int{0, 2}, doc.SignerIndexes()) + require.Empty(t, Document{}.SignerIndexes()) +} diff --git a/cmd/cmd_internal_test.go b/cmd/cmd_internal_test.go index 4bac4ed24a..64c1244ff4 100644 --- a/cmd/cmd_internal_test.go +++ b/cmd/cmd_internal_test.go @@ -16,6 +16,7 @@ import ( "github.com/obolnetwork/charon/app" "github.com/obolnetwork/charon/app/featureset" "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/p2p" "github.com/obolnetwork/charon/testutil" ) @@ -86,8 +87,8 @@ func TestCmdFlags(t *testing.T) { BuilderRegOverridesFilePath: ".charon/builder_registrations_overrides.json", PublishAddress: "https://api.obol.tech/v1", PublishTimeout: 5 * time.Minute, - BuilderBoostFactor: 100, - ProposerGasLimit: 200_000_000, + ProposerConfigFile: ".charon/vc-config/proposer-config.json", + ProposerConfigSeed: proposerconfig.Seed{GasLimit: 200_000_000, BuilderBoostFactor: 100}, }, }, { @@ -142,8 +143,8 @@ func TestCmdFlags(t *testing.T) { BuilderRegOverridesFilePath: ".charon/builder_registrations_overrides.json", PublishAddress: "https://api.obol.tech/v1", PublishTimeout: 5 * time.Minute, - BuilderBoostFactor: 100, - ProposerGasLimit: 200_000_000, + ProposerConfigFile: ".charon/vc-config/proposer-config.json", + ProposerConfigSeed: proposerconfig.Seed{GasLimit: 200_000_000, BuilderBoostFactor: 100}, TestConfig: app.TestConfig{ P2PFuzz: true, }, @@ -213,6 +214,68 @@ func TestCmdFlags(t *testing.T) { } } +func TestProposerConfigSeedFlags(t *testing.T) { + execute := func(t *testing.T, args ...string) (app.Config, error) { + t.Helper() + + var conf app.Config + + root := newRootCmd(newRunCmd(func(_ context.Context, config app.Config) error { + conf = config + return nil + }, false)) + root.SetArgs(append([]string{"run", "--beacon-node-endpoints=http://beacon.node"}, args...)) + + return conf, root.Execute() + } + + t.Run("new flags parse", func(t *testing.T) { + conf, err := execute(t, + "--proposer-config-file=pc.json", + "--proposer-config-gas-limit=60000000", + "--proposer-config-builder-urls=https://a.example.com,https://b.example.com", + "--proposer-config-builder-min-bid=1", + "--proposer-config-builder-boost-factor=90", + "--proposer-config-builder-max-execution-payment=2", + ) + require.NoError(t, err) + require.Equal(t, "pc.json", conf.ProposerConfigFile) + require.Equal(t, proposerconfig.Seed{ + GasLimit: 60_000_000, + BuilderURLs: []string{"https://a.example.com", "https://b.example.com"}, + BuilderMinBid: 1, + BuilderBoostFactor: 90, + BuilderMaxExecutionPayment: 2, + NonDefault: []string{ + "proposer-config-gas-limit", "proposer-config-builder-urls", "proposer-config-builder-min-bid", + "proposer-config-builder-boost-factor", "proposer-config-builder-max-execution-payment", + }, + }, conf.ProposerConfigSeed) + }) + + for _, flag := range []string{"proposer-gas-limit", "builder-urls", "builder-min-bid", "builder-boost-factor", "builder-max-execution-payment"} { + t.Run("old flag "+flag, func(t *testing.T) { + _, err := execute(t, "--"+flag+"=1") + require.ErrorContains(t, err, "unknown flag: --"+flag) + }) + } + + t.Run("builder value without urls", func(t *testing.T) { + _, err := execute(t, "--proposer-config-builder-min-bid=1") + require.ErrorContains(t, err, "require proposer-config-builder-urls") + }) + + t.Run("boost factor without urls", func(t *testing.T) { + _, err := execute(t, "--proposer-config-builder-boost-factor=100") + require.ErrorContains(t, err, "require proposer-config-builder-urls") + }) + + t.Run("zero gas limit", func(t *testing.T) { + _, err := execute(t, "--proposer-config-gas-limit=0") + require.ErrorContains(t, err, "proposer-config-gas-limit must be greater than 0") + }) +} + func TestFlagsToLogFields(t *testing.T) { set := pflag.NewFlagSet("test", pflag.PanicOnError) bindLokiFlags(set, &log.Config{}) @@ -287,7 +350,7 @@ func TestRedact(t *testing.T) { }, { name: "redact builder URL passwords", - flag: "builder-urls", + flag: "proposer-config-builder-urls", value: "https://0xabc:secret@relay.example.com", expected: "https://0xabc:xxxxx@relay.example.com", }, diff --git a/cmd/run.go b/cmd/run.go index b632ad0298..0bff71327f 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -16,7 +16,7 @@ import ( "github.com/obolnetwork/charon/app/featureset" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" - "github.com/obolnetwork/charon/core" + "github.com/obolnetwork/charon/cluster/proposerconfig" "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/p2p" ) @@ -51,6 +51,7 @@ func newRunCmd(runFunc func(context.Context, app.Config) error, unsafe bool) *co bindPrivKeyFlag(cmd, &conf.PrivKeyFile, &conf.PrivKeyLocking) bindRunFlags(cmd, &conf) + bindProposerConfigSeedFlags(cmd, &conf.ProposerConfigSeed) bindDebugMonitoringFlags(cmd, &conf.MonitoringAddr, &conf.DebugAddr, "127.0.0.1:3620") bindNoVerifyFlag(cmd.Flags(), &conf.NoVerify) bindP2PFlags(cmd, &conf.P2P) @@ -112,11 +113,7 @@ func bindRunFlags(cmd *cobra.Command, config *app.Config) { cmd.Flags().StringVar(&config.PublishAddress, "publish-address", "https://api.obol.tech/v1", "The URL of the remote API for background fee recipient fetching.") cmd.Flags().DurationVar(&config.PublishTimeout, "publish-timeout", 5*time.Minute, "Timeout for accessing the remote API.") cmd.Flags().BoolVar(&config.FetchFeerecipientUpdates, "fetch-feerecipient-updates", false, "Fetches updated fee recipients from a remote API.") - cmd.Flags().StringSliceVar(&config.BuilderURLs, "builder-urls", nil, "Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. Must be identical on all nodes in the cluster.") - cmd.Flags().Uint64Var(&config.BuilderMinBid, "builder-min-bid", 0, "Minimum builder bid value in gwei, bids below it lose to the locally built payload. Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster.") - cmd.Flags().Uint64Var(&config.BuilderBoostFactor, "builder-boost-factor", 100, "Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster.") - cmd.Flags().Uint64Var(&config.BuilderMaxExecutionPayment, "builder-max-execution-payment", 0, "Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster.") - cmd.Flags().Uint64Var(&config.ProposerGasLimit, "proposer-gas-limit", 200_000_000, "Preferred target gas limit for proposed execution payloads, seeding the generated validator client proposer config. Applies from the gloas fork onwards. Must be identical on all nodes in the cluster.") + cmd.Flags().StringVar(&config.ProposerConfigFile, "proposer-config-file", ".charon/vc-config/proposer-config.json", "The path to the validator client proposer config file. Written from the cluster lock and the proposer-config seeding flags if absent, verified on start otherwise.") wrapPreRunE(cmd, func(cc *cobra.Command, _ []string) error { if len(config.BeaconNodeAddrs) == 0 && !config.SimnetBMock { @@ -158,31 +155,6 @@ func bindRunFlags(cmd *cobra.Command, config *app.Config) { return errors.New("file vc-tls-key-file does not exist", z.Str("file", config.VCTLSKeyFile)) } - for _, u := range config.BuilderURLs { - parsed, err := url.Parse(u) - if err != nil || parsed.Scheme != "http" && parsed.Scheme != "https" || parsed.Host == "" { - return errors.New("builder-urls entry is not a valid http(s) URL", z.Str("url", u)) - } - - // A builder's URL is agreed with the proposals of its bids, which can't carry a longer one. - if len(u) > core.MaxBuilderURLSize { - return errors.New("builder-urls entry is longer than the maximum", z.Int("max", core.MaxBuilderURLSize)) - } - } - - if config.ProposerGasLimit == 0 { - return errors.New("proposer-gas-limit must be greater than 0") - } - - if config.BuilderBoostFactor == 0 { - return errors.New("builder-boost-factor must be greater than 0") - } - - if len(config.BuilderURLs) == 0 && - (config.BuilderMinBid != 0 || cc.Flags().Changed("builder-boost-factor") || config.BuilderMaxExecutionPayment != 0) { - return errors.New("builder-min-bid, builder-boost-factor and builder-max-execution-payment require builder-urls") - } - if config.FetchFeerecipientUpdates && config.PublishAddress == "" { return errors.New("--fetch-feerecipient-updates requires --publish-address to be set") } @@ -200,6 +172,37 @@ func bindPrivKeyFlag(cmd *cobra.Command, privKeyFile *string, privkeyLockEnabled cmd.Flags().BoolVar(privkeyLockEnabled, "private-key-file-lock", false, "Enables private key locking to prevent multiple instances using the same key.") } +// bindProposerConfigSeedFlags binds the flags seeding an unsigned (revision 0) proposer config file. +func bindProposerConfigSeedFlags(cmd *cobra.Command, seed *proposerconfig.Seed) { + // seedFlag records the flag name for the PreRunE below. + var names []string + + seedFlag := func(name string) string { + names = append(names, name) + return name + } + + const seedOnly = "Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster." + + cmd.Flags().Uint64Var(&seed.GasLimit, seedFlag("proposer-config-gas-limit"), proposerconfig.DefaultGasLimit, "Preferred target gas limit for proposed execution payloads from the gloas fork onwards. "+seedOnly) + cmd.Flags().StringSliceVar(&seed.BuilderURLs, seedFlag("proposer-config-builder-urls"), nil, "Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. "+seedOnly) + cmd.Flags().Uint64Var(&seed.BuilderMinBid, seedFlag("proposer-config-builder-min-bid"), 0, "Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. "+seedOnly) + cmd.Flags().Uint64Var(&seed.BuilderBoostFactor, seedFlag("proposer-config-builder-boost-factor"), proposerconfig.DefaultBuilderBoostFactor, "Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. "+seedOnly) + cmd.Flags().Uint64Var(&seed.BuilderMaxExecutionPayment, seedFlag("proposer-config-builder-max-execution-payment"), 0, "Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. "+seedOnly) + + wrapPreRunE(cmd, func(cc *cobra.Command, _ []string) error { + seed.NonDefault = nil + + for _, name := range names { + if cc.Flags().Changed(name) { + seed.NonDefault = append(seed.NonDefault, name) + } + } + + return seed.Validate() + }) +} + func bindLogFlags(flags *pflag.FlagSet, config *log.Config) { flags.StringVar(&config.Format, "log-format", "console", "Log format; console, logfmt or json") flags.StringVar(&config.Level, "log-level", "info", "Log level; debug, info, warn or error") diff --git a/cmd/run_internal_test.go b/cmd/run_internal_test.go index 3d05a44c33..9525ab730a 100644 --- a/cmd/run_internal_test.go +++ b/cmd/run_internal_test.go @@ -138,12 +138,12 @@ func TestBindRunFlagsValidation(t *testing.T) { }, { Name: "too long builder url", - Args: slice("run", "--beacon-node-endpoints", "http://beacon.node", "--builder-urls", "https://"+strings.Repeat("a", core.MaxBuilderURLSize)), - Err: "builder-urls entry is longer than the maximum", + Args: slice("run", "--beacon-node-endpoints", "http://beacon.node", "--proposer-config-builder-urls", "https://"+strings.Repeat("a", core.MaxBuilderURLSize)), + Err: "proposer-config-builder-urls entry is longer than the maximum", }, { Name: "valid builder url", - Args: slice("run", "--beacon-node-endpoints", "http://beacon.node", "--builder-urls", "https://builder.example.com"), + Args: slice("run", "--beacon-node-endpoints", "http://beacon.node", "--proposer-config-builder-urls", "https://builder.example.com"), }, { Name: "invalid hostname", @@ -170,3 +170,19 @@ func TestBindRunFlagsValidation(t *testing.T) { }) } } + +func TestRunProposerConfigSeedNonDefault(t *testing.T) { + t.Setenv("CHARON_PROPOSER_CONFIG_BUILDER_URLS", "https://b.example.com") + + var got app.Config + + root := newRootCmd(newRunCmd(func(_ context.Context, config app.Config) error { + got = config + return nil + }, false)) + root.SetArgs(slice("run", "--beacon-node-endpoints", "http://beacon.node", "--proposer-config-gas-limit", "60000000")) + require.NoError(t, root.Execute()) + + // Flags set by the operator, on the command line or in the environment, but not those left at their defaults. + require.ElementsMatch(t, []string{"proposer-config-gas-limit", "proposer-config-builder-urls"}, got.ProposerConfigSeed.NonDefault) +} diff --git a/docs/configuration.md b/docs/configuration.md index 359ee5bfbf..46a956adb6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -157,70 +157,71 @@ Usage: charon run [flags] Flags: - --beacon-node-endpoints strings Comma separated list of one or more beacon node endpoint URLs. - --beacon-node-headers strings Comma separated list of headers formatted as header=value - --beacon-node-submit-timeout duration Timeout for the submission-related HTTP requests Charon makes to the configured beacon nodes. (default 2s) - --beacon-node-timeout duration Timeout for the HTTP requests Charon makes to the configured beacon nodes. (default 2s) - --builder-api Enables the builder api. Will only produce builder blocks. Builder API must also be enabled on the validator client. Beacon node must be connected to a builder-relay to access the builder network. - --builder-boost-factor uint Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster. (default 100) - --builder-max-execution-payment uint Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster. - --builder-min-bid uint Minimum builder bid value in gwei, bids below it lose to the locally built payload. Applies from the gloas fork onwards. Requires builder-urls. Must be identical on all nodes in the cluster. - --builder-urls strings Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. Must be identical on all nodes in the cluster. - --consensus-protocol string Preferred consensus protocol name for the node. Selected automatically when not specified. - --debug-address string Listening address (ip and port) for the pprof and QBFT debug API. It is not enabled by default. - --execution-client-rpc-endpoint string The address of the execution engine JSON-RPC API. - --fallback-beacon-node-endpoints strings A list of beacon nodes to use if the primary list are offline or unhealthy. - --feature-set string Minimum feature set to enable by default: alpha, beta, or stable. Warning: modify at own risk. (default "stable") - --feature-set-disable strings Comma-separated list of features to disable, overriding the default minimum feature set. - --feature-set-enable strings Comma-separated list of features to enable, overriding the default minimum feature set. - --fetch-feerecipient-updates Fetches updated fee recipients from a remote API. - --graffiti strings Comma-separated list or single graffiti string to include in block proposals. List maps to validator's public key in cluster lock. Appends "OB" suffix to graffiti. Maximum 28 bytes per graffiti. - --graffiti-disable-client-append Disables appending "OB" suffix to graffiti. Increases maximum bytes per graffiti to 32. - -h, --help Help for run - --jaeger-address string [DISABLED] Listening address for jaeger tracing. - --jaeger-service string [DISABLED] Service name used for jaeger tracing. - --lock-file string The path to the cluster lock file defining the distributed validator cluster. If both cluster manifest and cluster lock files are provided, the cluster manifest file takes precedence. (default ".charon/cluster-lock.json") - --log-color string Log color; auto, force, disable. (default "auto") - --log-format string Log format; console, logfmt or json (default "console") - --log-level string Log level; debug, info, warn or error (default "info") - --log-output-path string Path in which to write on-disk logs. - --loki-addresses strings Enables sending of logfmt structured logs to these Loki log aggregation server addresses. This is in addition to normal stderr logs. - --loki-service string Service label sent with logs to Loki. (default "charon") - --manifest-file string [DEPRECATED] The path to the cluster manifest file. If both cluster manifest and cluster lock files are provided, the cluster manifest file takes precedence. (default ".charon/cluster-manifest.pb") - --monitoring-address string Listening address (ip and port) for the monitoring API (prometheus). (default "127.0.0.1:3620") - --nickname string Human friendly peer nickname. Maximum 32 characters. - --no-verify Disables cluster definition and lock file verification. - --otlp-address string Listening address for OTLP gRPC tracing backend. - --otlp-headers strings Comma separated list of headers formatted as header=value, to include in OTLP requests. - --otlp-insecure Use insecure connection (no TLS) when connecting to OTLP endpoint. - --otlp-service-name string Service name used for OTLP gRPC tracing. (default "charon") - --overrides-file string Path to the builder registrations overrides file. (default ".charon/builder_registrations_overrides.json") - --p2p-disable-reuseport Disables TCP port reuse for outgoing libp2p connections. - --p2p-external-hostname string The DNS hostname advertised by libp2p. This may be used to advertise an external DNS. - --p2p-external-ip string The IP address advertised by libp2p. This may be used to advertise an external IP. - --p2p-relays strings Comma-separated list of libp2p relay URLs or multiaddrs. (default [https://0.relay.obol.tech,https://1.relay.obol.tech,https://2.relay.obol.dev]) - --p2p-tcp-address strings Comma-separated list of listening TCP addresses (ip and port) for libP2P traffic. Empty default doesn't bind to local port therefore only supports outgoing connections. - --p2p-udp-address strings Comma-separated list of listening UDP addresses (ip and port) for libP2P traffic. Empty default doesn't bind to local port therefore only supports outgoing connections. - --private-key-file string The path to the charon enr private key file. (default ".charon/charon-enr-private-key") - --private-key-file-lock Enables private key locking to prevent multiple instances using the same key. - --proc-directory string Directory to look into in order to detect other stack components running on the host. Enabling this exports the command lines of detected validator clients to the monitoring endpoint and debug logs, with the values of secret-shaped flags redacted. - --proposer-gas-limit uint Preferred target gas limit for proposed execution payloads, seeding the generated validator client proposer config. Applies from the gloas fork onwards. Must be identical on all nodes in the cluster. (default 200000000) - --publish-address string The URL of the remote API for background fee recipient fetching. (default "https://api.obol.tech/v1") - --publish-timeout duration Timeout for accessing the remote API. (default 5m0s) - --simnet-beacon-mock Enables an internal mock beacon node for running a simnet. - --simnet-beacon-mock-fuzz Configures simnet beaconmock to return fuzzed responses. - --simnet-slot-duration duration Configures slot duration in simnet beacon mock. (default 1s) - --simnet-validator-keys-dir string The directory containing the simnet validator key shares. (default ".charon/validator_keys") - --simnet-validator-mock Enables an internal mock validator client when running a simnet. Requires simnet-beacon-mock. - --synthetic-block-proposals Enables additional synthetic block proposal duties. Used for testing of rare duties. - --testnet-capella-hard-fork string Capella hard fork version of the custom test network. - --testnet-chain-id uint Chain ID of the custom test network. - --testnet-fork-version string Genesis fork version in hex of the custom test network. - --testnet-genesis-timestamp int Genesis timestamp of the custom test network. - --testnet-name string Name of the custom test network. - --validator-api-address string Listening address (ip and port) for validator-facing traffic proxying the beacon-node API. (default "127.0.0.1:3600") - --vc-tls-cert-file string The path to the TLS certificate file used by charon for the validator client API endpoint. - --vc-tls-key-file string The path to the TLS private key file associated with the provided TLS certificate. + --beacon-node-endpoints strings Comma separated list of one or more beacon node endpoint URLs. + --beacon-node-headers strings Comma separated list of headers formatted as header=value + --beacon-node-submit-timeout duration Timeout for the submission-related HTTP requests Charon makes to the configured beacon nodes. (default 2s) + --beacon-node-timeout duration Timeout for the HTTP requests Charon makes to the configured beacon nodes. (default 2s) + --builder-api Enables the builder api. Will only produce builder blocks. Builder API must also be enabled on the validator client. Beacon node must be connected to a builder-relay to access the builder network. + --consensus-protocol string Preferred consensus protocol name for the node. Selected automatically when not specified. + --debug-address string Listening address (ip and port) for the pprof and QBFT debug API. It is not enabled by default. + --execution-client-rpc-endpoint string The address of the execution engine JSON-RPC API. + --fallback-beacon-node-endpoints strings A list of beacon nodes to use if the primary list are offline or unhealthy. + --feature-set string Minimum feature set to enable by default: alpha, beta, or stable. Warning: modify at own risk. (default "stable") + --feature-set-disable strings Comma-separated list of features to disable, overriding the default minimum feature set. + --feature-set-enable strings Comma-separated list of features to enable, overriding the default minimum feature set. + --fetch-feerecipient-updates Fetches updated fee recipients from a remote API. + --graffiti strings Comma-separated list or single graffiti string to include in block proposals. List maps to validator's public key in cluster lock. Appends "OB" suffix to graffiti. Maximum 28 bytes per graffiti. + --graffiti-disable-client-append Disables appending "OB" suffix to graffiti. Increases maximum bytes per graffiti to 32. + -h, --help Help for run + --jaeger-address string [DISABLED] Listening address for jaeger tracing. + --jaeger-service string [DISABLED] Service name used for jaeger tracing. + --lock-file string The path to the cluster lock file defining the distributed validator cluster. If both cluster manifest and cluster lock files are provided, the cluster manifest file takes precedence. (default ".charon/cluster-lock.json") + --log-color string Log color; auto, force, disable. (default "auto") + --log-format string Log format; console, logfmt or json (default "console") + --log-level string Log level; debug, info, warn or error (default "info") + --log-output-path string Path in which to write on-disk logs. + --loki-addresses strings Enables sending of logfmt structured logs to these Loki log aggregation server addresses. This is in addition to normal stderr logs. + --loki-service string Service label sent with logs to Loki. (default "charon") + --manifest-file string [DEPRECATED] The path to the cluster manifest file. If both cluster manifest and cluster lock files are provided, the cluster manifest file takes precedence. (default ".charon/cluster-manifest.pb") + --monitoring-address string Listening address (ip and port) for the monitoring API (prometheus). (default "127.0.0.1:3620") + --nickname string Human friendly peer nickname. Maximum 32 characters. + --no-verify Disables cluster definition and lock file verification. + --otlp-address string Listening address for OTLP gRPC tracing backend. + --otlp-headers strings Comma separated list of headers formatted as header=value, to include in OTLP requests. + --otlp-insecure Use insecure connection (no TLS) when connecting to OTLP endpoint. + --otlp-service-name string Service name used for OTLP gRPC tracing. (default "charon") + --overrides-file string Path to the builder registrations overrides file. (default ".charon/builder_registrations_overrides.json") + --p2p-disable-reuseport Disables TCP port reuse for outgoing libp2p connections. + --p2p-external-hostname string The DNS hostname advertised by libp2p. This may be used to advertise an external DNS. + --p2p-external-ip string The IP address advertised by libp2p. This may be used to advertise an external IP. + --p2p-relays strings Comma-separated list of libp2p relay URLs or multiaddrs. (default [https://0.relay.obol.tech,https://1.relay.obol.tech,https://2.relay.obol.dev]) + --p2p-tcp-address strings Comma-separated list of listening TCP addresses (ip and port) for libP2P traffic. Empty default doesn't bind to local port therefore only supports outgoing connections. + --p2p-udp-address strings Comma-separated list of listening UDP addresses (ip and port) for libP2P traffic. Empty default doesn't bind to local port therefore only supports outgoing connections. + --private-key-file string The path to the charon enr private key file. (default ".charon/charon-enr-private-key") + --private-key-file-lock Enables private key locking to prevent multiple instances using the same key. + --proc-directory string Directory to look into in order to detect other stack components running on the host. Enabling this exports the command lines of detected validator clients to the monitoring endpoint and debug logs, with the values of secret-shaped flags redacted. + --proposer-config-builder-boost-factor uint Percentage multiplier applied to builder bid values when comparing them to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. (default 100) + --proposer-config-builder-max-execution-payment uint Maximum execution layer payment in gwei counted when valuing a builder bid, 0 counts no execution payment (trustless bids only). Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. + --proposer-config-builder-min-bid uint Minimum builder bid value in gwei, bids below it lose to the locally built payload. Requires proposer-config-builder-urls. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. + --proposer-config-builder-urls strings Comma separated list of builder API URLs to request execution payload bids from directly, from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. + --proposer-config-file string The path to the validator client proposer config file. Written from the cluster lock and the proposer-config seeding flags if absent, verified on start otherwise. (default ".charon/vc-config/proposer-config.json") + --proposer-config-gas-limit uint Preferred target gas limit for proposed execution payloads from the gloas fork onwards. Seeds a new proposer config file only, disregarded once the cluster signed one with charon alpha edit proposer-config. Must be identical on all nodes in the cluster. (default 200000000) + --publish-address string The URL of the remote API for background fee recipient fetching. (default "https://api.obol.tech/v1") + --publish-timeout duration Timeout for accessing the remote API. (default 5m0s) + --simnet-beacon-mock Enables an internal mock beacon node for running a simnet. + --simnet-beacon-mock-fuzz Configures simnet beaconmock to return fuzzed responses. + --simnet-slot-duration duration Configures slot duration in simnet beacon mock. (default 1s) + --simnet-validator-keys-dir string The directory containing the simnet validator key shares. (default ".charon/validator_keys") + --simnet-validator-mock Enables an internal mock validator client when running a simnet. Requires simnet-beacon-mock. + --synthetic-block-proposals Enables additional synthetic block proposal duties. Used for testing of rare duties. + --testnet-capella-hard-fork string Capella hard fork version of the custom test network. + --testnet-chain-id uint Chain ID of the custom test network. + --testnet-fork-version string Genesis fork version in hex of the custom test network. + --testnet-genesis-timestamp int Genesis timestamp of the custom test network. + --testnet-name string Name of the custom test network. + --validator-api-address string Listening address (ip and port) for validator-facing traffic proxying the beacon-node API. (default "127.0.0.1:3600") + --vc-tls-cert-file string The path to the TLS certificate file used by charon for the validator client API endpoint. + --vc-tls-key-file string The path to the TLS private key file associated with the provided TLS certificate. ```` diff --git a/docs/metrics.md b/docs/metrics.md index d7f9bba3e6..cdcd13d318 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -58,6 +58,8 @@ when storing metrics from multiple nodes or clusters in one Prometheus instance. | `app_peerinfo_start_time_secs` | Gauge | Constant gauge set to the peer start time of the binary in unix seconds | `peer` | | `app_peerinfo_version` | Gauge | Constant gauge with version label set to peer`s charon version. | `peer, version` | | `app_peerinfo_version_support` | Gauge | Set to 1 if the peer`s version is supported by (compatible with) the current version, else 0 if unsupported. | `peer` | +| `app_proposer_config_invalid` | Gauge | Set to 1 while the proposer config file fails validation or cannot be loaded, 0 otherwise. | | +| `app_proposer_config_revision` | Gauge | The revision of the loaded proposer config document, 0 for an unsigned document derived locally from the lock and flags. | | | `app_start_time_secs` | Gauge | Gauge set to the app start time of the binary in unix seconds | | | `app_validator_stack_params` | Gauge | Parameters for each component of the validator stack in which this Charon instance is deployed into | `component, cli_parameters` | | `app_version` | Gauge | Constant gauge with label set to current app version | `version` | diff --git a/testutil/integration/simnet_test.go b/testutil/integration/simnet_test.go index 3662fa7779..eba363df54 100644 --- a/testutil/integration/simnet_test.go +++ b/testutil/integration/simnet_test.go @@ -19,6 +19,7 @@ import ( "github.com/obolnetwork/charon/app/log" "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/parsigex" "github.com/obolnetwork/charon/p2p" @@ -378,7 +379,7 @@ func testSimnet(t *testing.T, args simnetArgs, expect *simnetExpect) { Relays: []string{relayAddr}, }, BuilderAPI: args.BuilderAPI, - BuilderURLs: args.BuilderURLs, + ProposerConfigSeed: proposerconfig.Seed{BuilderURLs: args.BuilderURLs}, SyntheticBlockProposals: args.SyntheticProposals, }