@@ -244,6 +244,7 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro
244244 return err
245245 }
246246
247+ bitcoinFeeFloor := onchain .LegacyFeeFloorSatPerKw
247248 var bitcoinTxWatcher * txwatcher.BlockchainRpcTxWatcher
248249 var bitcoinOnChainService * onchain.BitcoinOnChain
249250 var bitcoinEnabled bool
@@ -253,6 +254,14 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro
253254 bitcoinEnabled = true
254255 bitcoinTxWatcher = txwatcher .NewBlockchainRpcTxWatcher (ctx , txwatcher .NewBitcoinRpc (bitcoinCli ), onchain .BitcoinMinConfs , onchain .BitcoinCsv )
255256
257+ floor , detectedVersion , floorErr := determineBitcoinFeeFloor (bitcoinCli )
258+ if floorErr != nil {
259+ log .Infof ("Unable to detect Bitcoin Core version, defaulting fee floor to %d sat/kw: %v" , floor , floorErr )
260+ } else {
261+ log .Infof ("Detected Bitcoin Core version %s, using fee floor %d sat/kw" , detectedVersion , floor )
262+ }
263+ bitcoinFeeFloor = floor
264+
256265 // We set the default Estimator to the static regtest estimator.
257266 var bitcoinEstimator onchain.Estimator
258267 bitcoinEstimator , _ = onchain .NewRegtestFeeEstimator ()
@@ -271,6 +280,7 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro
271280 bitcoinCli ,
272281 "ECONOMICAL" ,
273282 fallbackFeeRateSatPerKw ,
283+ bitcoinFeeFloor ,
274284 )
275285 if err != nil {
276286 return err
@@ -281,14 +291,12 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro
281291 return err
282292 }
283293
284- // Create the bitcoin onchain service with a fallback fee rate of
285- // 253 sat/kw. (This should be useless in this case).
286- // TODO: This fee rate does not matter right now but we might want to
287- // add a config flag to set this higher than the assumed floor fee rate
288- // of 275 sat/kw (1.1 sat/vb).
294+ // Create the bitcoin onchain service while keeping the same fee floor for
295+ // estimator and fallback paths.
289296 bitcoinOnChainService = onchain .NewBitcoinOnChain (
290297 bitcoinEstimator ,
291- btcutil .Amount (253 ),
298+ bitcoinFeeFloor ,
299+ bitcoinFeeFloor ,
292300 chain ,
293301 )
294302 } else {
@@ -508,6 +516,30 @@ func getBitcoinClient(li *glightning.Lightning, pluginConfig *clightning.Config)
508516 return bitcoin , nil
509517}
510518
519+ type getNetworkInfoRequest struct {}
520+
521+ func (r * getNetworkInfoRequest ) Name () string {
522+ return "getnetworkinfo"
523+ }
524+
525+ type bitcoindNetworkInfo struct {
526+ Subversion string `json:"subversion"`
527+ }
528+
529+ func determineBitcoinFeeFloor (bitcoinCli * gbitcoin.Bitcoin ) (btcutil.Amount , string , error ) {
530+ var networkInfo bitcoindNetworkInfo
531+ if err := bitcoinCli .Request (& getNetworkInfoRequest {}, & networkInfo ); err != nil {
532+ return onchain .LegacyFeeFloorSatPerKw , "" , err
533+ }
534+
535+ floor , normalized := onchain .DetermineFeeFloor (networkInfo .Subversion )
536+ if normalized == "" {
537+ return floor , "" , fmt .Errorf ("unable to parse bitcoin core subversion %q" , networkInfo .Subversion )
538+ }
539+
540+ return floor , normalized , nil
541+ }
542+
511543func checkClnVersion (network string , fullVersionString string ) (bool , error ) {
512544 // skip version check if running signet as it needs a custom build
513545 // ? Can someone explain why we need this here?
0 commit comments