-
Notifications
You must be signed in to change notification settings - Fork 84
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
base: alan/no-fork
Are you sure you want to change the base?
Conversation
pavelkrolevets
commented
Jun 27, 2024
- fix message/validation/validation_test.go
- partial fix network/p2p/p2p_test.go
network/p2p/p2p_sync.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ssvlabs/ssv/blob/alan/no-fork-fix-tests/network/p2p/p2p_sync.go#L191
Ill change here to senderID []byte.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
}
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
network/p2p/p2p_pubsub.go
Outdated
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove
network/p2p/p2p_pubsub.go
Outdated
|
||
signedSSVMessage := &spectypes.SignedSSVMessage{} | ||
if err := signedSSVMessage.Decode(msg.GetData()); err != nil { | ||
return fmt.Errorf("message was not decoded: %w", err) |
There was a problem hiding this comment.
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
network/p2p/p2p_setup.go
Outdated
@@ -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...") |
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
network/p2p/p2p_test.go
Outdated
// Signature: []byte("sVV0fsvqQlqliKv/ussGIatxpe8LDWhc9uoaM5WpjbiYvvxUr1eCpz0ja7UT1PGNDdmoGi6xbMC1g/ozhAt4uCdpy0Xdfqbv"), | ||
// Signers: []spectypes.OperatorID{1, 3, 4}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess remove it
There was a problem hiding this comment.
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
network/p2p/p2p_test.go
Outdated
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this ok?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
network/p2p/p2p_validation_test.go
Outdated
var validator [48]byte | ||
cryptorand.Read(validator[:]) | ||
validators[i] = hex.EncodeToString(validator[:]) | ||
validators[i] = "8e80066551a81b318258709edaf7dd1f63cd686a0e4db8b29bbb7acfe65608677af5a527d9448ee47835485e02b50bc0" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
network/p2p/p2p_validation_test.go
Outdated
// func (v *MockMessageValidator) ValidateSSVMessage(ssvMessage *queue.DecodedSSVMessage) (*queue.DecodedSSVMessage, validation.Descriptor, error) { | ||
// panic("not implemented") // TODO: Implement | ||
// } | ||
|
There was a problem hiding this comment.
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
network/p2p/test_utils.go
Outdated
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 { |
There was a problem hiding this comment.
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
network/p2p/test_utils.go
Outdated
// cfg.NodeStorage = mock.NodeStorage{ | ||
// MockPrivateKeyHash: hash, | ||
// RegisteredOperatorPublicKeyPEMs: []string{}, | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this
// if !strings.Contains(ni.Metadata.NodeVersion, "ALANTEST") { | ||
// return errors.New("non Alan node version is not supported") | ||
// } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
// 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) | ||
//}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
// 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) | ||
//}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete