From 10c3ee00c60c8ff0d2c1d452e5df82ba2539b07e Mon Sep 17 00:00:00 2001 From: Dhruv Bodani Date: Mon, 30 Oct 2023 15:52:38 +0530 Subject: [PATCH] cmd/combine: allow threshold number of keys to combine (#2664) Allows threshold number of keys to combine private keyshares into single validator keystore. category: refactor ticket: #2663 --- cmd/combine/combine.go | 6 +++--- cmd/combine/combine_test.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/combine/combine.go b/cmd/combine/combine.go index 6142d25ad..ed25a5224 100644 --- a/cmd/combine/combine.go +++ b/cmd/combine/combine.go @@ -88,11 +88,11 @@ func Combine(ctx context.Context, inputDir, outputDir string, force, noverify bo for valIdx := 0; valIdx < len(privkeys); valIdx++ { pkSet := privkeys[valIdx] - if len(pkSet) != len(cluster.Operators) { + if len(pkSet) < int(cluster.Threshold) { return errors.New( - "not all private key shares found for validator", + "insufficient private key shares found for validator", z.Int("validator_index", valIdx), - z.Int("expected", len(cluster.Operators)), + z.Int("expected", int(cluster.Threshold)), z.Int("actual", len(pkSet)), ) } diff --git a/cmd/combine/combine_test.go b/cmd/combine/combine_test.go index c655df9a1..75ed2281e 100644 --- a/cmd/combine/combine_test.go +++ b/cmd/combine/combine_test.go @@ -85,9 +85,10 @@ func TestCombineCannotLoadKeystore(t *testing.T) { } require.NoError(t, os.RemoveAll(filepath.Join(dir, "node0"))) + require.NoError(t, os.RemoveAll(filepath.Join(dir, "node1"))) err := combine.Combine(context.Background(), dir, od, false, false, combine.WithInsecureKeysForT(t)) - require.Error(t, err) + require.ErrorContains(t, err, "insufficient private key shares found for validator") } func TestCombineAllManifest(t *testing.T) {