Skip to content

Commit e6b78bd

Browse files
authored
Merge pull request #1163 from lightninglabs/minrelayfee
min_relay_fee check during channel funding
2 parents 588e58b + e111765 commit e6b78bd

File tree

11 files changed

+45
-84
lines changed

11 files changed

+45
-84
lines changed

chain_bridge.go

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/lightninglabs/taproot-assets/tapgarden"
1919
"github.com/lightningnetwork/lnd/chainntnfs"
2020
"github.com/lightningnetwork/lnd/funding"
21-
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
2221
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2322
"github.com/lightningnetwork/lnd/lnwire"
2423
"github.com/lightningnetwork/lnd/routing/route"
@@ -37,8 +36,6 @@ const (
3736
type LndRpcChainBridge struct {
3837
lnd *lndclient.LndServices
3938

40-
getBlockHeaderSupported *bool
41-
4239
blockTimestampCache *lru.Cache[uint32, cacheableTimestamp]
4340

4441
assetStore *tapdb.AssetStore
@@ -138,31 +135,6 @@ func (l *LndRpcChainBridge) GetBlockHash(ctx context.Context,
138135
return blockHash, nil
139136
}
140137

141-
// GetBlockHeaderSupported returns true if the chain backend supports the
142-
// `GetBlockHeader` RPC call.
143-
func (l *LndRpcChainBridge) GetBlockHeaderSupported(ctx context.Context) bool {
144-
// Check if we've already asserted the compatibility of the chain
145-
// backend.
146-
if l.getBlockHeaderSupported != nil {
147-
return *l.getBlockHeaderSupported
148-
}
149-
150-
// The ChainKit.GetBlockHeader() RPC call was added in lnd v0.17.1.
151-
getBlockHeaderMinimalVersion := &verrpc.Version{
152-
AppMajor: 0,
153-
AppMinor: 17,
154-
AppPatch: 1,
155-
}
156-
157-
getBlockHeaderUnsupported := lndclient.AssertVersionCompatible(
158-
l.lnd.Version, getBlockHeaderMinimalVersion,
159-
)
160-
getBlockHeaderSupported := getBlockHeaderUnsupported == nil
161-
162-
l.getBlockHeaderSupported = &getBlockHeaderSupported
163-
return *l.getBlockHeaderSupported
164-
}
165-
166138
// VerifyBlock returns an error if a block (with given header and height) is not
167139
// present on-chain. It also checks to ensure that block height corresponds to
168140
// the given block header.
@@ -194,12 +166,7 @@ func (l *LndRpcChainBridge) VerifyBlock(ctx context.Context,
194166
// Ensure that the block header corresponds to a block on-chain. Fetch
195167
// only the corresponding block header and not the entire block if
196168
// supported.
197-
if l.GetBlockHeaderSupported(ctx) {
198-
_, err = l.GetBlockHeader(ctx, header.BlockHash())
199-
return err
200-
}
201-
202-
_, err = l.GetBlock(ctx, header.BlockHash())
169+
_, err = l.GetBlockHeader(ctx, header.BlockHash())
203170
return err
204171
}
205172

@@ -233,20 +200,10 @@ func (l *LndRpcChainBridge) GetBlockTimestamp(ctx context.Context,
233200
return 0
234201
}
235202

236-
// Let's see if we can get the block header directly.
237-
var header *wire.BlockHeader
238-
if l.GetBlockHeaderSupported(ctx) {
239-
header, err = l.GetBlockHeader(ctx, hash)
240-
if err != nil {
241-
return 0
242-
}
243-
} else {
244-
block, err := l.lnd.ChainKit.GetBlock(ctx, hash)
245-
if err != nil {
246-
return 0
247-
}
248-
249-
header = &block.Header
203+
// Get block header.
204+
header, err := l.GetBlockHeader(ctx, hash)
205+
if err != nil {
206+
return 0
250207
}
251208

252209
ts := uint32(header.Timestamp.Unix())

docs/examples/basic-price-oracle/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ require (
9292
github.com/kkdai/bstream v1.0.0 // indirect
9393
github.com/lib/pq v1.10.9 // indirect
9494
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
95-
github.com/lightninglabs/lndclient v0.18.4-1 // indirect
95+
github.com/lightninglabs/lndclient v0.18.4-3 // indirect
9696
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
9797
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
9898
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect

docs/examples/basic-price-oracle/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQ
418418
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbxOCWwUA6TIZvrkE0APd1T3WjFAwg=
419419
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
420420
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
421-
github.com/lightninglabs/lndclient v0.18.4-1 h1:k2UnxHGNH243NRe5/dL2sKgrxc8WMHbFQRdnCtfilwc=
422-
github.com/lightninglabs/lndclient v0.18.4-1/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
421+
github.com/lightninglabs/lndclient v0.18.4-3 h1:Xk3ZuCQE4ZlF70jaToryL2MvRcryiE0zTfUjJbmzUBY=
422+
github.com/lightninglabs/lndclient v0.18.4-3/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
423423
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
424424
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
425425
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/lib/pq v1.10.9
2727
github.com/lightninglabs/aperture v0.3.2-beta.0.20241015115230-d59b5514c19a
2828
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
29-
github.com/lightninglabs/lndclient v0.18.4-1
29+
github.com/lightninglabs/lndclient v0.18.4-3
3030
github.com/lightninglabs/neutrino/cache v1.1.2
3131
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241025090009-615f3d633e61
3232
github.com/lightningnetwork/lnd/cert v1.2.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbx
486486
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha/go.mod h1:A9Pof9fETkH+F67BnOmrBDThPKstqp73wlImWOZvTXQ=
487487
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
488488
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
489-
github.com/lightninglabs/lndclient v0.18.4-1 h1:k2UnxHGNH243NRe5/dL2sKgrxc8WMHbFQRdnCtfilwc=
490-
github.com/lightninglabs/lndclient v0.18.4-1/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
489+
github.com/lightninglabs/lndclient v0.18.4-3 h1:Xk3ZuCQE4ZlF70jaToryL2MvRcryiE0zTfUjJbmzUBY=
490+
github.com/lightninglabs/lndclient v0.18.4-3/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
491491
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
492492
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
493493
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=

rpcserver.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import (
5252
"github.com/lightningnetwork/lnd/build"
5353
"github.com/lightningnetwork/lnd/keychain"
5454
"github.com/lightningnetwork/lnd/lnrpc"
55-
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
5655
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
5756
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
5857
"github.com/lightningnetwork/lnd/lnwire"
@@ -78,17 +77,6 @@ var (
7877
// P2TRChangeType is the type of change address that should be used for
7978
// funding PSBTs, as we'll always want to use P2TR change addresses.
8079
P2TRChangeType = walletrpc.ChangeAddressType_CHANGE_ADDRESS_TYPE_P2TR
81-
82-
// fundPsbtCoinSelectVersion is the version of lnd that enabled better
83-
// coin selection support in the FundPsbt RPC call.
84-
fundPsbtCoinSelectVersion = &verrpc.Version{
85-
AppMajor: 0,
86-
AppMinor: 17,
87-
AppPatch: 99,
88-
BuildTags: []string{
89-
"signrpc", "walletrpc", "chainrpc", "invoicesrpc",
90-
},
91-
}
9280
)
9381

9482
const (
@@ -2304,22 +2292,6 @@ func (r *rpcServer) CommitVirtualPsbts(ctx context.Context,
23042292
req *wrpc.CommitVirtualPsbtsRequest) (*wrpc.CommitVirtualPsbtsResponse,
23052293
error) {
23062294

2307-
// For this call we require `lnd` to be at least v0.17.99-beta (which
2308-
// will become v0.18.0-beta eventually) as we need the new coin
2309-
// selection mode in the FundPsbt call.
2310-
fundPsbtCoinSelectNotSupportedErr := fmt.Errorf("connected lnd "+
2311-
"version %v does not support advanced coin selection in the "+
2312-
"FundPsbt RPC, need at least v%d.%d.%d for this call",
2313-
r.cfg.Lnd.Version.Version, fundPsbtCoinSelectVersion.AppMajor,
2314-
fundPsbtCoinSelectVersion.AppMinor,
2315-
fundPsbtCoinSelectVersion.AppPatch)
2316-
verErr := lndclient.AssertVersionCompatible(
2317-
r.cfg.Lnd.Version, fundPsbtCoinSelectVersion,
2318-
)
2319-
if verErr != nil {
2320-
return nil, fundPsbtCoinSelectNotSupportedErr
2321-
}
2322-
23232295
if len(req.VirtualPsbts) == 0 {
23242296
return nil, fmt.Errorf("no virtual PSBTs specified")
23252297
}

tapcfg/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ var (
186186
// required in lnd to run tapd.
187187
minimalCompatibleVersion = &verrpc.Version{
188188
AppMajor: 0,
189-
AppMinor: 17,
190-
AppPatch: 99,
189+
AppMinor: 18,
190+
AppPatch: 4,
191191

192192
// We don't actually require the invoicesrpc calls. But if we
193193
// try to use lndclient on an lnd that doesn't have it enabled,

tapchannel/aux_funding_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,18 @@ func (f *FundingController) processFundingReq(fundingFlows fundingFlowIndex,
13541354
fundReq.PeerPub.SerializeCompressed())
13551355
}
13561356

1357+
// Before we proceed, we'll make sure the fee rate we're using is above
1358+
// the min relay fee.
1359+
minRelayFee, err := f.cfg.ChainWallet.MinRelayFee(fundReq.ctx)
1360+
if err != nil {
1361+
return fmt.Errorf("unable to establish min_relay_fee: %w",
1362+
err)
1363+
}
1364+
if fundReq.FeeRate.FeePerKWeight() < minRelayFee {
1365+
return fmt.Errorf("fee rate %v too low, min_relay_fee: %v",
1366+
fundReq.FeeRate.FeePerKWeight(), minRelayFee)
1367+
}
1368+
13571369
// To start, we'll make a new pending asset funding desc. This'll be
13581370
// our scratch pad during the asset funding process.
13591371
tempPID, err := newPendingChanID()

tapgarden/interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ type WalletAnchor interface {
372372
// relevant to the wallet are sent over.
373373
SubscribeTransactions(context.Context) (<-chan lndclient.Transaction,
374374
<-chan error, error)
375+
376+
// MinRelayFee returns the current minimum relay fee based on
377+
// our chain backend in sat/kw.
378+
MinRelayFee(ctx context.Context) (chainfee.SatPerKWeight, error)
375379
}
376380

377381
// KeyRing is a mirror of the keychain.KeyRing interface, with the addition of

tapgarden/mock.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ func (m *MockWalletAnchor) ListTransactions(ctx context.Context, _, _ int32,
302302
return m.Transactions, nil
303303
}
304304

305+
// MinRelayFee estimates the minimum fee rate required for a
306+
// transaction.
307+
func (m *MockWalletAnchor) MinRelayFee(
308+
ctx context.Context) (chainfee.SatPerKWeight, error) {
309+
310+
return chainfee.SatPerKWeight(10), nil
311+
}
312+
305313
type MockChainBridge struct {
306314
FeeEstimateSignal chan struct{}
307315
PublishReq chan *wire.MsgTx

0 commit comments

Comments
 (0)