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

decode messages to wire message #4188

Open
wants to merge 2 commits into
base: kishan/feat/network-bridge-rx
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions dot/parachain/network-bridge/collation_protocol_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ import (
)

func decodeCollationMessage(in []byte) (network.NotificationsMessage, error) {
// TODO : Decode a wire message instead #4108
collationMessage := collatorprotocolmessages.CollationProtocol{}

err := scale.Unmarshal(in, &collationMessage)
wireMessage := WireMessage{}
err := wireMessage.SetValue(collatorprotocolmessages.CollationProtocol{})
if err != nil {
return nil, fmt.Errorf("cannot set collation protocol message: %w", err)
}
err = scale.Unmarshal(in, &wireMessage)
if err != nil {
return nil, fmt.Errorf("cannot decode message: %w", err)
}

collationMessageV, err := wireMessage.Value()
if err != nil {
return nil, fmt.Errorf("failed to get collation protocol message value: %w", err)
}
collationMessage, ok := collationMessageV.(collatorprotocolmessages.CollationProtocol)
if !ok {
return nil, fmt.Errorf("failed to cast to collation protocol message")
}
return &collationMessage, nil
}

Expand Down
4 changes: 1 addition & 3 deletions dot/parachain/network-bridge/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ func signingKeyAndIndex(validators []parachaintypes.ValidatorID, ks keystore.Key

func (nbr *NetworkBridgeReceiver) handleCollationMessage(
sender peer.ID, msg network.NotificationsMessage) (bool, error) {

// TODO: this notification has to be a WireMessage. Check if it is a WireMessage
// TODO: Handle ViewUpdate message. ViewUpdate happens on both protocols.
// TODO: Handle ViewUpdate message. ViewUpdate happens on both protocols. #4156 #4155

// we don't propagate collation messages, so it will always be false
propagate := false
Expand Down
5 changes: 5 additions & 0 deletions dot/parachain/network-bridge/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"

"github.com/ChainSafe/gossamer/dot/network"
networkbridgemessages "github.com/ChainSafe/gossamer/dot/parachain/network-bridge/messages"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
)
Expand Down Expand Up @@ -67,6 +68,8 @@ func (nbs *NetworkBridgeSender) processMessage(msg any) error {
return fmt.Errorf("setting wire message: %w", err)
}

wireMessage.SetType(network.CollationMsgType)

for _, to := range msg.To {
err = nbs.net.SendMessage(to, wireMessage)
if err != nil {
Expand All @@ -81,6 +84,8 @@ func (nbs *NetworkBridgeSender) processMessage(msg any) error {
return fmt.Errorf("setting wire message: %w", err)
}

wireMessage.SetType(network.ValidationMsgType)

for _, to := range msg.To {
err = nbs.net.SendMessage(to, wireMessage)
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions dot/parachain/network-bridge/validation_protocol_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ import (
const MaxValidationMessageSize uint64 = 100 * 1024

func decodeValidationMessage(in []byte) (network.NotificationsMessage, error) {
validationMessage := validationprotocol.ValidationProtocol{}
wireMessage := WireMessage{}
err := wireMessage.SetValue(validationprotocol.ValidationProtocol{})
if err != nil {
return nil, fmt.Errorf("cannot set validation protocol message: %w", err)
}

err := scale.Unmarshal(in, &validationMessage)
err = scale.Unmarshal(in, &wireMessage)
if err != nil {
return nil, fmt.Errorf("cannot decode message: %w", err)
}

validationMessageV, err := wireMessage.Value()
if err != nil {
return nil, fmt.Errorf("failed to get validation protocol message value: %w", err)
}
validationMessage, ok := validationMessageV.(validationprotocol.ValidationProtocol)
if !ok {
return nil, fmt.Errorf("failed to cast to validation protocol message")
}

return &validationMessage, nil
}

Expand Down
11 changes: 8 additions & 3 deletions dot/parachain/network-bridge/wire_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"reflect"
"sort"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"

"github.com/ChainSafe/gossamer/dot/network"
collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
validationprotocol "github.com/ChainSafe/gossamer/dot/parachain/validation-protocol"
)

type WireMessage struct {
inner any
inner any
messageType network.MessageType
}

type WireMessageValues interface {
Expand Down Expand Up @@ -67,9 +68,13 @@ func (mvdt WireMessage) ValueAt(index uint) (value any, err error) {
return nil, scale.ErrUnknownVaryingDataTypeValue
}

func (w *WireMessage) SetType(messageType network.MessageType) {
w.messageType = messageType
}

func (w WireMessage) Type() network.MessageType {
// TODO: create a wire message type and return that #4108
return network.CollationMsgType
return w.messageType
}

func (w WireMessage) Hash() (common.Hash, error) {
Expand Down
Loading