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

Fix unreadable message errors #1585

Merged
merged 8 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
89 changes: 89 additions & 0 deletions message/internal_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package message

import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -65,6 +66,11 @@ type GetStateSummaryFrontierFailed struct {
RequestID uint32 `json:"request_id,omitempty"`
}

func (m *GetStateSummaryFrontierFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d",
m.ChainID, m.RequestID)
}

func (m *GetStateSummaryFrontierFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -94,6 +100,11 @@ type GetAcceptedStateSummaryFailed struct {
RequestID uint32 `json:"request_id,omitempty"`
}

func (m *GetAcceptedStateSummaryFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d",
m.ChainID, m.RequestID)
}

func (m *GetAcceptedStateSummaryFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -124,6 +135,11 @@ type GetAcceptedFrontierFailed struct {
EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (m *GetAcceptedFrontierFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d EngineType: %s",
m.ChainID, m.RequestID, m.EngineType)
}

func (m *GetAcceptedFrontierFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -160,6 +176,11 @@ type GetAcceptedFailed struct {
EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (m *GetAcceptedFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d EngineType: %s",
m.ChainID, m.RequestID, m.EngineType)
}

func (m *GetAcceptedFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -196,6 +217,11 @@ type GetAncestorsFailed struct {
EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (m *GetAncestorsFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d EngineType: %s",
m.ChainID, m.RequestID, m.EngineType)
}

func (m *GetAncestorsFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -232,6 +258,11 @@ type GetFailed struct {
EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (m *GetFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d EngineType: %s",
m.ChainID, m.RequestID, m.EngineType)
}

func (m *GetFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -268,6 +299,11 @@ type QueryFailed struct {
EngineType p2p.EngineType `json:"engine_type,omitempty"`
}

func (m *QueryFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d EngineType: %s",
m.ChainID, m.RequestID, m.EngineType)
}

func (m *QueryFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -303,6 +339,11 @@ type AppRequestFailed struct {
RequestID uint32 `json:"request_id,omitempty"`
}

func (m *AppRequestFailed) String() string {
return fmt.Sprintf("ChainID: %s RequestID: %d",
m.ChainID, m.RequestID)
}

func (m *AppRequestFailed) GetChainId() []byte {
return m.ChainID[:]
}
Expand Down Expand Up @@ -334,6 +375,12 @@ type CrossChainAppRequest struct {
Message []byte `json:"message,omitempty"`
}

func (m *CrossChainAppRequest) String() string {
return fmt.Sprintf(
"SourceChainID: %s DestinationChainID: %s EngineType: %d Message: %s",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.SourceChainID, m.DestinationChainID, m.RequestID, m.Message)
}

func (m *CrossChainAppRequest) GetSourceChainID() ids.ID {
return m.SourceChainID
}
Expand Down Expand Up @@ -373,6 +420,12 @@ type CrossChainAppRequestFailed struct {
RequestID uint32 `json:"request_id,omitempty"`
}

func (m *CrossChainAppRequestFailed) String() string {
return fmt.Sprintf(
"SourceChainID: %s DestinationChainID: %s EngineType: %d",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.SourceChainID, m.DestinationChainID, m.RequestID)
}

func (m *CrossChainAppRequestFailed) GetSourceChainID() ids.ID {
return m.SourceChainID
}
Expand Down Expand Up @@ -410,6 +463,12 @@ type CrossChainAppResponse struct {
Message []byte `json:"message,omitempty"`
}

func (m *CrossChainAppResponse) String() string {
return fmt.Sprintf(
"SourceChainID: %v DestinationChainID: %v EngineType: %v Message: %v",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.SourceChainID, m.DestinationChainID, m.RequestID, m.Message)
}

func (m *CrossChainAppResponse) GetSourceChainID() ids.ID {
return m.SourceChainID
}
Expand Down Expand Up @@ -446,6 +505,12 @@ type Connected struct {
NodeVersion *version.Application `json:"node_version,omitempty"`
}

func (m *Connected) String() string {
return fmt.Sprintf(
"NodeVersion: %v",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.NodeVersion)
}

func InternalConnected(nodeID ids.NodeID, nodeVersion *version.Application) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
Expand All @@ -463,6 +528,12 @@ type ConnectedSubnet struct {
SubnetID ids.ID `json:"subnet_id,omitempty"`
}

func (m *ConnectedSubnet) String() string {
return fmt.Sprintf(
"SubnetID: %v",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.SubnetID)
}

// InternalConnectedSubnet returns a message that indicates the node with [nodeID] is
// connected to the subnet with the given [subnetID].
func InternalConnectedSubnet(nodeID ids.NodeID, subnetID ids.ID) InboundMessage {
Expand All @@ -478,6 +549,10 @@ func InternalConnectedSubnet(nodeID ids.NodeID, subnetID ids.ID) InboundMessage

type Disconnected struct{}

func (_ Disconnected) String() string {
morrisettathena marked this conversation as resolved.
Show resolved Hide resolved
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a late question: Why some of these are empty?

}

func InternalDisconnected(nodeID ids.NodeID) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
Expand All @@ -491,6 +566,12 @@ type VMMessage struct {
Notification uint32 `json:"notification,omitempty"`
}

func (m *VMMessage) String() string {
return fmt.Sprintf(
"Notification: %v",
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
m.Notification)
}

func InternalVMMessage(
nodeID ids.NodeID,
notification uint32,
Expand All @@ -507,6 +588,10 @@ func InternalVMMessage(

type GossipRequest struct{}

func (_ GossipRequest) String() string {
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
return ""
}

func InternalGossipRequest(
nodeID ids.NodeID,
) InboundMessage {
Expand All @@ -520,6 +605,10 @@ func InternalGossipRequest(

type Timeout struct{}

func (_ Timeout) String() string {
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
return ""
}

func InternalTimeout(nodeID ids.NodeID) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
Expand Down
14 changes: 11 additions & 3 deletions message/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ var (

// InboundMessage represents a set of fields for an inbound message
type InboundMessage interface {
fmt.Stringer
// NodeID returns the ID of the node that sent this message
NodeID() ids.NodeID
// Op returns the op that describes this message type
Op() Op
// Message returns the message that was sent
Message() any
Message() fmt.Stringer
// Expiration returns the time that the sender will have already timed out
// this request
Expiration() time.Time
Expand All @@ -49,12 +50,14 @@ type InboundMessage interface {
// BytesSavedCompression returns the number of bytes that this message saved
// due to being compressed
BytesSavedCompression() int
// Returns string representation of message
String() string
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
}

type inboundMessage struct {
nodeID ids.NodeID
op Op
message any
message fmt.Stringer
expiration time.Time
onFinishedHandling func()
bytesSavedCompression int
Expand All @@ -68,7 +71,7 @@ func (m *inboundMessage) Op() Op {
return m.op
}

func (m *inboundMessage) Message() any {
func (m *inboundMessage) Message() fmt.Stringer {
return m.message
}

Expand All @@ -86,6 +89,11 @@ func (m *inboundMessage) BytesSavedCompression() int {
return m.bytesSavedCompression
}

func (m *inboundMessage) String() string {
return fmt.Sprintf("NodeID: %s Op: %s Message: %s",
m.nodeID, m.op, m.message)
}

// OutboundMessage represents a set of fields for an outbound message that can
// be serialized into a byte stream
type OutboundMessage interface {
Expand Down
2 changes: 1 addition & 1 deletion message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (op Op) String() string {
}
}

func Unwrap(m *p2p.Message) (interface{}, error) {
func Unwrap(m *p2p.Message) (fmt.Stringer, error) {
switch msg := m.GetMessage().(type) {
// Handshake:
case *p2p.Message_Ping:
Expand Down
2 changes: 1 addition & 1 deletion snow/networking/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (h *handler) dispatchChans(ctx context.Context) {

if err := h.handleChanMsg(msg); err != nil {
h.StopWithError(ctx, fmt.Errorf(
"%w while processing async message: %s",
"%w while processing chan message: %s",
err,
msg,
))
Expand Down
4 changes: 4 additions & 0 deletions snow/networking/handler/message_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type Message struct {
EngineType p2p.EngineType
}

func (m Message) String() string {
return m.Message().String()
}

StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
type MessageQueue interface {
// Add a message.
//
Expand Down