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

Alan/no fork fix unit tests #1442

Open
wants to merge 12 commits into
base: alan/no-fork
Choose a base branch
from

Conversation

pavelkrolevets
Copy link
Contributor

  • fix message/validation/validation_test.go
  • partial fix network/p2p/p2p_test.go

@MatusKysel MatusKysel requested a review from y0sher June 28, 2024 18:39
@@ -82,11 +82,11 @@ func (n *p2pNetwork) handleStream(logger *zap.Logger, handler p2pprotocol.Reques
}

// getSubsetOfPeers returns a subset of the peers from that topic
func (n *p2pNetwork) getSubsetOfPeers(logger *zap.Logger, senderID []byte, maxPeers int, filter func(peer.ID) bool) (peers []peer.ID, err error) {
func (n *p2pNetwork) getSubsetOfPeers(logger *zap.Logger, vpk spectypes.ValidatorPK, maxPeers int, filter func(peer.ID) bool) (peers []peer.ID, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why revert back to validator pk, if it could be either validator or committee? (so "sender")

Copy link
Contributor Author

@pavelkrolevets pavelkrolevets Jul 1, 2024

Choose a reason for hiding this comment

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

Comment on lines +617 to +622
for i := 0; i < 1000; i++ {
msg.Messages = append(msg.Messages, msg.Messages[0])
}

_, err := msg.Encode()
require.ErrorContains(t, err, "max expected 13 and 14 found")
require.ErrorContains(t, err, "max expected 1000 and 1001 found")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to increase this?

Copy link
Contributor Author

@pavelkrolevets pavelkrolevets Jul 4, 2024

Choose a reason for hiding this comment

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

we have max at ssz

type PartialSignatureMessages struct {
Type PartialSigMsgType
Slot phase0.Slot
Messages []*PartialSignatureMessage ssz-max:"1000"
}

Comment on lines -86 to -93
if msg.SSVMessage.MsgID.GetRoleType() == spectypes.RoleCommittee {
committeeID = spectypes.CommitteeID(msg.SSVMessage.MsgID.GetDutyExecutorID()[16:])
} else {
share := n.nodeStorage.ValidatorStore().Validator(msg.SSVMessage.MsgID.GetDutyExecutorID())
if share == nil {
return fmt.Errorf("could not find validator: %x", msg.SSVMessage.MsgID.GetDutyExecutorID())
}
committeeID = share.CommitteeID()
Copy link
Contributor

Choose a reason for hiding this comment

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

are you sure about this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This brakes tests. Not sure here. @y0sher @moshe-blox what do you think?

@@ -208,6 +219,7 @@ func (n *p2pNetwork) subscribe(logger *zap.Logger, pk spectypes.ValidatorPK) err
cmtid := n.nodeStorage.ValidatorStore().Validator(pk[:]).CommitteeID()
topics := commons.CommitteeTopicID(cmtid)
for _, topic := range topics {
n.interfaceLogger.Debug("subscribing to topic", fields.Topic(topic))
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove


signedSSVMessage := &spectypes.SignedSSVMessage{}
if err := signedSSVMessage.Decode(msg.GetData()); err != nil {
return fmt.Errorf("message was not decoded: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

add signed so we know which error we triggered

@@ -150,6 +150,7 @@ func (n *p2pNetwork) SetupServices(logger *zap.Logger) error {
if err := n.setupDiscovery(logger); err != nil {
return errors.Wrap(err, "could not setup discovery service")
}
fmt.Printf("Setting up pub sub...")
Copy link
Contributor

Choose a reason for hiding this comment

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

also please remove

Nodes: n,
MinConnected: n/2 - 1,
ks := spectestingutils.Testing4SharesSet()
pks := []string{"8e80066551a81b318258709edaf7dd1f63cd686a0e4db8b29bbb7acfe65608677af5a527d9448ee47835485e02b50bc0"}
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok that we use only one private key?

Copy link
Contributor Author

@pavelkrolevets pavelkrolevets Jul 4, 2024

Choose a reason for hiding this comment

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

We have all logic working with one PK, but if we want to add another PK, we need to use validator storage create shares etc. When we use spectestingutils.Testing4SharesSet() we have shares for only one PK.
@moshe-blox what do you think?

Comment on lines 436 to 437
// Signature: []byte("sVV0fsvqQlqliKv/ussGIatxpe8LDWhc9uoaM5WpjbiYvvxUr1eCpz0ja7UT1PGNDdmoGi6xbMC1g/ozhAt4uCdpy0Xdfqbv"),
// Signers: []spectypes.OperatorID{1, 3, 4},
Copy link
Contributor

Choose a reason for hiding this comment

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

we do not need this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah its from old code

signedSSVMsg, err := spectypes.SSVMessageToSignedSSVMessage(ssvMsg, 1, dummySignSSVMessage)
require.NoError(t, err)

return id, signedSSVMsg
}

func dummyMsgAttester(t *testing.T, pkHex string, height int) (spectypes.MessageID, *spectypes.SignedSSVMessage) {
return dummyMsg(t, pkHex, height, spectypes.BNRoleAttester)
return dummyMsg(t, pkHex, height, spectypes.RunnerRole(spectypes.BNRoleAttester))
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if this is needed you can put there committee right away

validatorCount = 20
validatorCount = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

is this ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here, we use spectestingutils.Testing4SharesSet() there only one PK. We use validator storage now, so to have 20 we need to create shares and store. I can try to mock it, if 20 is critical, but looks like with one we test all the logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 48 to 50
var validator [48]byte
cryptorand.Read(validator[:])
validators[i] = hex.EncodeToString(validator[:])
validators[i] = "8e80066551a81b318258709edaf7dd1f63cd686a0e4db8b29bbb7acfe65608677af5a527d9448ee47835485e02b50bc0"
Copy link
Contributor

Choose a reason for hiding this comment

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

what about this? are we creating validator with same key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah Ill rewrite it. Ill leave some logic commented.

Comment on lines 276 to 279
// func (v *MockMessageValidator) ValidateSSVMessage(ssvMessage *queue.DecodedSSVMessage) (*queue.DecodedSSVMessage, validation.Descriptor, error) {
// panic("not implemented") // TODO: Implement
// }

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you can delete this

operatorPubkey, err := keys.OperatorKey.Public().Base64()
if err != nil {
return nil, err
}

hash, err := keys.OperatorKey.StorageHash()
// hash, err := keys.OperatorKey.StorageHash()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not needed anymore

Comment on lines 152 to 155
// cfg.NodeStorage = mock.NodeStorage{
// MockPrivateKeyHash: hash,
// RegisteredOperatorPublicKeyPEMs: []string{},
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

also this

Comment on lines +156 to +158
// if !strings.Contains(ni.Metadata.NodeVersion, "ALANTEST") {
// return errors.New("non Alan node version is not supported")
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm did you need to change it due to tests? because we need this for stage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this brakes tests. Probably we need another approach

Comment on lines -106 to -119
// TODO: enable once topic validation is in place
//t.Run("wrong topic", func(t *testing.T) {
// pkHex := "b5de683dbcb3febe8320cc741948b9282d59b75a6970ed55d6f389da59f26325331b7ea0e71a2552373d0debb6048b8a"
// msg, err := dummySSVConsensusMsg(share.ValidatorPubKey, 15160)
// require.NoError(t, err)
// raw, err := msg.Encode()
// require.NoError(t, err)
// pk, err := hex.DecodeString("a297599ccf617c3b6118bbd248494d7072bb8c6c1cc342ea442a289415987d306bad34415f89469221450a2501a832ec")
// require.NoError(t, err)
// topics := commons.ValidatorTopicID(pk)
// pmsg := newPBMsg(raw, topics[0], []byte("16Uiu2HAkyWQyCb6reWXGQeBUt9EXArk6h3aq3PsFMwLNq3pPGH1r"))
// res := mv.ValidateP2PMessage(context.Background(), "16Uiu2HAkyWQyCb6reWXGQeBUt9EXArk6h3aq3PsFMwLNq3pPGH1r", pmsg)
// require.Equal(t, res, pubsub.ValidationReject)
//})
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

Comment on lines -127 to -136
// TODO: enable once topic validation is in place
//t.Run("invalid validator public key", func(t *testing.T) {
// msg, err := dummySSVConsensusMsg("10101011", 1)
// require.NoError(t, err)
// raw, err := msg.Encode()
// require.NoError(t, err)
// pmsg := newPBMsg(raw, "xxx", []byte{})
// res := mv.ValidateP2PMessage(context.Background(), "xxxx", pmsg)
// require.Equal(t, res, pubsub.ValidationReject)
//})
Copy link
Contributor

Choose a reason for hiding this comment

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

delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants