lnrpc+sweep: make sure public interface takes public types as params

This commit exports and renames the following variable names:
- `PendingInput` is now `PendingInputResponse` as it's responding to a
  request.
- `pendingInput` is now renamed and exported as `SweeperInput`.
- `pendingInputs` is now renamed and exported as `InputsMap`.

This commit is first made from running:
```
gofmt -d -w -r 'PendingInput -> PendingInputResponse' .
gofmt -d -w -r 'pendingInput -> SweeperInput' .
gofmt -d -w -r 'pendingInputs -> InputsMap' .
```
And followed by some docs and variable names fixes.
This commit is contained in:
yyforyongyu 2024-03-18 03:20:37 +08:00
parent 9e7d4b7e0b
commit 28df2d7327
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
9 changed files with 207 additions and 206 deletions

View file

@ -863,27 +863,27 @@ func (w *WalletKit) PendingSweeps(ctx context.Context,
// Retrieve all of the outputs the UtxoSweeper is currently trying to
// sweep.
pendingInputs, err := w.cfg.Sweeper.PendingInputs()
inputsMap, err := w.cfg.Sweeper.PendingInputs()
if err != nil {
return nil, err
}
// Convert them into their respective RPC format.
rpcPendingSweeps := make([]*PendingSweep, 0, len(pendingInputs))
for _, pendingInput := range pendingInputs {
witnessType, ok := allWitnessTypes[pendingInput.WitnessType]
rpcPendingSweeps := make([]*PendingSweep, 0, len(inputsMap))
for _, sweeperInput := range inputsMap {
witnessType, ok := allWitnessTypes[sweeperInput.WitnessType]
if !ok {
return nil, fmt.Errorf("unhandled witness type %v for "+
"input %v", pendingInput.WitnessType,
pendingInput.OutPoint)
"input %v", sweeperInput.WitnessType,
sweeperInput.OutPoint)
}
op := lnrpc.MarshalOutPoint(&pendingInput.OutPoint)
amountSat := uint32(pendingInput.Amount)
satPerVbyte := uint64(pendingInput.LastFeeRate.FeePerVByte())
broadcastAttempts := uint32(pendingInput.BroadcastAttempts)
op := lnrpc.MarshalOutPoint(&sweeperInput.OutPoint)
amountSat := uint32(sweeperInput.Amount)
satPerVbyte := uint64(sweeperInput.LastFeeRate.FeePerVByte())
broadcastAttempts := uint32(sweeperInput.BroadcastAttempts)
feePref := pendingInput.Params.Fee
feePref := sweeperInput.Params.Fee
requestedFee, ok := feePref.(sweep.FeeEstimateInfo)
if !ok {
return nil, fmt.Errorf("unknown fee preference type: "+
@ -900,7 +900,7 @@ func (w *WalletKit) PendingSweeps(ctx context.Context,
BroadcastAttempts: broadcastAttempts,
RequestedSatPerVbyte: requestedFeeRate,
RequestedConfTarget: requestedFee.ConfTarget,
Force: pendingInput.Params.Force,
Force: sweeperInput.Params.Force,
})
}

View file

@ -29,7 +29,7 @@ const (
type inputCluster struct {
lockTime *uint32
sweepFeeRate chainfee.SatPerKWeight
inputs pendingInputs
inputs InputsMap
}
// createInputSets goes through the cluster's inputs and constructs sets of
@ -41,7 +41,7 @@ func (c *inputCluster) createInputSets(maxFeeRate chainfee.SatPerKWeight,
maxInputs uint32) []InputSet {
// Turn the inputs into a slice so we can sort them.
inputList := make([]*pendingInput, 0, len(c.inputs))
inputList := make([]*SweeperInput, 0, len(c.inputs))
for _, input := range c.inputs {
inputList = append(inputList, input)
}
@ -53,7 +53,7 @@ func (c *inputCluster) createInputSets(maxFeeRate chainfee.SatPerKWeight,
//
// For witness size, the upper limit is taken. The actual size depends
// on the signature length, which is not known yet at this point.
calcYield := func(input *pendingInput) int64 {
calcYield := func(input *SweeperInput) int64 {
size, _, err := input.WitnessType().SizeUpperBound()
if err != nil {
log.Errorf("Failed to get input weight: %v", err)
@ -123,7 +123,7 @@ func (c *inputCluster) createInputSets(maxFeeRate chainfee.SatPerKWeight,
type UtxoAggregator interface {
// ClusterInputs takes a list of inputs and groups them into input
// sets. Each input set will be used to create a sweeping transaction.
ClusterInputs(pendingInputs) []InputSet
ClusterInputs(InputsMap) []InputSet
}
// SimpleAggregator aggregates inputs known by the Sweeper based on each
@ -175,7 +175,7 @@ func NewSimpleUtxoAggregator(estimator chainfee.Estimator,
// inputs known by the UtxoSweeper. It clusters inputs by
// 1) Required tx locktime
// 2) Similar fee rates.
func (s *SimpleAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
func (s *SimpleAggregator) ClusterInputs(inputs InputsMap) []InputSet {
// We start by getting the inputs clusters by locktime. Since the
// inputs commit to the locktime, they can only be clustered together
// if the locktime is equal.
@ -212,10 +212,10 @@ func (s *SimpleAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
// cluster. In addition to the created clusters, inputs that did not specify a
// required locktime are returned.
func (s *SimpleAggregator) clusterByLockTime(
inputs pendingInputs) ([]inputCluster, pendingInputs) {
inputs InputsMap) ([]inputCluster, InputsMap) {
locktimes := make(map[uint32]pendingInputs)
rem := make(pendingInputs)
locktimes := make(map[uint32]InputsMap)
rem := make(InputsMap)
// Go through all inputs and check if they require a certain locktime.
for op, input := range inputs {
@ -228,7 +228,7 @@ func (s *SimpleAggregator) clusterByLockTime(
// Check if we already have inputs with this locktime.
cluster, ok := locktimes[lt]
if !ok {
cluster = make(pendingInputs)
cluster = make(InputsMap)
}
// Get the fee rate based on the fee preference. If an error is
@ -281,7 +281,7 @@ func (s *SimpleAggregator) clusterByLockTime(
// sweep fee rate, which is determined by calculating the average fee rate of
// all inputs within that cluster.
func (s *SimpleAggregator) clusterBySweepFeeRate(
inputs pendingInputs) []inputCluster {
inputs InputsMap) []inputCluster {
bucketInputs := make(map[int]*bucketList)
inputFeeRates := make(map[wire.OutPoint]chainfee.SatPerKWeight)
@ -399,7 +399,7 @@ func mergeClusters(a, b inputCluster) []inputCluster {
newCluster.sweepFeeRate = b.sweepFeeRate
}
newCluster.inputs = make(pendingInputs)
newCluster.inputs = make(InputsMap)
for op, in := range a.inputs {
newCluster.inputs[op] = in
@ -492,7 +492,7 @@ func NewBudgetAggregator(estimator chainfee.Estimator,
}
// clusterGroup defines an alias for a set of inputs that are to be grouped.
type clusterGroup map[fn.Option[int32]][]pendingInput
type clusterGroup map[fn.Option[int32]][]SweeperInput
// ClusterInputs creates a list of input sets from pending inputs.
// 1. filter out inputs whose budget cannot cover min relay fee.
@ -500,7 +500,7 @@ type clusterGroup map[fn.Option[int32]][]pendingInput
// 3. sort the inputs in each cluster by their budget.
// 4. optionally split a cluster if it exceeds the max input limit.
// 5. create input sets from each of the clusters.
func (b *BudgetAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
func (b *BudgetAggregator) ClusterInputs(inputs InputsMap) []InputSet {
// Filter out inputs that have a budget below min relay fee.
filteredInputs := b.filterInputs(inputs)
@ -513,7 +513,7 @@ func (b *BudgetAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
height := input.params.DeadlineHeight
cluster, ok := clusters[height]
if !ok {
cluster = make([]pendingInput, 0)
cluster = make([]SweeperInput, 0)
}
cluster = append(cluster, *input)
@ -540,12 +540,12 @@ func (b *BudgetAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
// createInputSet takes a set of inputs which share the same deadline height
// and turns them into a list of `InputSet`, each set is then used to create a
// sweep transaction.
func (b *BudgetAggregator) createInputSets(inputs []pendingInput) []InputSet {
func (b *BudgetAggregator) createInputSets(inputs []SweeperInput) []InputSet {
// sets holds the InputSets that we will return.
sets := make([]InputSet, 0)
// Copy the inputs to a new slice so we can modify it.
remainingInputs := make([]pendingInput, len(inputs))
remainingInputs := make([]SweeperInput, len(inputs))
copy(remainingInputs, inputs)
// If the number of inputs is greater than the max inputs allowed, we
@ -556,7 +556,7 @@ func (b *BudgetAggregator) createInputSets(inputs []pendingInput) []InputSet {
// Copy the inputs to be put into the new set, and update the
// remaining inputs by removing currentInputs.
currentInputs := make([]pendingInput, b.maxInputs)
currentInputs := make([]SweeperInput, b.maxInputs)
copy(currentInputs, remainingInputs[:b.maxInputs])
remainingInputs = remainingInputs[b.maxInputs:]
@ -587,13 +587,13 @@ func (b *BudgetAggregator) createInputSets(inputs []pendingInput) []InputSet {
// filterInputs filters out inputs that have a budget below the min relay fee
// or have a required output that's below the dust.
func (b *BudgetAggregator) filterInputs(inputs pendingInputs) pendingInputs {
func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap {
// Get the current min relay fee for this round.
minFeeRate := b.estimator.RelayFeePerKW()
// filterInputs stores a map of inputs that has a budget that at least
// can pay the minimal fee.
filteredInputs := make(pendingInputs, len(inputs))
filteredInputs := make(InputsMap, len(inputs))
// Iterate all the inputs and filter out the ones whose budget cannot
// cover the min fee.
@ -647,10 +647,10 @@ func (b *BudgetAggregator) filterInputs(inputs pendingInputs) pendingInputs {
// number of inputs exceeds the maxInputs limit, it requires us to split them
// into smaller clusters. In that case, the sorting will make a difference as
// the budgets of the clusters will be different.
func (b *BudgetAggregator) sortInputs(inputs []pendingInput) []pendingInput {
func (b *BudgetAggregator) sortInputs(inputs []SweeperInput) []SweeperInput {
// sortedInputs is the final list of inputs sorted by their economical
// value.
sortedInputs := make([]pendingInput, 0, len(inputs))
sortedInputs := make([]SweeperInput, 0, len(inputs))
// Copy the inputs.
sortedInputs = append(sortedInputs, inputs...)

View file

@ -19,25 +19,25 @@ import (
//nolint:lll
var (
testInputsA = pendingInputs{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 0}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 1}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 2}: &pendingInput{},
testInputsA = InputsMap{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 0}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 1}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 2}: &SweeperInput{},
}
testInputsB = pendingInputs{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 10}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 11}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 12}: &pendingInput{},
testInputsB = InputsMap{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 10}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 11}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 12}: &SweeperInput{},
}
testInputsC = pendingInputs{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 0}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 1}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 2}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 10}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 11}: &pendingInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 12}: &pendingInput{},
testInputsC = InputsMap{
wire.OutPoint{Hash: chainhash.Hash{}, Index: 0}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 1}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 2}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 10}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 11}: &SweeperInput{},
wire.OutPoint{Hash: chainhash.Hash{}, Index: 12}: &SweeperInput{},
}
)
@ -132,7 +132,7 @@ func TestMergeClusters(t *testing.T) {
func TestZipClusters(t *testing.T) {
t.Parallel()
createCluster := func(inp pendingInputs,
createCluster := func(inp InputsMap,
f chainfee.SatPerKWeight) inputCluster {
return inputCluster{
@ -275,19 +275,19 @@ func TestClusterByLockTime(t *testing.T) {
// With the inner Input being mocked, we can now create the pending
// inputs.
input1 := &pendingInput{Input: input1LockTime1, params: param}
input2 := &pendingInput{Input: input2LockTime1, params: param}
input3 := &pendingInput{Input: input3LockTime2, params: param}
input4 := &pendingInput{Input: input4LockTime2, params: param}
input5 := &pendingInput{Input: input5NoLockTime, params: param}
input6 := &pendingInput{Input: input6NoLockTime, params: param}
input1 := &SweeperInput{Input: input1LockTime1, params: param}
input2 := &SweeperInput{Input: input2LockTime1, params: param}
input3 := &SweeperInput{Input: input3LockTime2, params: param}
input4 := &SweeperInput{Input: input4LockTime2, params: param}
input5 := &SweeperInput{Input: input5NoLockTime, params: param}
input6 := &SweeperInput{Input: input6NoLockTime, params: param}
// Create the pending inputs map, which will be passed to the method
// under test.
//
// NOTE: we don't care the actual outpoint values as long as they are
// unique.
inputs := pendingInputs{
inputs := InputsMap{
wire.OutPoint{Index: 1}: input1,
wire.OutPoint{Index: 2}: input2,
wire.OutPoint{Index: 3}: input3,
@ -298,18 +298,18 @@ func TestClusterByLockTime(t *testing.T) {
// Create expected clusters so we can shorten the line length in the
// test cases below.
cluster1 := pendingInputs{
cluster1 := InputsMap{
wire.OutPoint{Index: 1}: input1,
wire.OutPoint{Index: 2}: input2,
}
cluster2 := pendingInputs{
cluster2 := InputsMap{
wire.OutPoint{Index: 3}: input3,
wire.OutPoint{Index: 4}: input4,
}
// cluster3 should be the remaining inputs since they don't have
// locktime.
cluster3 := pendingInputs{
cluster3 := InputsMap{
wire.OutPoint{Index: 5}: input5,
wire.OutPoint{Index: 6}: input6,
}
@ -332,7 +332,7 @@ func TestClusterByLockTime(t *testing.T) {
setupMocker func()
testFeeRate chainfee.SatPerKWeight
expectedClusters []inputCluster
expectedRemainingInputs pendingInputs
expectedRemainingInputs InputsMap
}{
{
// Test a successful case where the locktime clusters
@ -518,33 +518,33 @@ func TestBudgetAggregatorFilterInputs(t *testing.T) {
})
// Create testing pending inputs.
inputs := pendingInputs{
inputs := InputsMap{
// The first input will be filtered out due to the error.
opErr: &pendingInput{
opErr: &SweeperInput{
Input: inpErr,
},
// The second input will be filtered out due to the budget.
opLow: &pendingInput{
opLow: &SweeperInput{
Input: inpLow,
params: Params{Budget: budgetLow},
},
// The third input will be included.
opEqual: &pendingInput{
opEqual: &SweeperInput{
Input: inpEqual,
params: Params{Budget: budgetEqual},
},
// The fourth input will be included.
opHigh: &pendingInput{
opHigh: &SweeperInput{
Input: inpHigh,
params: Params{Budget: budgetHigh},
},
// The fifth input will be filtered out due to the dust
// required.
opDust: &pendingInput{
opDust: &SweeperInput{
Input: inpDust,
params: Params{Budget: budgetHigh},
},
@ -578,7 +578,7 @@ func TestBudgetAggregatorSortInputs(t *testing.T) {
)
// Create an input with the low budget but forced.
inputLowForce := pendingInput{
inputLowForce := SweeperInput{
params: Params{
Budget: budgetLow,
Force: true,
@ -586,14 +586,14 @@ func TestBudgetAggregatorSortInputs(t *testing.T) {
}
// Create an input with the low budget.
inputLow := pendingInput{
inputLow := SweeperInput{
params: Params{
Budget: budgetLow,
},
}
// Create an input with the high budget and forced.
inputHighForce := pendingInput{
inputHighForce := SweeperInput{
params: Params{
Budget: budgetHight,
Force: true,
@ -601,14 +601,14 @@ func TestBudgetAggregatorSortInputs(t *testing.T) {
}
// Create an input with the high budget.
inputHigh := pendingInput{
inputHigh := SweeperInput{
params: Params{
Budget: budgetHight,
},
}
// Create a testing pending inputs.
inputs := []pendingInput{
inputs := []SweeperInput{
inputLowForce,
inputLow,
inputHighForce,
@ -652,25 +652,25 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
defer mockInput4.AssertExpectations(t)
// Create testing pending inputs.
pi1 := pendingInput{
pi1 := SweeperInput{
Input: mockInput1,
params: Params{
DeadlineHeight: fn.Some(int32(1)),
},
}
pi2 := pendingInput{
pi2 := SweeperInput{
Input: mockInput2,
params: Params{
DeadlineHeight: fn.Some(int32(1)),
},
}
pi3 := pendingInput{
pi3 := SweeperInput{
Input: mockInput3,
params: Params{
DeadlineHeight: fn.Some(int32(1)),
},
}
pi4 := pendingInput{
pi4 := SweeperInput{
Input: mockInput4,
params: Params{
// This input has a deadline height that is different
@ -686,7 +686,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
// Create test cases.
testCases := []struct {
name string
inputs []pendingInput
inputs []SweeperInput
setupMock func()
expectedNumSets int
}{
@ -694,7 +694,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
// When the number of inputs is below the max, a single
// input set is returned.
name: "num inputs below max",
inputs: []pendingInput{pi1},
inputs: []SweeperInput{pi1},
setupMock: func() {
// Mock methods used in loggings.
mockInput1.On("WitnessType").Return(
@ -708,7 +708,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
// When the number of inputs is equal to the max, a
// single input set is returned.
name: "num inputs equal to max",
inputs: []pendingInput{pi1, pi2},
inputs: []SweeperInput{pi1, pi2},
setupMock: func() {
// Mock methods used in loggings.
mockInput1.On("WitnessType").Return(
@ -727,7 +727,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
// When the number of inputs is above the max, multiple
// input sets are returned.
name: "num inputs above max",
inputs: []pendingInput{pi1, pi2, pi3},
inputs: []SweeperInput{pi1, pi2, pi3},
setupMock: func() {
// Mock methods used in loggings.
mockInput1.On("WitnessType").Return(
@ -751,7 +751,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) {
// error is returned from creating the first set, it
// shouldn't affect the remaining inputs.
name: "num inputs above max with error",
inputs: []pendingInput{pi1, pi4, pi3},
inputs: []SweeperInput{pi1, pi4, pi3},
setupMock: func() {
// Mock methods used in loggings.
mockInput1.On("WitnessType").Return(
@ -825,7 +825,7 @@ func TestBudgetInputSetClusterInputs(t *testing.T) {
)
// Create testing pending inputs.
inputs := make(pendingInputs)
inputs := make(InputsMap)
// For each deadline height, create two inputs with different budgets,
// one below the min fee rate and one above it. We should see the lower
@ -879,7 +879,7 @@ func TestBudgetInputSetClusterInputs(t *testing.T) {
inpHigh2.On("RequiredTxOut").Return(nil)
// Add the low input, which should be filtered out.
inputs[opLow] = &pendingInput{
inputs[opLow] = &SweeperInput{
Input: inpLow,
params: Params{
Budget: budgetLow,
@ -888,14 +888,14 @@ func TestBudgetInputSetClusterInputs(t *testing.T) {
}
// Add the high inputs, which should be included.
inputs[opHigh1] = &pendingInput{
inputs[opHigh1] = &SweeperInput{
Input: inpHigh1,
params: Params{
Budget: budgetHigh,
DeadlineHeight: deadline,
},
}
inputs[opHigh2] = &pendingInput{
inputs[opHigh2] = &SweeperInput{
Input: inpHigh2,
params: Params{
Budget: budgetHigh,

View file

@ -1,10 +1,10 @@
package sweep
// bucket contains a set of inputs that are not mutually exclusive.
type bucket pendingInputs
type bucket InputsMap
// tryAdd tries to add a new input to this bucket.
func (b bucket) tryAdd(input *pendingInput) bool {
func (b bucket) tryAdd(input *SweeperInput) bool {
exclusiveGroup := input.params.ExclusiveGroup
if exclusiveGroup != nil {
for _, input := range b {
@ -40,7 +40,7 @@ type bucketList struct {
// add adds a new input. If the input is not accepted by any of the existing
// buckets, a new bucket will be created.
func (b *bucketList) add(input *pendingInput) {
func (b *bucketList) add(input *SweeperInput) {
for _, existingBucket := range b.buckets {
if existingBucket.tryAdd(input) {
return

View file

@ -342,7 +342,7 @@ type mockUtxoAggregator struct {
var _ UtxoAggregator = (*mockUtxoAggregator)(nil)
// ClusterInputs takes a list of inputs and groups them into clusters.
func (m *mockUtxoAggregator) ClusterInputs(inputs pendingInputs) []InputSet {
func (m *mockUtxoAggregator) ClusterInputs(inputs InputsMap) []InputSet {
args := m.Called(inputs)
return args.Get(0).([]InputSet)

View file

@ -179,10 +179,10 @@ type RBFInfo struct {
Fee btcutil.Amount
}
// pendingInput is created when an input reaches the main loop for the first
// SweeperInput is created when an input reaches the main loop for the first
// time. It wraps the input and tracks all relevant state that is needed for
// sweeping.
type pendingInput struct {
type SweeperInput struct {
input.Input
// state tracks the current state of the input.
@ -212,20 +212,20 @@ type pendingInput struct {
}
// String returns a human readable interpretation of the pending input.
func (p *pendingInput) String() string {
func (p *SweeperInput) String() string {
return fmt.Sprintf("%v (%v)", p.Input.OutPoint(), p.Input.WitnessType())
}
// parameters returns the sweep parameters for this input.
//
// NOTE: Part of the txInput interface.
func (p *pendingInput) parameters() Params {
func (p *SweeperInput) parameters() Params {
return p.params
}
// terminated returns a boolean indicating whether the input has reached a
// final state.
func (p *pendingInput) terminated() bool {
func (p *SweeperInput) terminated() bool {
switch p.state {
// If the input has reached a final state, that it's either
// been swept, or failed, or excluded, we will remove it from
@ -238,20 +238,20 @@ func (p *pendingInput) terminated() bool {
}
}
// pendingInputs is a type alias for a set of pending inputs.
type pendingInputs = map[wire.OutPoint]*pendingInput
// InputsMap is a type alias for a set of pending inputs.
type InputsMap = map[wire.OutPoint]*SweeperInput
// pendingSweepsReq is an internal message we'll use to represent an external
// caller's intent to retrieve all of the pending inputs the UtxoSweeper is
// attempting to sweep.
type pendingSweepsReq struct {
respChan chan map[wire.OutPoint]*PendingInput
respChan chan map[wire.OutPoint]*PendingInputResponse
errChan chan error
}
// PendingInput contains information about an input that is currently being
// swept by the UtxoSweeper.
type PendingInput struct {
// PendingInputResponse contains information about an input that is currently
// being swept by the UtxoSweeper.
type PendingInputResponse struct {
// OutPoint is the identify outpoint of the input being swept.
OutPoint wire.OutPoint
@ -309,7 +309,7 @@ type UtxoSweeper struct {
// inputs is the total set of inputs the UtxoSweeper has been requested
// to sweep.
inputs pendingInputs
inputs InputsMap
currentOutputScript []byte
@ -408,7 +408,7 @@ func New(cfg *UtxoSweeperConfig) *UtxoSweeper {
updateReqs: make(chan *updateReq),
pendingSweepsReqs: make(chan *pendingSweepsReq),
quit: make(chan struct{}),
inputs: make(pendingInputs),
inputs: make(InputsMap),
bumpResultChan: make(chan *BumpResult, 100),
}
}
@ -768,7 +768,7 @@ func (s *UtxoSweeper) removeExclusiveGroup(group uint64) {
// signalResult notifies the listeners of the final result of the input sweep.
// It also cancels any pending spend notification.
func (s *UtxoSweeper) signalResult(pi *pendingInput, result Result) {
func (s *UtxoSweeper) signalResult(pi *SweeperInput, result Result) {
op := pi.OutPoint()
listeners := pi.listeners
@ -1012,8 +1012,10 @@ func (s *UtxoSweeper) monitorSpend(outpoint wire.OutPoint,
// PendingInputs returns the set of inputs that the UtxoSweeper is currently
// attempting to sweep.
func (s *UtxoSweeper) PendingInputs() (map[wire.OutPoint]*PendingInput, error) {
respChan := make(chan map[wire.OutPoint]*PendingInput, 1)
func (s *UtxoSweeper) PendingInputs() (
map[wire.OutPoint]*PendingInputResponse, error) {
respChan := make(chan map[wire.OutPoint]*PendingInputResponse, 1)
errChan := make(chan error, 1)
select {
case s.pendingSweepsReqs <- &pendingSweepsReq{
@ -1037,26 +1039,26 @@ func (s *UtxoSweeper) PendingInputs() (map[wire.OutPoint]*PendingInput, error) {
// handlePendingSweepsReq handles a request to retrieve all pending inputs the
// UtxoSweeper is attempting to sweep.
func (s *UtxoSweeper) handlePendingSweepsReq(
req *pendingSweepsReq) map[wire.OutPoint]*PendingInput {
req *pendingSweepsReq) map[wire.OutPoint]*PendingInputResponse {
pendingInputs := make(map[wire.OutPoint]*PendingInput, len(s.inputs))
for _, pendingInput := range s.inputs {
resps := make(map[wire.OutPoint]*PendingInputResponse, len(s.inputs))
for _, inp := range s.inputs {
// Only the exported fields are set, as we expect the response
// to only be consumed externally.
op := *pendingInput.OutPoint()
pendingInputs[op] = &PendingInput{
op := *inp.OutPoint()
resps[op] = &PendingInputResponse{
OutPoint: op,
WitnessType: pendingInput.WitnessType(),
WitnessType: inp.WitnessType(),
Amount: btcutil.Amount(
pendingInput.SignDesc().Output.Value,
inp.SignDesc().Output.Value,
),
LastFeeRate: pendingInput.lastFeeRate,
BroadcastAttempts: pendingInput.publishAttempts,
Params: pendingInput.params,
LastFeeRate: inp.lastFeeRate,
BroadcastAttempts: inp.publishAttempts,
Params: inp.params,
}
}
return pendingInputs
return resps
}
// UpdateParams allows updating the sweep parameters of a pending input in the
@ -1117,30 +1119,30 @@ func (s *UtxoSweeper) handleUpdateReq(req *updateReq) (
// batched with others which also have a similar fee rate, creating a
// higher fee rate transaction that replaces the original input's
// sweeping transaction.
pendingInput, ok := s.inputs[req.input]
sweeperInput, ok := s.inputs[req.input]
if !ok {
return nil, lnwallet.ErrNotMine
}
// Create the updated parameters struct. Leave the exclusive group
// unchanged.
newParams := pendingInput.params
newParams := sweeperInput.params
newParams.Fee = req.params.Fee
newParams.Force = req.params.Force
log.Debugf("Updating parameters for %v(state=%v) from (%v) to (%v)",
req.input, pendingInput.state, pendingInput.params, newParams)
req.input, sweeperInput.state, sweeperInput.params, newParams)
pendingInput.params = newParams
sweeperInput.params = newParams
// We need to reset the state so this input will be attempted again by
// our sweeper.
//
// TODO(yy): a dedicated state?
pendingInput.state = Init
sweeperInput.state = Init
resultChan := make(chan Result, 1)
pendingInput.listeners = append(pendingInput.listeners, resultChan)
sweeperInput.listeners = append(sweeperInput.listeners, resultChan)
return resultChan, nil
}
@ -1229,7 +1231,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) {
// Create a new pendingInput and initialize the listeners slice with
// the passed in result channel. If this input is offered for sweep
// again, the result channel will be appended to this slice.
pi = &pendingInput{
pi = &SweeperInput{
state: state,
listeners: []chan Result{input.resultChan},
Input: input.input,
@ -1294,8 +1296,7 @@ func (s *UtxoSweeper) decideStateAndRBFInfo(op wire.OutPoint) (
// If the tx is not found in the store, it means it's not broadcast by
// us, hence we can't find the fee info. This is fine as, later on when
// this tx is confirmed, we will remove the input from our
// pendingInputs.
// this tx is confirmed, we will remove the input from our inputs.
if errors.Is(err, ErrTxNotFound) {
log.Warnf("Spending tx %v not found in sweeper store", txid)
return Published, fn.None[RBFInfo]()
@ -1322,7 +1323,7 @@ func (s *UtxoSweeper) decideStateAndRBFInfo(op wire.OutPoint) (
// handleExistingInput processes an input that is already known to the sweeper.
// It will overwrite the params of the old input with the new ones.
func (s *UtxoSweeper) handleExistingInput(input *sweepInputMessage,
oldInput *pendingInput) {
oldInput *SweeperInput) {
// Before updating the input details, check if an exclusive group was
// set. In case the same input is registered again without an exclusive
@ -1412,9 +1413,9 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) {
outpoint := txIn.PreviousOutPoint
// Check if this input is known to us. It could probably be
// unknown if we canceled the registration, deleted from
// pendingInputs but the ntfn was in-flight already. Or this
// could be not one of our inputs.
// unknown if we canceled the registration, deleted from inputs
// map but the ntfn was in-flight already. Or this could be not
// one of our inputs.
input, ok := s.inputs[outpoint]
if !ok {
// It's very likely that a spending tx contains inputs
@ -1460,7 +1461,7 @@ func (s *UtxoSweeper) markInputsSwept(tx *wire.MsgTx, isOurTx bool) {
// markInputFailed marks the given input as failed and won't be retried. It
// will also notify all the subscribers of this input.
func (s *UtxoSweeper) markInputFailed(pi *pendingInput, err error) {
func (s *UtxoSweeper) markInputFailed(pi *SweeperInput, err error) {
log.Errorf("Failed to sweep input: %v, error: %v", pi, err)
pi.state = Failed
@ -1476,16 +1477,16 @@ func (s *UtxoSweeper) markInputFailed(pi *pendingInput, err error) {
// updateSweeperInputs updates the sweeper's internal state and returns a map
// of inputs to be swept. It will remove the inputs that are in final states,
// and returns a map of inputs that have either state Init or PublishFailed.
func (s *UtxoSweeper) updateSweeperInputs() pendingInputs {
func (s *UtxoSweeper) updateSweeperInputs() InputsMap {
// Create a map of inputs to be swept.
inputs := make(pendingInputs)
inputs := make(InputsMap)
// Iterate the pending inputs and update the sweeper's state.
//
// TODO(yy): sweeper is made to communicate via go channels, so no
// locks are needed to access the map. However, it'd be safer if we
// turn this pendingInputs into a SyncMap in case we wanna add
// concurrent access to the map in the future.
// turn this inputs map into a SyncMap in case we wanna add concurrent
// access to the map in the future.
for op, input := range s.inputs {
// If the input has reached a final state, that it's either
// been swept, or failed, or excluded, we will remove it from
@ -1524,7 +1525,7 @@ func (s *UtxoSweeper) updateSweeperInputs() pendingInputs {
// sweepPendingInputs is called when the ticker fires. It will create clusters
// and attempt to create and publish the sweeping transactions.
func (s *UtxoSweeper) sweepPendingInputs(inputs pendingInputs) {
func (s *UtxoSweeper) sweepPendingInputs(inputs InputsMap) {
// Cluster all of our inputs based on the specific Aggregator.
sets := s.cfg.Aggregator.ClusterInputs(inputs)

View file

@ -268,15 +268,15 @@ func (ctx *sweeperTestContext) assertPendingInputs(inputs ...input.Input) {
inputSet[*input.OutPoint()] = struct{}{}
}
pendingInputs, err := ctx.sweeper.PendingInputs()
inputsMap, err := ctx.sweeper.PendingInputs()
if err != nil {
ctx.t.Fatal(err)
}
if len(pendingInputs) != len(inputSet) {
if len(inputsMap) != len(inputSet) {
ctx.t.Fatalf("expected %d pending inputs, got %d",
len(inputSet), len(pendingInputs))
len(inputSet), len(inputsMap))
}
for input := range pendingInputs {
for input := range inputsMap {
if _, ok := inputSet[input]; !ok {
ctx.t.Fatalf("found unexpected input %v", input)
}
@ -2146,7 +2146,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputInit.On("OutPoint").Return(&wire.OutPoint{Index: 1})
s.inputs[*inputInit.OutPoint()] = &pendingInput{
s.inputs[*inputInit.OutPoint()] = &SweeperInput{
state: Init,
}
@ -2156,7 +2156,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputPendingPublish.On("OutPoint").Return(&wire.OutPoint{Index: 2})
s.inputs[*inputPendingPublish.OutPoint()] = &pendingInput{
s.inputs[*inputPendingPublish.OutPoint()] = &SweeperInput{
state: PendingPublish,
}
@ -2166,7 +2166,7 @@ func TestMarkInputsPendingPublish(t *testing.T) {
inputTerminated.On("OutPoint").Return(&wire.OutPoint{Index: 3})
s.inputs[*inputTerminated.OutPoint()] = &pendingInput{
s.inputs[*inputTerminated.OutPoint()] = &SweeperInput{
state: Excluded,
}
@ -2227,7 +2227,7 @@ func TestMarkInputsPublished(t *testing.T) {
inputInit := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.inputs[inputInit.PreviousOutPoint] = &pendingInput{
s.inputs[inputInit.PreviousOutPoint] = &SweeperInput{
state: Init,
}
@ -2235,7 +2235,7 @@ func TestMarkInputsPublished(t *testing.T) {
inputPendingPublish := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.inputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
s.inputs[inputPendingPublish.PreviousOutPoint] = &SweeperInput{
state: PendingPublish,
}
@ -2307,7 +2307,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
inputInit := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.inputs[inputInit.PreviousOutPoint] = &pendingInput{
s.inputs[inputInit.PreviousOutPoint] = &SweeperInput{
state: Init,
}
@ -2315,7 +2315,7 @@ func TestMarkInputsPublishFailed(t *testing.T) {
inputPendingPublish := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.inputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
s.inputs[inputPendingPublish.PreviousOutPoint] = &SweeperInput{
state: PendingPublish,
}
@ -2373,7 +2373,7 @@ func TestMarkInputsSwept(t *testing.T) {
inputInit := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 2},
}
s.inputs[inputInit.PreviousOutPoint] = &pendingInput{
s.inputs[inputInit.PreviousOutPoint] = &SweeperInput{
state: Init,
Input: mockInput,
}
@ -2382,7 +2382,7 @@ func TestMarkInputsSwept(t *testing.T) {
inputPendingPublish := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 3},
}
s.inputs[inputPendingPublish.PreviousOutPoint] = &pendingInput{
s.inputs[inputPendingPublish.PreviousOutPoint] = &SweeperInput{
state: PendingPublish,
Input: mockInput,
}
@ -2391,7 +2391,7 @@ func TestMarkInputsSwept(t *testing.T) {
inputTerminated := &wire.TxIn{
PreviousOutPoint: wire.OutPoint{Index: 4},
}
s.inputs[inputTerminated.PreviousOutPoint] = &pendingInput{
s.inputs[inputTerminated.PreviousOutPoint] = &SweeperInput{
state: Excluded,
Input: mockInput,
}
@ -2479,17 +2479,17 @@ func TestUpdateSweeperInputs(t *testing.T) {
s := New(nil)
// Create a list of inputs using all the states.
input0 := &pendingInput{state: Init}
input1 := &pendingInput{state: PendingPublish}
input2 := &pendingInput{state: Published}
input3 := &pendingInput{state: PublishFailed}
input4 := &pendingInput{state: Swept}
input5 := &pendingInput{state: Excluded}
input6 := &pendingInput{state: Failed}
input0 := &SweeperInput{state: Init}
input1 := &SweeperInput{state: PendingPublish}
input2 := &SweeperInput{state: Published}
input3 := &SweeperInput{state: PublishFailed}
input4 := &SweeperInput{state: Swept}
input5 := &SweeperInput{state: Excluded}
input6 := &SweeperInput{state: Failed}
// Add the inputs to the sweeper. After the update, we should see the
// terminated inputs being removed.
s.inputs = map[wire.OutPoint]*pendingInput{
s.inputs = map[wire.OutPoint]*SweeperInput{
{Index: 0}: input0,
{Index: 1}: input1,
{Index: 2}: input2,
@ -2501,7 +2501,7 @@ func TestUpdateSweeperInputs(t *testing.T) {
// We expect the inputs with `Swept`, `Excluded`, and `Failed` to be
// removed.
expectedInputs := map[wire.OutPoint]*pendingInput{
expectedInputs := map[wire.OutPoint]*SweeperInput{
{Index: 0}: input0,
{Index: 1}: input1,
{Index: 2}: input2,
@ -2510,7 +2510,7 @@ func TestUpdateSweeperInputs(t *testing.T) {
// We expect only the inputs with `Init` and `PublishFailed` to be
// returned.
expectedReturn := map[wire.OutPoint]*pendingInput{
expectedReturn := map[wire.OutPoint]*SweeperInput{
{Index: 0}: input0,
{Index: 3}: input3,
}
@ -2618,7 +2618,7 @@ func TestMarkInputFailed(t *testing.T) {
s := New(&UtxoSweeperConfig{})
// Create a testing pending input.
pi := &pendingInput{
pi := &SweeperInput{
state: Init,
Input: mockInput,
}
@ -2683,7 +2683,7 @@ func TestSweepPendingInputs(t *testing.T) {
// Make pending inputs for testing. We don't need real values here as
// the returned clusters are mocked.
pis := make(pendingInputs)
pis := make(InputsMap)
// Mock the aggregator to return the mocked input sets.
aggregator.On("ClusterInputs", pis).Return([]InputSet{
@ -2729,10 +2729,10 @@ func TestHandleBumpEventTxFailed(t *testing.T) {
defer input3.AssertExpectations(t)
// Construct the initial state for the sweeper.
s.inputs = pendingInputs{
op1: &pendingInput{Input: input1, state: PendingPublish},
op2: &pendingInput{Input: input2, state: PendingPublish},
op3: &pendingInput{Input: input3, state: PendingPublish},
s.inputs = InputsMap{
op1: &SweeperInput{Input: input1, state: PendingPublish},
op2: &SweeperInput{Input: input2, state: PendingPublish},
op3: &SweeperInput{Input: input3, state: PendingPublish},
}
// Create a testing tx that spends the first two inputs.
@ -2788,8 +2788,8 @@ func TestHandleBumpEventTxReplaced(t *testing.T) {
defer inp.AssertExpectations(t)
// Construct the initial state for the sweeper.
s.inputs = pendingInputs{
op: &pendingInput{Input: inp, state: PendingPublish},
s.inputs = InputsMap{
op: &SweeperInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.
@ -2878,8 +2878,8 @@ func TestHandleBumpEventTxPublished(t *testing.T) {
defer inp.AssertExpectations(t)
// Construct the initial state for the sweeper.
s.inputs = pendingInputs{
op: &pendingInput{Input: inp, state: PendingPublish},
s.inputs = InputsMap{
op: &SweeperInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.
@ -2930,8 +2930,8 @@ func TestMonitorFeeBumpResult(t *testing.T) {
defer inp.AssertExpectations(t)
// Construct the initial state for the sweeper.
s.inputs = pendingInputs{
op: &pendingInput{Input: inp, state: PendingPublish},
s.inputs = InputsMap{
op: &SweeperInput{Input: inp, state: PendingPublish},
}
// Create a testing tx that spends the input.

View file

@ -402,7 +402,7 @@ func (t *txInputSet) add(input input.Input, constraints addConstraints) bool {
// up the utxo set even if it costs us some fees up front. In the spirit of
// minimizing any negative externalities we cause for the Bitcoin system as a
// whole.
func (t *txInputSet) addPositiveYieldInputs(sweepableInputs []*pendingInput) {
func (t *txInputSet) addPositiveYieldInputs(sweepableInputs []*SweeperInput) {
for i, inp := range sweepableInputs {
// Apply relaxed constraints for force sweeps.
constraints := constraintsRegular
@ -549,7 +549,7 @@ func createWalletTxInput(utxo *lnwallet.Utxo) (input.Input, error) {
type BudgetInputSet struct {
// inputs is the set of inputs that have been added to the set after
// considering their economical contribution.
inputs []*pendingInput
inputs []*SweeperInput
// deadlineHeight is the height which the inputs in this set must be
// confirmed by.
@ -561,7 +561,7 @@ var _ InputSet = (*BudgetInputSet)(nil)
// validateInputs is used when creating new BudgetInputSet to ensure there are
// no duplicate inputs and they all share the same deadline heights, if set.
func validateInputs(inputs []pendingInput) error {
func validateInputs(inputs []SweeperInput) error {
// Sanity check the input slice to ensure it's non-empty.
if len(inputs) == 0 {
return fmt.Errorf("inputs slice is empty")
@ -597,7 +597,7 @@ func validateInputs(inputs []pendingInput) error {
}
// NewBudgetInputSet creates a new BudgetInputSet.
func NewBudgetInputSet(inputs []pendingInput) (*BudgetInputSet, error) {
func NewBudgetInputSet(inputs []SweeperInput) (*BudgetInputSet, error) {
// Validate the supplied inputs.
if err := validateInputs(inputs); err != nil {
return nil, err
@ -611,7 +611,7 @@ func NewBudgetInputSet(inputs []pendingInput) (*BudgetInputSet, error) {
deadlineHeight := inputs[0].params.DeadlineHeight
bi := &BudgetInputSet{
deadlineHeight: deadlineHeight,
inputs: make([]*pendingInput, 0, len(inputs)),
inputs: make([]*SweeperInput, 0, len(inputs)),
}
for _, input := range inputs {
@ -640,7 +640,7 @@ func (b *BudgetInputSet) String() string {
}
// addInput adds an input to the input set.
func (b *BudgetInputSet) addInput(input pendingInput) {
func (b *BudgetInputSet) addInput(input SweeperInput) {
b.inputs = append(b.inputs, &input)
}
@ -695,8 +695,8 @@ func (b *BudgetInputSet) NeedWalletInput() bool {
}
// copyInputs returns a copy of the slice of the inputs in the set.
func (b *BudgetInputSet) copyInputs() []*pendingInput {
inputs := make([]*pendingInput, len(b.inputs))
func (b *BudgetInputSet) copyInputs() []*SweeperInput {
inputs := make([]*SweeperInput, len(b.inputs))
copy(inputs, b.inputs)
return inputs
}
@ -745,7 +745,7 @@ func (b *BudgetInputSet) AddWalletInputs(wallet Wallet) error {
return err
}
pi := pendingInput{
pi := SweeperInput{
Input: input,
params: Params{
// Inherit the deadline height from the input

View file

@ -250,7 +250,7 @@ func TestNewBudgetInputSet(t *testing.T) {
rt := require.New(t)
// Pass an empty slice and expect an error.
set, err := NewBudgetInputSet([]pendingInput{})
set, err := NewBudgetInputSet([]SweeperInput{})
rt.ErrorContains(err, "inputs slice is empty")
rt.Nil(set)
@ -258,21 +258,21 @@ func TestNewBudgetInputSet(t *testing.T) {
inp0 := createP2WKHInput(1000)
inp1 := createP2WKHInput(1000)
inp2 := createP2WKHInput(1000)
input0 := pendingInput{
input0 := SweeperInput{
Input: inp0,
params: Params{
Budget: 100,
DeadlineHeight: fn.None[int32](),
},
}
input1 := pendingInput{
input1 := SweeperInput{
Input: inp1,
params: Params{
Budget: 100,
DeadlineHeight: fn.Some(int32(1)),
},
}
input2 := pendingInput{
input2 := SweeperInput{
Input: inp2,
params: Params{
Budget: 100,
@ -281,17 +281,17 @@ func TestNewBudgetInputSet(t *testing.T) {
}
// Pass a slice of inputs with different deadline heights.
set, err = NewBudgetInputSet([]pendingInput{input1, input2})
set, err = NewBudgetInputSet([]SweeperInput{input1, input2})
rt.ErrorContains(err, "inputs have different deadline heights")
rt.Nil(set)
// Pass a slice of inputs that only one input has the deadline height.
set, err = NewBudgetInputSet([]pendingInput{input0, input2})
set, err = NewBudgetInputSet([]SweeperInput{input0, input2})
rt.NoError(err)
rt.NotNil(set)
// Pass a slice of inputs that are duplicates.
set, err = NewBudgetInputSet([]pendingInput{input1, input1})
set, err = NewBudgetInputSet([]SweeperInput{input1, input1})
rt.ErrorContains(err, "duplicate inputs")
rt.Nil(set)
}
@ -303,7 +303,7 @@ func TestBudgetInputSetAddInput(t *testing.T) {
// Create a testing input with a budget of 100 satoshis.
input := createP2WKHInput(1000)
pi := &pendingInput{
pi := &SweeperInput{
Input: input,
params: Params{
Budget: 100,
@ -311,7 +311,7 @@ func TestBudgetInputSetAddInput(t *testing.T) {
}
// Initialize an input set, which adds the above input.
set, err := NewBudgetInputSet([]pendingInput{*pi})
set, err := NewBudgetInputSet([]SweeperInput{*pi})
require.NoError(t, err)
// Add the input to the set again.
@ -345,20 +345,20 @@ func TestNeedWalletInput(t *testing.T) {
const budget = 100
// Create the pending input that doesn't have a required output.
piBudget := &pendingInput{
piBudget := &SweeperInput{
Input: mockInput,
params: Params{Budget: budget},
}
// Create the pending input that has a required output.
piRequireOutput := &pendingInput{
piRequireOutput := &SweeperInput{
Input: mockInputRequireOutput,
params: Params{Budget: budget},
}
testCases := []struct {
name string
setupInputs func() []*pendingInput
setupInputs func() []*SweeperInput
need bool
}{
{
@ -366,7 +366,7 @@ func TestNeedWalletInput(t *testing.T) {
// wallet input. Technically this should be an invalid
// state.
name: "no inputs",
setupInputs: func() []*pendingInput {
setupInputs: func() []*SweeperInput {
return nil
},
need: false,
@ -375,7 +375,7 @@ func TestNeedWalletInput(t *testing.T) {
// When there's no required output, we don't need a
// wallet input.
name: "no required outputs",
setupInputs: func() []*pendingInput {
setupInputs: func() []*SweeperInput {
// Create a sign descriptor to be used in the
// pending input when calculating budgets can
// be borrowed.
@ -386,7 +386,7 @@ func TestNeedWalletInput(t *testing.T) {
}
mockInput.On("SignDesc").Return(sd).Once()
return []*pendingInput{piBudget}
return []*SweeperInput{piBudget}
},
need: false,
},
@ -394,7 +394,7 @@ func TestNeedWalletInput(t *testing.T) {
// When the output value cannot cover the budget, we
// need a wallet input.
name: "output value cannot cover budget",
setupInputs: func() []*pendingInput {
setupInputs: func() []*SweeperInput {
// Create a sign descriptor to be used in the
// pending input when calculating budgets can
// be borrowed.
@ -414,7 +414,7 @@ func TestNeedWalletInput(t *testing.T) {
input.CommitmentAnchor,
).Maybe()
return []*pendingInput{piBudget}
return []*SweeperInput{piBudget}
},
need: true,
},
@ -422,8 +422,8 @@ func TestNeedWalletInput(t *testing.T) {
// When there's only inputs that require outputs, we
// need wallet inputs.
name: "only required outputs",
setupInputs: func() []*pendingInput {
return []*pendingInput{piRequireOutput}
setupInputs: func() []*SweeperInput {
return []*SweeperInput{piRequireOutput}
},
need: true,
},
@ -432,7 +432,7 @@ func TestNeedWalletInput(t *testing.T) {
// budget cannot cover the required, we need a wallet
// input.
name: "not enough budget to be borrowed",
setupInputs: func() []*pendingInput {
setupInputs: func() []*SweeperInput {
// Create a sign descriptor to be used in the
// pending input when calculating budgets can
// be borrowed.
@ -446,7 +446,7 @@ func TestNeedWalletInput(t *testing.T) {
}
mockInput.On("SignDesc").Return(sd).Once()
return []*pendingInput{
return []*SweeperInput{
piBudget, piRequireOutput,
}
},
@ -457,7 +457,7 @@ func TestNeedWalletInput(t *testing.T) {
// borrowed covers the required, we don't need wallet
// inputs.
name: "enough budget to be borrowed",
setupInputs: func() []*pendingInput {
setupInputs: func() []*SweeperInput {
// Create a sign descriptor to be used in the
// pending input when calculating budgets can
// be borrowed.
@ -472,7 +472,7 @@ func TestNeedWalletInput(t *testing.T) {
mockInput.On("SignDesc").Return(sd).Once()
piBudget.Input = mockInput
return []*pendingInput{
return []*SweeperInput{
piBudget, piRequireOutput,
}
},
@ -567,7 +567,7 @@ func TestAddWalletInputNotEnoughInputs(t *testing.T) {
defer mockInput.AssertExpectations(t)
// Create a pending input that requires 10k satoshis.
pi := &pendingInput{
pi := &SweeperInput{
Input: mockInput,
params: Params{Budget: budget},
}
@ -583,7 +583,7 @@ func TestAddWalletInputNotEnoughInputs(t *testing.T) {
min, max).Return([]*lnwallet.Utxo{utxo}, nil).Once()
// Initialize an input set with the pending input.
set := BudgetInputSet{inputs: []*pendingInput{pi}}
set := BudgetInputSet{inputs: []*SweeperInput{pi}}
// Add wallet inputs to the input set, which should give us an error as
// the wallet cannot cover the budget.
@ -617,7 +617,7 @@ func TestAddWalletInputSuccess(t *testing.T) {
// Create a pending input that requires 10k satoshis.
deadline := int32(1000)
pi := &pendingInput{
pi := &SweeperInput{
Input: mockInput,
params: Params{
Budget: budget,
@ -643,7 +643,7 @@ func TestAddWalletInputSuccess(t *testing.T) {
min, max).Return([]*lnwallet.Utxo{utxo, utxo}, nil).Once()
// Initialize an input set with the pending input.
set, err := NewBudgetInputSet([]pendingInput{*pi})
set, err := NewBudgetInputSet([]SweeperInput{*pi})
require.NoError(t, err)
// Add wallet inputs to the input set, which should give us an error as