forked from kaspanet/kaspad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RPC SubmitTransaction: Dequeue old responses from previous requests (k…
- Loading branch information
1 parent
d2453f8
commit 6b38bf7
Showing
6 changed files
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 31 additions & 10 deletions
41
infrastructure/network/rpcclient/rpc_send_raw_transaction.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,44 @@ | ||
package rpcclient | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/kaspanet/kaspad/app/appmessage" | ||
) | ||
|
||
// SubmitTransaction sends an RPC request respective to the function's name and returns the RPC server's response | ||
func (c *RPCClient) SubmitTransaction(transaction *appmessage.RPCTransaction, allowOrphan bool) (*appmessage.SubmitTransactionResponseMessage, error) { | ||
func (c *RPCClient) SubmitTransaction(transaction *appmessage.RPCTransaction, transactionID string, allowOrphan bool) (*appmessage.SubmitTransactionResponseMessage, error) { | ||
err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewSubmitTransactionRequestMessage(transaction, allowOrphan)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
response, err := c.route(appmessage.CmdSubmitTransactionResponseMessage).DequeueWithTimeout(c.timeout) | ||
if err != nil { | ||
return nil, err | ||
} | ||
submitTransactionResponse := response.(*appmessage.SubmitTransactionResponseMessage) | ||
if submitTransactionResponse.Error != nil { | ||
return nil, c.convertRPCError(submitTransactionResponse.Error) | ||
} | ||
for { | ||
response, err := c.route(appmessage.CmdSubmitTransactionResponseMessage).DequeueWithTimeout(c.timeout) | ||
if err != nil { | ||
return nil, err | ||
} | ||
submitTransactionResponse := response.(*appmessage.SubmitTransactionResponseMessage) | ||
// Match the response to the expected ID. If they are different it means we got an old response which we | ||
// previously timed-out on, so we log and continue waiting for the correct current response. | ||
if submitTransactionResponse.TransactionID != transactionID { | ||
if submitTransactionResponse.Error != nil { | ||
// A non-updated Kaspad might return an empty ID in the case of error, so in | ||
// such a case we fallback to checking if the error contains the expected ID | ||
if submitTransactionResponse.TransactionID != "" || !strings.Contains(submitTransactionResponse.Error.Message, transactionID) { | ||
log.Warnf("SubmitTransaction: received an error response for previous request: %s", submitTransactionResponse.Error) | ||
continue | ||
} | ||
|
||
} else { | ||
log.Warnf("SubmitTransaction: received a successful response for previous request with ID %s", | ||
submitTransactionResponse.TransactionID) | ||
continue | ||
} | ||
} | ||
if submitTransactionResponse.Error != nil { | ||
return nil, c.convertRPCError(submitTransactionResponse.Error) | ||
} | ||
|
||
return submitTransactionResponse, nil | ||
return submitTransactionResponse, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters