From 530eed92a0fe60c0ad9468e0a7167d3a20d6ed21 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 3 Nov 2023 19:20:10 +0800 Subject: [PATCH] multi: rename `FeePreference` to `FeeEstimateInfo` Results from running, ``` gofmt -d -w -r 'FeePreference -> FeeEstimateInfo' . ``` --- contractcourt/anchor_resolver.go | 2 +- contractcourt/channel_arbitrator.go | 2 +- contractcourt/commit_sweep_resolver.go | 2 +- contractcourt/commit_sweep_resolver_test.go | 2 +- contractcourt/htlc_success_resolver.go | 6 ++-- contractcourt/htlc_timeout_resolver.go | 4 +-- contractcourt/interfaces.go | 2 +- contractcourt/utxonursery.go | 2 +- lnrpc/rpc_utils.go | 2 +- lnrpc/walletrpc/walletkit_server.go | 2 +- rpcserver.go | 2 +- sweep/sweeper.go | 6 ++-- sweep/sweeper_test.go | 32 +++++++++++---------- sweep/walletsweep.go | 10 +++---- sweep/walletsweep_test.go | 26 +++++++++-------- 15 files changed, 53 insertions(+), 49 deletions(-) diff --git a/contractcourt/anchor_resolver.go b/contractcourt/anchor_resolver.go index d96960026..6aa25cd22 100644 --- a/contractcourt/anchor_resolver.go +++ b/contractcourt/anchor_resolver.go @@ -115,7 +115,7 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) { resultChan, err := c.Sweeper.SweepInput( &anchorInput, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ FeeRate: relayFeeRate, }, }, diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index e6f91d3cd..dd29ab41f 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -1359,7 +1359,7 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions, _, err = c.cfg.Sweeper.SweepInput( &anchorInput, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ ConfTarget: deadline, }, Force: force, diff --git a/contractcourt/commit_sweep_resolver.go b/contractcourt/commit_sweep_resolver.go index cd59f9654..195d423c9 100644 --- a/contractcourt/commit_sweep_resolver.go +++ b/contractcourt/commit_sweep_resolver.go @@ -351,7 +351,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) { // sweeper. c.log.Infof("sweeping commit output") - feePref := sweep.FeePreference{ConfTarget: commitOutputConfTarget} + feePref := sweep.FeeEstimateInfo{ConfTarget: commitOutputConfTarget} resultChan, err := c.Sweeper.SweepInput(inp, sweep.Params{Fee: feePref}) if err != nil { c.log.Errorf("unable to sweep input: %v", err) diff --git a/contractcourt/commit_sweep_resolver_test.go b/contractcourt/commit_sweep_resolver_test.go index daf382b7b..bbcc1e1b8 100644 --- a/contractcourt/commit_sweep_resolver_test.go +++ b/contractcourt/commit_sweep_resolver_test.go @@ -141,7 +141,7 @@ func (s *mockSweeper) SweepInput(input input.Input, params sweep.Params) ( } func (s *mockSweeper) CreateSweepTx(inputs []input.Input, - feePref sweep.FeePreference) (*wire.MsgTx, error) { + feePref sweep.FeeEstimateInfo) (*wire.MsgTx, error) { // We will wait for the test to supply the sweep tx to return. sweepTx := <-s.createSweepTxChan diff --git a/contractcourt/htlc_success_resolver.go b/contractcourt/htlc_success_resolver.go index a9c9aeb52..d37ed012f 100644 --- a/contractcourt/htlc_success_resolver.go +++ b/contractcourt/htlc_success_resolver.go @@ -263,7 +263,7 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx() ( _, err := h.Sweeper.SweepInput( &secondLevelInput, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ ConfTarget: secondLevelConfTarget, }, }, @@ -375,7 +375,7 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx() ( _, err = h.Sweeper.SweepInput( inp, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ ConfTarget: sweepConfTarget, }, }, @@ -436,7 +436,7 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput() ( var err error h.sweepTx, err = h.Sweeper.CreateSweepTx( []input.Input{inp}, - sweep.FeePreference{ + sweep.FeeEstimateInfo{ ConfTarget: sweepConfTarget, }, ) diff --git a/contractcourt/htlc_timeout_resolver.go b/contractcourt/htlc_timeout_resolver.go index 8adcb63b3..63bfa58fc 100644 --- a/contractcourt/htlc_timeout_resolver.go +++ b/contractcourt/htlc_timeout_resolver.go @@ -486,7 +486,7 @@ func (h *htlcTimeoutResolver) sweepSecondLevelTx() error { _, err := h.Sweeper.SweepInput( inp, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ ConfTarget: secondLevelConfTarget, }, Force: true, @@ -702,7 +702,7 @@ func (h *htlcTimeoutResolver) handleCommitSpend( _, err = h.Sweeper.SweepInput( inp, sweep.Params{ - Fee: sweep.FeePreference{ + Fee: sweep.FeeEstimateInfo{ ConfTarget: sweepConfTarget, }, }, diff --git a/contractcourt/interfaces.go b/contractcourt/interfaces.go index 91c526b2b..bdcb6c5de 100644 --- a/contractcourt/interfaces.go +++ b/contractcourt/interfaces.go @@ -54,7 +54,7 @@ type UtxoSweeper interface { // that spends from them. This method also makes an accurate fee // estimate before generating the required witnesses. CreateSweepTx(inputs []input.Input, - feePref sweep.FeePreference) (*wire.MsgTx, error) + feePref sweep.FeeEstimateInfo) (*wire.MsgTx, error) // RelayFeePerKW returns the minimum fee rate required for transactions // to be relayed. diff --git a/contractcourt/utxonursery.go b/contractcourt/utxonursery.go index 57a3709e9..6b8742255 100644 --- a/contractcourt/utxonursery.go +++ b/contractcourt/utxonursery.go @@ -823,7 +823,7 @@ func (u *UtxoNursery) sweepMatureOutputs(classHeight uint32, utxnLog.Infof("Sweeping %v CSV-delayed outputs with sweep tx for "+ "height %v", len(kgtnOutputs), classHeight) - feePref := sweep.FeePreference{ConfTarget: kgtnOutputConfTarget} + feePref := sweep.FeeEstimateInfo{ConfTarget: kgtnOutputConfTarget} for _, output := range kgtnOutputs { // Create local copy to prevent pointer to loop variable to be // passed in with disastrous consequences. diff --git a/lnrpc/rpc_utils.go b/lnrpc/rpc_utils.go index 1cc4b1754..9792cf35c 100644 --- a/lnrpc/rpc_utils.go +++ b/lnrpc/rpc_utils.go @@ -222,7 +222,7 @@ func CalculateFeeRate(satPerByte, satPerVByte uint64, targetConf uint32, // Based on the passed fee related parameters, we'll determine an // appropriate fee rate for this transaction. - feePref := sweep.FeePreference{ + feePref := sweep.FeeEstimateInfo{ ConfTarget: targetConf, FeeRate: satPerKw, } diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index b25c187ff..b6ad08cde 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -965,7 +965,7 @@ func (w *WalletKit) BumpFee(ctx context.Context, in.SatPerByte * 1000, ).FeePerKWeight() } - feePreference := sweep.FeePreference{ + feePreference := sweep.FeeEstimateInfo{ ConfTarget: uint32(in.TargetConf), FeeRate: satPerKw, } diff --git a/rpcserver.go b/rpcserver.go index 8203744a6..d73c87756 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1175,7 +1175,7 @@ func (r *rpcServer) EstimateFee(ctx context.Context, // Query the fee estimator for the fee rate for the given confirmation // target. target := in.TargetConf - feePref := sweep.FeePreference{ + feePref := sweep.FeeEstimateInfo{ ConfTarget: uint32(target), } diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 234ff17ef..97028facc 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -68,7 +68,7 @@ type Params struct { // Fee is the fee preference of the client who requested the input to be // swept. If a confirmation target is specified, then we'll map it into // a fee rate whenever we attempt to cluster inputs for a sweep. - Fee FeePreference + Fee FeeEstimateInfo // Force indicates whether the input should be swept regardless of // whether it is economical to do so. @@ -84,7 +84,7 @@ type ParamsUpdate struct { // Fee is the fee preference of the client who requested the input to be // swept. If a confirmation target is specified, then we'll map it into // a fee rate whenever we attempt to cluster inputs for a sweep. - Fee FeePreference + Fee FeeEstimateInfo // Force indicates whether the input should be swept regardless of // whether it is economical to do so. @@ -1426,7 +1426,7 @@ func (s *UtxoSweeper) handleUpdateReq(req *updateReq) ( // - Thwart future possible fee sniping attempts. // - Make us blend in with the bitcoind wallet. func (s *UtxoSweeper) CreateSweepTx(inputs []input.Input, - feePref FeePreference) (*wire.MsgTx, error) { + feePref FeeEstimateInfo) (*wire.MsgTx, error) { feePerKw, err := feePref.Estimate( s.cfg.FeeEstimator, s.cfg.MaxFeeRate.FeePerKWeight(), diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 94dba8558..854d430fd 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -31,7 +31,7 @@ var ( testMaxInputsPerTx = 3 - defaultFeePref = Params{Fee: FeePreference{ConfTarget: 1}} + defaultFeePref = Params{Fee: FeeEstimateInfo{ConfTarget: 1}} ) type sweeperTestContext struct { @@ -432,7 +432,7 @@ func TestWalletUtxo(t *testing.T) { _, err := ctx.sweeper.SweepInput( &dustInput, - Params{Fee: FeePreference{FeeRate: chainfee.FeePerKwFloor}}, + Params{Fee: FeeEstimateInfo{FeeRate: chainfee.FeePerKwFloor}}, ) if err != nil { t.Fatal(err) @@ -926,11 +926,11 @@ func TestDifferentFeePreferences(t *testing.T) { // with the higher fee preference, and the last with the lower. We do // this to ensure the sweeper can broadcast distinct transactions for // each sweep with a different fee preference. - lowFeePref := FeePreference{ConfTarget: 12} + lowFeePref := FeeEstimateInfo{ConfTarget: 12} lowFeeRate := chainfee.SatPerKWeight(5000) ctx.estimator.blocksToFee[lowFeePref.ConfTarget] = lowFeeRate - highFeePref := FeePreference{ConfTarget: 6} + highFeePref := FeeEstimateInfo{ConfTarget: 6} highFeeRate := chainfee.SatPerKWeight(10000) ctx.estimator.blocksToFee[highFeePref.ConfTarget] = highFeeRate @@ -995,12 +995,12 @@ func TestPendingInputs(t *testing.T) { highFeeRate = 10000 ) - lowFeePref := FeePreference{ + lowFeePref := FeeEstimateInfo{ ConfTarget: 12, } ctx.estimator.blocksToFee[lowFeePref.ConfTarget] = lowFeeRate - highFeePref := FeePreference{ + highFeePref := FeeEstimateInfo{ ConfTarget: 6, } ctx.estimator.blocksToFee[highFeePref.ConfTarget] = highFeeRate @@ -1060,7 +1060,7 @@ func TestPendingInputs(t *testing.T) { func TestBumpFeeRBF(t *testing.T) { ctx := createSweeperTestContext(t) - lowFeePref := FeePreference{ConfTarget: 144} + lowFeePref := FeeEstimateInfo{ConfTarget: 144} lowFeeRate := chainfee.FeePerKwFloor ctx.estimator.blocksToFee[lowFeePref.ConfTarget] = lowFeeRate @@ -1095,7 +1095,7 @@ func TestBumpFeeRBF(t *testing.T) { assertTxFeeRate(t, &lowFeeTx, lowFeeRate, changePk, &input) // We'll then attempt to bump its fee rate. - highFeePref := FeePreference{ConfTarget: 6} + highFeePref := FeeEstimateInfo{ConfTarget: 6} highFeeRate := DefaultMaxFeeRate.FeePerKWeight() ctx.estimator.blocksToFee[highFeePref.ConfTarget] = highFeeRate @@ -1132,7 +1132,7 @@ func TestExclusiveGroup(t *testing.T) { exclusiveGroup := uint64(1) result, err := ctx.sweeper.SweepInput( spendableInputs[i], Params{ - Fee: FeePreference{ConfTarget: 6}, + Fee: FeeEstimateInfo{ConfTarget: 6}, ExclusiveGroup: &exclusiveGroup, }, ) @@ -1209,7 +1209,7 @@ func TestCpfp(t *testing.T) { }, ) - feePref := FeePreference{ConfTarget: 6} + feePref := FeeEstimateInfo{ConfTarget: 6} result, err := ctx.sweeper.SweepInput( &input, Params{Fee: feePref, Force: true}, ) @@ -1564,7 +1564,7 @@ func TestLockTimes(t *testing.T) { result, err := ctx.sweeper.SweepInput( inp, Params{ - Fee: FeePreference{ConfTarget: 6}, + Fee: FeeEstimateInfo{ConfTarget: 6}, }, ) if err != nil { @@ -1582,7 +1582,7 @@ func TestLockTimes(t *testing.T) { inp := spendableInputs[i+numSweeps*2] result, err := ctx.sweeper.SweepInput( inp, Params{ - Fee: FeePreference{ConfTarget: 6}, + Fee: FeeEstimateInfo{ConfTarget: 6}, }, ) if err != nil { @@ -2027,7 +2027,9 @@ func TestRequiredTxOuts(t *testing.T) { for _, inp := range testCase.inputs { result, err := ctx.sweeper.SweepInput( inp, Params{ - Fee: FeePreference{ConfTarget: 6}, + Fee: FeeEstimateInfo{ + ConfTarget: 6, + }, }, ) if err != nil { @@ -2141,7 +2143,7 @@ func TestClusterByLockTime(t *testing.T) { // Create a test param with a dummy fee preference. This is needed so // `feeRateForPreference` won't throw an error. - param := Params{Fee: FeePreference{ConfTarget: 1}} + param := Params{Fee: FeeEstimateInfo{ConfTarget: 1}} // We begin the test by creating three clusters of inputs, the first // cluster has a locktime of 1, the second has a locktime of 2, and the @@ -2316,7 +2318,7 @@ func TestGetInputLists(t *testing.T) { // Create a test param with a dummy fee preference. This is needed so // `feeRateForPreference` won't throw an error. - param := Params{Fee: FeePreference{ConfTarget: 1}} + param := Params{Fee: FeeEstimateInfo{ConfTarget: 1}} // Create a mock input and mock all the methods used in this test. testInput := &input.MockInput{} diff --git a/sweep/walletsweep.go b/sweep/walletsweep.go index c6ee39d3d..be3b69399 100644 --- a/sweep/walletsweep.go +++ b/sweep/walletsweep.go @@ -33,9 +33,9 @@ var ( ErrFeePreferenceConflict = errors.New("fee preference conflict") ) -// FeePreference allows callers to express their time value for inclusion of a -// transaction into a block via either a confirmation target, or a fee rate. -type FeePreference struct { +// FeeEstimateInfo allows callers to express their time value for inclusion of +// a transaction into a block via either a confirmation target, or a fee rate. +type FeeEstimateInfo struct { // ConfTarget if non-zero, signals a fee preference expressed in the // number of desired blocks between first broadcast, and confirmation. ConfTarget uint32 @@ -46,7 +46,7 @@ type FeePreference struct { } // String returns a human-readable string of the fee preference. -func (p FeePreference) String() string { +func (p FeeEstimateInfo) String() string { if p.ConfTarget != 0 { return fmt.Sprintf("%v blocks", p.ConfTarget) } @@ -56,7 +56,7 @@ func (p FeePreference) String() string { // Estimate returns a fee rate for the given fee preference. It ensures that // the fee rate respects the bounds of the relay fee and the max fee rates, if // specified. -func (f FeePreference) Estimate(estimator chainfee.Estimator, +func (f FeeEstimateInfo) Estimate(estimator chainfee.Estimator, maxFeeRate chainfee.SatPerKWeight) (chainfee.SatPerKWeight, error) { var ( diff --git a/sweep/walletsweep_test.go b/sweep/walletsweep_test.go index 44e236b15..c4d1681a0 100644 --- a/sweep/walletsweep_test.go +++ b/sweep/walletsweep_test.go @@ -18,8 +18,8 @@ import ( "github.com/stretchr/testify/require" ) -// TestFeePreferenceEstimate checks `Estimate` method works as expected. -func TestFeePreferenceEstimate(t *testing.T) { +// TestFeeEstimateInfo checks `Estimate` method works as expected. +func TestFeeEstimateInfo(t *testing.T) { t.Parallel() dummyErr := errors.New("dummy") @@ -44,7 +44,7 @@ func TestFeePreferenceEstimate(t *testing.T) { testCases := []struct { name string setupMocker func() - feePref FeePreference + feePref FeeEstimateInfo expectedFeeRate chainfee.SatPerKWeight expectedErr error }{ @@ -52,14 +52,14 @@ func TestFeePreferenceEstimate(t *testing.T) { // When the fee preference is empty, we should see an // error. name: "empty fee preference", - feePref: FeePreference{}, + feePref: FeeEstimateInfo{}, expectedErr: ErrNoFeePreference, }, { // When the fee preference has conflicts, we should see // an error. name: "conflict fee preference", - feePref: FeePreference{ + feePref: FeeEstimateInfo{ FeeRate: validFeeRate, ConfTarget: conf, }, @@ -74,12 +74,12 @@ func TestFeePreferenceEstimate(t *testing.T) { chainfee.SatPerKWeight(0), dummyErr, ).Once() }, - feePref: FeePreference{ConfTarget: conf}, + feePref: FeeEstimateInfo{ConfTarget: conf}, expectedErr: dummyErr, }, { - // When FeePreference uses a too small value, we should - // return an error. + // When FeeEstimateInfo uses a too small value, we + // should return an error. name: "fee rate below relay fee rate", setupMocker: func() { // Mock the relay fee rate. @@ -87,11 +87,11 @@ func TestFeePreferenceEstimate(t *testing.T) { chainfee.SatPerKWeight(relayFeeRate), ).Once() }, - feePref: FeePreference{FeeRate: relayFeeRate - 1}, + feePref: FeeEstimateInfo{FeeRate: relayFeeRate - 1}, expectedErr: ErrFeePreferenceTooLow, }, { - // When FeePreference gives a too large value, we + // When FeeEstimateInfo gives a too large value, we // should cap it at the max fee rate. name: "fee rate above max fee rate", setupMocker: func() { @@ -100,7 +100,9 @@ func TestFeePreferenceEstimate(t *testing.T) { chainfee.SatPerKWeight(relayFeeRate), ).Once() }, - feePref: FeePreference{FeeRate: maxFeeRate + 1}, + feePref: FeeEstimateInfo{ + FeeRate: maxFeeRate + 1, + }, expectedFeeRate: maxFeeRate, }, { @@ -117,7 +119,7 @@ func TestFeePreferenceEstimate(t *testing.T) { chainfee.SatPerKWeight(relayFeeRate), ).Once() }, - feePref: FeePreference{ConfTarget: conf}, + feePref: FeeEstimateInfo{ConfTarget: conf}, expectedFeeRate: validFeeRate, }, }