From 6e9cbc19f95ecc4e4f40e91fe72af0bb18bb887b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 31 Oct 2019 21:45:44 -0700 Subject: [PATCH] lnwallet+funding: pass the pending channel ID into the reservation context In this commit, we start to thread the pending channel ID from wire protocol all the way down into the reservation context. This change will allow negotiation to take place _outside_ the protocol that may result in a particular chanfunding.Assembler being dispatched. --- fundingmanager.go | 12 +++++++----- lnwallet/reservation.go | 8 +++++++- lnwallet/wallet.go | 6 +++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 760687fd..e87dd9f1 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1216,6 +1216,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { chainHash := chainhash.Hash(msg.ChainHash) req := &lnwallet.InitFundingReserveMsg{ ChainHash: &chainHash, + PendingChanID: msg.PendingChannelID, NodeID: fmsg.peer.IdentityKey(), NodeAddr: fmsg.peer.Address(), LocalFundingAmt: 0, @@ -2781,6 +2782,10 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { channelFlags = lnwire.FFAnnounceChannel } + // Obtain a new pending channel ID which is used to track this + // reservation throughout its lifetime. + chanID := f.nextPendingChanID() + // Initialize a funding reservation with the local wallet. If the // wallet doesn't have enough funds to commit to this channel, then the // request will fail, and be aborted. @@ -2798,6 +2803,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { tweaklessCommitment := localTweakless && remoteTweakless req := &lnwallet.InitFundingReserveMsg{ ChainHash: &msg.chainHash, + PendingChanID: chanID, NodeID: peerKey, NodeAddr: msg.peer.Address(), SubtractFees: msg.subtractFees, @@ -2823,11 +2829,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { // SubtractFees=true. capacity := reservation.Capacity() - // Obtain a new pending channel ID which is used to track this - // reservation throughout its lifetime. - chanID := f.nextPendingChanID() - - fndgLog.Infof("Target commit tx sat/kw for pending_id(%x): %v", chanID, + fndgLog.Infof("Target commit tx sat/kw for pendingID(%x): %v", chanID, int64(commitFeePerKw)) // If the remote CSV delay was not set in the open channel request, diff --git a/lnwallet/reservation.go b/lnwallet/reservation.go index 4447e845..19f49eea 100644 --- a/lnwallet/reservation.go +++ b/lnwallet/reservation.go @@ -110,6 +110,10 @@ type ChannelReservation struct { // throughout its lifetime. reservationID uint64 + // pendingChanID is the pending channel ID for this channel as + // identified within the wire protocol. + pendingChanID [32]byte + // pushMSat the amount of milli-satoshis that should be pushed to the // responder of a single funding channel as part of the initial // commitment state. @@ -129,7 +133,8 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, commitFeePerKw chainfee.SatPerKWeight, wallet *LightningWallet, id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash, flags lnwire.FundingFlag, tweaklessCommit bool, - fundingAssembler chanfunding.Assembler) (*ChannelReservation, error) { + fundingAssembler chanfunding.Assembler, + pendingChanID [32]byte) (*ChannelReservation, error) { var ( ourBalance lnwire.MilliSatoshi @@ -263,6 +268,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, Db: wallet.Cfg.Database, }, pushMSat: pushMSat, + pendingChanID: pendingChanID, reservationID: id, wallet: wallet, chanFunder: fundingAssembler, diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index c59de2c5..0851f207 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -48,6 +48,10 @@ type InitFundingReserveMsg struct { // target channel. ChainHash *chainhash.Hash + // PendingChanID is the pending channel ID for this funding flow as + // used in the wire protocol. + PendingChanID [32]byte + // NodeID is the ID of the remote node we would like to open a channel // with. NodeID *btcec.PublicKey @@ -513,7 +517,7 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg reservation, err := NewChannelReservation( capacity, localFundingAmt, req.CommitFeePerKw, l, id, req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags, - req.Tweakless, req.ChanFunder, + req.Tweakless, req.ChanFunder, req.PendingChanID, ) if err != nil { if fundingIntent != nil {