Skip to content

Commit b40f165

Browse files
authored
Merge pull request #8891 from yyforyongyu/fix-fee-estimator
chainfee: allow specifying min relay feerate from the API source
2 parents b10ebb2 + d992cf9 commit b40f165

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+298
-435
lines changed

chanbackup/log.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,3 @@ func DisableLog() {
2727
func UseLogger(logger btclog.Logger) {
2828
log = logger
2929
}
30-
31-
// logClosure is used to provide a closure over expensive logging operations so
32-
// don't have to be performed when the logging level doesn't warrant it.
33-
type logClosure func() string
34-
35-
// String invokes the underlying function and returns the result.
36-
func (c logClosure) String() string {
37-
return c()
38-
}
39-
40-
// newLogClosure returns a new closure over a function that returns a string
41-
// which itself provides a Stringer interface so that it can be used with the
42-
// logging system.
43-
func newLogClosure(c func() string) logClosure {
44-
return logClosure(c)
45-
}

chanbackup/pubsub.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/wire"
1111
"github.com/lightningnetwork/lnd/channeldb"
1212
"github.com/lightningnetwork/lnd/keychain"
13+
"github.com/lightningnetwork/lnd/lnutils"
1314
)
1415

1516
// Swapper is an interface that allows the chanbackup.SubSwapper to update the
@@ -278,9 +279,8 @@ func (s *SubSwapper) backupUpdater() {
278279
)
279280
for i, closedChan := range chanUpdate.ClosedChans {
280281
log.Debugf("Removing channel %v from backup "+
281-
"state", newLogClosure(func() string {
282-
return chanUpdate.ClosedChans[i].String()
283-
}))
282+
"state", lnutils.NewLogClosure(
283+
chanUpdate.ClosedChans[i].String))
284284

285285
delete(s.backupState, closedChan)
286286

chanbackup/recover.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"net"
55

66
"github.com/btcsuite/btcd/btcec/v2"
7-
"github.com/davecgh/go-spew/spew"
87
"github.com/lightningnetwork/lnd/channeldb"
98
"github.com/lightningnetwork/lnd/keychain"
9+
"github.com/lightningnetwork/lnd/lnutils"
1010
)
1111

1212
// ChannelRestorer is an interface that allows the Recover method to map the
@@ -63,9 +63,8 @@ func Recover(backups []Single, restorer ChannelRestorer,
6363
log.Infof("Attempting to connect to node=%x (addrs=%v) to "+
6464
"restore ChannelPoint(%v)",
6565
backup.RemoteNodePub.SerializeCompressed(),
66-
newLogClosure(func() string {
67-
return spew.Sdump(backups[i].Addresses)
68-
}), backup.FundingOutpoint)
66+
lnutils.SpewLogClosure(backups[i].Addresses),
67+
backup.FundingOutpoint)
6968

7069
err = peerConnector.ConnectPeer(
7170
backup.RemoteNodePub, backup.Addresses,

contractcourt/breach_arbitrator.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
"github.com/btcsuite/btcd/chaincfg/chainhash"
1414
"github.com/btcsuite/btcd/txscript"
1515
"github.com/btcsuite/btcd/wire"
16-
"github.com/davecgh/go-spew/spew"
1716
"github.com/lightningnetwork/lnd/chainntnfs"
1817
"github.com/lightningnetwork/lnd/channeldb"
1918
"github.com/lightningnetwork/lnd/input"
2019
"github.com/lightningnetwork/lnd/kvdb"
2120
"github.com/lightningnetwork/lnd/labels"
2221
"github.com/lightningnetwork/lnd/lntypes"
22+
"github.com/lightningnetwork/lnd/lnutils"
2323
"github.com/lightningnetwork/lnd/lnwallet"
2424
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2525
)
@@ -732,9 +732,8 @@ justiceTxBroadcast:
732732
}
733733
finalTx := justiceTxs.spendAll
734734

735-
brarLog.Debugf("Broadcasting justice tx: %v", newLogClosure(func() string {
736-
return spew.Sdump(finalTx)
737-
}))
735+
brarLog.Debugf("Broadcasting justice tx: %v", lnutils.SpewLogClosure(
736+
finalTx))
738737

739738
// We'll now attempt to broadcast the transaction which finalized the
740739
// channel's retribution against the cheating counter party.
@@ -857,9 +856,7 @@ Loop:
857856

858857
brarLog.Debugf("Broadcasting justice tx "+
859858
"spending commitment outs: %v",
860-
newLogClosure(func() string {
861-
return spew.Sdump(tx)
862-
}))
859+
lnutils.SpewLogClosure(tx))
863860

