Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
corverroos committed Oct 14, 2022
1 parent 1e9a476 commit 46e2d87
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
8 changes: 1 addition & 7 deletions cluster/cluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,7 @@ func randomDefinition(t *testing.T, op0, op1 Operator) Definition {
rand.New(rand.NewSource(1)))
require.NoError(t, err)

// TODO(xenowits): Remove the line below when v1.3 is the current version.
definition.Version = v1_3

resp, err := definition.SetDefinitionHashes()
require.NoError(t, err)

return resp
return definition
}

func TestSupportEIP712Sigs(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ func TestEncode(t *testing.T) {
},
},
rand.New(rand.NewSource(0)),
func(d *cluster.Definition) {
d.Version = version
d.Timestamp = "2022-07-19T18:19:58+02:00" // Make deterministic
},
)
require.NoError(t, err)
definition.Version = version

// Definition version prior to v1.3.0 don't support EIP712 signatures.
if version == "v1.0.0" || version == "v1.1.0" || version == "v1.2.0" {
Expand All @@ -74,8 +77,6 @@ func TestEncode(t *testing.T) {
}
}

definition.Timestamp = "2022-07-19T18:19:58+02:00" // Make deterministic

t.Run("definition_json_"+vStr, func(t *testing.T) {
testutil.RequireGoldenJSON(t, definition,
testutil.WithFilename("cluster_definition_"+vStr+".json"))
Expand Down
9 changes: 7 additions & 2 deletions cluster/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ type NodeIdx struct {
}

// NewDefinition returns a new definition populated with the latest version, timestamp and UUID.
// The hashes are also populated accordingly. Note that the hashes need to be recalculated when any field is modified.
func NewDefinition(name string, numVals int, threshold int, feeRecipientAddress string, withdrawalAddress string,
forkVersionHex string, operators []Operator, random io.Reader,
forkVersionHex string, operators []Operator, random io.Reader, opts ...func(*Definition),
) (Definition, error) {
def := Definition{
Version: currentVersion,
Expand All @@ -64,7 +65,11 @@ func NewDefinition(name string, numVals int, threshold int, feeRecipientAddress
return Definition{}, err
}

return def, nil
for _, opt := range opts {
opt(&def)
}

return def.SetDefinitionHashes()
}

// Definition defines an intended charon cluster configuration excluding validators.
Expand Down
9 changes: 0 additions & 9 deletions cluster/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ func (l *Lock) UnmarshalJSON(data []byte) error {
return errors.New("unsupported version")
}

hash, err := hashLock(lock)
if err != nil {
return errors.Wrap(err, "hash lock")
}

if !bytes.Equal(lock.LockHash, hash[:]) {
return errors.New("invalid lock hash")
}

*l = lock

return nil
Expand Down
10 changes: 2 additions & 8 deletions cluster/test_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, opts ...func(*Definition)) (Lock,

def, err := NewDefinition("test cluster", dv, k,
testutil.RandomETHAddress(), testutil.RandomETHAddress(),
"0x00000000", ops, random)
require.NoError(t, err)

for _, opt := range opts {
opt(&def)
}

def, err = def.SetDefinitionHashes()
"0x00000000", ops, random, opts...)
require.NoError(t, err)

// Definition version prior to v1.3.0 don't support EIP712 signatures.
Expand All @@ -133,6 +126,7 @@ func NewForT(t *testing.T, dv, k, n, seed int, opts ...func(*Definition)) (Lock,
require.NoError(t, err)
}

// Recalculate definition hash after adding signatures.
def, err = def.SetDefinitionHashes()
require.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/createcluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func testCreateCluster(t *testing.T, conf clusterConfig) {

var lock cluster.Lock
require.NoError(t, json.Unmarshal(b, &lock))

require.NoError(t, lock.VerifyHashes())
require.NoError(t, lock.VerifySignatures())
})
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/createdkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,20 @@ func runCreateDKG(ctx context.Context, conf createDKGConfig) (err error) {
return err
}

def, err := cluster.NewDefinition(conf.Name, conf.NumValidators, conf.Threshold, conf.FeeRecipient, conf.WithdrawalAddress,
forkVersion, operators, crand.Reader)
def, err := cluster.NewDefinition(
conf.Name, conf.NumValidators, conf.Threshold,
conf.FeeRecipient, conf.WithdrawalAddress,
forkVersion, operators, crand.Reader,
func(d *cluster.Definition) {
d.DKGAlgorithm = conf.DKGAlgo
})
if err != nil {
return err
}

def.DKGAlgorithm = conf.DKGAlgo

if err := def.VerifyHashes(); err != nil {
return err
}
if err := def.VerifySignatures(); err != nil {
return err
}
Expand Down

0 comments on commit 46e2d87

Please sign in to comment.