Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

*: removing mutable config #3307

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
return core.NewDeadliner(ctx, label, deadlineFunc)
}

mutableConf := newMutableConfig(ctx, conf)

sched, err := scheduler.New(corePubkeys, eth2Cl, mutableConf.BuilderAPI)
sched, err := scheduler.New(corePubkeys, eth2Cl, conf.BuilderAPI)
if err != nil {
return err
}
Expand Down Expand Up @@ -479,20 +477,19 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
return err
}

fetch, err := fetcher.New(eth2Cl, feeRecipientFunc, mutableConf.BuilderAPI)
fetch, err := fetcher.New(eth2Cl, feeRecipientFunc, conf.BuilderAPI)
if err != nil {
return err
}

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

vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, feeRecipientFunc,
mutableConf.BuilderAPI, seenPubkeys)
vapi, err := validatorapi.NewComponent(eth2Cl, allPubSharesByKey, nodeIdx.ShareIdx, feeRecipientFunc, conf.BuilderAPI, seenPubkeys)
if err != nil {
return err
}

if err := wireVAPIRouter(ctx, life, conf.ValidatorAPIAddr, eth2Cl, vapi, vapiCalls, mutableConf); err != nil {
if err := wireVAPIRouter(ctx, life, conf.ValidatorAPIAddr, eth2Cl, vapi, vapiCalls, conf.BuilderAPI); err != nil {
return err
}

Expand Down Expand Up @@ -536,7 +533,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
}

