Skip to content

Commit

Permalink
Merge pull request #5782 from multiversx/fix-managed-peers-holder-202…
Browse files Browse the repository at this point in the history
…3.12.19

Fixed managed peers holder
  • Loading branch information
iulianpascalau authored Dec 21, 2023
2 parents 3935103 + 58cf7c7 commit 2af5088
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keysManagement/managedPeersHolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ 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,
}
holder.defaultPeerInfoCurrentIndex++
}

pInfo.handler = common.NewRedundancyHandler()
pInfo.pid = pid
pInfo.p2pPrivateKeyBytes = p2pPrivateKeyBytes
pInfo.privateKey = privateKey
Expand Down
34 changes: 34 additions & 0 deletions keysManagement/managedPeersHolder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2af5088

Please sign in to comment.