Skip to content

Commit

Permalink
cmd: fixing builder registration timestamp (#2892)
Browse files Browse the repository at this point in the history
Cherrypick of #2810 

---

Use the current timestamp for builder registration messages when using `--split-existing-keys` mode.

See [the issue](#2770) for the full context.

category: bug
ticket: #2770
  • Loading branch information
gsora authored Feb 21, 2024
1 parent 31540d4 commit 3c5fdad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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 @@ import (
"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 @@ func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) erro
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 @@ func signDepositDatas(secrets []tbls.PrivateKey, withdrawalAddresses []string, n
}

// 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 @@ func signValidatorRegistrations(secrets []tbls.PrivateKey, feeAddresses []string
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
}
}

unsignedReg, err := registration.NewMessage(
Expand Down Expand Up @@ -569,12 +576,12 @@ func writeDepositData(depositDatas []eth2p0.DepositData, network string, cluster
}

// 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

0 comments on commit 3c5fdad

Please sign in to comment.