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

cmd: fixing builder registration timestamp #2892

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"path/filepath"
"strings"
"testing"
"time"

eth2api "github.com/attestantio/go-eth2-client/api"
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
Expand Down Expand Up @@ -240,7 +241,7 @@
return err
}

valRegs, err := createValidatorRegistrations(def.FeeRecipientAddresses(), secrets, def.ForkVersion)
valRegs, err := createValidatorRegistrations(def.FeeRecipientAddresses(), secrets, def.ForkVersion, conf.SplitKeys)
if err != nil {
return err
}
Expand Down Expand Up @@ -408,7 +409,7 @@
}

// signValidatorRegistrations returns a slice of validator registrations for each private key in secrets.
func signValidatorRegistrations(secrets []tbls.PrivateKey, feeAddresses []string, forkVersion []byte) ([]core.VersionedSignedValidatorRegistration, error) {
func signValidatorRegistrations(secrets []tbls.PrivateKey, feeAddresses []string, forkVersion []byte, useCurrentTimestamp bool) ([]core.VersionedSignedValidatorRegistration, error) {
if len(secrets) != len(feeAddresses) {
return nil, errors.New("insufficient fee addresses")
}
Expand All @@ -425,9 +426,15 @@
return nil, errors.Wrap(err, "secret to pubkey")
}

timestamp, err := eth2util.ForkVersionToGenesisTime(forkVersion)
if err != nil {
return nil, err
var timestamp time.Time
if useCurrentTimestamp {
// Used in --split-existing-keys mode
timestamp = time.Now().UTC()
} else {
timestamp, err = eth2util.ForkVersionToGenesisTime(forkVersion)
if err != nil {
return nil, err
}

Check warning on line 437 in cmd/createcluster.go

View check run for this annotation

Codecov / codecov/patch

cmd/createcluster.go#L436-L437

Added lines #L436 - L437 were not covered by tests
}

unsignedReg, err := registration.NewMessage(
Expand Down Expand Up @@ -569,12 +576,12 @@
}

// createValidatorRegistrations creates a slice of builder validator registrations using the provided parameters and returns it.
func createValidatorRegistrations(feeAddresses []string, secrets []tbls.PrivateKey, forkVersion []byte) ([]core.VersionedSignedValidatorRegistration, error) {
func createValidatorRegistrations(feeAddresses []string, secrets []tbls.PrivateKey, forkVersion []byte, useCurrentTimestamp bool) ([]core.VersionedSignedValidatorRegistration, error) {
if len(feeAddresses) != len(secrets) {
return nil, errors.New("insufficient fee addresses")
}

return signValidatorRegistrations(secrets, feeAddresses, forkVersion)
return signValidatorRegistrations(secrets, feeAddresses, forkVersion, useCurrentTimestamp)
}

// writeLock creates a cluster lock and writes it to disk for all peers.
Expand Down
8 changes: 8 additions & 0 deletions cmd/createcluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func testCreateCluster(t *testing.T, conf clusterConfig, def cluster.Definition,
}

previousVersions := []string{"v1.0.0", "v1.1.0", "v1.2.0", "v1.3.0", "v1.4.0", "v1.5.0"}
nowUTC := time.Now().UTC()
for _, val := range lock.Validators {
if isAnyVersion(lock.Version, previousVersions...) {
break
Expand All @@ -330,6 +331,13 @@ func testCreateCluster(t *testing.T, conf clusterConfig, def cluster.Definition,
if isAnyVersion(lock.Version, "v1.7.0") {
require.NotEmpty(t, val.BuilderRegistration)
}

if conf.SplitKeys {
// For SplitKeys mode, builder registration timestamp must be close to Now().
// This assumes the test does not execute longer than five minutes.
// We just need to make sure the message timestamp is not a genesis time.
require.Less(t, nowUTC.Sub(val.BuilderRegistration.Message.Timestamp), 5*time.Minute, "likely a genesis timestamp")
}
}

if isAnyVersion(lock.Version, "v1.7.0") {
Expand Down
Loading