lnwallet: disallow creating a funding reservation with zero total satoshis
This commit is contained in:
2 files changed
+22
-6
No files matched your search
@@ -140,17 +140,25 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
|
|||||||
var ourBalance btcutil.Amount
|
var ourBalance btcutil.Amount
|
||||||
var theirBalance btcutil.Amount
|
var theirBalance btcutil.Amount
|
||||||
|
|
||||||
|
// If we're the responder to a single-funder reservation, then we have
|
||||||
|
// no initial balance in the channel.
|
||||||
if fundingAmt == 0 {
|
if fundingAmt == 0 {
|
||||||
ourBalance = 0
|
ourBalance = 0
|
||||||
theirBalance = capacity - commitFee
|
theirBalance = capacity - commitFee
|
||||||
} else {
|
} else {
|
||||||
// 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+commitFee { // Single funder
|
|
||||||
|
// If we're initiating a single funder workflow, then we pay
|
||||||
|
// all the initial fees within the commitment transaction.
|
||||||
|
if capacity == fundingAmt+commitFee {
|
||||||
ourBalance = capacity - commitFee
|
ourBalance = capacity - commitFee
|
||||||
|
// Otherwise, this is a dual funder workflow where both slides
|
||||||
|
// split the amount funded and the commitment fee.
|
||||||
} else {
|
} else {
|
||||||
ourBalance = fundingAmt - commitFee
|
ourBalance = fundingAmt - commitFee
|
||||||
}
|
}
|
||||||
|
|
||||||
theirBalance = capacity - fundingAmt - commitFee
|
theirBalance = capacity - fundingAmt - commitFee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -495,6 +495,14 @@ func (l *LightningWallet) InitChannelReservation(capacity,
|
|||||||
// handleFundingReserveRequest processes a message intending to create, and
|
// handleFundingReserveRequest processes a message intending to create, and
|
||||||
// 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.
|
||||||
|
if req.fundingAmount+req.capacity == 0 {
|
||||||
|
req.err <- fmt.Errorf("cannot have channel with zero " +
|
||||||
|
"satoshis funded")
|
||||||
|
req.resp <- nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
id := atomic.AddUint64(&l.nextFundingID, 1)
|
id := atomic.AddUint64(&l.nextFundingID, 1)
|
||||||
totalCapacity := req.capacity + commitFee
|
totalCapacity := req.capacity + commitFee
|
||||||
reservation := NewChannelReservation(totalCapacity, req.fundingAmount,
|
reservation := NewChannelReservation(totalCapacity, req.fundingAmount,
|
||||||
@@ -612,11 +620,11 @@ func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMs
|
|||||||
req.err <- nil
|
req.err <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleFundingCounterPartyFunds processes the second workflow step for the
|
// handleContributionMsg processes the second workflow step for the lifetime of
|
||||||
// lifetime of a channel reservation. Upon completion, the reservation will
|
// a channel reservation. Upon completion, the reservation will carry a
|
||||||
// carry a completed funding transaction (minus the counterparty's input
|
// completed funding transaction (minus the counterparty's input signatures),
|
||||||
// signatures), both versions of the commitment transaction, and our signature
|
// both versions of the commitment transaction, and our signature for their
|
||||||
// for their version of the commitment transaction.
|
// version of the commitment transaction.
|
||||||
func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||||
l.limboMtx.Lock()
|
l.limboMtx.Lock()
|
||||||
pendingReservation, ok := l.fundingLimbo[req.pendingFundingID]
|
pendingReservation, ok := l.fundingLimbo[req.pendingFundingID]
|
||||||
|
|||||||
Reference in new issue
Block a user