Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multikey peer authentication sender integration #4394

Merged
merged 13 commits into from Aug 31, 2022

Conversation

sstanculeanu
Copy link
Contributor

@sstanculeanu sstanculeanu commented Aug 24, 2022

Description of the reasoning behind the pull request (what feature was missing / how the problem was manifesting itself / what was the motive behind the refactoring)

  • peer authentication sender is not compatible with the multikey system

Proposed Changes

  • integrate keysHolder into newly added component multikeyPeerAuthenticationSender in order to support multikey
  • updated keysHolder with the needed methods
  • factory which will create the proper one(multikeyPeerAuthenticationSender or peerAuthenticationSender) will come in a further PR

Testing procedure

  • system test hbv2

@sstanculeanu sstanculeanu marked this pull request as ready for review August 24, 2022 15:54
@sstanculeanu sstanculeanu removed the status:work-in-progress Work In Progress label Aug 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2022

Codecov Report

Merging #4394 (8b91a00) into feat/multisigner (75dc784) will increase coverage by 0.01%.
The diff coverage is 84.72%.

@@                 Coverage Diff                  @@
##           feat/multisigner    #4394      +/-   ##
====================================================
+ Coverage             73.69%   73.71%   +0.01%     
====================================================
  Files                   681      683       +2     
  Lines                 87093    87268     +175     
====================================================
+ Hits                  64187    64333     +146     
- Misses                18051    18072      +21     
- Partials               4855     4863       +8     
Impacted Files Coverage Δ
p2p/crypto/p2pSigner.go 84.61% <60.00%> (-5.87%) ⬇️
...artbeat/sender/multikeyPeerAuthenticationSender.go 78.33% <78.33%> (ø)
heartbeat/sender/peerAuthenticationSender.go 93.67% <90.00%> (+0.03%) ⬆️
heartbeat/sender/commonPeerAuthenticationSender.go 90.90% <90.90%> (ø)
keysManagement/keysHolder.go 100.00% <100.00%> (ø)
keysManagement/peerInfo.go 100.00% <100.00%> (ø)
...t/processor/peerAuthenticationRequestsProcessor.go 94.40% <0.00%> (-2.40%) ⬇️
p2p/libp2p/netMessenger.go 77.55% <0.00%> (+0.25%) ⬆️
storage/txcache/txListBySenderMap.go 100.00% <0.00%> (+2.50%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


// P2PIdentityGenerator defines the operations of an entity that can generate P2P identities
type P2PIdentityGenerator interface {
CreateRandomP2PIdentity() ([]byte, core.PeerID, error)
IsInterfaceNil() bool
}

// KeysHolder defines the operations of an entity that holds virtual identities for a node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be moved where it is used: example: heartbeat package

@@ -15,6 +16,10 @@ type peerInfo struct {
nodeName string
nodeIdentity string

mutPeerAuthenticationData sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this sync.RWMutex and use instead the mutChangeableData instance for both isValidator and nextPeerAuthenticationTime

@@ -285,6 +286,54 @@ func (holder *virtualPeersHolder) IsPidManagedByCurrentNode(pid core.PeerID) boo
return found
}

// IsKeyValidator returns true if the key validator status was set to true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing unit tests for these 4 functions


data, isHardforkTriggered, err := sender.prepareMessage([]byte(pk), sk)
if err != nil {
setTimeErr := sender.keysHolder.SetNextPeerAuthenticationTime(pkBytes, currentTimeStamp.Add(sender.timeBetweenSendsWhenError))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to simplify the logic, we can make the SetNextPeerAuthenticationTime not output an error, and just ignore the call if the set method did not find the provided public key bytes

if isHardforkTriggered {
nextTimeStamp := currentTimeStamp.Add(sender.computeRandomDuration(sender.hardforkTimeBetweenSends))
setTimeErr := sender.keysHolder.SetNextPeerAuthenticationTime(pkBytes, nextTimeStamp)
if setTimeErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here, we can simplify the logic

return fmt.Errorf("%w while seting next peer authentication time", setTimeErr)
}

setValidatorErr := sender.keysHolder.SetValidatorState(pkBytes, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can also be simplified

}
isValidatorNow, shardID := sender.getIsValidatorStatusAndShardID(pkBytes)
isHardforkSource := sender.isHardforkSource(pkBytes)
oldIsValidator, err := sender.keysHolder.IsKeyValidator(pkBytes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can output only false if the provided key does not belong to this node

}

func (sender *multikeyPeerAuthenticationSender) sendData(index int, pkBytes []byte, data []byte, isHardforkTriggered bool) {
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as seen in the next heartbeat sender implementation, we can drop the usage of the go async call and the usage of the index value and just start the call with a fixed time.Sleep call.
This will prevent launching more go routines & should simplify the testing procedure with virtually no drawback.

Pubkey: pkBytes,
}

hardforkPayload, isTriggered := sender.getHardforkPayload()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function contains a lot of duplicated code with the original peerAuthenticationSender implementation. Can we extract duplicated code as seen in the heartbeat sender future implementation?

senderInstance, _ := newMultikeyPeerAuthenticationSender(args)
senderInstance.Execute()

time.Sleep(time.Second * 2) // allow the go routines to finish
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we remove the go routines all these waits should be removed.

@bogdan-rosianu bogdan-rosianu self-requested a review August 30, 2022 08:19
p2pSkBytes []byte,
pidBytes []byte,
) ([]byte, bool, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove first empty line


p2pSk, pid, err := sender.keysHolder.GetP2PIdentity(pkBytes)
if err != nil {
log.Error("could not get identity for pk", "pk", hex.EncodeToString(pkBytes))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log the error as well


nextTimeToCheck, err := sender.keysHolder.GetNextPeerAuthenticationTime(pkBytes)
if err != nil {
log.Error("could not get next peer authentication time for pk", "pk", hex.EncodeToString(pkBytes))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log the error as well

@@ -16,8 +16,10 @@ import (
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
Broadcast(topic string, buff []byte)
BroadcastWithSk(topic string, buff []byte, pid core.PeerID, skBytes []byte)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we raname this into BroadcastUsingSk (or BroadcastSigningWithSk)? I know that the naming convention follows libp2p's PublishWithSk but I find it very misleading, I really thought we were sending the sk over the wire. (SendableData having an SK member doesn't help either :)) @iulianpascalau thoughts?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, let's rename to BroadcastWithPrivateKey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed

ID() core.PeerID
Sign(payload []byte) ([]byte, error)
SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also follow the naming convention above (either abbreviation of secret key, or private key)

iulianpascalau
iulianpascalau previously approved these changes Aug 30, 2022
ccorcoveanu
ccorcoveanu previously approved these changes Aug 30, 2022
@sstanculeanu sstanculeanu merged commit a0130de into feat/multisigner Aug 31, 2022
@sstanculeanu sstanculeanu deleted the integrate_peerauthentication_sender branch August 31, 2022 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants