Skip to content

Commit 689d2a2

Browse files
authored
Use definition values when specifying external def file in create cluster (#4559)
1 parent a864e63 commit 689d2a2

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

cmd/createcluster.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ func runCreateCluster(ctx context.Context, w io.Writer, conf clusterConfig) erro
230230
}
231231

232232
conf.Network = network
233+
conf.TargetGasLimit = def.TargetGasLimit
234+
conf.Compounding = def.Compounding
233235
depositAmounts = def.DepositAmounts
234236
} else { // Create new definition from cluster config
235237
def, err = newDefFromConfig(ctx, conf)

cmd/createcluster_internal_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,88 @@ func TestTargetGasLimit(t *testing.T) {
759759
}
760760
}
761761

762+
func TestDefinitionFileIsAuthoritative(t *testing.T) {
763+
ctx := context.Background()
764+
765+
const (
766+
numNodes = 4
767+
numDVs = 2
768+
threshold = 3
769+
)
770+
771+
network := eth2util.Hoodi.Name
772+
773+
defConf := clusterConfig{
774+
Name: "authoritative-test",
775+
NumNodes: numNodes,
776+
NumDVs: numDVs,
777+
Threshold: threshold,
778+
Network: network,
779+
TargetGasLimit: 30000000,
780+
Compounding: true,
781+
}
782+
for range numDVs {
783+
defConf.FeeRecipientAddrs = append(defConf.FeeRecipientAddrs, testutil.RandomETHAddress())
784+
defConf.WithdrawalAddrs = append(defConf.WithdrawalAddrs, zeroAddress)
785+
}
786+
787+
def, err := newDefFromConfig(ctx, defConf)
788+
require.NoError(t, err)
789+
790+
defBytes, err := json.MarshalIndent(def, "", " ")
791+
require.NoError(t, err)
792+
793+
defPath := filepath.Join(t.TempDir(), "cluster-definition.json")
794+
require.NoError(t, os.WriteFile(defPath, defBytes, 0o600))
795+
796+
clusterDir := t.TempDir()
797+
runConf := clusterConfig{
798+
DefFile: defPath,
799+
ClusterDir: clusterDir,
800+
InsecureKeys: true,
801+
Network: network,
802+
TargetGasLimit: 60000000,
803+
Compounding: false,
804+
}
805+
require.NoError(t, runCreateCluster(ctx, io.Discard, runConf))
806+
807+
b, err := os.ReadFile(path.Join(nodeDir(clusterDir, 0), "cluster-lock.json"))
808+
require.NoError(t, err)
809+
810+
var lock cluster.Lock
811+
require.NoError(t, json.Unmarshal(b, &lock))
812+
require.NoError(t, lock.VerifyHashes())
813+
require.NoError(t, lock.VerifySignatures(nil))
814+
815+
require.Equal(t, def.TargetGasLimit, lock.TargetGasLimit)
816+
require.Equal(t, def.Compounding, lock.Compounding)
817+
require.Equal(t, def.DepositAmounts, lock.DepositAmounts)
818+
require.Equal(t, def.FeeRecipientAddresses(), lock.FeeRecipientAddresses())
819+
820+
expectedAmounts := lock.DepositAmounts
821+
if len(expectedAmounts) == 0 {
822+
expectedAmounts = deposit.DefaultDepositAmounts(lock.Compounding)
823+
}
824+
825+
wantCredPrefix := byte(0x01)
826+
if lock.Compounding {
827+
wantCredPrefix = 0x02
828+
}
829+
830+
require.NotEmpty(t, lock.Validators)
831+
832+
for _, val := range lock.Validators {
833+
require.Equal(t, int(lock.TargetGasLimit), val.BuilderRegistration.Message.GasLimit)
834+
require.Len(t, val.PartialDepositData, len(expectedAmounts))
835+
836+
for i, pdd := range val.PartialDepositData {
837+
require.EqualValues(t, expectedAmounts[i], pdd.Amount)
838+
require.NotEmpty(t, pdd.WithdrawalCredentials)
839+
require.Equal(t, wantCredPrefix, pdd.WithdrawalCredentials[0])
840+
}
841+
}
842+
}
843+
762844
// TestKeymanager tests keymanager support by letting create cluster command split a single secret and then receiving those keyshares using test
763845
// keymanager servers. These shares are then combined to create the combined share which is then compared to the original secret that was split.
764846
func TestKeymanager(t *testing.T) {

0 commit comments

Comments
 (0)