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

Remove cross-chain requests #3277

Merged
merged 27 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/DataDog/zstd v1.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/antithesishq/antithesis-sdk-go v0.3.8
github.com/ava-labs/coreth v0.13.8-fix-genesis-upgrade
github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
github.com/antithesishq/antithesis-sdk-go v0.3.8 h1:OvGoHxIcOXFJLyn9IJQ5DzByZ3YVAWNBc394ObzDRb8=
github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/coreth v0.13.8-fix-genesis-upgrade h1:xWsvSGtZcGna3B2BLU2BvK3qskbcc9ZNtgC0ck91CkI=
github.com/ava-labs/coreth v0.13.8-fix-genesis-upgrade/go.mod h1:Ouul9dJouniUIJVX1gDqx8CrHyGvmwZkK28mrgKb/4I=
github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180 h1:6aIHp7wbyGVYdhHVQUbG7BEcbCMEQ5SYopPPJyipyvk=
github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240813194342-7635a96aa180/go.mod h1:/wNBVq7J7wlC2Kbov7kk6LV5xZvau7VF9zwTVOeyAjY=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95 h1:dOVbtdnZL++pENdTCNZ1nu41eYDQkTML4sWebDnnq8c=
github.com/ava-labs/ledger-avalanche/go v0.0.0-20240610153809-9c955cc90a95/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
Expand Down
158 changes: 0 additions & 158 deletions message/internal_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package message

import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/proto/pb/p2p"
Expand Down Expand Up @@ -48,21 +47,6 @@ var (
_ chainIDGetter = (*QueryFailed)(nil)
_ requestIDGetter = (*QueryFailed)(nil)

_ fmt.Stringer = (*CrossChainAppRequest)(nil)
_ sourceChainIDGetter = (*CrossChainAppRequest)(nil)
_ chainIDGetter = (*CrossChainAppRequest)(nil)
_ requestIDGetter = (*CrossChainAppRequest)(nil)

_ fmt.Stringer = (*CrossChainAppRequestFailed)(nil)
_ sourceChainIDGetter = (*CrossChainAppRequestFailed)(nil)
_ chainIDGetter = (*CrossChainAppRequestFailed)(nil)
_ requestIDGetter = (*CrossChainAppRequestFailed)(nil)

_ fmt.Stringer = (*CrossChainAppResponse)(nil)
_ sourceChainIDGetter = (*CrossChainAppResponse)(nil)
_ chainIDGetter = (*CrossChainAppResponse)(nil)
_ requestIDGetter = (*CrossChainAppResponse)(nil)

_ fmt.Stringer = (*Disconnected)(nil)

_ fmt.Stringer = (*GossipRequest)(nil)
Expand Down Expand Up @@ -329,148 +313,6 @@ func InternalQueryFailed(
}
}

type CrossChainAppRequest struct {
SourceChainID ids.ID `json:"source_chain_id,omitempty"`
DestinationChainID ids.ID `json:"destination_chain_id,omitempty"`
RequestID uint32 `json:"request_id,omitempty"`
Message []byte `json:"message,omitempty"`
}

func (m *CrossChainAppRequest) String() string {
return fmt.Sprintf(
"SourceChainID: %s DestinationChainID: %s RequestID: %d Message: 0x%x",
m.SourceChainID, m.DestinationChainID, m.RequestID, m.Message,
)
}

func (m *CrossChainAppRequest) GetSourceChainID() ids.ID {
return m.SourceChainID
}

func (m *CrossChainAppRequest) GetChainId() []byte {
return m.DestinationChainID[:]
}

func (m *CrossChainAppRequest) GetRequestId() uint32 {
return m.RequestID
}

func InternalCrossChainAppRequest(
nodeID ids.NodeID,
sourceChainID ids.ID,
destinationChainID ids.ID,
requestID uint32,
deadline time.Duration,
msg []byte,
) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
op: CrossChainAppRequestOp,
message: &CrossChainAppRequest{
SourceChainID: sourceChainID,
DestinationChainID: destinationChainID,
RequestID: requestID,
Message: msg,
},
expiration: time.Now().Add(deadline),
}
}

