itest: assert unspent before performing CPFP
This reduces the flakiness of the CPFP test by asserting the wallet has seen the unspent output before attempting to perform the walletkit's BumpFee method. Previously the attempt to bump the fee of the target transaction could be made before the wallet had had a chance to fully process the transaction, causing a flaky error.
This commit is contained in:
parent
3e1b4eadbb
commit
0e73d2d243
@ -678,6 +678,8 @@ func (w *WalletKit) BumpFee(ctx context.Context,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("Attempting to CPFP outpoint %s", op)
|
||||||
|
|
||||||
// Since we're unable to perform a bump through RBF, we'll assume the
|
// Since we're unable to perform a bump through RBF, we'll assume the
|
||||||
// user is attempting to bump an unconfirmed transaction's fee rate by
|
// user is attempting to bump an unconfirmed transaction's fee rate by
|
||||||
// sweeping an output within it under control of the wallet with a
|
// sweeping an output within it under control of the wallet with a
|
||||||
|
@ -155,6 +155,39 @@ func assertTxInBlock(t *harnessTest, block *wire.MsgBlock, txid *chainhash.Hash)
|
|||||||
t.Fatalf("tx was not included in block")
|
t.Fatalf("tx was not included in block")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertWalletUnspent(t *harnessTest, node *lntest.HarnessNode, out *lnrpc.OutPoint) {
|
||||||
|
t.t.Helper()
|
||||||
|
|
||||||
|
err := wait.NoError(func() error {
|
||||||
|
ctxt, cancel := context.WithTimeout(context.Background(), defaultTimeout)
|
||||||
|
defer cancel()
|
||||||
|
unspent, err := node.ListUnspent(ctxt, &lnrpc.ListUnspentRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = errors.New("tx with wanted txhash never found")
|
||||||
|
for _, utxo := range unspent.Utxos {
|
||||||
|
if !bytes.Equal(utxo.Outpoint.TxidBytes, out.TxidBytes) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = errors.New("wanted output is not a wallet utxo")
|
||||||
|
if utxo.Outpoint.OutputIndex != out.OutputIndex {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}, defaultTimeout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("outpoint %s not unspent by %s's wallet: %v", out,
|
||||||
|
node.Name(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func rpcPointToWirePoint(t *harnessTest, chanPoint *lnrpc.ChannelPoint) wire.OutPoint {
|
func rpcPointToWirePoint(t *harnessTest, chanPoint *lnrpc.ChannelPoint) wire.OutPoint {
|
||||||
txid, err := lnd.GetChanPointFundingTxid(chanPoint)
|
txid, err := lnd.GetChanPointFundingTxid(chanPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,12 +86,15 @@ func testCPFP(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("bob's output was not found within the transaction")
|
t.Fatalf("bob's output was not found within the transaction")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll attempt to bump the fee of this transaction by performing a
|
// Wait until bob has seen the tx and considers it as owned.
|
||||||
// CPFP from Alice's point of view.
|
|
||||||
op := &lnrpc.OutPoint{
|
op := &lnrpc.OutPoint{
|
||||||
TxidBytes: txid[:],
|
TxidBytes: txid[:],
|
||||||
OutputIndex: uint32(bobOutputIdx),
|
OutputIndex: uint32(bobOutputIdx),
|
||||||
}
|
}
|
||||||
|
assertWalletUnspent(t, net.Bob, op)
|
||||||
|
|
||||||
|
// We'll attempt to bump the fee of this transaction by performing a
|
||||||
|
// CPFP from Alice's point of view.
|
||||||
bumpFeeReq := &walletrpc.BumpFeeRequest{
|
bumpFeeReq := &walletrpc.BumpFeeRequest{
|
||||||
Outpoint: op,
|
Outpoint: op,
|
||||||
SatPerByte: uint32(sweep.DefaultMaxFeeRate.FeePerKVByte() / 2000),
|
SatPerByte: uint32(sweep.DefaultMaxFeeRate.FeePerKVByte() / 2000),
|
||||||
|
Loading…
Reference in New Issue
Block a user