mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 14:22:37 +01:00
lnwallet+funding: rename Capacity and FundingAmt
Instead use LocalFundingAmt and RemoteFundingAmt to make it clear who is contributing funds.
This commit is contained in:
parent
e716251805
commit
fcf74debe6
4 changed files with 113 additions and 107 deletions
|
@ -1084,16 +1084,16 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||
// funds to the channel ourselves.
|
||||
chainHash := chainhash.Hash(msg.ChainHash)
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: &chainHash,
|
||||
NodeID: fmsg.peer.IdentityKey(),
|
||||
NodeAddr: fmsg.peer.Address(),
|
||||
FundingAmount: 0,
|
||||
Capacity: amt,
|
||||
CommitFeePerKw: lnwallet.SatPerKWeight(msg.FeePerKiloWeight),
|
||||
FundingFeePerKw: 0,
|
||||
PushMSat: msg.PushAmount,
|
||||
Flags: msg.ChannelFlags,
|
||||
MinConfs: 1,
|
||||
ChainHash: &chainHash,
|
||||
NodeID: fmsg.peer.IdentityKey(),
|
||||
NodeAddr: fmsg.peer.Address(),
|
||||
LocalFundingAmt: 0,
|
||||
RemoteFundingAmt: amt,
|
||||
CommitFeePerKw: lnwallet.SatPerKWeight(msg.FeePerKiloWeight),
|
||||
FundingFeePerKw: 0,
|
||||
PushMSat: msg.PushAmount,
|
||||
Flags: msg.ChannelFlags,
|
||||
MinConfs: 1,
|
||||
}
|
||||
|
||||
reservation, err := f.cfg.Wallet.InitChannelReservation(req)
|
||||
|
@ -2783,16 +2783,16 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||
// wallet doesn't have enough funds to commit to this channel, then the
|
||||
// request will fail, and be aborted.
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: &msg.chainHash,
|
||||
NodeID: peerKey,
|
||||
NodeAddr: msg.peer.Address(),
|
||||
FundingAmount: localAmt,
|
||||
Capacity: capacity,
|
||||
CommitFeePerKw: commitFeePerKw,
|
||||
FundingFeePerKw: msg.fundingFeePerKw,
|
||||
PushMSat: msg.pushAmt,
|
||||
Flags: channelFlags,
|
||||
MinConfs: msg.minConfs,
|
||||
ChainHash: &msg.chainHash,
|
||||
NodeID: peerKey,
|
||||
NodeAddr: msg.peer.Address(),
|
||||
LocalFundingAmt: localAmt,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: commitFeePerKw,
|
||||
FundingFeePerKw: msg.fundingFeePerKw,
|
||||
PushMSat: msg.pushAmt,
|
||||
Flags: channelFlags,
|
||||
MinConfs: msg.minConfs,
|
||||
}
|
||||
|
||||
reservation, err := f.cfg.Wallet.InitChannelReservation(req)
|
||||
|
|
|
@ -415,15 +415,15 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
|||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
aliceReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: fundingAmount,
|
||||
Capacity: fundingAmount * 2,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: fundingAmount,
|
||||
RemoteFundingAmt: fundingAmount,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
aliceChanReservation, err := alice.InitChannelReservation(aliceReq)
|
||||
if err != nil {
|
||||
|
@ -458,15 +458,15 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
|||
// receives' Alice's contribution, and consumes that so we can continue
|
||||
// the funding process.
|
||||
bobReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: alicePub,
|
||||
NodeAddr: aliceAddr,
|
||||
FundingAmount: fundingAmount,
|
||||
Capacity: fundingAmount * 2,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: alicePub,
|
||||
NodeAddr: aliceAddr,
|
||||
LocalFundingAmt: fundingAmount,
|
||||
RemoteFundingAmt: fundingAmount,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
bobChanReservation, err := bob.InitChannelReservation(bobReq)
|
||||
if err != nil {
|
||||
|
@ -618,15 +618,15 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
|||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: fundingAmount,
|
||||
Capacity: fundingAmount,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: fundingAmount,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
if _, err := alice.InitChannelReservation(req); err != nil {
|
||||
t.Fatalf("unable to initialize funding reservation 1: %v", err)
|
||||
|
@ -640,15 +640,15 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
|
|||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
failedReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: amt,
|
||||
Capacity: amt,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: amt,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
failedReservation, err := alice.InitChannelReservation(failedReq)
|
||||
if err == nil {
|
||||
|
@ -676,15 +676,15 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
|
|||
t.Fatalf("unable to create amt: %v", err)
|
||||
}
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: fundingAmount,
|
||||
Capacity: fundingAmount,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: fundingAmount,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
chanReservation, err := alice.InitChannelReservation(req)
|
||||
if err != nil {
|
||||
|
@ -766,15 +766,15 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
|
|||
numBTC * numBTC * btcutil.SatoshiPerBitcoin,
|
||||
)
|
||||
req := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: fundingAmount,
|
||||
Capacity: fundingAmount,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: fundingAmount,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
_, err = alice.InitChannelReservation(req)
|
||||
switch {
|
||||
|
@ -847,15 +847,15 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
|||
t.Fatalf("unable to query fee estimator: %v", err)
|
||||
}
|
||||
aliceReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
FundingAmount: fundingAmt,
|
||||
Capacity: fundingAmt,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: bobPub,
|
||||
NodeAddr: bobAddr,
|
||||
LocalFundingAmt: fundingAmt,
|
||||
RemoteFundingAmt: 0,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
aliceChanReservation, err := alice.InitChannelReservation(aliceReq)
|
||||
if err != nil {
|
||||
|
@ -890,15 +890,15 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
|||
// Next, Bob receives the initial request, generates a corresponding
|
||||
// reservation initiation, then consume Alice's contribution.
|
||||
bobReq := &lnwallet.InitFundingReserveMsg{
|
||||
ChainHash: chainHash,
|
||||
NodeID: alicePub,
|
||||
NodeAddr: aliceAddr,
|
||||
FundingAmount: 0,
|
||||
Capacity: fundingAmt,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
ChainHash: chainHash,
|
||||
NodeID: alicePub,
|
||||
NodeAddr: aliceAddr,
|
||||
LocalFundingAmt: 0,
|
||||
RemoteFundingAmt: fundingAmt,
|
||||
CommitFeePerKw: feePerKw,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
}
|
||||
bobChanReservation, err := bob.InitChannelReservation(bobReq)
|
||||
if err != nil {
|
||||
|
|
|
@ -127,7 +127,7 @@ type ChannelReservation struct {
|
|||
// used only internally by lnwallet. In order to concurrent safety, the
|
||||
// creation of all channel reservations should be carried out via the
|
||||
// lnwallet.InitChannelReservation interface.
|
||||
func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
|
||||
func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
||||
commitFeePerKw SatPerKWeight, wallet *LightningWallet,
|
||||
id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash,
|
||||
flags lnwire.FundingFlag) (*ChannelReservation, error) {
|
||||
|
@ -139,14 +139,16 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
|
|||
)
|
||||
|
||||
commitFee := commitFeePerKw.FeeForWeight(input.CommitWeight)
|
||||
fundingMSat := lnwire.NewMSatFromSatoshis(fundingAmt)
|
||||
localFundingMSat := lnwire.NewMSatFromSatoshis(localFundingAmt)
|
||||
// TODO(halseth): make method take remote funding amount direcly
|
||||
// instead of inferring it from capacity and local amt.
|
||||
capacityMSat := lnwire.NewMSatFromSatoshis(capacity)
|
||||
feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
|
||||
|
||||
// If we're the responder to a single-funder reservation, then we have
|
||||
// no initial balance in the channel unless the remote party is pushing
|
||||
// some funds to us within the first commitment state.
|
||||
if fundingAmt == 0 {
|
||||
if localFundingAmt == 0 {
|
||||
ourBalance = pushMSat
|
||||
theirBalance = capacityMSat - feeMSat - pushMSat
|
||||
initiator = false
|
||||
|
@ -163,7 +165,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
|
|||
// TODO(roasbeef): need to rework fee structure in general and
|
||||
// also when we "unlock" dual funder within the daemon
|
||||
|
||||
if capacity == fundingAmt {
|
||||
if capacity == localFundingAmt {
|
||||
// If we're initiating a single funder workflow, then
|
||||
// we pay all the initial fees within the commitment
|
||||
// transaction. We also deduct our balance by the
|
||||
|
@ -174,8 +176,8 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
|
|||
// Otherwise, this is a dual funder workflow where both
|
||||
// slides split the amount funded and the commitment
|
||||
// fee.
|
||||
ourBalance = fundingMSat - (feeMSat / 2)
|
||||
theirBalance = capacityMSat - fundingMSat - (feeMSat / 2) + pushMSat
|
||||
ourBalance = localFundingMSat - (feeMSat / 2)
|
||||
theirBalance = capacityMSat - localFundingMSat - (feeMSat / 2) + pushMSat
|
||||
}
|
||||
|
||||
initiator = true
|
||||
|
|
|
@ -69,12 +69,13 @@ type InitFundingReserveMsg struct {
|
|||
// workflow.
|
||||
NodeAddr net.Addr
|
||||
|
||||
// FundingAmount is the amount of funds requested for this channel.
|
||||
FundingAmount btcutil.Amount
|
||||
// LocalFundingAmt is the amount of funds requested from us for this
|
||||
// channel.
|
||||
LocalFundingAmt btcutil.Amount
|
||||
|
||||
// Capacity is the total capacity of the channel which includes the
|
||||
// amount of funds the remote party contributes (if any).
|
||||
Capacity btcutil.Amount
|
||||
// RemoteFundingAmnt is the amount of funds the remote will contribute
|
||||
// to this channel.
|
||||
RemoteFundingAmt btcutil.Amount
|
||||
|
||||
// CommitFeePerKw is the starting accepted satoshis/Kw fee for the set
|
||||
// of initial commitment transactions. In order to ensure timely
|
||||
|
@ -431,7 +432,7 @@ func (l *LightningWallet) InitChannelReservation(
|
|||
// validate a funding reservation request.
|
||||
func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg) {
|
||||
// It isn't possible to create a channel with zero funds committed.
|
||||
if req.FundingAmount+req.Capacity == 0 {
|
||||
if req.LocalFundingAmt+req.RemoteFundingAmt == 0 {
|
||||
err := ErrZeroCapacity()
|
||||
req.err <- err
|
||||
req.resp <- nil
|
||||
|
@ -449,9 +450,12 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
|||
return
|
||||
}
|
||||
|
||||
capacity := req.LocalFundingAmt + req.RemoteFundingAmt
|
||||
localFundingAmt := req.LocalFundingAmt
|
||||
|
||||
id := atomic.AddUint64(&l.nextFundingID, 1)
|
||||
reservation, err := NewChannelReservation(
|
||||
req.Capacity, req.FundingAmount, req.CommitFeePerKw, l, id,
|
||||
capacity, localFundingAmt, req.CommitFeePerKw, l, id,
|
||||
req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags,
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -470,11 +474,11 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
|
|||
// If we're on the receiving end of a single funder channel then we
|
||||
// don't need to perform any coin selection. Otherwise, attempt to
|
||||
// obtain enough coins to meet the required funding amount.
|
||||
if req.FundingAmount != 0 {
|
||||
if req.LocalFundingAmt != 0 {
|
||||
// Coin selection is done on the basis of sat/kw, so we'll use
|
||||
// the fee rate passed in to perform coin selection.
|
||||
err := l.selectCoinsAndChange(
|
||||
req.FundingFeePerKw, req.FundingAmount, req.MinConfs,
|
||||
req.FundingFeePerKw, req.LocalFundingAmt, req.MinConfs,
|
||||
reservation.ourContribution,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue