diff --git a/contractcourt/breach_arbitrator.go b/contractcourt/breach_arbitrator.go index 017e8bdac..89927b6e1 100644 --- a/contractcourt/breach_arbitrator.go +++ b/contractcourt/breach_arbitrator.go @@ -1102,8 +1102,8 @@ func (bo *breachedOutput) Amount() btcutil.Amount { // OutPoint returns the breached output's identifier that is to be included as a // transaction input. -func (bo *breachedOutput) OutPoint() *wire.OutPoint { - return &bo.outpoint +func (bo *breachedOutput) OutPoint() wire.OutPoint { + return bo.outpoint } // RequiredTxOut returns a non-nil TxOut if input commits to a certain @@ -1547,7 +1547,7 @@ func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight int64, // transaction. for _, inp := range inputs { txn.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *inp.OutPoint(), + PreviousOutPoint: inp.OutPoint(), Sequence: inp.BlocksToMaturity(), }) } @@ -1641,7 +1641,7 @@ func taprootBriefcaseFromRetInfo(retInfo *retributionInfo) *taprootBriefcase { case input.TaprootHtlcAcceptedRevoke: fallthrough case input.TaprootHtlcOfferedRevoke: - resID := newResolverID(*bo.OutPoint()) + resID := newResolverID(bo.OutPoint()) var firstLevelTweak [32]byte copy(firstLevelTweak[:], bo.signDesc.TapTweak) @@ -1684,7 +1684,7 @@ func applyTaprootRetInfo(tapCase *taprootBriefcase, case input.TaprootHtlcAcceptedRevoke: fallthrough case input.TaprootHtlcOfferedRevoke: - resID := newResolverID(*bo.OutPoint()) + resID := newResolverID(bo.OutPoint()) tap1, ok := tapCase.TapTweaks.BreachedHtlcTweaks[resID] if !ok { diff --git a/contractcourt/breach_arbitrator_test.go b/contractcourt/breach_arbitrator_test.go index fdc1239b4..2fe4644db 100644 --- a/contractcourt/breach_arbitrator_test.go +++ b/contractcourt/breach_arbitrator_test.go @@ -1202,8 +1202,13 @@ func TestBreachCreateJusticeTx(t *testing.T) { for i, wt := range outputTypes { // Create a fake breached output for each type, ensuring they // have different outpoints for our logic to accept them. + // + // NOTE: although they are fake, we need to make sure the + // outputs are not empty values, otherwise they will be equal + // to `EmptyOutPoint` and `MultiPrevOutFetcher` will return an + // error. op := breachedOutputs[0].outpoint - op.Index = uint32(i) + op.Index = uint32(1000 + i) breachedOutputs[i] = makeBreachedOutput( &op, wt, diff --git a/contractcourt/htlc_success_resolver_test.go b/contractcourt/htlc_success_resolver_test.go index d2c9bf051..f1c401cc1 100644 --- a/contractcourt/htlc_success_resolver_test.go +++ b/contractcourt/htlc_success_resolver_test.go @@ -394,7 +394,7 @@ func TestHtlcSuccessSecondStageResolutionSweeper(t *testing.T) { resolver := ctx.resolver.(*htlcSuccessResolver) inp := <-resolver.Sweeper.(*mockSweeper).sweptInputs op := inp.OutPoint() - if *op != commitOutpoint { + if op != commitOutpoint { return fmt.Errorf("outpoint %v swept, "+ "expected %v", op, commitOutpoint) @@ -443,7 +443,7 @@ func TestHtlcSuccessSecondStageResolutionSweeper(t *testing.T) { Hash: reSignedHash, Index: 1, } - if *op != exp { + if op != exp { return fmt.Errorf("swept outpoint %v, expected %v", op, exp) } diff --git a/contractcourt/htlc_timeout_resolver_test.go b/contractcourt/htlc_timeout_resolver_test.go index 931361ff5..6797a21f7 100644 --- a/contractcourt/htlc_timeout_resolver_test.go +++ b/contractcourt/htlc_timeout_resolver_test.go @@ -1030,7 +1030,7 @@ func TestHtlcTimeoutSecondStageSweeper(t *testing.T) { resolver := ctx.resolver.(*htlcTimeoutResolver) inp := <-resolver.Sweeper.(*mockSweeper).sweptInputs op := inp.OutPoint() - if *op != commitOutpoint { + if op != commitOutpoint { return fmt.Errorf("outpoint %v swept, "+ "expected %v", op, commitOutpoint) @@ -1095,7 +1095,7 @@ func TestHtlcTimeoutSecondStageSweeper(t *testing.T) { Hash: reSignedHash, Index: 1, } - if *op != exp { + if op != exp { return fmt.Errorf("wrong outpoint swept") } @@ -1205,7 +1205,7 @@ func TestHtlcTimeoutSecondStageSweeperRemoteSpend(t *testing.T) { resolver := ctx.resolver.(*htlcTimeoutResolver) inp := <-resolver.Sweeper.(*mockSweeper).sweptInputs op := inp.OutPoint() - if *op != commitOutpoint { + if op != commitOutpoint { return fmt.Errorf("outpoint %v swept, "+ "expected %v", op, commitOutpoint) diff --git a/contractcourt/nursery_store.go b/contractcourt/nursery_store.go index 3dc3416f7..a976ed89c 100644 --- a/contractcourt/nursery_store.go +++ b/contractcourt/nursery_store.go @@ -212,7 +212,7 @@ func prefixChainKey(sysPrefix []byte, hash *chainhash.Hash) ([]byte, error) { // outpoint with the provided state prefix. The returned bytes will be of the // form . func prefixOutputKey(statePrefix []byte, - outpoint *wire.OutPoint) ([]byte, error) { + outpoint wire.OutPoint) ([]byte, error) { // Create a buffer to which we will first write the state prefix, // followed by the outpoint. @@ -221,7 +221,7 @@ func prefixOutputKey(statePrefix []byte, return nil, err } - err := writeOutpoint(&pfxOutputBuffer, outpoint) + err := writeOutpoint(&pfxOutputBuffer, &outpoint) if err != nil { return nil, err } diff --git a/contractcourt/utxonursery.go b/contractcourt/utxonursery.go index c2f0264d3..d823618c8 100644 --- a/contractcourt/utxonursery.go +++ b/contractcourt/utxonursery.go @@ -1134,7 +1134,7 @@ func (c *ContractMaturityReport) AddLimboStage1TimeoutHtlc(baby *babyOutput) { // TODO(roasbeef): bool to indicate stage 1 vs stage 2? c.Htlcs = append(c.Htlcs, HtlcMaturityReport{ - Outpoint: *baby.OutPoint(), + Outpoint: baby.OutPoint(), Amount: baby.Amount(), MaturityHeight: baby.expiry, Stage: 1, @@ -1148,7 +1148,7 @@ func (c *ContractMaturityReport) AddLimboDirectHtlc(kid *kidOutput) { c.LimboBalance += kid.Amount() htlcReport := HtlcMaturityReport{ - Outpoint: *kid.OutPoint(), + Outpoint: kid.OutPoint(), Amount: kid.Amount(), MaturityHeight: kid.absoluteMaturity, Stage: 2, @@ -1164,7 +1164,7 @@ func (c *ContractMaturityReport) AddLimboStage1SuccessHtlc(kid *kidOutput) { c.LimboBalance += kid.Amount() c.Htlcs = append(c.Htlcs, HtlcMaturityReport{ - Outpoint: *kid.OutPoint(), + Outpoint: kid.OutPoint(), Amount: kid.Amount(), Stage: 1, }) @@ -1176,7 +1176,7 @@ func (c *ContractMaturityReport) AddLimboStage2Htlc(kid *kidOutput) { c.LimboBalance += kid.Amount() htlcReport := HtlcMaturityReport{ - Outpoint: *kid.OutPoint(), + Outpoint: kid.OutPoint(), Amount: kid.Amount(), Stage: 2, } @@ -1197,7 +1197,7 @@ func (c *ContractMaturityReport) AddRecoveredHtlc(kid *kidOutput) { c.RecoveredBalance += kid.Amount() c.Htlcs = append(c.Htlcs, HtlcMaturityReport{ - Outpoint: *kid.OutPoint(), + Outpoint: kid.OutPoint(), Amount: kid.Amount(), MaturityHeight: kid.ConfHeight() + kid.BlocksToMaturity(), }) @@ -1421,7 +1421,8 @@ func (k *kidOutput) Encode(w io.Writer) error { return err } - if err := writeOutpoint(w, k.OutPoint()); err != nil { + op := k.OutPoint() + if err := writeOutpoint(w, &op); err != nil { return err } if err := writeOutpoint(w, k.OriginChanPoint()); err != nil { diff --git a/contractcourt/utxonursery_test.go b/contractcourt/utxonursery_test.go index 05cda32ca..59a4de118 100644 --- a/contractcourt/utxonursery_test.go +++ b/contractcourt/utxonursery_test.go @@ -1065,7 +1065,7 @@ func newMockSweeperFull(t *testing.T) *mockSweeperFull { func (s *mockSweeperFull) sweepInput(input input.Input, _ sweep.Params) (chan sweep.Result, error) { - log.Debugf("mockSweeper sweepInput called for %v", *input.OutPoint()) + log.Debugf("mockSweeper sweepInput called for %v", input.OutPoint()) select { case s.sweepChan <- input: @@ -1077,7 +1077,7 @@ func (s *mockSweeperFull) sweepInput(input input.Input, defer s.lock.Unlock() c := make(chan sweep.Result, 1) - s.resultChans[*input.OutPoint()] = c + s.resultChans[input.OutPoint()] = c return c, nil } diff --git a/input/input.go b/input/input.go index fe7971eed..516ebbdbe 100644 --- a/input/input.go +++ b/input/input.go @@ -9,6 +9,9 @@ import ( "github.com/lightningnetwork/lnd/lntypes" ) +// EmptyOutPoint is a zeroed outpoint. +var EmptyOutPoint wire.OutPoint + // Input represents an abstract UTXO which is to be spent using a sweeping // transaction. The method provided give the caller all information needed to // construct a valid input within a sweeping transaction to sweep this @@ -16,7 +19,7 @@ import ( type Input interface { // Outpoint returns the reference to the output being spent, used to // construct the corresponding transaction input. - OutPoint() *wire.OutPoint + OutPoint() wire.OutPoint // RequiredTxOut returns a non-nil TxOut if input commits to a certain // transaction output. This is used in the SINGLE|ANYONECANPAY case to @@ -107,8 +110,8 @@ type inputKit struct { // OutPoint returns the breached output's identifier that is to be included as // a transaction input. -func (i *inputKit) OutPoint() *wire.OutPoint { - return &i.outpoint +func (i *inputKit) OutPoint() wire.OutPoint { + return i.outpoint } // RequiredTxOut returns a nil for the base input type. diff --git a/input/mocks.go b/input/mocks.go index 23ce6930e..915e4ea69 100644 --- a/input/mocks.go +++ b/input/mocks.go @@ -23,15 +23,11 @@ var _ Input = (*MockInput)(nil) // Outpoint returns the reference to the output being spent, used to construct // the corresponding transaction input. -func (m *MockInput) OutPoint() *wire.OutPoint { +func (m *MockInput) OutPoint() wire.OutPoint { args := m.Called() op := args.Get(0) - if op == nil { - return nil - } - - return op.(*wire.OutPoint) + return op.(wire.OutPoint) } // RequiredTxOut returns a non-nil TxOut if input commits to a certain diff --git a/input/taproot.go b/input/taproot.go index 935050f78..34cdb974d 100644 --- a/input/taproot.go +++ b/input/taproot.go @@ -43,7 +43,7 @@ func MultiPrevOutFetcher(inputs []Input) (*txscript.MultiPrevOutFetcher, error) op := inp.OutPoint() desc := inp.SignDesc() - if op == nil { + if op == EmptyOutPoint { return nil, fmt.Errorf("missing input outpoint") } @@ -51,7 +51,7 @@ func MultiPrevOutFetcher(inputs []Input) (*txscript.MultiPrevOutFetcher, error) return nil, fmt.Errorf("missing input utxo information") } - fetcher.AddPrevOut(*op, desc.Output) + fetcher.AddPrevOut(op, desc.Output) } return fetcher, nil diff --git a/sweep/aggregator.go b/sweep/aggregator.go index ad84eb2f1..09a691fb0 100644 --- a/sweep/aggregator.go +++ b/sweep/aggregator.go @@ -521,7 +521,7 @@ func (b *BudgetAggregator) ClusterInputs(inputs InputsMap) []InputSet { // Put exclusive inputs in their own set. if input.params.ExclusiveGroup != nil { log.Tracef("Input %v is exclusive", input.OutPoint()) - exclusiveInputs[*input.OutPoint()] = input + exclusiveInputs[input.OutPoint()] = input continue } @@ -655,7 +655,7 @@ func (b *BudgetAggregator) filterInputs(inputs InputsMap) InputsMap { } } - filteredInputs[*op] = pi + filteredInputs[op] = pi } return filteredInputs diff --git a/sweep/aggregator_test.go b/sweep/aggregator_test.go index cc4993707..fce02de32 100644 --- a/sweep/aggregator_test.go +++ b/sweep/aggregator_test.go @@ -460,7 +460,7 @@ func TestBudgetAggregatorFilterInputs(t *testing.T) { // Mock the `OutPoint` method to return a unique outpoint. opErr := wire.OutPoint{Hash: chainhash.Hash{1}} - inpErr.On("OutPoint").Return(&opErr).Once() + inpErr.On("OutPoint").Return(opErr).Once() // Mock the estimator to return a constant fee rate. const minFeeRate = chainfee.SatPerKWeight(1000) @@ -502,10 +502,10 @@ func TestBudgetAggregatorFilterInputs(t *testing.T) { inpDust.On("WitnessType").Return(wt) // Mock the `OutPoint` method to return the unique outpoint. - inpLow.On("OutPoint").Return(&opLow) - inpEqual.On("OutPoint").Return(&opEqual) - inpHigh.On("OutPoint").Return(&opHigh) - inpDust.On("OutPoint").Return(&opDust) + inpLow.On("OutPoint").Return(opLow) + inpEqual.On("OutPoint").Return(opEqual) + inpHigh.On("OutPoint").Return(opHigh) + inpDust.On("OutPoint").Return(opDust) // Mock the `RequiredTxOut` to return nil. inpEqual.On("RequiredTxOut").Return(nil) @@ -700,7 +700,7 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) { mockInput1.On("WitnessType").Return( input.CommitmentAnchor) mockInput1.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{1}}) + wire.OutPoint{Hash: chainhash.Hash{1}}) }, expectedNumSets: 1, }, @@ -717,9 +717,9 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) { input.CommitmentAnchor) mockInput1.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{1}}) + wire.OutPoint{Hash: chainhash.Hash{1}}) mockInput2.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{2}}) + wire.OutPoint{Hash: chainhash.Hash{2}}) }, expectedNumSets: 1, }, @@ -738,11 +738,11 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) { input.CommitmentAnchor) mockInput1.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{1}}) + wire.OutPoint{Hash: chainhash.Hash{1}}) mockInput2.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{2}}) + wire.OutPoint{Hash: chainhash.Hash{2}}) mockInput3.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{3}}) + wire.OutPoint{Hash: chainhash.Hash{3}}) }, expectedNumSets: 2, }, @@ -760,11 +760,11 @@ func TestBudgetAggregatorCreateInputSets(t *testing.T) { input.CommitmentAnchor) mockInput1.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{1}}) + wire.OutPoint{Hash: chainhash.Hash{1}}) mockInput3.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{3}}) + wire.OutPoint{Hash: chainhash.Hash{3}}) mockInput4.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{2}}) + wire.OutPoint{Hash: chainhash.Hash{2}}) }, expectedNumSets: 1, }, @@ -837,7 +837,7 @@ func TestBudgetInputSetClusterInputs(t *testing.T) { // 3. when assigning the input to the exclusiveInputs. // 4. when iterating the exclusiveInputs. opExclusive := wire.OutPoint{Hash: chainhash.Hash{1, 2, 3, 4, 5}} - inpExclusive.On("OutPoint").Return(&opExclusive).Times(4) + inpExclusive.On("OutPoint").Return(opExclusive).Times(4) // Mock the `WitnessType` method to return the witness type. inpExclusive.On("WitnessType").Return(wt) @@ -891,13 +891,13 @@ func TestBudgetInputSetClusterInputs(t *testing.T) { // // We expect the low budget input to call this method once in // `filterInputs`. - inpLow.On("OutPoint").Return(&opLow).Once() + inpLow.On("OutPoint").Return(opLow).Once() // We expect the high budget input to call this method three // times, one in `filterInputs` and one in `createInputSet`, // and one in `NewBudgetInputSet`. - inpHigh1.On("OutPoint").Return(&opHigh1).Times(3) - inpHigh2.On("OutPoint").Return(&opHigh2).Times(3) + inpHigh1.On("OutPoint").Return(opHigh1).Times(3) + inpHigh2.On("OutPoint").Return(opHigh2).Times(3) // Mock the `WitnessType` method to return the witness type. inpLow.On("WitnessType").Return(wt) diff --git a/sweep/bucket_list.go b/sweep/bucket_list.go index fdaf2cf66..e5a2cfea6 100644 --- a/sweep/bucket_list.go +++ b/sweep/bucket_list.go @@ -28,7 +28,7 @@ func (b bucket) tryAdd(input *SweeperInput) bool { } } - b[*input.OutPoint()] = input + b[input.OutPoint()] = input return true } diff --git a/sweep/fee_bumper.go b/sweep/fee_bumper.go index f44f5e11d..e7569d5da 100644 --- a/sweep/fee_bumper.go +++ b/sweep/fee_bumper.go @@ -996,7 +996,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input, changePkScript []byte, idxs = append(idxs, o) sweepTx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *o.OutPoint(), + PreviousOutPoint: o.OutPoint(), Sequence: o.BlocksToMaturity(), }) sweepTx.AddTxOut(o.RequiredTxOut()) @@ -1011,7 +1011,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input, changePkScript []byte, idxs = append(idxs, o) sweepTx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *o.OutPoint(), + PreviousOutPoint: o.OutPoint(), Sequence: o.BlocksToMaturity(), }) } diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 1a7a8b94f..37817361b 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -502,10 +502,12 @@ func (s *UtxoSweeper) Stop() error { // cannot make a local copy in sweeper. // // TODO(yy): make sure the caller is using the Result chan. -func (s *UtxoSweeper) SweepInput(input input.Input, +func (s *UtxoSweeper) SweepInput(inp input.Input, params Params) (chan Result, error) { - if input == nil || input.OutPoint() == nil || input.SignDesc() == nil { + if inp == nil || inp.OutPoint() == input.EmptyOutPoint || + inp.SignDesc() == nil { + return nil, errors.New("nil input received") } @@ -521,16 +523,16 @@ func (s *UtxoSweeper) SweepInput(input input.Input, } } - absoluteTimeLock, _ := input.RequiredLockTime() + absoluteTimeLock, _ := inp.RequiredLockTime() log.Infof("Sweep request received: out_point=%v, witness_type=%v, "+ "relative_time_lock=%v, absolute_time_lock=%v, amount=%v, "+ - "parent=(%v), params=(%v), currentHeight=%v", input.OutPoint(), - input.WitnessType(), input.BlocksToMaturity(), absoluteTimeLock, - btcutil.Amount(input.SignDesc().Output.Value), - input.UnconfParent(), params, s.currentHeight) + "parent=(%v), params=(%v)", inp.OutPoint(), inp.WitnessType(), + inp.BlocksToMaturity(), absoluteTimeLock, + btcutil.Amount(inp.SignDesc().Output.Value), + inp.UnconfParent(), params) sweeperInput := &sweepInputMessage{ - input: input, + input: inp, params: params, resultChan: make(chan Result, 1), } @@ -837,7 +839,7 @@ func (s *UtxoSweeper) sweep(set InputSet) error { if err != nil { outpoints := make([]wire.OutPoint, len(set.Inputs())) for i, inp := range set.Inputs() { - outpoints[i] = *inp.OutPoint() + outpoints[i] = inp.OutPoint() } // TODO(yy): find out which input is causing the failure. @@ -860,7 +862,7 @@ func (s *UtxoSweeper) sweep(set InputSet) error { func (s *UtxoSweeper) markInputsPendingPublish(set InputSet) { // Reschedule sweep. for _, input := range set.Inputs() { - pi, ok := s.inputs[*input.OutPoint()] + pi, ok := s.inputs[input.OutPoint()] if !ok { // It could be that this input is an additional wallet // input that was attached. In that case there also @@ -1045,7 +1047,7 @@ func (s *UtxoSweeper) handlePendingSweepsReq( for _, inp := range s.inputs { // Only the exported fields are set, as we expect the response // to only be consumed externally. - op := *inp.OutPoint() + op := inp.OutPoint() resps[op] = &PendingInputResponse{ OutPoint: op, WitnessType: inp.WitnessType(), @@ -1220,7 +1222,7 @@ func (s *UtxoSweeper) mempoolLookup(op wire.OutPoint) fn.Option[wire.MsgTx] { // handleNewInput processes a new input by registering spend notification and // scheduling sweeping for it. func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) { - outpoint := *input.input.OutPoint() + outpoint := input.input.OutPoint() pi, pending := s.inputs[outpoint] if pending { log.Debugf("Already has pending input %v received", outpoint) @@ -1233,7 +1235,7 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) { // This is a new input, and we want to query the mempool to see if this // input has already been spent. If so, we'll start the input with // state Published and attach the RBFInfo. - state, rbfInfo := s.decideStateAndRBFInfo(*input.input.OutPoint()) + state, rbfInfo := s.decideStateAndRBFInfo(input.input.OutPoint()) // Create a new pendingInput and initialize the listeners slice with // the passed in result channel. If this input is offered for sweep diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 51f21ce98..57fa74116 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -264,7 +264,7 @@ func (ctx *sweeperTestContext) assertPendingInputs(inputs ...input.Input) { inputSet := make(map[wire.OutPoint]struct{}, len(inputs)) for _, input := range inputs { - inputSet[*input.OutPoint()] = struct{}{} + inputSet[input.OutPoint()] = struct{}{} } inputsMap, err := ctx.sweeper.PendingInputs() @@ -295,7 +295,7 @@ func assertTxSweepsInputs(t *testing.T, sweepTx *wire.MsgTx, } m := make(map[wire.OutPoint]struct{}, len(inputs)) for _, input := range inputs { - m[*input.OutPoint()] = struct{}{} + m[input.OutPoint()] = struct{}{} } for _, txIn := range sweepTx.TxIn { if _, ok := m[txIn.PreviousOutPoint]; !ok { @@ -322,7 +322,7 @@ func assertTxFeeRate(t *testing.T, tx *wire.MsgTx, m := make(map[wire.OutPoint]input.Input, len(inputs)) for _, input := range inputs { - m[*input.OutPoint()] = input + m[input.OutPoint()] = input } var inputAmt int64 @@ -387,7 +387,7 @@ func TestSuccess(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{{ - PreviousOutPoint: *inp.OutPoint(), + PreviousOutPoint: inp.OutPoint(), }}, } @@ -473,8 +473,8 @@ func TestDust(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *largeInput.OutPoint()}, - {PreviousOutPoint: *dustInput.OutPoint()}, + {PreviousOutPoint: largeInput.OutPoint()}, + {PreviousOutPoint: dustInput.OutPoint()}, }, } @@ -541,7 +541,7 @@ func TestWalletUtxo(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *dustInput.OutPoint()}, + {PreviousOutPoint: dustInput.OutPoint()}, }, } @@ -615,8 +615,8 @@ func TestNegativeInput(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *largeInput.OutPoint()}, - {PreviousOutPoint: *positiveInput.OutPoint()}, + {PreviousOutPoint: largeInput.OutPoint()}, + {PreviousOutPoint: positiveInput.OutPoint()}, }, } @@ -675,9 +675,8 @@ func TestNegativeInput(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *negInput.OutPoint()}, - {PreviousOutPoint: *secondLargeInput. - OutPoint()}, + {PreviousOutPoint: negInput.OutPoint()}, + {PreviousOutPoint: secondLargeInput.OutPoint()}, }, } @@ -735,9 +734,9 @@ func TestChunks(t *testing.T) { //nolint:lll tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *spendableInputs[0].OutPoint()}, - {PreviousOutPoint: *spendableInputs[1].OutPoint()}, - {PreviousOutPoint: *spendableInputs[2].OutPoint()}, + {PreviousOutPoint: spendableInputs[0].OutPoint()}, + {PreviousOutPoint: spendableInputs[1].OutPoint()}, + {PreviousOutPoint: spendableInputs[2].OutPoint()}, }, } @@ -764,8 +763,8 @@ func TestChunks(t *testing.T) { //nolint:lll tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *spendableInputs[3].OutPoint()}, - {PreviousOutPoint: *spendableInputs[4].OutPoint()}, + {PreviousOutPoint: spendableInputs[3].OutPoint()}, + {PreviousOutPoint: spendableInputs[4].OutPoint()}, }, } @@ -838,7 +837,7 @@ func testRemoteSpend(t *testing.T, postSweep bool) { // will be spent by the remote. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *spendableInputs[1].OutPoint()}, + {PreviousOutPoint: spendableInputs[1].OutPoint()}, }, } @@ -874,7 +873,7 @@ func testRemoteSpend(t *testing.T, postSweep bool) { // Spend the input with an unknown tx. remoteTx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *(spendableInputs[0].OutPoint())}, + {PreviousOutPoint: spendableInputs[0].OutPoint()}, }, } err = ctx.backend.publishTransaction(remoteTx) @@ -954,7 +953,7 @@ func TestIdempotency(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input.OutPoint()}, + {PreviousOutPoint: input.OutPoint()}, }, } @@ -1039,7 +1038,7 @@ func TestRestart(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input1.OutPoint()}, + {PreviousOutPoint: input1.OutPoint()}, }, } @@ -1082,7 +1081,7 @@ func TestRestart(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input2.OutPoint()}, + {PreviousOutPoint: input2.OutPoint()}, }, } @@ -1170,7 +1169,7 @@ func TestRestartRemoteSpend(t *testing.T) { // will be spent by the remote. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input2.OutPoint()}, + {PreviousOutPoint: input2.OutPoint()}, }, } @@ -1213,7 +1212,7 @@ func TestRestartRemoteSpend(t *testing.T) { remoteTx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input1.OutPoint()}, + {PreviousOutPoint: input1.OutPoint()}, }, } err = ctx.backend.publishTransaction(remoteTx) @@ -1280,7 +1279,7 @@ func TestRestartConfirmed(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input.OutPoint()}, + {PreviousOutPoint: input.OutPoint()}, }, } @@ -1349,7 +1348,7 @@ func TestRetry(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *inp0.OutPoint()}, + {PreviousOutPoint: inp0.OutPoint()}, }, } @@ -1384,7 +1383,7 @@ func TestRetry(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *inp1.OutPoint()}, + {PreviousOutPoint: inp1.OutPoint()}, }, } @@ -1464,8 +1463,8 @@ func TestDifferentFeePreferences(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input1.OutPoint()}, - {PreviousOutPoint: *input2.OutPoint()}, + {PreviousOutPoint: input1.OutPoint()}, + {PreviousOutPoint: input2.OutPoint()}, }, } @@ -1491,7 +1490,7 @@ func TestDifferentFeePreferences(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input3.OutPoint()}, + {PreviousOutPoint: input3.OutPoint()}, }, } @@ -1596,8 +1595,8 @@ func TestPendingInputs(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input1.OutPoint()}, - {PreviousOutPoint: *input2.OutPoint()}, + {PreviousOutPoint: input1.OutPoint()}, + {PreviousOutPoint: input2.OutPoint()}, }, } @@ -1623,7 +1622,7 @@ func TestPendingInputs(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input3.OutPoint()}, + {PreviousOutPoint: input3.OutPoint()}, }, } @@ -1707,7 +1706,7 @@ func TestExclusiveGroup(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input1.OutPoint()}, + {PreviousOutPoint: input1.OutPoint()}, }, } @@ -1733,7 +1732,7 @@ func TestExclusiveGroup(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input2.OutPoint()}, + {PreviousOutPoint: input2.OutPoint()}, }, } @@ -1759,7 +1758,7 @@ func TestExclusiveGroup(t *testing.T) { // Create a fake sweep tx. tx := &wire.MsgTx{ TxIn: []*wire.TxIn{ - {PreviousOutPoint: *input3.OutPoint()}, + {PreviousOutPoint: input3.OutPoint()}, }, } @@ -1954,7 +1953,7 @@ func TestLockTimes(t *testing.T) { } op := inp.OutPoint() - inputs[*op] = inp + inputs[op] = inp cluster, ok := clusters[lt] if !ok { @@ -1966,7 +1965,7 @@ func TestLockTimes(t *testing.T) { for i := 0; i < 3; i++ { inp := spendableInputs[i+numSweeps*2] - inputs[*inp.OutPoint()] = inp + inputs[inp.OutPoint()] = inp lt := uint32(10 + (i % numSweeps)) clusters[lt] = append(clusters[lt], inp) @@ -1982,7 +1981,7 @@ func TestLockTimes(t *testing.T) { // Append the inputs. for _, inp := range cluster { txIn := &wire.TxIn{ - PreviousOutPoint: *inp.OutPoint(), + PreviousOutPoint: inp.OutPoint(), } tx.TxIn = append(tx.TxIn, txIn) } @@ -2137,15 +2136,15 @@ func TestMarkInputsPendingPublish(t *testing.T) { inputNotExist := &input.MockInput{} defer inputNotExist.AssertExpectations(t) - inputNotExist.On("OutPoint").Return(&wire.OutPoint{Index: 0}) + inputNotExist.On("OutPoint").Return(wire.OutPoint{Index: 0}) // inputInit specifies a newly created input. inputInit := &input.MockInput{} defer inputInit.AssertExpectations(t) - inputInit.On("OutPoint").Return(&wire.OutPoint{Index: 1}) + inputInit.On("OutPoint").Return(wire.OutPoint{Index: 1}) - s.inputs[*inputInit.OutPoint()] = &SweeperInput{ + s.inputs[inputInit.OutPoint()] = &SweeperInput{ state: Init, } @@ -2153,9 +2152,9 @@ func TestMarkInputsPendingPublish(t *testing.T) { inputPendingPublish := &input.MockInput{} defer inputPendingPublish.AssertExpectations(t) - inputPendingPublish.On("OutPoint").Return(&wire.OutPoint{Index: 2}) + inputPendingPublish.On("OutPoint").Return(wire.OutPoint{Index: 2}) - s.inputs[*inputPendingPublish.OutPoint()] = &SweeperInput{ + s.inputs[inputPendingPublish.OutPoint()] = &SweeperInput{ state: PendingPublish, } @@ -2163,9 +2162,9 @@ func TestMarkInputsPendingPublish(t *testing.T) { inputTerminated := &input.MockInput{} defer inputTerminated.AssertExpectations(t) - inputTerminated.On("OutPoint").Return(&wire.OutPoint{Index: 3}) + inputTerminated.On("OutPoint").Return(wire.OutPoint{Index: 3}) - s.inputs[*inputTerminated.OutPoint()] = &SweeperInput{ + s.inputs[inputTerminated.OutPoint()] = &SweeperInput{ state: Excluded, } @@ -2181,16 +2180,14 @@ func TestMarkInputsPendingPublish(t *testing.T) { require.Len(s.inputs, 3) // We expect the init input's state to become pending publish. - require.Equal(PendingPublish, - s.inputs[*inputInit.OutPoint()].state) + require.Equal(PendingPublish, s.inputs[inputInit.OutPoint()].state) // We expect the pending-publish to stay unchanged. require.Equal(PendingPublish, - s.inputs[*inputPendingPublish.OutPoint()].state) + s.inputs[inputPendingPublish.OutPoint()].state) // We expect the terminated to stay unchanged. - require.Equal(Excluded, - s.inputs[*inputTerminated.OutPoint()].state) + require.Equal(Excluded, s.inputs[inputTerminated.OutPoint()].state) } // TestMarkInputsPublished checks that given a list of inputs with different @@ -2355,7 +2352,7 @@ func TestMarkInputsSwept(t *testing.T) { defer mockInput.AssertExpectations(t) // Mock the `OutPoint` to return a dummy outpoint. - mockInput.On("OutPoint").Return(&wire.OutPoint{Hash: chainhash.Hash{1}}) + mockInput.On("OutPoint").Return(wire.OutPoint{Hash: chainhash.Hash{1}}) // Create a test sweeper. s := New(&UtxoSweeperConfig{}) @@ -2639,7 +2636,7 @@ func TestMarkInputFailed(t *testing.T) { defer mockInput.AssertExpectations(t) // Mock the `OutPoint` to return a dummy outpoint. - mockInput.On("OutPoint").Return(&wire.OutPoint{Hash: chainhash.Hash{1}}) + mockInput.On("OutPoint").Return(wire.OutPoint{Hash: chainhash.Hash{1}}) // Create a test sweeper. s := New(&UtxoSweeperConfig{}) diff --git a/sweep/tx_input_set.go b/sweep/tx_input_set.go index 48b5115a3..132f66fbe 100644 --- a/sweep/tx_input_set.go +++ b/sweep/tx_input_set.go @@ -568,7 +568,7 @@ func validateInputs(inputs []SweeperInput) error { } // dedupInputs is a map used to track unique outpoints of the inputs. - dedupInputs := make(map[*wire.OutPoint]struct{}) + dedupInputs := make(map[wire.OutPoint]struct{}) // deadlineSet stores unique deadline heights. deadlineSet := make(map[fn.Option[int32]]struct{}) diff --git a/sweep/tx_input_set_test.go b/sweep/tx_input_set_test.go index ba6a8900f..cbe1abb8e 100644 --- a/sweep/tx_input_set_test.go +++ b/sweep/tx_input_set_test.go @@ -411,7 +411,7 @@ func TestNeedWalletInput(t *testing.T) { // These two methods are only invoked when the // unit test is running with a logger. mockInput.On("OutPoint").Return( - &wire.OutPoint{Hash: chainhash.Hash{1}}, + wire.OutPoint{Hash: chainhash.Hash{1}}, ).Maybe() mockInput.On("WitnessType").Return( input.CommitmentAnchor, @@ -632,7 +632,7 @@ func TestAddWalletInputSuccess(t *testing.T) { // // NOTE: these methods are not functional as they are only used for // loggings in debug or trace mode so we use arbitrary values. - mockInput.On("OutPoint").Return(&wire.OutPoint{Hash: chainhash.Hash{1}}) + mockInput.On("OutPoint").Return(wire.OutPoint{Hash: chainhash.Hash{1}}) mockInput.On("WitnessType").Return(input.CommitmentAnchor) // Create a wallet utxo that cannot cover the budget. diff --git a/sweep/txgenerator.go b/sweep/txgenerator.go index a6afd92bf..30e11023e 100644 --- a/sweep/txgenerator.go +++ b/sweep/txgenerator.go @@ -74,7 +74,7 @@ func createSweepTx(inputs []input.Input, outputs []*wire.TxOut, idxs = append(idxs, o) sweepTx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *o.OutPoint(), + PreviousOutPoint: o.OutPoint(), Sequence: o.BlocksToMaturity(), }) sweepTx.AddTxOut(o.RequiredTxOut()) @@ -102,7 +102,7 @@ func createSweepTx(inputs []input.Input, outputs []*wire.TxOut, idxs = append(idxs, o) sweepTx.AddTxIn(&wire.TxIn{ - PreviousOutPoint: *o.OutPoint(), + PreviousOutPoint: o.OutPoint(), Sequence: o.BlocksToMaturity(), }) @@ -309,9 +309,7 @@ func inputTypeSummary(inputs []input.Input) string { var parts []string for _, i := range sortedInputs { - part := fmt.Sprintf("%v (%v)", - *i.OutPoint(), i.WitnessType()) - + part := fmt.Sprintf("%v (%v)", i.OutPoint(), i.WitnessType()) parts = append(parts, part) } return strings.Join(parts, ", ") diff --git a/watchtower/wtclient/backup_task.go b/watchtower/wtclient/backup_task.go index 44a82aacb..49f917514 100644 --- a/watchtower/wtclient/backup_task.go +++ b/watchtower/wtclient/backup_task.go @@ -67,10 +67,10 @@ func newBackupTask(id wtdb.BackupID, sweepPkScript []byte) *backupTask { func (t *backupTask) inputs() map[wire.OutPoint]input.Input { inputs := make(map[wire.OutPoint]input.Input) if t.toLocalInput != nil { - inputs[*t.toLocalInput.OutPoint()] = t.toLocalInput + inputs[t.toLocalInput.OutPoint()] = t.toLocalInput } if t.toRemoteInput != nil { - inputs[*t.toRemoteInput.OutPoint()] = t.toRemoteInput + inputs[t.toRemoteInput.OutPoint()] = t.toRemoteInput } return inputs @@ -297,7 +297,7 @@ func (t *backupTask) craftSessionPayload( commitType := t.commitmentType for _, inp := range inputs { // Lookup the input's new post-sort position. - i := inputIndex[*inp.OutPoint()] + i := inputIndex[inp.OutPoint()] // Construct the full witness required to spend this input. inputScript, err := inp.CraftInputScript( diff --git a/watchtower/wtclient/backup_task_internal_test.go b/watchtower/wtclient/backup_task_internal_test.go index d8c207c0f..695c4f9ec 100644 --- a/watchtower/wtclient/backup_task_internal_test.go +++ b/watchtower/wtclient/backup_task_internal_test.go @@ -580,10 +580,10 @@ func testBackupTask(t *testing.T, test backupTaskTest) { // task's inputs() method. expInputs := make(map[wire.OutPoint]input.Input) if task.toLocalInput != nil { - expInputs[*task.toLocalInput.OutPoint()] = task.toLocalInput + expInputs[task.toLocalInput.OutPoint()] = task.toLocalInput } if task.toRemoteInput != nil { - expInputs[*task.toRemoteInput.OutPoint()] = task.toRemoteInput + expInputs[task.toRemoteInput.OutPoint()] = task.toRemoteInput } // Assert that the inputs method returns the correct slice of