itest+lntest: fix itest re the new sweeping behavior
This commit is contained in:
6 files changed
+281
-142
No files matched your search
@@ -2042,57 +2042,6 @@ func (h *HarnessTest) CalculateTxesFeeRate(txns []*wire.MsgTx) int64 {
|
||||
return feeRate
|
||||
}
|
||||
|
||||
type SweptOutput struct {
|
||||
OutPoint wire.OutPoint
|
||||
SweepTx *wire.MsgTx
|
||||
}
|
||||
|
||||
// FindCommitAndAnchor looks for a commitment sweep and anchor sweep in the
|
||||
// mempool. Our anchor output is identified by having multiple inputs in its
|
||||
// sweep transition, because we have to bring another input to add fees to the
|
||||
// anchor. Note that the anchor swept output may be nil if the channel did not
|
||||
// have anchors.
|
||||
func (h *HarnessTest) FindCommitAndAnchor(sweepTxns []*wire.MsgTx,
|
||||
closeTx string) (*SweptOutput, *SweptOutput) {
|
||||
|
||||
var commitSweep, anchorSweep *SweptOutput
|
||||
|
||||
for _, tx := range sweepTxns {
|
||||
txHash := tx.TxHash()
|
||||
sweepTx := h.Miner.GetRawTransaction(&txHash)
|
||||
|
||||
// We expect our commitment sweep to have a single input, and,
|
||||
// our anchor sweep to have more inputs (because the wallet
|
||||
// needs to add balance to the anchor amount). We find their
|
||||
// sweep txids here to setup appropriate resolutions. We also
|
||||
// need to find the outpoint for our resolution, which we do by
|
||||
// matching the inputs to the sweep to the close transaction.
|
||||
inputs := sweepTx.MsgTx().TxIn
|
||||
if len(inputs) == 1 {
|
||||
commitSweep = &SweptOutput{
|
||||
OutPoint: inputs[0].PreviousOutPoint,
|
||||
SweepTx: tx,
|
||||
}
|
||||
} else {
|
||||
// Since we have more than one input, we run through
|
||||
// them to find the one whose previous outpoint matches
|
||||
// the closing txid, which means this input is spending
|
||||
// the close tx. This will be our anchor output.
|
||||
for _, txin := range inputs {
|
||||
op := txin.PreviousOutPoint.Hash.String()
|
||||
if op == closeTx {
|
||||
anchorSweep = &SweptOutput{
|
||||
OutPoint: txin.PreviousOutPoint,
|
||||
SweepTx: tx,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return commitSweep, anchorSweep
|
||||
}
|
||||
|
||||
// AssertSweepFound looks up a sweep in a nodes list of broadcast sweeps and
|
||||
// asserts it's found.
|
||||
//
|
||||
|
||||
+38
-16
@@ -2149,16 +2149,29 @@ func (h *HarnessTest) AssertHtlcEventTypes(client rpc.HtlcEventsClient,
|
||||
func (h *HarnessTest) AssertFeeReport(hn *node.HarnessNode,
|
||||
day, week, month int) {
|
||||
|
||||
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
|
||||
defer cancel()
|
||||
err := wait.NoError(func() error {
|
||||
feeReport, err := hn.RPC.LN.FeeReport(
|
||||
h.runCtx, &lnrpc.FeeReportRequest{},
|
||||
)
|
||||
require.NoError(h, err, "unable to query for fee report")
|
||||
|
||||
feeReport, err := hn.RPC.LN.FeeReport(ctxt, &lnrpc.FeeReportRequest{})
|
||||
require.NoError(h, err, "unable to query for fee report")
|
||||
if uint64(day) != feeReport.DayFeeSum {
|
||||
return fmt.Errorf("day fee mismatch, want %d, got %d",
|
||||
day, feeReport.DayFeeSum)
|
||||
}
|
||||
|
||||
require.EqualValues(h, day, feeReport.DayFeeSum, "day fee mismatch")
|
||||
require.EqualValues(h, week, feeReport.WeekFeeSum, "day week mismatch")
|
||||
require.EqualValues(h, month, feeReport.MonthFeeSum,
|
||||
"day month mismatch")
|
||||
if uint64(week) != feeReport.WeekFeeSum {
|
||||
return fmt.Errorf("week fee mismatch, want %d, got %d",
|
||||
week, feeReport.WeekFeeSum)
|
||||
}
|
||||
if uint64(month) != feeReport.MonthFeeSum {
|
||||
return fmt.Errorf("month fee mismatch, want %d, got %d",
|
||||
month, feeReport.MonthFeeSum)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, wait.DefaultTimeout)
|
||||
require.NoErrorf(h, err, "%s: time out checking fee report", hn.Name())
|
||||
}
|
||||
|
||||
// AssertHtlcEvents consumes events from a client and ensures that they are of
|
||||
@@ -2575,19 +2588,28 @@ func (h *HarnessTest) AssertNumPendingSweeps(hn *node.HarnessNode,
|
||||
resp := hn.RPC.PendingSweeps()
|
||||
num := len(resp.PendingSweeps)
|
||||
|
||||
numDesc := "\n"
|
||||
for _, s := range resp.PendingSweeps {
|
||||
desc := fmt.Sprintf("op=%v:%v, amt=%v, type=%v, "+
|
||||
"deadline=%v\n", s.Outpoint.TxidStr,
|
||||
s.Outpoint.OutputIndex, s.AmountSat,
|
||||
s.WitnessType, s.DeadlineHeight)
|
||||
numDesc += desc
|
||||
|
||||
// The deadline height must be set, otherwise the
|
||||
// pending input response is not update-to-date.
|
||||
if s.DeadlineHeight == 0 {
|
||||
return fmt.Errorf("input not updated: %s", desc)
|
||||
}
|
||||
}
|
||||
|
||||
if num == n {
|
||||
results = resp.PendingSweeps
|
||||
return nil
|
||||
}
|
||||
|
||||
desc := "\n"
|
||||
for _, s := range resp.PendingSweeps {
|
||||
desc += fmt.Sprintf("op=%v:%v, amt=%v, type=%v\n",
|
||||
s.Outpoint.TxidStr, s.Outpoint.OutputIndex,
|
||||
s.AmountSat, s.WitnessType)
|
||||
}
|
||||
|
||||
return fmt.Errorf("want %d , got %d, sweeps: %s", n, num, desc)
|
||||
return fmt.Errorf("want %d , got %d, sweeps: %s", n, num,
|
||||
numDesc)
|
||||
}, DefaultTimeout)
|
||||
|
||||
require.NoErrorf(h, err, "%s: check pending sweeps timeout", hn.Name())
|
||||
|
||||
Reference in new issue
Block a user