Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dot/parachain): sender side of network bridge #3891

Open
wants to merge 18 commits into
base: feat/parachain
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ func (s *Service) ReportPeer(change peerset.ReputationChange, p peer.ID) {
s.host.cm.peerSetHandler.ReportPeer(change, p)
}

func (s *Service) DisconnectPeer(setID int, p peer.ID) {
s.host.cm.peerSetHandler.DisconnectPeer(setID, p)
}

func (s *Service) startPeerSetHandler() {
s.host.cm.peerSetHandler.Start(s.ctx)
// wait for peerSetHandler to start.
Expand Down
1 change: 1 addition & 0 deletions dot/network/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type PeerSetHandler interface {
PeerAdd
PeerRemove
Peer
DisconnectPeer(setID int, peers ...peer.ID)
}

// PeerAdd is the interface used by the PeerSetHandler to add peers in peerSet.
Expand Down
45 changes: 28 additions & 17 deletions dot/parachain/collator-protocol/collator_side.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ChainSafe/gossamer/dot/network"
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
networkbridgemessages "github.com/ChainSafe/gossamer/dot/parachain/network-bridge/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/libp2p/go-libp2p/core/peer"
Expand All @@ -21,7 +22,8 @@ const propagate = false
var ErrNotExpectedOnCollatorSide = errors.New("message is not expected on the collator side of the protocol")

type CollatorProtocolCollatorSide struct {
net Network
SubSystemToOverseer chan<- any

collatingOn parachaintypes.ParaID //nolint
}

Expand Down Expand Up @@ -73,7 +75,7 @@ func (cpcs CollatorProtocolCollatorSide) handleCollationMessage(
network.CollationMsgType, msg.Type())
}

collatorProtocol, ok := msg.(*CollationProtocol)
collatorProtocol, ok := msg.(*collatorprotocolmessages.CollationProtocol)
if !ok {
return propagate, fmt.Errorf(
"failed to cast into collator protocol message, expected: *CollationProtocol, got: %T",
Expand All @@ -84,7 +86,7 @@ func (cpcs CollatorProtocolCollatorSide) handleCollationMessage(
if err != nil {
return propagate, fmt.Errorf("getting collator protocol value: %w", err)
}
collatorProtocolMessage, ok := collatorProtocolVal.(CollatorProtocolMessage)
collatorProtocolMessage, ok := collatorProtocolVal.(collatorprotocolmessages.CollatorProtocolMessage)
if !ok {
return propagate, errors.New("expected value to be collator protocol message")
}
Expand All @@ -95,28 +97,37 @@ func (cpcs CollatorProtocolCollatorSide) handleCollationMessage(
}

switch collatorProtocolMessageV.(type) {
case Declare:
case collatorprotocolmessages.Declare:
logger.Errorf("unexpected collation declare message from peer %s, decreasing its reputation", sender)
cpcs.net.ReportPeer(peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
}, sender)
case AdvertiseCollation:

cpcs.SubSystemToOverseer <- networkbridgemessages.ReportPeer{
PeerID: sender,
ReputationChange: peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
},
}
case collatorprotocolmessages.AdvertiseCollation:
logger.Errorf("unexpected collation advertise collation message from peer %s, decreasing its reputation", sender)
cpcs.net.ReportPeer(peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
}, sender)
case CollationSeconded:

cpcs.SubSystemToOverseer <- networkbridgemessages.ReportPeer{
PeerID: sender,
ReputationChange: peerset.ReputationChange{
Value: peerset.UnexpectedMessageValue,
Reason: peerset.UnexpectedMessageReason,
},
}
case collatorprotocolmessages.CollationSeconded:
// TODO: handle collation seconded message #3824
}

return propagate, nil
}

func RegisterCollatorSide(net Network, protocolID protocol.ID) (*CollatorProtocolCollatorSide, error) {
func RegisterCollatorSide(net Network, protocolID protocol.ID, SubSystemToOverseer chan<- any,
) (*CollatorProtocolCollatorSide, error) {
cpcs := CollatorProtocolCollatorSide{
net: net,
SubSystemToOverseer: SubSystemToOverseer,
}

// register collation protocol
Expand All @@ -129,7 +140,7 @@ func RegisterCollatorSide(net Network, protocolID protocol.ID) (*CollatorProtoco
decodeCollationMessage,
cpcs.handleCollationMessage,
nil,
MaxCollationMessageSize,
collatorprotocolmessages.MaxCollationMessageSize,
)
if err != nil {
return nil, fmt.Errorf("registering collation protocol, new: %w", err)
Expand Down