lnwallet+funding: rename Capacity and FundingAmt

Instead use LocalFundingAmt and RemoteFundingAmt to make it clear who is
contributing funds.
This commit is contained in:
Johan T. Halseth 2019-07-11 13:14:36 +02:00
parent e716251805
commit fcf74debe6
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
4 changed files with 113 additions and 107 deletions

@ -1087,8 +1087,8 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
ChainHash: &chainHash, ChainHash: &chainHash,
NodeID: fmsg.peer.IdentityKey(), NodeID: fmsg.peer.IdentityKey(),
NodeAddr: fmsg.peer.Address(), NodeAddr: fmsg.peer.Address(),
FundingAmount: 0, LocalFundingAmt: 0,
Capacity: amt, RemoteFundingAmt: amt,
CommitFeePerKw: lnwallet.SatPerKWeight(msg.FeePerKiloWeight), CommitFeePerKw: lnwallet.SatPerKWeight(msg.FeePerKiloWeight),
FundingFeePerKw: 0, FundingFeePerKw: 0,
PushMSat: msg.PushAmount, PushMSat: msg.PushAmount,
@ -2786,8 +2786,8 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
ChainHash: &msg.chainHash, ChainHash: &msg.chainHash,
NodeID: peerKey, NodeID: peerKey,
NodeAddr: msg.peer.Address(), NodeAddr: msg.peer.Address(),
FundingAmount: localAmt, LocalFundingAmt: localAmt,
Capacity: capacity, RemoteFundingAmt: 0,
CommitFeePerKw: commitFeePerKw, CommitFeePerKw: commitFeePerKw,
FundingFeePerKw: msg.fundingFeePerKw, FundingFeePerKw: msg.fundingFeePerKw,
PushMSat: msg.pushAmt, PushMSat: msg.pushAmt,

@ -418,8 +418,8 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: fundingAmount, LocalFundingAmt: fundingAmount,
Capacity: fundingAmount * 2, RemoteFundingAmt: fundingAmount,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -461,8 +461,8 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: alicePub, NodeID: alicePub,
NodeAddr: aliceAddr, NodeAddr: aliceAddr,
FundingAmount: fundingAmount, LocalFundingAmt: fundingAmount,
Capacity: fundingAmount * 2, RemoteFundingAmt: fundingAmount,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -621,8 +621,8 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: fundingAmount, LocalFundingAmt: fundingAmount,
Capacity: fundingAmount, RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -643,8 +643,8 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: amt, LocalFundingAmt: amt,
Capacity: amt, RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -679,8 +679,8 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: fundingAmount, LocalFundingAmt: fundingAmount,
Capacity: fundingAmount, RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -769,8 +769,8 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: fundingAmount, LocalFundingAmt: fundingAmount,
Capacity: fundingAmount, RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: 0, PushMSat: 0,
@ -850,8 +850,8 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: bobPub, NodeID: bobPub,
NodeAddr: bobAddr, NodeAddr: bobAddr,
FundingAmount: fundingAmt, LocalFundingAmt: fundingAmt,
Capacity: fundingAmt, RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: pushAmt, PushMSat: pushAmt,
@ -893,8 +893,8 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash, ChainHash: chainHash,
NodeID: alicePub, NodeID: alicePub,
NodeAddr: aliceAddr, NodeAddr: aliceAddr,
FundingAmount: 0, LocalFundingAmt: 0,
Capacity: fundingAmt, RemoteFundingAmt: fundingAmt,
CommitFeePerKw: feePerKw, CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw, FundingFeePerKw: feePerKw,
PushMSat: pushAmt, PushMSat: pushAmt,

