diff --git a/itest/lnd_revocation_test.go b/itest/lnd_revocation_test.go index 82415e039..fd368af6b 100644 --- a/itest/lnd_revocation_test.go +++ b/itest/lnd_revocation_test.go @@ -109,7 +109,11 @@ func breachRetributionTestCase(ht *lntest.HarnessTest, // broadcasting his current channel state. This is actually the // commitment transaction of a prior *revoked* state, so he'll soon // feel the wrath of Carol's retribution. - _, breachTXID := ht.CloseChannelAssertPending(bob, chanPoint, true) + _, breachCloseUpd := ht.CloseChannelAssertPending(bob, chanPoint, true) + closeUpd := breachCloseUpd.GetClosePending() + require.NotNil(ht, closeUpd) + breachTXID, err := chainhash.NewHash(closeUpd.Txid) + require.NoError(ht, err) // Here, Carol sees Bob's breach transaction in the mempool, but is // waiting for it to confirm before continuing her retribution. We @@ -543,9 +547,13 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest, // broadcasting her current channel state. This is actually the // commitment transaction of a prior *revoked* state, so she'll soon // feel the wrath of Dave's retribution. - closeUpdates, closeTxID := ht.CloseChannelAssertPending( + closeUpdates, closeUpd := ht.CloseChannelAssertPending( carol, chanPoint, true, ) + pendingCloseUpd := closeUpd.GetClosePending() + require.NotNil(ht, pendingCloseUpd) + closeTxID, err := chainhash.NewHash(pendingCloseUpd.Txid) + require.NoError(ht, err) // Generate a single block to mine the breach transaction. block := ht.MineBlocksAndAssertNumTxes(1, 1)[0] @@ -593,7 +601,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest, return nil, errNotFound } - err := wait.NoError(func() error { + err = wait.NoError(func() error { txid, err := findJusticeTx() if err != nil { return err diff --git a/lntest/harness.go b/lntest/harness.go index e8996e9a6..8a243e323 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -1255,14 +1255,40 @@ func (h *HarnessTest) OpenChannelAssertErr(srcNode, destNode *node.HarnessNode, "error returned, want %v, got %v", expectedErr, err) } +// closeChannelOpts holds the options for closing a channel. +type closeChannelOpts struct { + feeRate fn.Option[chainfee.SatPerVByte] +} + +// CloseChanOpt is a functional option to modify the way we close a channel. +type CloseChanOpt func(*closeChannelOpts) + +// WithCoopCloseFeeRate is a functional option to set the fee rate for a coop +// close attempt. +func WithCoopCloseFeeRate(rate chainfee.SatPerVByte) CloseChanOpt { + return func(o *closeChannelOpts) { + o.feeRate = fn.Some(rate) + } +} + +// defaultCloseOpts returns the set of default close options. +func defaultCloseOpts() *closeChannelOpts { + return &closeChannelOpts{} +} + // CloseChannelAssertPending attempts to close the channel indicated by the // passed channel point, initiated by the passed node. Once the CloseChannel // rpc is called, it will consume one event and assert it's a close pending // event. In addition, it will check that the closing tx can be found in the // mempool. func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, - cp *lnrpc.ChannelPoint, - force bool) (rpc.CloseChanClient, *chainhash.Hash) { + cp *lnrpc.ChannelPoint, force bool, + opts ...CloseChanOpt) (rpc.CloseChanClient, *lnrpc.CloseStatusUpdate) { + + closeOpts := defaultCloseOpts() + for _, optFunc := range opts { + optFunc(closeOpts) + } // Calls the rpc to close the channel. closeReq := &lnrpc.CloseChannelRequest{ @@ -1271,10 +1297,9 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, NoWait: true, } - // For coop close, we use a default confg target of 6. - if !force { - closeReq.TargetConf = 6 - } + closeOpts.feeRate.WhenSome(func(feeRate chainfee.SatPerVByte) { + closeReq.SatPerVbyte = uint64(feeRate) + }) var ( stream rpc.CloseChanClient @@ -1307,7 +1332,7 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode, // Assert the closing tx is in the mempool. h.miner.AssertTxInMempool(closeTxid) - return stream, closeTxid + return stream, event } // CloseChannel attempts to coop close a non-anchored channel identified by the