864861
err = b.cfg.PublishTransaction(tx, label)
865862
if err != nil {
@@ -874,9 +871,7 @@ Loop:
874871

875872
brarLog.Debugf("Broadcasting justice tx "+
876873
"spending HTLC outs: %v",
877-
newLogClosure(func() string {
878-
return spew.Sdump(tx)
879-
}))
874+
lnutils.SpewLogClosure(tx))
880875

881876
err = b.cfg.PublishTransaction(tx, label)
882877
if err != nil {
@@ -891,9 +886,7 @@ Loop:
891886

892887
brarLog.Debugf("Broadcasting justice tx "+
893888
"spending second-level HTLC output: %v",
894-
newLogClosure(func() string {
895-
return spew.Sdump(tx)
896-
}))
889+
lnutils.SpewLogClosure(tx))
897890

898891
err = b.cfg.PublishTransaction(tx, label)
899892
if err != nil {

contractcourt/chain_watcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightningnetwork/lnd/channeldb"
2121
"github.com/lightningnetwork/lnd/fn"
2222
"github.com/lightningnetwork/lnd/input"
23+
"github.com/lightningnetwork/lnd/lnutils"
2324
"github.com/lightningnetwork/lnd/lnwallet"
2425
"github.com/lightningnetwork/lnd/lnwire"
2526
)
@@ -1254,7 +1255,7 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail
12541255
spendHeight := uint32(spendEvent.SpendingHeight)
12551256

