mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-30 17:50:58 +02:00
Merge pull request #8896 from ziggie1984/batchopen-feerate-fix
Fix batchopen fee calculation
This commit is contained in:
commit
b7c59b36a7
@ -32,6 +32,9 @@
|
|||||||
* [Avoids duplicate wallet addresses being
|
* [Avoids duplicate wallet addresses being
|
||||||
created](https://github.com/lightningnetwork/lnd/pull/8921) when multiple RPC
|
created](https://github.com/lightningnetwork/lnd/pull/8921) when multiple RPC
|
||||||
calls are made concurrently.
|
calls are made concurrently.
|
||||||
|
|
||||||
|
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8896) that caused
|
||||||
|
LND to use a default fee rate for the batch channel opening flow.
|
||||||
|
|
||||||
# New Features
|
# New Features
|
||||||
## Functional Enhancements
|
## Functional Enhancements
|
||||||
@ -148,3 +151,4 @@
|
|||||||
* Oliver Gugger
|
* Oliver Gugger
|
||||||
* Slyghtning
|
* Slyghtning
|
||||||
* Yong Yu
|
* Yong Yu
|
||||||
|
* Ziggie
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -968,11 +969,16 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
|
|||||||
ht.EnsureConnected(alice, dave)
|
ht.EnsureConnected(alice, dave)
|
||||||
ht.EnsureConnected(alice, eve)
|
ht.EnsureConnected(alice, eve)
|
||||||
|
|
||||||
|
expectedFeeRate := chainfee.SatPerKWeight(2500)
|
||||||
|
|
||||||
|
// We verify that the channel opening uses the correct fee rate.
|
||||||
|
ht.SetFeeEstimateWithConf(expectedFeeRate, 3)
|
||||||
|
|
||||||
// Let's create our batch TX request. This first one should fail as we
|
// Let's create our batch TX request. This first one should fail as we
|
||||||
// open a channel to Carol that is too small for her min chan size.
|
// open a channel to Carol that is too small for her min chan size.
|
||||||
batchReq := &lnrpc.BatchOpenChannelRequest{
|
batchReq := &lnrpc.BatchOpenChannelRequest{
|
||||||
SatPerVbyte: 12,
|
TargetConf: 3,
|
||||||
MinConfs: 1,
|
MinConfs: 1,
|
||||||
Channels: []*lnrpc.BatchOpenChannel{{
|
Channels: []*lnrpc.BatchOpenChannel{{
|
||||||
NodePubkey: bob.PubKey[:],
|
NodePubkey: bob.PubKey[:],
|
||||||
LocalFundingAmount: 100_000,
|
LocalFundingAmount: 100_000,
|
||||||
@ -1069,6 +1075,12 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
|
|||||||
rawTx := ht.GetRawTransaction(txHash)
|
rawTx := ht.GetRawTransaction(txHash)
|
||||||
require.Len(ht, rawTx.MsgTx().TxOut, 5)
|
require.Len(ht, rawTx.MsgTx().TxOut, 5)
|
||||||
|
|
||||||
|
// Check the fee rate of the batch-opening transaction. We expect slight
|
||||||
|
// inaccuracies because of the DER signature fee estimation.
|
||||||
|
openingFeeRate := ht.CalculateTxFeeRate(rawTx.MsgTx())
|
||||||
|
require.InEpsilonf(ht, uint64(expectedFeeRate), uint64(openingFeeRate),
|
||||||
|
0.01, "want %v, got %v", expectedFeeRate, openingFeeRate)
|
||||||
|
|
||||||
// For calculating the change output index we use the formula for the
|
// For calculating the change output index we use the formula for the
|
||||||
// sum of consecutive of integers (n(n+1)/2). All the channel point
|
// sum of consecutive of integers (n(n+1)/2). All the channel point
|
||||||
// indexes are known, so we just calculate the difference to get the
|
// indexes are known, so we just calculate the difference to get the
|
||||||
|
36
rpcserver.go
36
rpcserver.go
@ -2159,30 +2159,24 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
return nil, fmt.Errorf("cannot open channel to self")
|
return nil, fmt.Errorf("cannot open channel to self")
|
||||||
}
|
}
|
||||||
|
|
||||||
var feeRate chainfee.SatPerKWeight
|
// NOTE: We also need to do the fee rate calculation for the psbt
|
||||||
|
// funding flow because the `batchfund` depends on it.
|
||||||
|
targetConf := maybeUseDefaultConf(
|
||||||
|
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
|
||||||
|
)
|
||||||
|
|
||||||
// Skip estimating fee rate for PSBT funding.
|
// Calculate an appropriate fee rate for this transaction.
|
||||||
if in.FundingShim == nil || in.FundingShim.GetPsbtShim() == nil {
|
feeRate, err := lnrpc.CalculateFeeRate(
|
||||||
// Keep the old behavior prior to 0.18.0 - when the user
|
uint64(in.SatPerByte), in.SatPerVbyte,
|
||||||
// doesn't set fee rate or conf target, the default conf target
|
targetConf, r.server.cc.FeeEstimator,
|
||||||
// of 6 is used.
|
)
|
||||||
targetConf := maybeUseDefaultConf(
|
if err != nil {
|
||||||
in.SatPerByte, in.SatPerVbyte, uint32(in.TargetConf),
|
return nil, err
|
||||||
)
|
|
||||||
|
|
||||||
// Calculate an appropriate fee rate for this transaction.
|
|
||||||
feeRate, err = lnrpc.CalculateFeeRate(
|
|
||||||
uint64(in.SatPerByte), in.SatPerVbyte,
|
|
||||||
targetConf, r.server.cc.FeeEstimator,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for "+
|
|
||||||
"funding tx", int64(feeRate))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for "+
|
||||||
|
"funding tx", int64(feeRate))
|
||||||
|
|
||||||
script, err := chancloser.ParseUpfrontShutdownAddress(
|
script, err := chancloser.ParseUpfrontShutdownAddress(
|
||||||
in.CloseAddress, r.cfg.ActiveNetParams.Params,
|
in.CloseAddress, r.cfg.ActiveNetParams.Params,
|
||||||
)
|
)
|
||||||
|
17
server.go
17
server.go
@ -4578,16 +4578,15 @@ func (s *server) OpenChannel(
|
|||||||
return req.Updates, req.Err
|
return req.Updates, req.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the fee rate wasn't specified, then we'll use a default
|
// If the fee rate wasn't specified at this point we fail the funding
|
||||||
// confirmation target.
|
// because of the missing fee rate information. The caller of the
|
||||||
|
// `OpenChannel` method needs to make sure that default values for the
|
||||||
|
// fee rate are set beforehand.
|
||||||
if req.FundingFeePerKw == 0 {
|
if req.FundingFeePerKw == 0 {
|
||||||
estimator := s.cc.FeeEstimator
|
req.Err <- fmt.Errorf("no FundingFeePerKw specified for " +
|
||||||
feeRate, err := estimator.EstimateFeePerKW(6)
|
"the channel opening transaction")
|
||||||
if err != nil {
|
|
||||||
req.Err <- err
|
return req.Updates, req.Err
|
||||||
return req.Updates, req.Err
|
|
||||||
}
|
|
||||||
req.FundingFeePerKw = feeRate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn a goroutine to send the funding workflow request to the funding
|
// Spawn a goroutine to send the funding workflow request to the funding
|
||||||
|
Loading…
x
Reference in New Issue
Block a user