multi: rename FeePreference to FeeEstimateInfo

Results from running,
```
gofmt -d -w -r 'FeePreference -> FeeEstimateInfo' .
```
This commit is contained in:
yyforyongyu committed 2024-04-19 21:33:21 +08:00
1 parent 6ff6c86155
commit 530eed92a0
15 files changed
+53 -49

No files matched your search

+3 -3
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(),
+17 -15
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{}
+5 -5
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 (
+14 -12
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,
},
}