From 22bcfd2c340a8cb682468e5a7112404aee1e3849 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 22 Sep 2020 23:23:33 +0800 Subject: [PATCH] Update Message ID (#7304) * shorten message id * Merge refs/heads/master into updateMessageID * Merge refs/heads/master into updateMessageID --- beacon-chain/p2p/pubsub.go | 7 ++----- beacon-chain/p2p/pubsub_test.go | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/beacon-chain/p2p/pubsub.go b/beacon-chain/p2p/pubsub.go index 75f6795a9..736177583 100644 --- a/beacon-chain/p2p/pubsub.go +++ b/beacon-chain/p2p/pubsub.go @@ -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() { diff --git a/beacon-chain/p2p/pubsub_test.go b/beacon-chain/p2p/pubsub_test.go index fb76de182..8c9b95dc1 100644 --- a/beacon-chain/p2p/pubsub_test.go +++ b/beacon-chain/p2p/pubsub_test.go @@ -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") }