mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
Update Message ID (#7304)
* shorten message id * Merge refs/heads/master into updateMessageID * Merge refs/heads/master into updateMessageID
This commit is contained in:
parent
ba440abe2d
commit
22bcfd2c34
@ -2,7 +2,6 @@ package p2p
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
@ -80,12 +79,10 @@ func (s *Service) SubscribeToTopic(topic string, opts ...pubsub.SubOpt) (*pubsub
|
||||
// Content addressable ID function.
|
||||
//
|
||||
// ETH2 spec defines the message ID as:
|
||||
// message-id: base64(SHA256(message.data))
|
||||
// where base64 is the URL-safe base64 alphabet with
|
||||
// padding characters omitted.
|
||||
// message-id: SHA256(message.data)[:8]
|
||||
func msgIDFunction(pmsg *pubsub_pb.Message) string {
|
||||
h := hashutil.Hash(pmsg.Data)
|
||||
return base64.RawURLEncoding.EncodeToString(h[:])
|
||||
return string(h[:8])
|
||||
}
|
||||
|
||||
func setPubSubParameters() {
|
||||
|
@ -2,7 +2,6 @@ package p2p
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -34,6 +33,6 @@ func TestMessageIDFunction_HashesCorrectly(t *testing.T) {
|
||||
msg := [32]byte{'J', 'U', 'N', 'K'}
|
||||
pMsg := &pubsubpb.Message{Data: msg[:]}
|
||||
hashedData := hashutil.Hash(pMsg.Data)
|
||||
msgID := base64.RawURLEncoding.EncodeToString(hashedData[:])
|
||||
msgID := string(hashedData[:8])
|
||||
assert.Equal(t, msgID, msgIDFunction(pMsg), "Got incorrect msg id")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user