err = wirePrioritise(ctx, conf, life, tcpNode, peerIDs, int(cluster.GetThreshold()),
sender.SendReceive, cons, sched, p2pKey, deadlineFunc, mutableConf)
sender.SendReceive, cons, sched, p2pKey, deadlineFunc)
if err != nil {
return err
}
Expand Down Expand Up @@ -588,7 +585,6 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
func wirePrioritise(ctx context.Context, conf Config, life *lifecycle.Manager, tcpNode host.Host,
peers []peer.ID, threshold int, sendFunc p2p.SendReceiveFunc, coreCons core.Consensus,
sched core.Scheduler, p2pKey *k1.PrivateKey, deadlineFunc func(duty core.Duty) (time.Time, bool),
mutableConf *mutableConfig,
) error {
cons, ok := coreCons.(*consensus.Component)
if !ok {
Expand All @@ -612,8 +608,6 @@ func wirePrioritise(ctx context.Context, conf Config, life *lifecycle.Manager, t
ProposalTypes(conf.BuilderAPI, conf.SyntheticBlockProposals),
)

mutableConf.SetInfoSync(isync)

// Trigger info syncs in last slot of the epoch (for the next epoch).
sched.SubscribeSlots(func(ctx context.Context, slot core.Slot) error {
if !slot.LastInEpoch() {
Expand Down Expand Up @@ -967,11 +961,9 @@ func createMockValidators(pubkeys []eth2p0.BLSPubKey) beaconmock.ValidatorSet {

// wireVAPIRouter constructs the validator API router and registers it with the life cycle manager.
func wireVAPIRouter(ctx context.Context, life *lifecycle.Manager, vapiAddr string, eth2Cl eth2wrap.Client,
handler validatorapi.Handler, vapiCalls func(), mutableConf *mutableConfig,
handler validatorapi.Handler, vapiCalls func(), builderEnabled bool,
) error {
vrouter, err := validatorapi.NewRouter(ctx, handler, eth2Cl, func(slot uint64) bool {
return mutableConf.BuilderAPI(slot)
})
vrouter, err := validatorapi.NewRouter(ctx, handler, eth2Cl, builderEnabled)
if err != nil {
return errors.Wrap(err, "new monitoring server")
}
Expand Down
47 changes: 0 additions & 47 deletions app/priorities.go

This file was deleted.

7 changes: 7 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/pflag"

"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/core/consensus"
)

type versionConfig struct {
Expand Down Expand Up @@ -62,4 +63,10 @@ func runVersionCmd(out io.Writer, config versionConfig) {
}
_, _ = fmt.Fprintf(out, "\t%v %v\n", dep.Path, dep.Version)
}

_, _ = fmt.Fprint(out, "Consensus protocols:\n")

for _, cp := range consensus.Protocols() {
_, _ = fmt.Fprintf(out, "\t%s\n", cp)
}
}
6 changes: 0 additions & 6 deletions core/config.go

This file was deleted.

6 changes: 3 additions & 3 deletions core/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

// New returns a new fetcher instance.
func New(eth2Cl eth2wrap.Client, feeRecipientFunc func(core.PubKey) string, builderEnabled core.BuilderEnabled) (*Fetcher, error) {
func New(eth2Cl eth2wrap.Client, feeRecipientFunc func(core.PubKey) string, builderEnabled bool) (*Fetcher, error) {
return &Fetcher{
eth2Cl: eth2Cl,
feeRecipientFunc: feeRecipientFunc,
Expand All @@ -37,7 +37,7 @@ type Fetcher struct {
subs []func(context.Context, core.Duty, core.UnsignedDataSet) error
aggSigDBFunc func(context.Context, core.Duty, core.PubKey) (core.SignedData, error)
awaitAttDataFunc func(ctx context.Context, slot, commIdx uint64) (*eth2p0.AttestationData, error)
builderEnabled core.BuilderEnabled
builderEnabled bool
}

// Subscribe registers a callback for fetched duties.
Expand Down Expand Up @@ -252,7 +252,7 @@ func (f *Fetcher) fetchProposerData(ctx context.Context, slot uint64, defSet cor
copy(graffiti[:], fmt.Sprintf("charon/%v-%s", version.Version, commitSHA))

var bbf uint64
if f.builderEnabled(slot) {
if f.builderEnabled {
// This gives maximum priority to builder blocks:
// https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV3
bbf = math.MaxUint64
Expand Down
8 changes: 2 additions & 6 deletions core/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,7 @@ func TestFetchSyncContribution(t *testing.T) {
func mustCreateFetcher(t *testing.T, bmock beaconmock.Mock) *fetcher.Fetcher {
t.Helper()

fetch, err := fetcher.New(bmock, nil, func(uint64) bool {
return true
})
fetch, err := fetcher.New(bmock, nil, true)
require.NoError(t, err)

return fetch
Expand All @@ -524,9 +522,7 @@ func mustCreateFetcherWithAddress(t *testing.T, bmock beaconmock.Mock, addr stri

fetch, err := fetcher.New(bmock, func(core.PubKey) string {
return addr
}, func(uint64) bool {
return true
})
}, true)
require.NoError(t, err)

return fetch
Expand Down
2 changes: 2 additions & 0 deletions core/infosync/infosync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (

// maxResults limits the number of results to keep.
maxResults = 100

TopicProtocol = topicProtocol
)

// New returns a new infosync component.
Expand Down
6 changes: 3 additions & 3 deletions core/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, pubkeys [
) *Scheduler {
t.Helper()

s, err := New(pubkeys, eth2Cl, func(uint64) bool { return builderAPI })
s, err := New(pubkeys, eth2Cl, builderAPI)
require.NoError(t, err)

s.clock = clock
Expand All @@ -43,7 +43,7 @@ func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, pubkeys [
}

// New returns a new scheduler.
func New(pubkeys []core.PubKey, eth2Cl eth2wrap.Client, builderEnabled core.BuilderEnabled) (*Scheduler, error) {
func New(pubkeys []core.PubKey, eth2Cl eth2wrap.Client, builderEnabled bool) (*Scheduler, error) {
return &Scheduler{
eth2Cl: eth2Cl,
pubkeys: pubkeys,
Expand Down Expand Up @@ -73,7 +73,7 @@ type Scheduler struct {
dutiesMutex sync.Mutex
dutySubs []func(context.Context, core.Duty, core.DutyDefinitionSet) error
slotSubs []func(context.Context, core.Slot) error
builderEnabled core.BuilderEnabled
builderEnabled bool
}

// SubscribeDuties subscribes a callback function for triggered duties.
Expand Down
6 changes: 2 additions & 4 deletions core/scheduler/scheduler_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ func setupScheduler(t *testing.T) (*Scheduler, validators) {
}

sched := &Scheduler{
eth2Cl: eth2Cl,
builderEnabled: func(_ uint64) bool {
return false
},
eth2Cl: eth2Cl,
builderEnabled: false,
}

return sched, schedVals
Expand Down
3 changes: 1 addition & 2 deletions core/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func TestIntegration(t *testing.T) {
"0xb790b322e1cce41c48e3c344cf8d752bdc3cfd51e8eeef44a4bdaac081bc92b53b73e823a9878b5d7a532eb9d9dce1e3",
}

builderDisabled := func(uint64) bool { return false }
s, err := scheduler.New(pubkeys, eth2Cl, builderDisabled)
s, err := scheduler.New(pubkeys, eth2Cl, false)
require.NoError(t, err)

count := 10
Expand Down
8 changes: 4 additions & 4 deletions core/validatorapi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Handler interface {
// NewRouter returns a new validator http server router. The http router
// translates http requests related to the distributed validator to the Handler.
// All other requests are reverse-proxied to the beacon-node address.
func NewRouter(ctx context.Context, h Handler, eth2Cl eth2wrap.Client, isBuilderEnabled core.BuilderEnabled) (*mux.Router, error) {
func NewRouter(ctx context.Context, h Handler, eth2Cl eth2wrap.Client, builderEnabled bool) (*mux.Router, error) {
// Register subset of distributed validator related endpoints.
endpoints := []struct {
Name string
Expand Down Expand Up @@ -149,7 +149,7 @@ func NewRouter(ctx context.Context, h Handler, eth2Cl eth2wrap.Client, isBuilder
{
Name: "propose_block_v3",
Path: "/eth/v3/validator/blocks/{slot}",
Handler: proposeBlockV3(h, isBuilderEnabled),
Handler: proposeBlockV3(h, builderEnabled),
Methods: []string{http.MethodGet},
},
{
Expand Down Expand Up @@ -639,15 +639,15 @@ func respond404() handlerFunc {
}

// proposeBlockV3 returns a handler function returning an unsigned BeaconBlock or BlindedBeaconBlock.
func proposeBlockV3(p eth2client.ProposalProvider, builderEnabled core.BuilderEnabled) handlerFunc {
func proposeBlockV3(p eth2client.ProposalProvider, builderEnabled bool) handlerFunc {
return func(ctx context.Context, params map[string]string, query url.Values, _ contentType, _ []byte) (any, http.Header, error) {
slot, randao, graffiti, err := getProposeBlockParams(params, query)
if err != nil {
return nil, nil, err
}

var bbf uint64
if builderEnabled(slot) {
if builderEnabled {
// This gives maximum priority to builder blocks:
// https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV3
bbf = math.MaxUint64
Expand Down
24 changes: 9 additions & 15 deletions core/validatorapi/router_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/eth2wrap"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/eth2util/eth2exp"
"github.com/obolnetwork/charon/testutil"
)
Expand Down Expand Up @@ -88,8 +87,7 @@ func TestRouterIntegration(t *testing.T) {
t.Skip("Skipping integration test since BEACON_URL not found")
}

builderAPIEnabled := func(_ uint64) bool { return true }
r, err := NewRouter(context.Background(), Handler(nil), testBeaconAddr{addr: beaconURL}, builderAPIEnabled)
r, err := NewRouter(context.Background(), Handler(nil), testBeaconAddr{addr: beaconURL}, true)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand Down Expand Up @@ -593,7 +591,7 @@ func TestRawRouter(t *testing.T) {
}

// BuilderAPI is disabled, we expect to get the blinded block
testRawRouterEx(t, handler, callback, func(_ uint64) bool { return true })
testRawRouterEx(t, handler, callback, true)
})
}

Expand All @@ -615,8 +613,7 @@ func TestRouter(t *testing.T) {
proxy := httptest.NewServer(h.newBeaconHandler(t))
defer proxy.Close()

builderAPIEnabled := func(_ uint64) bool { return true }
r, err := NewRouter(ctx, h, testBeaconAddr{addr: proxy.URL}, builderAPIEnabled)
r, err := NewRouter(ctx, h, testBeaconAddr{addr: proxy.URL}, true)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand Down Expand Up @@ -1386,8 +1383,7 @@ func TestBeaconCommitteeSelections(t *testing.T) {
proxy := httptest.NewServer(handler.newBeaconHandler(t))
defer proxy.Close()

builderAPIEnabled := func(_ uint64) bool { return true }
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, builderAPIEnabled)
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, true)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand Down Expand Up @@ -1449,8 +1445,7 @@ func TestSubmitAggregateAttestations(t *testing.T) {
proxy := httptest.NewServer(handler.newBeaconHandler(t))
defer proxy.Close()

builderAPIEnabled := func(_ uint64) bool { return true }
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, builderAPIEnabled)
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, true)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand Down Expand Up @@ -1742,8 +1737,7 @@ func testRouter(t *testing.T, handler testHandler, callback func(context.Context

ctx := context.Background()

builderAPIEnabled := func(_ uint64) bool { return true }
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, builderAPIEnabled)
r, err := NewRouter(ctx, handler, testBeaconAddr{addr: proxy.URL}, true)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand All @@ -1761,17 +1755,17 @@ func testRouter(t *testing.T, handler testHandler, callback func(context.Context
func testRawRouter(t *testing.T, handler testHandler, callback func(context.Context, string)) {
t.Helper()

testRawRouterEx(t, handler, callback, func(_ uint64) bool { return true })
testRawRouterEx(t, handler, callback, true)
}

// testRawRouterEX is a helper function same as testRawRouter() but accepts GetBuilderAPIFlagFunc.
func testRawRouterEx(t *testing.T, handler testHandler, callback func(context.Context, string), isBuilderEnabled core.BuilderEnabled) {
func testRawRouterEx(t *testing.T, handler testHandler, callback func(context.Context, string), builderEnabled bool) {
t.Helper()

proxy := httptest.NewServer(handler.newBeaconHandler(t))
defer proxy.Close()

r, err := NewRouter(context.Background(), handler, testBeaconAddr{addr: proxy.URL}, isBuilderEnabled)
r, err := NewRouter(context.Background(), handler, testBeaconAddr{addr: proxy.URL}, builderEnabled)
require.NoError(t, err)

server := httptest.NewServer(r)
Expand Down
Loading
Loading