From 9ce45c1d9e105871d581bbf316c8c37fea2d77e8 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Fri, 15 Jul 2022 15:40:29 -0400 Subject: [PATCH 1/6] feat: update grandpa protocol ID --- lib/grandpa/network.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index 50fffe956e..1966aab7a7 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -5,6 +5,7 @@ package grandpa import ( "fmt" + "strings" "time" "github.com/ChainSafe/gossamer/dot/network" @@ -15,10 +16,9 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" ) -var ( - grandpaID protocol.ID = "/paritytech/grandpa/1" - messageID = network.ConsensusMsgType - neighbourMessageInterval = time.Minute * 5 +const ( + grandpaID1 = "grandpa/1" + neighbourMessageInterval = time.Minute * 5 ) // Handshake is an alias for network.Handshake @@ -38,9 +38,10 @@ type GrandpaHandshake struct { //nolint:revive Roles byte } +// TODO: should we remove the SubProtocol mehtod from the `Message` interface? // SubProtocol returns the grandpa sub-protocol func (*GrandpaHandshake) SubProtocol() string { - return string(grandpaID) + return "" } // String formats a BlockAnnounceHandshake as a string @@ -74,9 +75,13 @@ func (*GrandpaHandshake) IsHandshake() bool { } func (s *Service) registerProtocol() error { + genesisHash := s.blockState.GenesisHash().String() + genesisHash = strings.TrimPrefix(genesisHash, "0x") + grandpaProtocolID := fmt.Sprintf("/%s/%s", genesisHash, grandpaID1) + return s.network.RegisterNotificationsProtocol( - grandpaID, - messageID, + protocol.ID(grandpaProtocolID), + network.ConsensusMsgType, s.getHandshake, s.decodeHandshake, s.validateHandshake, From cae11f58fd61ad6f186ef65ab10e520a009a525a Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 19 Jul 2022 08:37:36 -0400 Subject: [PATCH 2/6] chore: quick fix typo --- lib/grandpa/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index 1966aab7a7..7f145b91f7 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -38,7 +38,7 @@ type GrandpaHandshake struct { //nolint:revive Roles byte } -// TODO: should we remove the SubProtocol mehtod from the `Message` interface? +// TODO: should we remove the SubProtocol method from the `Message` interface? // SubProtocol returns the grandpa sub-protocol func (*GrandpaHandshake) SubProtocol() string { return "" From f823c09d971a459590ea9fa099f9dcba9fd7711b Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 19 Jul 2022 11:52:54 -0400 Subject: [PATCH 3/6] chore: solve test failing at grandpa pkg --- lib/grandpa/grandpa.go | 2 +- lib/grandpa/network.go | 4 ++-- lib/grandpa/network_test.go | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/grandpa/grandpa.go b/lib/grandpa/grandpa.go index 058ce2117b..7843cc5066 100644 --- a/lib/grandpa/grandpa.go +++ b/lib/grandpa/grandpa.go @@ -200,7 +200,7 @@ func (s *Service) Start() error { } }() - go s.sendNeighbourMessage() + go s.sendNeighbourMessage(neighbourMessageInterval) return nil } diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index 7f145b91f7..2b758565ae 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -180,8 +180,8 @@ func (s *Service) sendMessage(msg GrandpaMessage) error { return nil } -func (s *Service) sendNeighbourMessage() { - t := time.NewTicker(neighbourMessageInterval) +func (s *Service) sendNeighbourMessage(interval time.Duration) { + t := time.NewTicker(interval) defer t.Stop() for { select { diff --git a/lib/grandpa/network_test.go b/lib/grandpa/network_test.go index 92e8c4cc1f..4684cbf6d8 100644 --- a/lib/grandpa/network_test.go +++ b/lib/grandpa/network_test.go @@ -80,11 +80,7 @@ func TestHandleNetworkMessage(t *testing.T) { func TestSendNeighbourMessage(t *testing.T) { gs, st := newTestService(t) - neighbourMessageInterval = time.Second - defer func() { - neighbourMessageInterval = time.Minute * 5 - }() - go gs.sendNeighbourMessage() + go gs.sendNeighbourMessage(time.Second) digest := types.NewDigest() prd, err := types.NewBabeSecondaryPlainPreDigest(0, 1).ToPreRuntimeDigest() From 103cffa475467883f0a80d0adfd40a05addd1ca1 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Tue, 19 Jul 2022 11:57:12 -0400 Subject: [PATCH 4/6] chore: solve lint wanrs --- lib/grandpa/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index 2b758565ae..ff87c24f0e 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -38,8 +38,8 @@ type GrandpaHandshake struct { //nolint:revive Roles byte } -// TODO: should we remove the SubProtocol method from the `Message` interface? // SubProtocol returns the grandpa sub-protocol +// TODO: should we remove the SubProtocol method from the `Message` interface? func (*GrandpaHandshake) SubProtocol() string { return "" } From 94bf8d990c3731b0b17f7f41c33186136925022a Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Fri, 22 Jul 2022 11:30:05 -0400 Subject: [PATCH 5/6] chore: normalizing time char order --- lib/grandpa/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index ff87c24f0e..0db9ba050d 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -18,7 +18,7 @@ import ( const ( grandpaID1 = "grandpa/1" - neighbourMessageInterval = time.Minute * 5 + neighbourMessageInterval = 5 * time.Minute ) // Handshake is an alias for network.Handshake From a380a089f4122015588d7d8de2e90d6a8a8d8320 Mon Sep 17 00:00:00 2001 From: EclesioMeloJunior Date: Mon, 25 Jul 2022 16:13:43 -0400 Subject: [PATCH 6/6] chore: remove `SubProtocol` method from `Message` interface --- dot/network/block_announce.go | 10 ---------- dot/network/light.go | 10 ---------- dot/network/message.go | 16 ---------------- dot/network/transaction.go | 10 ---------- lib/grandpa/network.go | 6 ------ 5 files changed, 52 deletions(-) diff --git a/dot/network/block_announce.go b/dot/network/block_announce.go index 8c5771b67e..033ded1e4b 100644 --- a/dot/network/block_announce.go +++ b/dot/network/block_announce.go @@ -30,11 +30,6 @@ type BlockAnnounceMessage struct { BestBlock bool } -// SubProtocol returns the block-announces sub-protocol -func (*BlockAnnounceMessage) SubProtocol() string { - return blockAnnounceID -} - // Type returns BlockAnnounceMsgType func (*BlockAnnounceMessage) Type() byte { return BlockAnnounceMsgType @@ -114,11 +109,6 @@ type BlockAnnounceHandshake struct { GenesisHash common.Hash } -// SubProtocol returns the block-announces sub-protocol -func (*BlockAnnounceHandshake) SubProtocol() string { - return blockAnnounceID -} - // String formats a BlockAnnounceHandshake as a string func (hs *BlockAnnounceHandshake) String() string { return fmt.Sprintf("BlockAnnounceHandshake Roles=%d BestBlockNumber=%d BestBlockHash=%s GenesisHash=%s", diff --git a/dot/network/light.go b/dot/network/light.go index 15a009194d..e1f0839fc7 100644 --- a/dot/network/light.go +++ b/dot/network/light.go @@ -125,11 +125,6 @@ func newRequest() *request { } } -// SubProtocol returns the light sub-protocol -func (l *LightRequest) SubProtocol() string { - return lightID -} - // Encode encodes a LightRequest message using SCALE and appends the type byte to the start func (l *LightRequest) Encode() ([]byte, error) { req := request{ @@ -206,11 +201,6 @@ func newResponse() *response { } } -// SubProtocol returns the light sub-protocol -func (l *LightResponse) SubProtocol() string { - return lightID -} - // Encode encodes a LightResponse message using SCALE and appends the type byte to the start func (l *LightResponse) Encode() ([]byte, error) { resp := response{ diff --git a/dot/network/message.go b/dot/network/message.go index 8c26974138..2a9db0d4f9 100644 --- a/dot/network/message.go +++ b/dot/network/message.go @@ -26,7 +26,6 @@ const ( // Message must be implemented by all network messages type Message interface { - SubProtocol() string Encode() ([]byte, error) Decode([]byte) error String() string @@ -82,11 +81,6 @@ type BlockRequestMessage struct { Max *uint32 } -// SubProtocol returns the sync sub-protocol -func (bm *BlockRequestMessage) SubProtocol() string { - return syncID -} - // String formats a BlockRequestMessage as a string func (bm *BlockRequestMessage) String() string { hash := common.Hash{} @@ -207,11 +201,6 @@ type BlockResponseMessage struct { BlockData []*types.BlockData } -// SubProtocol returns the sync sub-protocol -func (bm *BlockResponseMessage) SubProtocol() string { - return syncID -} - // String formats a BlockResponseMessage as a string func (bm *BlockResponseMessage) String() string { if bm == nil { @@ -362,11 +351,6 @@ type ConsensusMessage struct { Data []byte } -// SubProtocol returns the empty, since consensus message sub-protocol is determined by the package using it -func (cm *ConsensusMessage) SubProtocol() string { - return "" -} - // Type returns ConsensusMsgType func (cm *ConsensusMessage) Type() byte { return ConsensusMsgType diff --git a/dot/network/transaction.go b/dot/network/transaction.go index e8a41087d4..e22e70344b 100644 --- a/dot/network/transaction.go +++ b/dot/network/transaction.go @@ -28,11 +28,6 @@ type TransactionMessage struct { Extrinsics []types.Extrinsic } -// SubProtocol returns the transactions sub-protocol -func (*TransactionMessage) SubProtocol() string { - return transactionsID -} - // Type returns TransactionMsgType func (*TransactionMessage) Type() byte { return TransactionMsgType @@ -69,11 +64,6 @@ func (*TransactionMessage) IsHandshake() bool { type transactionHandshake struct{} -// SubProtocol returns the transactions sub-protocol -func (*transactionHandshake) SubProtocol() string { - return transactionsID -} - // String formats a transactionHandshake as a string func (*transactionHandshake) String() string { return "transactionHandshake" diff --git a/lib/grandpa/network.go b/lib/grandpa/network.go index 0db9ba050d..84d40e2df1 100644 --- a/lib/grandpa/network.go +++ b/lib/grandpa/network.go @@ -38,12 +38,6 @@ type GrandpaHandshake struct { //nolint:revive Roles byte } -// SubProtocol returns the grandpa sub-protocol -// TODO: should we remove the SubProtocol method from the `Message` interface? -func (*GrandpaHandshake) SubProtocol() string { - return "" -} - // String formats a BlockAnnounceHandshake as a string func (hs *GrandpaHandshake) String() string { return fmt.Sprintf("GrandpaHandshake Roles=%d", hs.Roles)