From 58cf7c7663dc8aff62ed0095076f5af12ae466e2 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 19 Dec 2023 21:17:26 +0200 Subject: [PATCH] - fixed managed peers holder --- keysManagement/managedPeersHolder.go | 2 +- keysManagement/managedPeersHolder_test.go | 34 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/keysManagement/managedPeersHolder.go b/keysManagement/managedPeersHolder.go index 875f83608c5..93e48fa2e30 100644 --- a/keysManagement/managedPeersHolder.go +++ b/keysManagement/managedPeersHolder.go @@ -163,7 +163,6 @@ func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { pInfo, found = holder.providedIdentities[string(publicKeyBytes)] if !found { pInfo = &peerInfo{ - handler: common.NewRedundancyHandler(), machineID: generateRandomMachineID(), nodeName: generateNodeName(holder.defaultName, holder.defaultPeerInfoCurrentIndex), nodeIdentity: holder.defaultIdentity, @@ -171,6 +170,7 @@ func (holder *managedPeersHolder) AddManagedPeer(privateKeyBytes []byte) error { holder.defaultPeerInfoCurrentIndex++ } + pInfo.handler = common.NewRedundancyHandler() pInfo.pid = pid pInfo.p2pPrivateKeyBytes = p2pPrivateKeyBytes pInfo.privateKey = privateKey diff --git a/keysManagement/managedPeersHolder_test.go b/keysManagement/managedPeersHolder_test.go index 8300eb743d9..7c2d278f9cd 100644 --- a/keysManagement/managedPeersHolder_test.go +++ b/keysManagement/managedPeersHolder_test.go @@ -419,6 +419,40 @@ func TestManagedPeersHolder_GetPrivateKey(t *testing.T) { assert.Equal(t, testName+"-00", name) assert.Equal(t, testIdentity, identity) }) + t.Run("identity provided on slave machine should not panic on increment rounds without received message", func(t *testing.T) { + defer func() { + r := recover() + if r != nil { + assert.Fail(t, fmt.Sprintf("should have not panicked %v", r)) + } + }() + + argsLocal := createMockArgsManagedPeersHolder() + argsLocal.PrefsConfig.Preferences.RedundancyLevel = 1 + argsLocal.MaxRoundsOfInactivity = 3 + namedIdentity := config.NamedIdentity{ + Identity: testIdentity, + NodeName: testName, + BLSKeys: []string{hex.EncodeToString(pkBytes0)}, + } + + argsLocal.PrefsConfig.NamedIdentity = append(argsLocal.PrefsConfig.NamedIdentity, namedIdentity) + holderLocal, err := keysManagement.NewManagedPeersHolder(argsLocal) + assert.Nil(t, err) + + _ = holderLocal.AddManagedPeer(skBytes0) + skRecovered, err := holderLocal.GetPrivateKey(pkBytes0) + skBytesRecovered, _ := skRecovered.ToByteArray() + assert.Equal(t, skBytes0, skBytesRecovered) + assert.Nil(t, err) + + name, identity, err := holderLocal.GetNameAndIdentity(pkBytes0) + assert.Nil(t, err) + assert.Equal(t, testName+"-00", name) + assert.Equal(t, testIdentity, identity) + + holderLocal.IncrementRoundsWithoutReceivedMessages(pkBytes0) + }) } func TestManagedPeersHolder_GetP2PIdentity(t *testing.T) {