12561257
log.Debugf("Punishment breach retribution created: %v",
1257-
newLogClosure(func() string {
1258+
lnutils.NewLogClosure(func() string {
12581259
retribution.KeyRing.LocalHtlcKey = nil
12591260
retribution.KeyRing.RemoteHtlcKey = nil
12601261
retribution.KeyRing.ToLocalKey = nil

contractcourt/channel_arbitrator.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/btcsuite/btcd/chaincfg/chainhash"
1515
"github.com/btcsuite/btcd/txscript"
1616
"github.com/btcsuite/btcd/wire"
17-
"github.com/davecgh/go-spew/spew"
1817
"github.com/lightningnetwork/lnd/channeldb"
1918
"github.com/lightningnetwork/lnd/channeldb/models"
2019
"github.com/lightningnetwork/lnd/fn"
@@ -24,6 +23,7 @@ import (
2423
"github.com/lightningnetwork/lnd/kvdb"
2524
"github.com/lightningnetwork/lnd/labels"
2625
"github.com/lightningnetwork/lnd/lntypes"
26+
"github.com/lightningnetwork/lnd/lnutils"
2727
"github.com/lightningnetwork/lnd/lnwallet"
2828
"github.com/lightningnetwork/lnd/lnwire"
2929
"github.com/lightningnetwork/lnd/sweep"
@@ -465,10 +465,8 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error {
465465
}
466466

467467
log.Debugf("Starting ChannelArbitrator(%v), htlc_set=%v, state=%v",
468-
c.cfg.ChanPoint, newLogClosure(func() string {
469-
return spew.Sdump(c.activeHTLCs)
470-
}), state.currentState,
471-
)
468+
c.cfg.ChanPoint, lnutils.SpewLogClosure(c.activeHTLCs),
469+
state.currentState)
472470

473471
// Set our state from our starting state.
474472
c.state = state.currentState
@@ -958,10 +956,7 @@ func (c *ChannelArbitrator) stateStep(
958956
// Otherwise, we'll log that we checked the HTLC actions as the
959957
// commitment transaction has already been broadcast.
960958
log.Tracef("ChannelArbitrator(%v): logging chain_actions=%v",
961-
c.cfg.ChanPoint,
962-
newLogClosure(func() string {
963-
return spew.Sdump(chainActions)
964-
}))
959+
c.cfg.ChanPoint, lnutils.SpewLogClosure(chainActions))
965960

966961
// Depending on the type of trigger, we'll either "tunnel"
967962
// through to a farther state, or just proceed linearly to the
@@ -1096,10 +1091,7 @@ func (c *ChannelArbitrator) stateStep(
10961091
// channel resolution state.
10971092
log.Infof("Broadcasting force close transaction %v, "+
10981093
"ChannelPoint(%v): %v", closeTx.TxHash(),
1099-
c.cfg.ChanPoint,
1100-
newLogClosure(func() string {
1101-
return spew.Sdump(closeTx)
1102-
}))
1094+
c.cfg.ChanPoint, lnutils.SpewLogClosure(closeTx))
11031095

11041096
// At this point, we'll now broadcast the commitment
11051097
// transaction itself.
@@ -1224,9 +1216,7 @@ func (c *ChannelArbitrator) stateStep(
12241216
if len(pktsToSend) != 0 {
12251217
log.Debugf("ChannelArbitrator(%v): sending "+
12261218
"resolution message=%v", c.cfg.ChanPoint,
1227-
newLogClosure(func() string {
1228-
return spew.Sdump(pktsToSend)
1229-
}))
1219+
lnutils.SpewLogClosure(pktsToSend))
12301220

12311221
err := c.cfg.DeliverResolutionMsg(pktsToSend...)
12321222
if err != nil {
@@ -2741,11 +2731,7 @@ func (c *ChannelArbitrator) notifyContractUpdate(upd *ContractUpdate) {
27412731
c.unmergedSet[upd.HtlcKey] = newHtlcSet(upd.Htlcs)
27422732

27432733
log.Tracef("ChannelArbitrator(%v): fresh set of htlcs=%v",
2744-
c.cfg.ChanPoint,
2745-
newLogClosure(func() string {
2746-
return spew.Sdump(upd)
2747-
}),
2748-
)
2734+
c.cfg.ChanPoint, lnutils.SpewLogClosure(upd))
27492735
}
27502736

27512737
// updateActiveHTLCs merges the unmerged set of HTLCs from the link with

contractcourt/log.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,3 @@ func UseBreachLogger(logger btclog.Logger) {
5151
func UseNurseryLogger(logger btclog.Logger) {
5252
utxnLog = logger
5353
}
54-
55-
// logClosure is used to provide a closure over expensive logging operations so
56-
// don't have to be performed when the logging level doesn't warrant it.
57-
type logClosure func() string
58-
59-
// String invokes the underlying function and returns the result.
60-
func (c logClosure) String() string {
61-
return c()
62-
}
63-
64-
// newLogClosure returns a new closure over a function that returns a string
65-
// which itself provides a Stringer interface so that it can be used with the
66-
// logging system.
67-
func newLogClosure(c func() string) logClosure {
68-
return logClosure(c)
69-
}

contractcourt/utxonursery.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/lightningnetwork/lnd/fn"
1919
"github.com/lightningnetwork/lnd/input"
2020
"github.com/lightningnetwork/lnd/labels"
21+
"github.com/lightningnetwork/lnd/lnutils"
2122
"github.com/lightningnetwork/lnd/lnwallet"
2223
"github.com/lightningnetwork/lnd/sweep"
2324
)
@@ -947,10 +948,7 @@ func (u *UtxoNursery) waitForSweepConf(classHeight uint32,
947948
func (u *UtxoNursery) sweepCribOutput(classHeight uint32, baby *babyOutput) error {
948949
utxnLog.Infof("Publishing CLTV-delayed HTLC output using timeout tx "+
949950
"(txid=%v): %v", baby.timeoutTx.TxHash(),
950-
newLogClosure(func() string {
951-
return spew.Sdump(baby.timeoutTx)
952-
}),
953-
)
951+
lnutils.SpewLogClosure(baby.timeoutTx))
954952

955953
// We'll now broadcast the HTLC transaction, then wait for it to be
956954
// confirmed before transitioning it to kindergarten.

discovery/bootstrapper.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
"github.com/btcsuite/btcd/btcec/v2"
1616
"github.com/btcsuite/btcd/btcutil/bech32"
17-
"github.com/davecgh/go-spew/spew"
1817
"github.com/lightningnetwork/lnd/autopilot"
18+
"github.com/lightningnetwork/lnd/lnutils"
1919
"github.com/lightningnetwork/lnd/lnwire"
2020
"github.com/lightningnetwork/lnd/tor"
2121
"github.com/miekg/dns"
@@ -431,10 +431,7 @@ search:
431431
}
432432

433433
log.Tracef("Retrieved SRV records from dns seed: %v",
434-
newLogClosure(func() string {
435-
return spew.Sdump(addrs)
436-
}),
437-
)
434+
lnutils.SpewLogClosure(addrs))
438435

439436
// Next, we'll need to issue an A record request for each of
440437
// the nodes, skipping it if nothing comes back.

discovery/log.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,3 @@ func DisableLog() {
2727
func UseLogger(logger btclog.Logger) {
2828
log = logger
2929
}
30-
31-
// logClosure is used to provide a closure over expensive logging operations
32-
// so don't have to be performed when the logging level doesn't warrant it.
33-
type logClosure func() string
34-
35-
// String invokes the underlying function and returns the result.
36-
func (c logClosure) String() string {
37-
return c()
38-
}
39-
40-
// newLogClosure returns a new closure over a function that returns a string
41-
// which itself provides a Stringer interface so that it can be used with the
42-
// logging system.
43-
func newLogClosure(c func() string) logClosure {
44-
return logClosure(c)
45-
}

0 commit comments

Comments
 (0)