mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
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.
|
// Content addressable ID function.
|
||||||
//
|
//
|
||||||
// ETH2 spec defines the message ID as:
|
// ETH2 spec defines the message ID as:
|
||||||
// message-id: base64(SHA256(message.data))
|
// message-id: SHA256(message.data)[:8]
|
||||||
// where base64 is the URL-safe base64 alphabet with
|
|
||||||
// padding characters omitted.
|
|
||||||
func msgIDFunction(pmsg *pubsub_pb.Message) string {
|
func msgIDFunction(pmsg *pubsub_pb.Message) string {
|
||||||
h := hashutil.Hash(pmsg.Data)
|
h := hashutil.Hash(pmsg.Data)
|
||||||
return base64.RawURLEncoding.EncodeToString(h[:])
|
return string(h[:8])
|
||||||
}
|
}
|
||||||
|
|
||||||
func setPubSubParameters() {
|
func setPubSubParameters() {
|
||||||
|
@ -2,7 +2,6 @@ package p2p
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@ -34,6 +33,6 @@ func TestMessageIDFunction_HashesCorrectly(t *testing.T) {
|
|||||||
msg := [32]byte{'J', 'U', 'N', 'K'}
|
msg := [32]byte{'J', 'U', 'N', 'K'}
|
||||||
pMsg := &pubsubpb.Message{Data: msg[:]}
|
pMsg := &pubsubpb.Message{Data: msg[:]}
|
||||||
hashedData := hashutil.Hash(pMsg.Data)
|
hashedData := hashutil.Hash(pMsg.Data)
|
||||||
msgID := base64.RawURLEncoding.EncodeToString(hashedData[:])
|
msgID := string(hashedData[:8])
|
||||||
assert.Equal(t, msgID, msgIDFunction(pMsg), "Got incorrect msg id")
|
assert.Equal(t, msgID, msgIDFunction(pMsg), "Got incorrect msg id")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user