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 #2810

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -236,7 +237,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 @@ -405,7 +406,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, useNowTimestamp bool) ([]core.VersionedSignedValidatorRegistration, error) {
pinebit marked this conversation as resolved.
Show resolved Hide resolved
if len(secrets) != len(feeAddresses) {
return nil, errors.New("insufficient fee addresses")
}
Expand All @@ -422,9 +423,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 useNowTimestamp {
pinebit marked this conversation as resolved.
Show resolved Hide resolved
// 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 434 in cmd/createcluster.go

View check run for this annotation

Codecov / codecov/patch

cmd/createcluster.go#L433-L434

Added lines #L433 - L434 were not covered by tests
}

unsignedReg, err := registration.NewMessage(
Expand Down Expand Up @@ -566,12 +573,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, useNowTimestamp bool) ([]core.VersionedSignedValidatorRegistration, error) {
pinebit marked this conversation as resolved.
Show resolved Hide resolved
if len(feeAddresses) != len(secrets) {
return nil, errors.New("insufficient fee addresses")
}

return signValidatorRegistrations(secrets, feeAddresses, forkVersion)
return signValidatorRegistrations(secrets, feeAddresses, forkVersion, useNowTimestamp)
pinebit marked this conversation as resolved.
Show resolved Hide resolved
}

// 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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, considering our CI isn't the fastest, I wonder if we'll ever reach a state in which this statement fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is fast, it does not deploy and run a cluster. On a dev box it is executing in ~0.2 sec. Hence, the assumption about 5 minutes to be extremely sufficient..

}
}

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