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 committed 2019-07-18 00:33:14 +02:00
1 parent e716251805
commit fcf74debe6
4 files changed
+41 -35

No files matched your search

+4 -4
View File
@@ -1087,8 +1087,8 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
ChainHash: &chainHash,
NodeID: fmsg.peer.IdentityKey(),
NodeAddr: fmsg.peer.Address(),
FundingAmount: 0,
Capacity: amt,
LocalFundingAmt: 0,
RemoteFundingAmt: amt,
CommitFeePerKw: lnwallet.SatPerKWeight(msg.FeePerKiloWeight),
FundingFeePerKw: 0,
PushMSat: msg.PushAmount,
@@ -2786,8 +2786,8 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
ChainHash: &msg.chainHash,
NodeID: peerKey,
NodeAddr: msg.peer.Address(),
FundingAmount: localAmt,
Capacity: capacity,
LocalFundingAmt: localAmt,
RemoteFundingAmt: 0,
CommitFeePerKw: commitFeePerKw,
FundingFeePerKw: msg.fundingFeePerKw,
PushMSat: msg.pushAmt,
+16 -16
View File
@@ -418,8 +418,8 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: fundingAmount,
Capacity: fundingAmount * 2,
LocalFundingAmt: fundingAmount,
RemoteFundingAmt: fundingAmount,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -461,8 +461,8 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: alicePub,
NodeAddr: aliceAddr,
FundingAmount: fundingAmount,
Capacity: fundingAmount * 2,
LocalFundingAmt: fundingAmount,
RemoteFundingAmt: fundingAmount,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -621,8 +621,8 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: fundingAmount,
Capacity: fundingAmount,
LocalFundingAmt: fundingAmount,
RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -643,8 +643,8 @@ func testFundingTransactionLockedOutputs(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: amt,
Capacity: amt,
LocalFundingAmt: amt,
RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -679,8 +679,8 @@ func testFundingCancellationNotEnoughFunds(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: fundingAmount,
Capacity: fundingAmount,
LocalFundingAmt: fundingAmount,
RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -769,8 +769,8 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: fundingAmount,
Capacity: fundingAmount,
LocalFundingAmt: fundingAmount,
RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: 0,
@@ -850,8 +850,8 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: bobPub,
NodeAddr: bobAddr,
FundingAmount: fundingAmt,
Capacity: fundingAmt,
LocalFundingAmt: fundingAmt,
RemoteFundingAmt: 0,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: pushAmt,
@@ -893,8 +893,8 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
ChainHash: chainHash,
NodeID: alicePub,
NodeAddr: aliceAddr,
FundingAmount: 0,
Capacity: fundingAmt,
LocalFundingAmt: 0,
RemoteFundingAmt: fundingAmt,
CommitFeePerKw: feePerKw,
FundingFeePerKw: feePerKw,
PushMSat: pushAmt,
+8 -6
View File
@@ -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
+13 -9
View File
@@ -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 {