Skip to content

Commit

Permalink
lnwallet+funding: pass the pending channel ID into the reservation co…
Browse files Browse the repository at this point in the history
…ntext

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.
  • Loading branch information
Roasbeef committed Dec 2, 2019
1 parent c3157ae commit 6e9cbc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 7 additions & 5 deletions fundingmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion lnwallet/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -263,6 +268,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
Db: wallet.Cfg.Database,
},
pushMSat: pushMSat,
pendingChanID: pendingChanID,
reservationID: id,
wallet: wallet,
chanFunder: fundingAssembler,
Expand Down
6 changes: 5 additions & 1 deletion lnwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6e9cbc1

Please sign in to comment.