Skip to content

Commit

Permalink
multi: add minrelayfee check to tapchannel funding
Browse files Browse the repository at this point in the history
This commit adds `MinRelayFee` to the `WalletAnchor` and uses it during
tapchannel funding to check whether the feerate meets the minimum relay
fee.
  • Loading branch information
gijswijs committed Nov 1, 2024
1 parent 05ad64b commit e111765
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/examples/basic-price-oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ require (
github.com/kkdai/bstream v1.0.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/lndclient v0.18.4-1 // indirect
github.com/lightninglabs/lndclient v0.18.4-3 // indirect
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/basic-price-oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQ
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbxOCWwUA6TIZvrkE0APd1T3WjFAwg=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
github.com/lightninglabs/lndclient v0.18.4-1 h1:k2UnxHGNH243NRe5/dL2sKgrxc8WMHbFQRdnCtfilwc=
github.com/lightninglabs/lndclient v0.18.4-1/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
github.com/lightninglabs/lndclient v0.18.4-3 h1:Xk3ZuCQE4ZlF70jaToryL2MvRcryiE0zTfUjJbmzUBY=
github.com/lightninglabs/lndclient v0.18.4-3/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/lib/pq v1.10.9
github.com/lightninglabs/aperture v0.3.2-beta.0.20241015115230-d59b5514c19a
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
github.com/lightninglabs/lndclient v0.18.4-1
github.com/lightninglabs/lndclient v0.18.4-3
github.com/lightninglabs/neutrino/cache v1.1.2
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241025090009-615f3d633e61
github.com/lightningnetwork/lnd/cert v1.2.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbx
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha/go.mod h1:A9Pof9fETkH+F67BnOmrBDThPKstqp73wlImWOZvTXQ=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
github.com/lightninglabs/lndclient v0.18.4-1 h1:k2UnxHGNH243NRe5/dL2sKgrxc8WMHbFQRdnCtfilwc=
github.com/lightninglabs/lndclient v0.18.4-1/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
github.com/lightninglabs/lndclient v0.18.4-3 h1:Xk3ZuCQE4ZlF70jaToryL2MvRcryiE0zTfUjJbmzUBY=
github.com/lightninglabs/lndclient v0.18.4-3/go.mod h1:/HLqmZGL9MtP8F1g+laq+L9VrsugBN5tsTct3C5wWCg=
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
Expand Down
12 changes: 12 additions & 0 deletions tapchannel/aux_funding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,18 @@ func (f *FundingController) processFundingReq(fundingFlows fundingFlowIndex,
fundReq.PeerPub.SerializeCompressed())
}

// Before we proceed, we'll make sure the fee rate we're using is above
// the min relay fee.
minRelayFee, err := f.cfg.ChainWallet.MinRelayFee(fundReq.ctx)
if err != nil {
return fmt.Errorf("unable to establish min_relay_fee: %w",
err)
}
if fundReq.FeeRate.FeePerKWeight() < minRelayFee {
return fmt.Errorf("fee rate %v too low, min_relay_fee: %v",
fundReq.FeeRate.FeePerKWeight(), minRelayFee)
}

// To start, we'll make a new pending asset funding desc. This'll be
// our scratch pad during the asset funding process.
tempPID, err := newPendingChanID()
Expand Down
4 changes: 4 additions & 0 deletions tapgarden/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ type WalletAnchor interface {
// relevant to the wallet are sent over.
SubscribeTransactions(context.Context) (<-chan lndclient.Transaction,
<-chan error, error)

// MinRelayFee returns the current minimum relay fee based on
// our chain backend in sat/kw.
MinRelayFee(ctx context.Context) (chainfee.SatPerKWeight, error)
}

// KeyRing is a mirror of the keychain.KeyRing interface, with the addition of
Expand Down
8 changes: 8 additions & 0 deletions tapgarden/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ func (m *MockWalletAnchor) ListTransactions(ctx context.Context, _, _ int32,
return m.Transactions, nil
}

// MinRelayFee estimates the minimum fee rate required for a
// transaction.
func (m *MockWalletAnchor) MinRelayFee(
ctx context.Context) (chainfee.SatPerKWeight, error) {

return chainfee.SatPerKWeight(10), nil
}

type MockChainBridge struct {
FeeEstimateSignal chan struct{}
PublishReq chan *wire.MsgTx
Expand Down
8 changes: 8 additions & 0 deletions wallet_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func (l *LndRpcWalletAnchor) ListChannels(
return l.lnd.Client.ListChannels(ctx, true, false)
}

// MinRelayFee estimates the minimum fee rate required for a
// transaction.
func (l *LndRpcWalletAnchor) MinRelayFee(
ctx context.Context) (chainfee.SatPerKWeight, error) {

return l.lnd.WalletKit.MinRelayFee(ctx)
}

// A compile time assertion to ensure LndRpcWalletAnchor meets the
// tapgarden.WalletAnchor interface.
var _ tapgarden.WalletAnchor = (*LndRpcWalletAnchor)(nil)
Expand Down

0 comments on commit e111765

Please sign in to comment.