From b749b2db0b089ba1665b72d4aa1fc4446126c2b1 Mon Sep 17 00:00:00 2001 From: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> Date: Thu, 24 Dec 2020 10:40:56 +0200 Subject: [PATCH] Fix transaction relay not working (#1279) * Implement HandleGetMempoolEntry. * Fix equality bug in handleRelayedTransactionsFlow. --- .../handle_relayed_transactions.go | 2 +- app/rpc/rpchandlers/get_mempool_entry.go | 25 ++++++++++++++++++- testing/integration/tx_relay_test.go | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/protocol/flows/transactionrelay/handle_relayed_transactions.go b/app/protocol/flows/transactionrelay/handle_relayed_transactions.go index 26f9d6d2c..2bcd8afc9 100644 --- a/app/protocol/flows/transactionrelay/handle_relayed_transactions.go +++ b/app/protocol/flows/transactionrelay/handle_relayed_transactions.go @@ -168,7 +168,7 @@ func (flow *handleRelayedTransactionsFlow) receiveTransactions(requestedTransact } tx := appmessage.MsgTxToDomainTransaction(msgTx) txID := consensushashing.TransactionID(tx) - if txID != expectedID { + if !txID.Equal(expectedID) { return protocolerrors.Errorf(true, "expected transaction %s, but got %s", expectedID, txID) } diff --git a/app/rpc/rpchandlers/get_mempool_entry.go b/app/rpc/rpchandlers/get_mempool_entry.go index 104441a37..3a3bc5db3 100644 --- a/app/rpc/rpchandlers/get_mempool_entry.go +++ b/app/rpc/rpchandlers/get_mempool_entry.go @@ -3,10 +3,33 @@ package rpchandlers import ( "github.com/kaspanet/kaspad/app/appmessage" "github.com/kaspanet/kaspad/app/rpc/rpccontext" + "github.com/kaspanet/kaspad/domain/consensus/utils/transactionid" "github.com/kaspanet/kaspad/infrastructure/network/netadapter/router" ) // HandleGetMempoolEntry handles the respectively named RPC command func HandleGetMempoolEntry(context *rpccontext.Context, _ *router.Router, request appmessage.Message) (appmessage.Message, error) { - return &appmessage.GetMempoolEntryResponseMessage{}, nil + getMempoolEntryRequest := request.(*appmessage.GetMempoolEntryRequestMessage) + + transactionID, err := transactionid.FromString(getMempoolEntryRequest.TxID) + if err != nil { + errorMessage := &appmessage.GetMempoolEntryResponseMessage{} + errorMessage.Error = appmessage.RPCErrorf("Transaction ID could not be parsed: %s", err) + return errorMessage, nil + } + + transaction, ok := context.Domain.MiningManager().GetTransaction(transactionID) + if !ok { + errorMessage := &appmessage.GetMempoolEntryResponseMessage{} + errorMessage.Error = appmessage.RPCErrorf("Transaction %s was not found", transactionID) + return errorMessage, nil + } + + transactionVerboseData, err := context.BuildTransactionVerboseData( + transaction, getMempoolEntryRequest.TxID, nil, "") + if err != nil { + return nil, err + } + + return appmessage.NewGetMempoolEntryResponseMessage(transaction.Fee, transactionVerboseData), nil } diff --git a/testing/integration/tx_relay_test.go b/testing/integration/tx_relay_test.go index 3c23e0a73..3e6b85fe3 100644 --- a/testing/integration/tx_relay_test.go +++ b/testing/integration/tx_relay_test.go @@ -60,7 +60,7 @@ func TestTxRelay(t *testing.T) { for range ticker.C { _, err := payee.rpcClient.GetMempoolEntry(txID) if err != nil { - if strings.Contains(err.Error(), "transaction is not in the pool") { + if strings.Contains(err.Error(), "not found") { continue }