type CrossChainAppRequestFailed struct {
SourceChainID ids.ID `json:"source_chain_id,omitempty"`
DestinationChainID ids.ID `json:"destination_chain_id,omitempty"`
RequestID uint32 `json:"request_id,omitempty"`
ErrorCode int32 `json:"error_code,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
}

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

func (m *CrossChainAppRequestFailed) GetSourceChainID() ids.ID {
return m.SourceChainID
}

func (m *CrossChainAppRequestFailed) GetChainId() []byte {
return m.DestinationChainID[:]
}

func (m *CrossChainAppRequestFailed) GetRequestId() uint32 {
return m.RequestID
}

func InternalCrossChainAppError(
nodeID ids.NodeID,
sourceChainID ids.ID,
destinationChainID ids.ID,
requestID uint32,
errorCode int32,
errorMessage string,
) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
op: CrossChainAppErrorOp,
message: &CrossChainAppRequestFailed{
SourceChainID: sourceChainID,
DestinationChainID: destinationChainID,
RequestID: requestID,
ErrorCode: errorCode,
ErrorMessage: errorMessage,
},
expiration: mockable.MaxTime,
}
}

type CrossChainAppResponse struct {
SourceChainID ids.ID `json:"source_chain_id,omitempty"`
DestinationChainID ids.ID `json:"destination_chain_id,omitempty"`
RequestID uint32 `json:"request_id,omitempty"`
Message []byte `json:"message,omitempty"`
}

func (m *CrossChainAppResponse) String() string {
return fmt.Sprintf(
"SourceChainID: %s DestinationChainID: %s RequestID: %d Message: 0x%x",
m.SourceChainID, m.DestinationChainID, m.RequestID, m.Message,
)
}

func (m *CrossChainAppResponse) GetSourceChainID() ids.ID {
return m.SourceChainID
}

func (m *CrossChainAppResponse) GetChainId() []byte {
return m.DestinationChainID[:]
}

func (m *CrossChainAppResponse) GetRequestId() uint32 {
return m.RequestID
}

func InternalCrossChainAppResponse(
nodeID ids.NodeID,
sourceChainID ids.ID,
destinationChainID ids.ID,
requestID uint32,
msg []byte,
) InboundMessage {
return &inboundMessage{
nodeID: nodeID,
op: CrossChainAppResponseOp,
message: &CrossChainAppResponse{
SourceChainID: sourceChainID,
DestinationChainID: destinationChainID,
RequestID: requestID,
Message: msg,
},
expiration: mockable.MaxTime,
}
}

type Connected struct {
NodeVersion *version.Application `json:"node_version,omitempty"`
}
Expand Down
22 changes: 1 addition & 21 deletions message/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ const (
AppErrorOp
AppResponseOp
AppGossipOp
// Cross chain:
CrossChainAppRequestOp
CrossChainAppErrorOp
CrossChainAppResponseOp
// Internal:
ConnectedOp
ConnectedSubnetOp
Expand Down Expand Up @@ -116,9 +112,6 @@ var (
GetAncestorsFailedOp,
GetFailedOp,
QueryFailedOp,
CrossChainAppRequestOp,
CrossChainAppErrorOp,
CrossChainAppResponseOp,
ConnectedOp,
ConnectedSubnetOp,
DisconnectedOp,
Expand Down Expand Up @@ -168,10 +161,6 @@ var (
AppErrorOp,
AppGossipOp,
AppResponseOp,
// Cross chain
CrossChainAppRequestOp,
CrossChainAppErrorOp,
CrossChainAppResponseOp,
}

FailedToResponseOps = map[Op]Op{
Expand All @@ -183,7 +172,6 @@ var (
GetFailedOp: PutOp,
QueryFailedOp: ChitsOp,
AppErrorOp: AppResponseOp,
CrossChainAppErrorOp: CrossChainAppResponseOp,
}
UnrequestedOps = set.Of(
GetAcceptedFrontierOp,
Expand All @@ -194,7 +182,6 @@ var (
PullQueryOp,
AppRequestOp,
AppGossipOp,
CrossChainAppRequestOp,
GetStateSummaryFrontierOp,
GetAcceptedStateSummaryOp,
)
Expand Down Expand Up @@ -271,14 +258,7 @@ func (op Op) String() string {
return "app_response"
case AppGossipOp:
return "app_gossip"
// Cross chain
case CrossChainAppRequestOp:
return "cross_chain_app_request"
case CrossChainAppErrorOp:
return "cross_chain_app_error"
case CrossChainAppResponseOp:
return "cross_chain_app_response"
// Internal
// Internal
case ConnectedOp:
return "connected"
case ConnectedSubnetOp:
Expand Down
62 changes: 0 additions & 62 deletions network/p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ type AppResponseCallback func(
err error,
)

// CrossChainAppResponseCallback is called upon receiving an
// CrossChainAppResponse for a CrossChainAppRequest issued by Client.
// Callers should check [err] to see whether the AppRequest failed or not.
type CrossChainAppResponseCallback func(
ctx context.Context,
chainID ids.ID,
responseBytes []byte,
err error,
)

type Client struct {
handlerID uint64
handlerIDStr string
Expand Down Expand Up @@ -140,58 +130,6 @@ func (c *Client) AppGossip(
)
}

// CrossChainAppRequest sends a cross chain app request to another vm.
// [onResponse] is invoked upon an error or a response.
func (c *Client) CrossChainAppRequest(
ctx context.Context,
chainID ids.ID,
appRequestBytes []byte,
onResponse CrossChainAppResponseCallback,
) error {
// Cancellation is removed from this context to avoid erroring unexpectedly.
// SendCrossChainAppRequest should be non-blocking and any error other than
// context cancellation is unexpected.
//
// This guarantees that the router should never receive an unexpected
// CrossChainAppResponse.
ctxWithoutCancel := context.WithoutCancel(ctx)

c.router.lock.Lock()
defer c.router.lock.Unlock()

requestID := c.router.requestID
if _, ok := c.router.pendingCrossChainAppRequests[requestID]; ok {
return fmt.Errorf(
"failed to issue request with request id %d: %w",
requestID,
ErrRequestPending,
)
}

if err := c.sender.SendCrossChainAppRequest(
ctxWithoutCancel,
chainID,
requestID,
PrefixMessage(c.handlerPrefix, appRequestBytes),
); err != nil {
c.router.log.Error("unexpected error when sending message",
zap.Stringer("op", message.CrossChainAppRequestOp),
zap.Stringer("chainID", chainID),
zap.Uint32("requestID", requestID),
zap.Error(err),
)
return err
}

c.router.pendingCrossChainAppRequests[requestID] = pendingCrossChainAppRequest{
handlerID: c.handlerIDStr,
callback: onResponse,
}
c.router.requestID += 2

return nil
}

// PrefixMessage prefixes the original message with the protocol identifier.
//
// Only gossip and request messages need to be prefixed.
Expand Down
Loading
Loading