Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/grandpa/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *Service) Start() error {
}
}()

go s.sendNeighbourMessage()
go s.sendNeighbourMessage(neighbourMessageInterval)

return nil
}
Expand Down
23 changes: 14 additions & 9 deletions lib/grandpa/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package grandpa

import (
"fmt"
"strings"
"time"

"github.com/ChainSafe/gossamer/dot/network"
Expand All @@ -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
Comment thread
EclesioMeloJunior marked this conversation as resolved.
Outdated
)

// Handshake is an alias for network.Handshake
Expand All @@ -39,8 +39,9 @@ type GrandpaHandshake struct { //nolint:revive
}

// SubProtocol returns the grandpa sub-protocol
// TODO: should we remove the SubProtocol method from the `Message` interface?
Comment thread
EclesioMeloJunior marked this conversation as resolved.
Outdated
func (*GrandpaHandshake) SubProtocol() string {
return string(grandpaID)
return ""
}

// String formats a BlockAnnounceHandshake as a string
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -175,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 {
Expand Down
6 changes: 1 addition & 5 deletions lib/grandpa/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down