Skip to content

Commit fa13a63

Browse files
committed
lnwallet: set anchor=false during funding reservation
Preparing for funding flow to be able to set anchor type if agreed upon.
1 parent f173062 commit fa13a63

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

fundingmanager.go

+2
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
12411241
Flags: msg.ChannelFlags,
12421242
MinConfs: 1,
12431243
Tweakless: tweaklessCommitment,
1244+
AnchorOutputs: false,
12441245
}
12451246

12461247
reservation, err := f.cfg.Wallet.InitChannelReservation(req)
@@ -2907,6 +2908,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
29072908
MinConfs: msg.minConfs,
29082909
Tweakless: tweaklessCommitment,
29092910
ChanFunder: msg.chanFunder,
2911+
AnchorOutputs: false,
29102912
}
29112913

29122914
reservation, err := f.cfg.Wallet.InitChannelReservation(req)

lnwallet/interface_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func testCancelNonExistentReservation(miner *rpctest.Harness,
700700
// Create our own reservation, give it some ID.
701701
res, err := lnwallet.NewChannelReservation(
702702
10000, 10000, feePerKw, alice, 22, 10, &testHdSeed,
703-
lnwire.FFAnnounceChannel, true, nil, [32]byte{},
703+
lnwire.FFAnnounceChannel, true, false, nil, [32]byte{},
704704
)
705705
if err != nil {
706706
t.Fatalf("unable to create res: %v", err)

lnwallet/reservation.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ type ChannelReservation struct {
136136
func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
137137
commitFeePerKw chainfee.SatPerKWeight, wallet *LightningWallet,
138138
id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash,
139-
flags lnwire.FundingFlag, tweaklessCommit bool,
139+
flags lnwire.FundingFlag, tweaklessCommit, anchorOutputs bool,
140140
fundingAssembler chanfunding.Assembler,
141141
pendingChanID [32]byte) (*ChannelReservation, error) {
142142

@@ -151,7 +151,13 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
151151
// TODO(halseth): make method take remote funding amount directly
152152
// instead of inferring it from capacity and local amt.
153153
capacityMSat := lnwire.NewMSatFromSatoshis(capacity)
154+
155+
// The total fee paid by the initiator will be the commitment fee in
156+
// addition to the two anchor outputs.
154157
feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
158+
if anchorOutputs {
159+
feeMSat += 2 * lnwire.NewMSatFromSatoshis(anchorSize)
160+
}
155161

156162
// If we're the responder to a single-funder reservation, then we have
157163
// no initial balance in the channel unless the remote party is pushing
@@ -251,6 +257,11 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
251257
chanType |= channeldb.DualFunderBit
252258
}
253259

260+
// We are adding anchor outputs to our commitment.
261+
if anchorOutputs {
262+
chanType |= channeldb.AnchorOutputsBit
263+
}
264+
254265
return &ChannelReservation{
255266
ourContribution: &ChannelContribution{
256267
FundingAmount: ourBalance.ToSatoshis(),

lnwallet/wallet.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ type InitFundingReserveMsg struct {
102102
// commitment format or not.
103103
Tweakless bool
104104

105+
// AnchorSize is set if we agreed to add anchor outputs to the
106+
// commitments.
107+
AnchorOutputs bool
108+
105109
// ChanFunder is an optional channel funder that allows the caller to
106110
// control exactly how the channel funding is carried out. If not
107111
// specified, then the default chanfunding.WalletAssembler will be
@@ -568,7 +572,8 @@ func (l *LightningWallet) handleFundingReserveRequest(req *InitFundingReserveMsg
568572
reservation, err := NewChannelReservation(
569573
capacity, localFundingAmt, req.CommitFeePerKw, l, id,
570574
req.PushMSat, l.Cfg.NetParams.GenesisHash, req.Flags,
571-
req.Tweakless, req.ChanFunder, req.PendingChanID,
575+
req.Tweakless, req.AnchorOutputs, req.ChanFunder,
576+
req.PendingChanID,
572577
)
573578
if err != nil {
574579
if fundingIntent != nil {

0 commit comments

Comments
 (0)