multi: rename FeePreference to FeeEstimateInfo

Results from running,
```
gofmt -d -w -r 'FeePreference -> FeeEstimateInfo' .
```
This commit is contained in:
yyforyongyu 2023-11-03 19:20:10 +08:00
parent 6ff6c86155
commit 530eed92a0
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
15 changed files with 53 additions and 49 deletions

View File

@ -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,
},
},

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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,
},
)

View File

@ -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,
},
},

View File

@ -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.

View File

@ -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.

View File

@ -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,
}

View File

@ -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,
}

View File

@ -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),
}

View File

@ -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(),

View File

@ -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{}

View File

@ -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 (

View File

@ -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,
},
}