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

Add AppError to Sender interface #2737

Merged
merged 5 commits into from
Feb 19, 2024
Merged
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
15 changes: 15 additions & 0 deletions message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var (
PutOp,
ChitsOp,
AppResponseOp,
AppErrorOp,
}
// AppGossip is the only message that is sent unrequested without the
// expectation of a response
Expand All @@ -115,7 +116,6 @@ var (
GetAncestorsFailedOp,
GetFailedOp,
QueryFailedOp,
AppErrorOp,
CrossChainAppRequestOp,
CrossChainAppErrorOp,
CrossChainAppResponseOp,
Expand Down
24 changes: 24 additions & 0 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ type OutboundMsgBuilder interface {
msg []byte,
) (OutboundMessage, error)

AppError(
chainID ids.ID,
requestID uint32,
errorCode int32,
errorMessage string,
) (OutboundMessage, error)

AppGossip(
chainID ids.ID,
msg []byte,
Expand Down Expand Up @@ -710,6 +717,23 @@ func (b *outMsgBuilder) AppResponse(chainID ids.ID, requestID uint32, msg []byte
)
}

func (b *outMsgBuilder) AppError(chainID ids.ID, requestID uint32, errorCode int32, errorMessage string) (OutboundMessage, error) {
return b.builder.createOutbound(
&p2p.Message{
Message: &p2p.Message_AppError{
AppError: &p2p.AppError{
ChainId: chainID[:],
RequestId: requestID,
ErrorCode: errorCode,
ErrorMessage: errorMessage,
},
},
},
b.compressionType,
false,
)
}

func (b *outMsgBuilder) AppGossip(chainID ids.ID, msg []byte) (OutboundMessage, error) {
return b.builder.createOutbound(
&p2p.Message{
Expand Down
24 changes: 24 additions & 0 deletions proto/appsender/appsender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ option go_package = "github.com/ava-labs/avalanchego/proto/pb/appsender";
service AppSender {
rpc SendAppRequest(SendAppRequestMsg) returns (google.protobuf.Empty);
rpc SendAppResponse(SendAppResponseMsg) returns (google.protobuf.Empty);
rpc SendAppError(SendAppErrorMsg) returns (google.protobuf.Empty);
rpc SendAppGossip(SendAppGossipMsg) returns (google.protobuf.Empty);
rpc SendAppGossipSpecific(SendAppGossipSpecificMsg) returns (google.protobuf.Empty);

rpc SendCrossChainAppRequest(SendCrossChainAppRequestMsg) returns (google.protobuf.Empty);
rpc SendCrossChainAppResponse(SendCrossChainAppResponseMsg) returns (google.protobuf.Empty);
rpc SendCrossChainAppError(SendCrossChainAppErrorMsg) returns (google.protobuf.Empty);
}

message SendAppRequestMsg {
Expand All @@ -34,6 +36,17 @@ message SendAppResponseMsg {
bytes response = 3;
}

message SendAppErrorMsg {
// The node to send a response to
bytes node_id = 1;
// ID of this request
uint32 request_id = 2;
// Application-defined error code
sint32 error_code = 3;
// Application-defined error message
string error_message = 4;
}

message SendAppGossipMsg {
// The message body
bytes msg = 1;
Expand Down Expand Up @@ -63,3 +76,14 @@ message SendCrossChainAppResponseMsg {
// The response body
bytes response = 3;
}

message SendCrossChainAppErrorMsg {
// The chain to send a response to
bytes chain_id = 1;
// ID of this request
uint32 request_id = 2;
// Application-defined error code
sint32 error_code = 3;
// Application-defined error message
string error_message = 4;
}
Loading
Loading