mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 12:10:05 +00:00
p2p: Handle nil topic (#9522)
* fix nil topic * fmt Co-authored-by: nisdas <nishdas93@gmail.com>
This commit is contained in:
parent
30b2adc5d6
commit
265b5feabf
@ -21,7 +21,7 @@ import (
|
||||
// the concatenation of `MESSAGE_DOMAIN_INVALID_SNAPPY` with the raw message data,
|
||||
// i.e. `SHA256(MESSAGE_DOMAIN_INVALID_SNAPPY + message.data)[:20]`.
|
||||
func MsgID(genesisValidatorsRoot []byte, pmsg *pubsub_pb.Message) string {
|
||||
if pmsg == nil || pmsg.Data == nil {
|
||||
if pmsg == nil || pmsg.Data == nil || pmsg.Topic == nil {
|
||||
// Impossible condition that should
|
||||
// never be hit.
|
||||
msg := make([]byte, 20)
|
||||
|
@ -63,3 +63,16 @@ func TestMessageIDFunction_HashesCorrectlyAltair(t *testing.T) {
|
||||
msgID = string(hashedData[:20])
|
||||
assert.Equal(t, msgID, p2p.MsgID(genesisValidatorsRoot, nMsg), "Got incorrect msg id")
|
||||
}
|
||||
|
||||
func TestMsgID_WithNilTopic(t *testing.T) {
|
||||
msg := &pubsubpb.Message{
|
||||
Data: make([]byte, 32),
|
||||
Topic: nil,
|
||||
}
|
||||
|
||||
invalid := make([]byte, 20)
|
||||
copy(invalid, "invalid")
|
||||
|
||||
res := p2p.MsgID([]byte{0x01}, msg)
|
||||
assert.Equal(t, res, string(invalid))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user