Skip to content

Commit d0441a2

Browse files
committed
multi: add default conf targt in SendCoins/SendMany/OpenChannel/CloseChannel
1 parent 2089a88 commit d0441a2

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

itest/lnd_misc_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,18 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
815815
TargetConf: 6,
816816
})
817817

818+
// TODO(yy): we still allow default values to be used when neither conf
819+
// target or fee rate is set in 0.18.0. When future release forbidden
820+
// this behavior, we should revive the test below, which asserts either
821+
// conf target or fee rate is set.
822+
//
818823
// Send coins to a compatible address without specifying fee rate or
819824
// conf target.
820-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
821-
Addr: ht.Miner.NewMinerAddress().String(),
822-
SendAll: true,
823-
Label: sendCoinsLabel,
824-
})
825+
// ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
826+
// Addr: ht.Miner.NewMinerAddress().String(),
827+
// SendAll: true,
828+
// Label: sendCoinsLabel,
829+
// })
825830

826831
// Send coins to a compatible address.
827832
ainz.RPC.SendCoins(&lnrpc.SendCoinsRequest{

rpcserver.go

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ import (
8585
"gopkg.in/macaroon-bakery.v2/bakery"
8686
)
8787

88+
const (
89+
// defaultNumBlocksEstimate is the number of blocks that we fall back
90+
// to issuing an estimate for if a fee pre fence doesn't specify an
91+
// explicit conf target or fee rate.
92+
defaultNumBlocksEstimate = 6
93+
)
94+
8895
var (
8996
// readPermissions is a slice of all entities that allow read
9097
// permissions for authorization purposes, all lowercase.
@@ -1239,15 +1246,46 @@ func (r *rpcServer) EstimateFee(ctx context.Context,
12391246
return resp, nil
12401247
}
12411248

1249+
// maybeUseDefaultConf makes sure that when the user doesn't set either the fee
1250+
// rate or conf target, the default conf target is used.
1251+
func maybeUseDefaultConf(satPerByte int64, satPerVByte uint64,
1252+
targetConf uint32) uint32 {
1253+
1254+
// If the fee rate is set, there's no need to use the default conf
1255+
// target. In this case, we just return the targetConf from the
1256+
// request.
1257+
if satPerByte != 0 || satPerVByte != 0 {
1258+
return targetConf
1259+
}
1260+
1261+
// Return the user specified conf target if set.
1262+
if targetConf != 0 {
1263+
return targetConf
1264+
}
1265+
1266+
// If the fee rate is not set, yet the conf target is zero, the default
1267+
// 6 will be returned.
1268+
rpcsLog.Errorf("Expected either 'sat_per_vbyte' or 'conf_target' to " +
1269+
"be set, using default conf of 6 instead")
1270+
1271+
return defaultNumBlocksEstimate
1272+
}
1273+
12421274
// SendCoins executes a request to send coins to a particular address. Unlike
12431275
// SendMany, this RPC call only allows creating a single output at a time.
12441276
func (r *rpcServer) SendCoins(ctx context.Context,
12451277
in *lnrpc.SendCoinsRequest) (*lnrpc.SendCoinsResponse, error) {
12461278

1279+
// Keep the old behavior prior to 0.18.0 - when the user doesn't set
1280+
// fee rate or conf target, the default conf target of 6 is used.
1281+
targetConf := maybeUseDefaultConf(
1282+
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
1283+
)
1284+
12471285
// Calculate an appropriate fee rate for this transaction.
12481286
feePerKw, err := lnrpc.CalculateFeeRate(
12491287
uint64(in.SatPerByte), in.SatPerVbyte, // nolint:staticcheck
1250-
uint32(in.TargetConf), r.server.cc.FeeEstimator,
1288+
targetConf, r.server.cc.FeeEstimator,
12511289
)
12521290
if err != nil {
12531291
return nil, err
@@ -1465,10 +1503,16 @@ func (r *rpcServer) SendCoins(ctx context.Context,
14651503
func (r *rpcServer) SendMany(ctx context.Context,
14661504
in *lnrpc.SendManyRequest) (*lnrpc.SendManyResponse, error) {
14671505

1506+
// Keep the old behavior prior to 0.18.0 - when the user doesn't set
1507+
// fee rate or conf target, the default conf target of 6 is used.
1508+
targetConf := maybeUseDefaultConf(
1509+
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
1510+
)
1511+
14681512
// Calculate an appropriate fee rate for this transaction.
14691513
feePerKw, err := lnrpc.CalculateFeeRate(
14701514
uint64(in.SatPerByte), in.SatPerVbyte, // nolint:staticcheck
1471-
uint32(in.TargetConf), r.server.cc.FeeEstimator,
1515+
targetConf, r.server.cc.FeeEstimator,
14721516
)
14731517
if err != nil {
14741518
return nil, err
@@ -2129,10 +2173,17 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
21292173

21302174
// Skip estimating fee rate for PSBT funding.
21312175
if in.FundingShim == nil || in.FundingShim.GetPsbtShim() == nil {
2176+
// Keep the old behavior prior to 0.18.0 - when the user
2177+
// doesn't set fee rate or conf target, the default conf target
2178+
// of 6 is used.
2179+
targetConf := maybeUseDefaultConf(
2180+
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
2181+
)
2182+
21322183
// Calculate an appropriate fee rate for this transaction.
21332184
feeRate, err = lnrpc.CalculateFeeRate(
21342185
uint64(in.SatPerByte), in.SatPerVbyte,
2135-
uint32(in.TargetConf), r.server.cc.FeeEstimator,
2186+
targetConf, r.server.cc.FeeEstimator,
21362187
)
21372188
if err != nil {
21382189
return nil, err
@@ -2680,12 +2731,19 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
26802731
"is offline (try force closing it instead): %v", err)
26812732
}
26822733

2734+
// Keep the old behavior prior to 0.18.0 - when the user
2735+
// doesn't set fee rate or conf target, the default conf target
2736+
// of 6 is used.
2737+
targetConf := maybeUseDefaultConf(
2738+
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
2739+
)
2740+
26832741
// Based on the passed fee related parameters, we'll determine
26842742
// an appropriate fee rate for the cooperative closure
26852743
// transaction.
26862744
feeRate, err := lnrpc.CalculateFeeRate(
26872745
uint64(in.SatPerByte), in.SatPerVbyte, // nolint:staticcheck
2688-
uint32(in.TargetConf), r.server.cc.FeeEstimator,
2746+
targetConf, r.server.cc.FeeEstimator,
26892747
)
26902748
if err != nil {
26912749
return err

sweep/walletsweep.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import (
1616
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
1717
)
1818

19-
const (
20-
// defaultNumBlocksEstimate is the number of blocks that we fall back
21-
// to issuing an estimate for if a fee pre fence doesn't specify an
22-
// explicit conf target or fee rate.
23-
defaultNumBlocksEstimate = 6
24-
)
25-
2619
var (
2720
// ErrNoFeePreference is returned when we attempt to satisfy a sweep
2821
// request from a client whom did not specify a fee preference.

0 commit comments

Comments
 (0)