Skip to content

Commit

Permalink
fix(ARCO-212): Node client not finding ancestors in mempool does not …
Browse files Browse the repository at this point in the history
…return an error
  • Loading branch information
boecklim committed Nov 20, 2024
1 parent 4f28f61 commit 73cb0db
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
9 changes: 3 additions & 6 deletions internal/node_client/node_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"runtime"
"strings"

sdkTx "github.com/bitcoin-sv/go-sdk/transaction"
"github.com/ordishs/go-bitcoin"
Expand Down Expand Up @@ -51,8 +50,6 @@ func New(n *bitcoin.Bitcoind, opts ...func(client *NodeClient)) (NodeClient, err
return node, nil
}

var ErrTransactionNotInMempool = errors.New("Transaction not in mempool")

func (n NodeClient) GetMempoolAncestors(ctx context.Context, ids []string) ([]string, error) {
_, span := tracing.StartTracing(ctx, "NodeClient_GetMempoolAncestors", n.tracingEnabled, n.tracingAttributes...)
defer tracing.EndTracing(span)
Expand All @@ -64,9 +61,9 @@ func (n NodeClient) GetMempoolAncestors(ctx context.Context, ids []string) ([]st
nTx, err := n.bitcoinClient.GetMempoolAncestors(id, false)
tracing.EndTracing(span)
if err != nil {
if strings.Contains(err.Error(), "Transaction not in mempool") {
continue
}
//if strings.Contains(err.Error(), "Transaction not in mempool") {
// continue
//}

return nil, errors.Join(ErrFailedToGetMempoolAncestors, err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/node_client/node_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ func TestNodeClient(t *testing.T) {
require.ErrorIs(t, err, node_client.ErrFailedToGetMempoolAncestors)

// when
_, err = sut.GetMempoolAncestors(ctx, []string{"792bb5c0d5e4937572e6368dc713ba0b4935d27a7b7ac654c2b384d6c8b2fb89"})
actual, err := sut.GetMempoolAncestors(ctx, []string{"792bb5c0d5e4937572e6368dc713ba0b4935d27a7b7ac654c2b384d6c8b2fb89"}) // tx id not existing in the mempool

// then
require.ErrorIs(t, err, node_client.ErrTransactionNotInMempool)
require.NoError(t, err)
require.Empty(t, actual)
})
}
61 changes: 53 additions & 8 deletions test/submit_01_single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,11 @@ func TestPostCumulativeFeesValidation(t *testing.T) {
}

tt := []struct {
name string
options validationOpts
lastTxFee uint64
chainLong int
name string
options validationOpts
lastTxFee uint64
chainLong int
minedAncestors int

expectedStatusCode int
expectedTxStatus string
Expand All @@ -599,7 +600,7 @@ func TestPostCumulativeFeesValidation(t *testing.T) {
expectedTxStatus: StatusSeenOnNetwork,
},
{
name: "post txs chain with too low fee with cumulative fees validation",
name: "post txs chain with too low fee with cumulative fees validation",
options: validationOpts{
performCumulativeFeesValidation: true,
},
Expand All @@ -608,16 +609,36 @@ func TestPostCumulativeFeesValidation(t *testing.T) {
expectedError: "arc error 473: transaction fee is too low\nminimum expected cumulative fee: 84, actual fee: 1",
},
{
name: "post txs chain with suficient fee with cumulative fees validation",
name: "post txs chain with too low fee with cumulative fees validation - some ancestors are mined",
options: validationOpts{
performCumulativeFeesValidation: true,
},
lastTxFee: 1,
minedAncestors: 2,
expectedStatusCode: 473,
expectedError: "arc error 473: transaction fee is too low\nminimum expected cumulative fee: 84, actual fee: 1",
},
{
name: "post txs chain with sufficient fee with cumulative fees validation",
options: validationOpts{
performCumulativeFeesValidation: true,
},
lastTxFee: 90,
expectedStatusCode: 200,
expectedTxStatus: StatusSeenOnNetwork,
},
{
name: "post txs chain with sufficient fee with cumulative fees validation - some ancestors are mined",
options: validationOpts{
performCumulativeFeesValidation: true,
},
lastTxFee: 90,
minedAncestors: 2,
expectedStatusCode: 200,
expectedTxStatus: StatusSeenOnNetwork,
},
{
name: "post txs chain with cumulative fees validation - chain too long - ignore it",
name: "post txs chain with cumulative fees validation - chain too long - ignore it",
options: validationOpts{
performCumulativeFeesValidation: true,
},
Expand Down Expand Up @@ -673,7 +694,7 @@ func TestPostCumulativeFeesValidation(t *testing.T) {
Vout: 0,
Address: address,
ScriptPubKey: output.LockingScript.String(),
Amount: float64(float64(output.Satoshis) / 1e8),
Amount: float64(output.Satoshis) / 1e8,
}

tx, err := node_client.CreateTx(privateKey, address, utxo, zeroFee)
Expand Down Expand Up @@ -715,6 +736,30 @@ func TestPostCumulativeFeesValidation(t *testing.T) {
}
}

txRequests := make([]TransactionRequest, 0)
for _, chain := range zeroFeeChains {
for _, tx := range chain {
rawTx, err := tx.EFHex()
require.NoError(t, err)
body := TransactionRequest{RawTx: rawTx}
txRequests = append(txRequests, body)
}
}

for i, body := range txRequests {
if tc.minedAncestors > 0 && i == tc.minedAncestors {
node_client.Generate(t, bitcoind, 1)
}

resp := postRequest[TransactionResponse](t, arcEndpointV1Tx, createPayload(t, body),
map[string]string{
"X-WaitFor": StatusSeenOnNetwork,
"X-SkipFeeValidation": strconv.FormatBool(true),
}, 200)

require.Equal(t, StatusSeenOnNetwork, resp.TxStatus)
}

// then
// create last transaction
var nodeUtxos []node_client.UnspentOutput
Expand Down

0 comments on commit 73cb0db

Please sign in to comment.