@@ -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+
8895var (
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.
12441276func (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,
14651503func (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
0 commit comments