Skip to content

Improve swap status poller and error reporting wrt context errors #44

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

Merged
merged 1 commit into from
Jan 30, 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
9 changes: 7 additions & 2 deletions pkg/code/server/grpc/transaction/v2/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transaction_v2

import (
"context"
"errors"
"fmt"

Expand Down Expand Up @@ -226,8 +227,10 @@ func handleSubmitIntentError(streamer transactionpb.Transaction_SubmitIntentServ

// Case 2: Errors that map to gRPC status errors
switch err {
case ErrTimedOutReceivingRequest:
case ErrTimedOutReceivingRequest, context.DeadlineExceeded:
return status.Error(codes.DeadlineExceeded, err.Error())
case context.Canceled:
return status.Error(codes.Canceled, err.Error())
case transaction.ErrNoAvailableNonces:
return status.Error(codes.Unavailable, "")
}
Expand Down Expand Up @@ -281,8 +284,10 @@ func handleSwapError(streamer transactionpb.Transaction_SwapServer, err error) e

// Case 2: Errors that map to gRPC status errors
switch err {
case ErrTimedOutReceivingRequest:
case ErrTimedOutReceivingRequest, context.DeadlineExceeded:
return status.Error(codes.DeadlineExceeded, err.Error())
case context.Canceled:
return status.Error(codes.Canceled, err.Error())
}
return status.Error(codes.Internal, "rpc server failure")
}
Expand Down
47 changes: 25 additions & 22 deletions pkg/code/server/grpc/transaction/v2/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,32 +380,35 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
}

for {
time.Sleep(time.Second)

statuses, err := s.data.GetBlockchainSignatureStatuses(ctx, []solana.Signature{solana.Signature(txn.Signature())})
if err != nil {
continue
}
select {
case <-time.After(time.Second):
statuses, err := s.data.GetBlockchainSignatureStatuses(ctx, []solana.Signature{solana.Signature(txn.Signature())})
if err != nil {
continue
}

if len(statuses) == 0 || statuses[0] == nil {
continue
}
if len(statuses) == 0 || statuses[0] == nil {
continue
}

if statuses[0].ErrorResult != nil {
log.WithError(statuses[0].ErrorResult).Warn("transaction failed")
return handleSwapStructuredError(streamer, transactionpb.SwapResponse_Error_SWAP_FAILED)
}
if statuses[0].ErrorResult != nil {
log.WithError(statuses[0].ErrorResult).Warn("transaction failed")
return handleSwapStructuredError(streamer, transactionpb.SwapResponse_Error_SWAP_FAILED)
}

if statuses[0].Finalized() {
log.Debug("transaction succeeded and is finalized")
err = streamer.Send(&transactionpb.SwapResponse{
Response: &transactionpb.SwapResponse_Success_{
Success: &transactionpb.SwapResponse_Success{
Code: transactionpb.SwapResponse_Success_SWAP_FINALIZED,
if statuses[0].Finalized() {
log.Debug("transaction succeeded and is finalized")
err = streamer.Send(&transactionpb.SwapResponse{
Response: &transactionpb.SwapResponse_Success_{
Success: &transactionpb.SwapResponse_Success{
Code: transactionpb.SwapResponse_Success_SWAP_FINALIZED,
},
},
},
})
return handleSwapError(streamer, err)
})
return handleSwapError(streamer, err)
}
case <-ctx.Done():
return handleSwapError(streamer, ctx.Err())
}
}
}
Expand Down