@ -127,7 +127,7 @@ type ChannelReservation struct {
// used only internally by lnwallet. In order to concurrent safety, the // used only internally by lnwallet. In order to concurrent safety, the
// creation of all channel reservations should be carried out via the // creation of all channel reservations should be carried out via the
// lnwallet.InitChannelReservation interface. // lnwallet.InitChannelReservation interface.
func NewChannelReservation(capacity, fundingAmt btcutil.Amount, func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
commitFeePerKw SatPerKWeight, wallet *LightningWallet, commitFeePerKw SatPerKWeight, wallet *LightningWallet,
id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash, id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash,
flags lnwire.FundingFlag) (*ChannelReservation, error) { flags lnwire.FundingFlag) (*ChannelReservation, error) {
@ -139,14 +139,16 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
) )
commitFee := commitFeePerKw.FeeForWeight(input.CommitWeight) 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) capacityMSat := lnwire.NewMSatFromSatoshis(capacity)
feeMSat := lnwire.NewMSatFromSatoshis(commitFee) feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
// If we're the responder to a single-funder reservation, then we have // 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 // no initial balance in the channel unless the remote party is pushing
// some funds to us within the first commitment state. // some funds to us within the first commitment state.
if fundingAmt == 0 { if localFundingAmt == 0 {
ourBalance = pushMSat ourBalance = pushMSat
theirBalance = capacityMSat - feeMSat - pushMSat theirBalance = capacityMSat - feeMSat - pushMSat
initiator = false initiator = false
@ -163,7 +165,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount,
// TODO(roasbeef): need to rework fee structure in general and // TODO(roasbeef): need to rework fee structure in general and
// also when we "unlock" dual funder within the daemon // also when we "unlock" dual funder within the daemon
if capacity == fundingAmt { if capacity == localFundingAmt {
// If we're initiating a single funder workflow, then // If we're initiating a single funder workflow, then
// we pay all the initial fees within the commitment // we pay all the initial fees within the commitment
// transaction. We also deduct our balance by the // 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 // Otherwise, this is a dual funder workflow where both
// slides split the amount funded and the commitment // slides split the amount funded and the commitment
// fee. // fee.
ourBalance = fundingMSat - (feeMSat / 2) ourBalance = localFundingMSat - (feeMSat / 2)
theirBalance = capacityMSat - fundingMSat - (feeMSat / 2) + pushMSat theirBalance = capacityMSat - localFundingMSat - (feeMSat / 2) + pushMSat
} }
initiator = true initiator = true

@ -69,12 +69,13 @@ type InitFundingReserveMsg struct {
// workflow. // workflow.
NodeAddr net.Addr NodeAddr net.Addr
// FundingAmount is the amount of funds requested for this channel. // LocalFundingAmt is the amount of funds requested from us for this
FundingAmount btcutil.Amount // channel.
LocalFundingAmt btcutil.Amount
// Capacity is the total capacity of the channel which includes the // RemoteFundingAmnt is the amount of funds the remote will contribute
// amount of funds the remote party contributes (if any). // to this channel.
Capacity btcutil.Amount RemoteFundingAmt btcutil.Amount
// CommitFeePerKw is the starting accepted satoshis/Kw fee for the set // CommitFeePerKw is the starting accepted satoshis/Kw fee for the set
// of initial commitment transactions. In order to ensure timely // of initial commitment transactions. In order to ensure timely
@ -431,7 +432,7 @@ func (l *LightningWallet) InitChannelReservation(
// validate a funding reservation request. // validate a funding reservation request.
func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg) { func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg) {
// It isn't possible to create a channel with zero funds committed. // 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() err := ErrZeroCapacity()
req.err <- err req.err <- err
req.resp <- nil req.resp <- nil
@ -449,9 +450,12 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
return return
} }
capacity := req.LocalFundingAmt + req.RemoteFundingAmt
localFundingAmt := req.LocalFundingAmt
id := atomic.AddUint64(&l.nextFundingID, 1) id := atomic.AddUint64(&l.nextFundingID, 1)
reservation, err := NewChannelReservation( 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, req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags,
) )
if err != nil { 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 // 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 // don't need to perform any coin selection. Otherwise, attempt to
// obtain enough coins to meet the required funding amount. // 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 // Coin selection is done on the basis of sat/kw, so we'll use
// the fee rate passed in to perform coin selection. // the fee rate passed in to perform coin selection.
err := l.selectCoinsAndChange( err := l.selectCoinsAndChange(
req.FundingFeePerKw, req.FundingAmount, req.MinConfs, req.FundingFeePerKw, req.LocalFundingAmt, req.MinConfs,
reservation.ourContribution, reservation.ourContribution,
) )
if err != nil { if err != nil {