Skip to content

Commit 6d90088

Browse files
authored
*: cherry pick for v1.8.0 (#4185)
Cherry pick of #4183 category: misc ticket: none
1 parent 31a7707 commit 6d90088

File tree

4 files changed

+108
-82
lines changed

4 files changed

+108
-82
lines changed

app/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
405405
) error {
406406
// Convert and prep public keys and public shares
407407
var (
408-
builderRegistrations []clusterpkg.BuilderRegistration
408+
builderRegistrations []*eth2api.VersionedSignedValidatorRegistration
409409
eth2Pubkeys []eth2p0.BLSPubKey
410410
pubshares []eth2p0.BLSPubKey
411411
allPubSharesByKey = make(map[core.PubKey]map[int]tbls.PublicKey) // map[pubkey]map[shareIdx]pubshare
@@ -449,12 +449,12 @@ func wireCoreWorkflow(ctx context.Context, life *lifecycle.Manager, conf Config,
449449
allPubSharesByKey[corePubkey] = allPubShares
450450
feeRecipientAddrByCorePubkey[corePubkey] = val.GetFeeRecipientAddress()
451451

452-
var builderRegistration clusterpkg.BuilderRegistration
452+
var builderRegistration eth2api.VersionedSignedValidatorRegistration
453453
if err := json.Unmarshal(val.GetBuilderRegistrationJson(), &builderRegistration); err != nil {
454454
return errors.Wrap(err, "unmarshal builder registration")
455455
}
456456

457-
builderRegistrations = append(builderRegistrations, builderRegistration)
457+
builderRegistrations = append(builderRegistrations, &builderRegistration)
458458
}
459459

460460
peers, err := manifest.ClusterPeers(cluster)

core/scheduler/scheduler.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"time"
1212

1313
eth2api "github.com/attestantio/go-eth2-client/api"
14-
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
15-
eth2spec "github.com/attestantio/go-eth2-client/spec"
1614
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
1715
"github.com/jonboulle/clockwork"
1816
"github.com/stretchr/testify/require"
@@ -24,7 +22,6 @@ import (
2422
"github.com/obolnetwork/charon/app/featureset"
2523
"github.com/obolnetwork/charon/app/log"
2624
"github.com/obolnetwork/charon/app/z"
27-
"github.com/obolnetwork/charon/cluster"
2825
"github.com/obolnetwork/charon/core"
2926
)
3027

@@ -38,7 +35,7 @@ type delayFunc func(duty core.Duty, deadline time.Time) <-chan time.Time
3835
type schedSlotFunc func(ctx context.Context, slot core.Slot)
3936

4037
// NewForT returns a new scheduler for testing using a fake clock.
41-
func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, builderRegistrations []cluster.BuilderRegistration,
38+
func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, builderRegistrations []*eth2api.VersionedSignedValidatorRegistration,
4239
eth2Cl eth2wrap.Client, schedSlotFunc schedSlotFunc, builderEnabled bool,
4340
) *Scheduler {
4441
t.Helper()
@@ -54,35 +51,10 @@ func NewForT(t *testing.T, clock clockwork.Clock, delayFunc delayFunc, builderRe
5451
}
5552

5653
// New returns a new scheduler.
57-
func New(builderRegistrations []cluster.BuilderRegistration, eth2Cl eth2wrap.Client, builderEnabled bool) (*Scheduler, error) {
58-
registrations := make([]*eth2api.VersionedSignedValidatorRegistration, 0, len(builderRegistrations))
59-
60-
for _, builderRegistration := range builderRegistrations {
61-
regMessage := &eth2v1.ValidatorRegistration{
62-
Timestamp: builderRegistration.Message.Timestamp,
63-
GasLimit: uint64(builderRegistration.Message.GasLimit),
64-
}
65-
66-
copy(regMessage.FeeRecipient[:], builderRegistration.Message.FeeRecipient)
67-
copy(regMessage.Pubkey[:], builderRegistration.Message.PubKey)
68-
69-
var signature eth2p0.BLSSignature
70-
copy(signature[:], builderRegistration.Signature)
71-
72-
registration := &eth2v1.SignedValidatorRegistration{
73-
Message: regMessage,
74-
Signature: signature,
75-
}
76-
77-
registrations = append(registrations, &eth2api.VersionedSignedValidatorRegistration{
78-
Version: eth2spec.BuilderVersionV1,
79-
V1: registration,
80-
})
81-
}
82-
54+
func New(builderRegistrations []*eth2api.VersionedSignedValidatorRegistration, eth2Cl eth2wrap.Client, builderEnabled bool) (*Scheduler, error) {
8355
return &Scheduler{
8456
eth2Cl: eth2Cl,
85-
builderRegistrations: registrations,
57+
builderRegistrations: builderRegistrations,
8658
quit: make(chan struct{}),
8759
duties: make(map[core.Duty]core.DutyDefinitionSet),
8860
dutiesByEpoch: make(map[uint64][]core.Duty),

core/scheduler/scheduler_test.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
eth2api "github.com/attestantio/go-eth2-client/api"
1717
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
18+
eth2spec "github.com/attestantio/go-eth2-client/spec"
1819
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
1920
"github.com/jonboulle/clockwork"
2021
"github.com/stretchr/testify/require"
@@ -23,7 +24,6 @@ import (
2324
"github.com/obolnetwork/charon/app/eth2wrap"
2425
"github.com/obolnetwork/charon/app/expbackoff"
2526
"github.com/obolnetwork/charon/app/featureset"
26-
"github.com/obolnetwork/charon/cluster"
2727
"github.com/obolnetwork/charon/core"
2828
"github.com/obolnetwork/charon/core/scheduler"
2929
"github.com/obolnetwork/charon/testutil"
@@ -50,24 +50,30 @@ func TestIntegration(t *testing.T) {
5050
require.NoError(t, err)
5151

5252
// Builder registrations for mainnet validators
53-
valRegs := []cluster.BuilderRegistration{
53+
valRegs := []*eth2api.VersionedSignedValidatorRegistration{
5454
{
55-
Message: cluster.Registration{
56-
FeeRecipient: beaconmock.MustBytesFromHex("0x388c818ca8b9251b393131c08a736a67ccb19297"),
57-
GasLimit: 36000000,
58-
Timestamp: time.Unix(1606824023, 0),
59-
PubKey: beaconmock.MustBytesFromHex("0x8f4ef114368b24863b369bbf597ace2eab5f77e4726f7931f988ba757fbd1dffd2f44270bbed42d5dfa72e10c79dcb6d"),
55+
Version: eth2spec.BuilderVersionV1,
56+
V1: &eth2v1.SignedValidatorRegistration{
57+
Message: &eth2v1.ValidatorRegistration{
58+
FeeRecipient: beaconmock.MustExecutionAddress("0x388c818ca8b9251b393131c08a736a67ccb19297"),
59+
GasLimit: 36000000,
60+
Timestamp: time.Unix(1606824023, 0),
61+
Pubkey: beaconmock.MustBLSPubKey("0x8f4ef114368b24863b369bbf597ace2eab5f77e4726f7931f988ba757fbd1dffd2f44270bbed42d5dfa72e10c79dcb6d"),
62+
},
63+
Signature: beaconmock.MustBLSSignature("0xacc05896c51c57177306d3f1eb9de64a6a1fb50b88cf4afe276a3c53673ce1227af2337ef607c769624f45472968cbde15f87c355dfa43bca81c882ea2d89ad301a4ce1c4169874bf9f9b1bafe70838519af34741d774930edbad40a7fefc7e6"),
6064
},
61-
Signature: beaconmock.MustBytesFromHex("0xacc05896c51c57177306d3f1eb9de64a6a1fb50b88cf4afe276a3c53673ce1227af2337ef607c769624f45472968cbde15f87c355dfa43bca81c882ea2d89ad301a4ce1c4169874bf9f9b1bafe70838519af34741d774930edbad40a7fefc7e6"),
6265
},
6366
{
64-
Message: cluster.Registration{
65-
FeeRecipient: beaconmock.MustBytesFromHex("0x388c818ca8b9251b393131c08a736a67ccb19297"),
66-
GasLimit: 36000000,
67-
Timestamp: time.Unix(1606824023, 0),
68-
PubKey: beaconmock.MustBytesFromHex("0xa0753f1bdb24b39441aee027a44af9ec5117a572678aa987944d26d92d332789208cf0733ca99f1d96fae50f7e889c22"),
67+
Version: eth2spec.BuilderVersionV1,
68+
V1: &eth2v1.SignedValidatorRegistration{
69+
Message: &eth2v1.ValidatorRegistration{
70+
FeeRecipient: beaconmock.MustExecutionAddress("0x388c818ca8b9251b393131c08a736a67ccb19297"),
71+
GasLimit: 36000000,
72+
Timestamp: time.Unix(1606824023, 0),
73+
Pubkey: beaconmock.MustBLSPubKey("0xa0753f1bdb24b39441aee027a44af9ec5117a572678aa987944d26d92d332789208cf0733ca99f1d96fae50f7e889c22"),
74+
},
75+
Signature: beaconmock.MustBLSSignature("0x8de77931277c745c05879db7e57853a07c5d3bd45d4d5757f55bdf05de3266c6ddac81b3b0316552b2ceb77405aa5c701311db3cd6a6ca176c792a9f1814ede89907b8cd05061a15bfb6618c8390577b349b3b4a75693311f1c638f53c186c58"),
6976
},
70-
Signature: beaconmock.MustBytesFromHex("0x8de77931277c745c05879db7e57853a07c5d3bd45d4d5757f55bdf05de3266c6ddac81b3b0316552b2ceb77405aa5c701311db3cd6a6ca176c792a9f1814ede89907b8cd05061a15bfb6618c8390577b349b3b4a75693311f1c638f53c186c58"),
7177
},
7278
}
7379

@@ -599,11 +605,11 @@ func TestSubmitValidatorRegistrations(t *testing.T) {
599605

600606
// Verify registration data matches BuilderRegistrationSetA
601607
for i, reg := range registrations {
602-
require.Equal(t, valRegs[i].Message.GasLimit, int(reg.V1.Message.GasLimit))
603-
require.Equal(t, valRegs[i].Message.Timestamp.Unix(), reg.V1.Message.Timestamp.Unix())
604-
require.Equal(t, valRegs[i].Message.FeeRecipient, reg.V1.Message.FeeRecipient[:])
605-
require.Equal(t, valRegs[i].Message.PubKey, reg.V1.Message.Pubkey[:])
606-
require.Equal(t, valRegs[i].Signature, reg.V1.Signature[:])
608+
require.Equal(t, valRegs[i].V1.Message.GasLimit, reg.V1.Message.GasLimit)
609+
require.Equal(t, valRegs[i].V1.Message.Timestamp.Unix(), reg.V1.Message.Timestamp.Unix())
610+
require.Equal(t, valRegs[i].V1.Message.FeeRecipient, reg.V1.Message.FeeRecipient)
611+
require.Equal(t, valRegs[i].V1.Message.Pubkey, reg.V1.Message.Pubkey)
612+
require.Equal(t, valRegs[i].V1.Signature, reg.V1.Signature)
607613
}
608614
}
609615

testutil/beaconmock/options.go

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/obolnetwork/charon/app/errors"
3232
"github.com/obolnetwork/charon/app/eth2wrap"
3333
"github.com/obolnetwork/charon/app/log"
34-
"github.com/obolnetwork/charon/cluster"
3534
"github.com/obolnetwork/charon/core"
3635
"github.com/obolnetwork/charon/testutil"
3736
)
@@ -145,35 +144,39 @@ var ValidatorSetA = ValidatorSet{
145144
},
146145
}
147146

147+
// mustBuilderRegistration creates a builder registration, panicking on error.
148+
func mustBuilderRegistration(feeRecipient, pubkey, signature string) *eth2api.VersionedSignedValidatorRegistration {
149+
return &eth2api.VersionedSignedValidatorRegistration{
150+
Version: eth2spec.BuilderVersionV1,
151+
V1: &eth2v1.SignedValidatorRegistration{
152+
Message: &eth2v1.ValidatorRegistration{
153+
FeeRecipient: MustExecutionAddress(feeRecipient),
154+
GasLimit: 30000000,
155+
Timestamp: time.Unix(1609459200, 0), // 2021-01-01 00:00:00 UTC
156+
Pubkey: MustBLSPubKey(pubkey),
157+
},
158+
Signature: MustBLSSignature(signature),
159+
},
160+
}
161+
}
162+
148163
// BuilderRegistrationSetA defines a set of 3 deterministic builder registrations for ValidatorSetA.
149-
var BuilderRegistrationSetA = []cluster.BuilderRegistration{
150-
{
151-
Message: cluster.Registration{
152-
FeeRecipient: MustBytesFromHex("0x0000000000000000000000000000000000000001"),
153-
GasLimit: 30000000,
154-
Timestamp: time.Unix(1609459200, 0), // 2021-01-01 00:00:00 UTC
155-
PubKey: MustBytesFromHex("0x914cff835a769156ba43ad50b931083c2dadd94e8359ce394bc7a3e06424d0214922ddf15f81640530b9c25c0bc0d490"),
156-
},
157-
Signature: MustBytesFromHex("0xa1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6"),
158-
},
159-
{
160-
Message: cluster.Registration{
161-
FeeRecipient: MustBytesFromHex("0x0000000000000000000000000000000000000002"),
162-
GasLimit: 30000000,
163-
Timestamp: time.Unix(1609459200, 0), // 2021-01-01 00:00:00 UTC
164-
PubKey: MustBytesFromHex("0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea"),
165-
},
166-
Signature: MustBytesFromHex("0xb2b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6"),
167-
},
168-
{
169-
Message: cluster.Registration{
170-
FeeRecipient: MustBytesFromHex("0x0000000000000000000000000000000000000003"),
171-
GasLimit: 30000000,
172-
Timestamp: time.Unix(1609459200, 0), // 2021-01-01 00:00:00 UTC
173-
PubKey: MustBytesFromHex("0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76"),
174-
},
175-
Signature: MustBytesFromHex("0xc3b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6"),
176-
},
164+
var BuilderRegistrationSetA = []*eth2api.VersionedSignedValidatorRegistration{
165+
mustBuilderRegistration(
166+
"0x0000000000000000000000000000000000000001",
167+
"0x914cff835a769156ba43ad50b931083c2dadd94e8359ce394bc7a3e06424d0214922ddf15f81640530b9c25c0bc0d490",
168+
"0xa1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6",
169+
),
170+
mustBuilderRegistration(
171+
"0x0000000000000000000000000000000000000002",
172+
"0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea",
173+
"0xb2b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6",
174+
),
175+
mustBuilderRegistration(
176+
"0x0000000000000000000000000000000000000003",
177+
"0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76",
178+
"0xc3b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6",
179+
),
177180
}
178181

179182
// WithValidatorSet configures the mock with the provided validator set.
@@ -802,6 +805,36 @@ func mustPKFromHex(pubkeyHex string) eth2p0.BLSPubKey {
802805
return resp
803806
}
804807

808+
// must20ByteArray converts a byte slice to a 20-byte array, panicking if wrong size.
809+
func must20ByteArray(b []byte) [20]byte {
810+
if len(b) != 20 {
811+
panic(fmt.Sprintf("expected 20 bytes, got %d", len(b)))
812+
}
813+
var arr [20]byte
814+
copy(arr[:], b)
815+
return arr
816+
}
817+
818+
// must48ByteArray converts a byte slice to a 48-byte array, panicking if wrong size.
819+
func must48ByteArray(b []byte) [48]byte {
820+
if len(b) != 48 {
821+
panic(fmt.Sprintf("expected 48 bytes, got %d", len(b)))
822+
}
823+
var arr [48]byte
824+
copy(arr[:], b)
825+
return arr
826+
}
827+
828+
// must96ByteArray converts a byte slice to a 96-byte array, panicking if wrong size.
829+
func must96ByteArray(b []byte) [96]byte {
830+
if len(b) != 96 {
831+
panic(fmt.Sprintf("expected 96 bytes, got %d", len(b)))
832+
}
833+
var arr [96]byte
834+
copy(arr[:], b)
835+
return arr
836+
}
837+
805838
// MustBytesFromHex converts a hex string to bytes, panicking on error.
806839
func MustBytesFromHex(hexStr string) []byte {
807840
hexStr = strings.TrimPrefix(hexStr, "0x")
@@ -813,3 +846,18 @@ func MustBytesFromHex(hexStr string) []byte {
813846

814847
return b
815848
}
849+
850+
// MustExecutionAddress converts a hex string to an execution address (20 bytes), panicking on error.
851+
func MustExecutionAddress(hexStr string) [20]byte {
852+
return must20ByteArray(MustBytesFromHex(hexStr))
853+
}
854+
855+
// MustBLSPubKey converts a hex string to a BLS public key (48 bytes), panicking on error.
856+
func MustBLSPubKey(hexStr string) [48]byte {
857+
return must48ByteArray(MustBytesFromHex(hexStr))
858+
}
859+
860+
// MustBLSSignature converts a hex string to a BLS signature (96 bytes), panicking on error.
861+
func MustBLSSignature(hexStr string) [96]byte {
862+
return must96ByteArray(MustBytesFromHex(hexStr))
863+
}

0 commit comments

Comments
 (0)