lnwallet: update funding flow to use new channeldb API's

This commit is contained in:
Olaoluwa Osuntokun 2017-11-10 14:18:41 -08:00
parent 367c6b10fc
commit 7f667e2dbc
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 31 additions and 21 deletions

@ -205,16 +205,24 @@ func NewChannelReservation(capacity, fundingAmt, feePerKw btcutil.Amount,
ChannelConfig: &channeldb.ChannelConfig{},
},
partialState: &channeldb.OpenChannel{
ChainHash: *chainHash,
Db: wallet.Cfg.Database,
Capacity: capacity,
IsInitiator: initiator,
IsPending: true,
ChanType: chanType,
LocalBalance: ourBalance,
RemoteBalance: theirBalance,
FeePerKw: feePerKw,
CommitFee: commitFee,
ChanType: chanType,
ChainHash: *chainHash,
IsPending: true,
IsInitiator: initiator,
Capacity: capacity,
LocalCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance,
RemoteBalance: theirBalance,
FeePerKw: feePerKw,
CommitFee: commitFee,
},
RemoteCommitment: channeldb.ChannelCommitment{
LocalBalance: ourBalance,
RemoteBalance: theirBalance,
FeePerKw: feePerKw,
CommitFee: commitFee,
},
Db: wallet.Cfg.Database,
},
pushMSat: pushMSat,
reservationID: id,

@ -805,8 +805,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
}
// With the funding tx complete, create both commitment transactions.
localBalance := pendingReservation.partialState.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis()
localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance, ourContribution.ChannelConfig,
theirContribution.ChannelConfig,
@ -857,7 +857,8 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
// Record newly available information within the open channel state.
chanState.FundingOutpoint = *fundingOutpoint
chanState.CommitTx = *ourCommitTx
chanState.LocalCommitment.CommitTx = ourCommitTx
chanState.RemoteCommitment.CommitTx = theirCommitTx
// Generate a signature for their version of the initial commitment
// transaction.
@ -999,7 +1000,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// At this point, we can also record and verify their signature for our
// commitment transaction.
res.theirCommitmentSig = msg.theirCommitmentSig
commitTx := res.partialState.CommitTx
commitTx := res.partialState.LocalCommitment.CommitTx
ourKey := res.ourContribution.MultiSigKey
theirKey := res.theirContribution.MultiSigKey
@ -1017,9 +1018,9 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
// Next, create the spending scriptSig, and then verify that the script
// is complete, allowing us to spend from the funding transaction.
channelValue := int64(res.partialState.Capacity)
hashCache := txscript.NewTxSigHashes(&commitTx)
hashCache := txscript.NewTxSigHashes(commitTx)
sigHash, err := txscript.CalcWitnessSigHash(witnessScript, hashCache,
txscript.SigHashAll, &commitTx, 0, channelValue)
txscript.SigHashAll, commitTx, 0, channelValue)
if err != nil {
msg.err <- err
msg.completeChan <- nil
@ -1039,7 +1040,7 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
msg.completeChan <- nil
return
}
res.partialState.CommitSig = theirCommitSig
res.partialState.LocalCommitment.CommitSig = theirCommitSig
// Funding complete, this entry can be removed from limbo.
l.limboMtx.Lock()
@ -1119,8 +1120,8 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// Now that we have the funding outpoint, we can generate both versions
// of the commitment transaction, and generate a signature for the
// remote node's commitment transactions.
localBalance := pendingReservation.partialState.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.RemoteBalance.ToSatoshis()
localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
localBalance, remoteBalance,
pendingReservation.ourContribution.ChannelConfig,
@ -1148,7 +1149,8 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
// without further synchronization.
txsort.InPlaceSort(ourCommitTx)
txsort.InPlaceSort(theirCommitTx)
chanState.CommitTx = *ourCommitTx
chanState.LocalCommitment.CommitTx = ourCommitTx
chanState.RemoteCommitment.CommitTx = theirCommitTx
channelValue := int64(pendingReservation.partialState.Capacity)
hashCache := txscript.NewTxSigHashes(ourCommitTx)
@ -1182,7 +1184,7 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
req.completeChan <- nil
return
}
chanState.CommitSig = req.theirCommitmentSig
chanState.LocalCommitment.CommitSig = req.theirCommitmentSig
// With their signature for our version of the commitment transactions
// verified, we can now generate a signature for their version,