multi: update funding workflow to be aware of new tweakless commits
In this commit, we update the funding workflow to be aware of the new channel type that doesn't tweak the remote party's output within the non-delay script on their commitment transaction. To do this, we now allow the caller of `InnitChannelReservation` to signal if they want the old or new (tweakless) commitment style. The funding tests are also updated to test both funding variants, as we'll still need to understand the legacy format for older nodes.
This commit is contained in:
9 files changed
+75
-28
No files matched your search
@@ -698,7 +698,7 @@ func testCancelNonExistentReservation(miner *rpctest.Harness,
|
||||
// Create our own reservation, give it some ID.
|
||||
res, err := lnwallet.NewChannelReservation(
|
||||
10000, 10000, feePerKw, alice, 22, 10, &testHdSeed,
|
||||
lnwire.FFAnnounceChannel,
|
||||
lnwire.FFAnnounceChannel, true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create res: %v", err)
|
||||
@@ -736,6 +736,7 @@ func testReservationInitiatorBalanceBelowDustCancel(miner *rpctest.Harness,
|
||||
FundingFeePerKw: 1000,
|
||||
PushMSat: 0,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
Tweakless: true,
|
||||
}
|
||||
_, err = alice.InitChannelReservation(req)
|
||||
switch {
|
||||
@@ -790,7 +791,7 @@ func assertContributionInitPopulated(t *testing.T, c *lnwallet.ChannelContributi
|
||||
}
|
||||
|
||||
func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
alice, bob *lnwallet.LightningWallet, t *testing.T) {
|
||||
alice, bob *lnwallet.LightningWallet, t *testing.T, tweakless bool) {
|
||||
|
||||
// For this scenario, Alice will be the channel initiator while bob
|
||||
// will act as the responder to the workflow.
|
||||
@@ -817,6 +818,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
Tweakless: tweakless,
|
||||
}
|
||||
aliceChanReservation, err := alice.InitChannelReservation(aliceReq)
|
||||
if err != nil {
|
||||
@@ -860,6 +862,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
FundingFeePerKw: feePerKw,
|
||||
PushMSat: pushAmt,
|
||||
Flags: lnwire.FFAnnounceChannel,
|
||||
Tweakless: tweakless,
|
||||
}
|
||||
bobChanReservation, err := bob.InitChannelReservation(bobReq)
|
||||
if err != nil {
|
||||
@@ -966,7 +969,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
if !aliceChannels[0].IsInitiator {
|
||||
t.Fatalf("alice not detected as channel initiator")
|
||||
}
|
||||
if aliceChannels[0].ChanType != channeldb.SingleFunder {
|
||||
if !aliceChannels[0].ChanType.IsSingleFunder() {
|
||||
t.Fatalf("channel type is incorrect, expected %v instead got %v",
|
||||
channeldb.SingleFunder, aliceChannels[0].ChanType)
|
||||
}
|
||||
@@ -986,7 +989,7 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
if bobChannels[0].IsInitiator {
|
||||
t.Fatalf("bob not detected as channel responder")
|
||||
}
|
||||
if bobChannels[0].ChanType != channeldb.SingleFunder {
|
||||
if !bobChannels[0].ChanType.IsSingleFunder() {
|
||||
t.Fatalf("channel type is incorrect, expected %v instead got %v",
|
||||
channeldb.SingleFunder, bobChannels[0].ChanType)
|
||||
}
|
||||
@@ -2515,7 +2518,23 @@ var walletTests = []walletTestCase{
|
||||
},
|
||||
{
|
||||
name: "single funding workflow",
|
||||
test: testSingleFunderReservationWorkflow,
|
||||
test: func(miner *rpctest.Harness, alice,
|
||||
bob *lnwallet.LightningWallet, t *testing.T) {
|
||||
|
||||
testSingleFunderReservationWorkflow(
|
||||
miner, alice, bob, t, false,
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "single funding workflow tweakless",
|
||||
test: func(miner *rpctest.Harness, alice,
|
||||
bob *lnwallet.LightningWallet, t *testing.T) {
|
||||
|
||||
testSingleFunderReservationWorkflow(
|
||||
miner, alice, bob, t, true,
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dual funder workflow",
|
||||
|
||||
@@ -130,7 +130,8 @@ type ChannelReservation struct {
|
||||
func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
||||
commitFeePerKw SatPerKWeight, wallet *LightningWallet,
|
||||
id uint64, pushMSat lnwire.MilliSatoshi, chainHash *chainhash.Hash,
|
||||
flags lnwire.FundingFlag) (*ChannelReservation, error) {
|
||||
flags lnwire.FundingFlag,
|
||||
tweaklessCommit bool) (*ChannelReservation, error) {
|
||||
|
||||
var (
|
||||
ourBalance lnwire.MilliSatoshi
|
||||
@@ -140,7 +141,7 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
||||
|
||||
commitFee := commitFeePerKw.FeeForWeight(input.CommitWeight)
|
||||
localFundingMSat := lnwire.NewMSatFromSatoshis(localFundingAmt)
|
||||
// TODO(halseth): make method take remote funding amount direcly
|
||||
// TODO(halseth): make method take remote funding amount directly
|
||||
// instead of inferring it from capacity and local amt.
|
||||
capacityMSat := lnwire.NewMSatFromSatoshis(capacity)
|
||||
feeMSat := lnwire.NewMSatFromSatoshis(commitFee)
|
||||
@@ -213,7 +214,11 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
|
||||
// non-zero push amt (there's no pushing for dual funder), then this is
|
||||
// a single-funder channel.
|
||||
if ourBalance == 0 || theirBalance == 0 || pushMSat != 0 {
|
||||
chanType = channeldb.SingleFunder
|
||||
if tweaklessCommit {
|
||||
chanType = channeldb.SingleFunderTweakless
|
||||
} else {
|
||||
chanType = channeldb.SingleFunder
|
||||
}
|
||||
} else {
|
||||
// Otherwise, this is a dual funder channel, and no side is
|
||||
// technically the "initiator"
|
||||
|
||||
+12
-4
@@ -88,8 +88,11 @@ var (
|
||||
// allocated to each side. Within the channel, Alice is the initiator. The
|
||||
// function also returns a "cleanup" function that is meant to be called once
|
||||
// the test has been finalized. The clean up function will remote all temporary
|
||||
// files created
|
||||
func CreateTestChannels(tweaklessCommits bool) (*LightningChannel, *LightningChannel, func(), error) {
|
||||
// files created. If tweaklessCommits is true, then the commits within the
|
||||
// channels will use the new format, otherwise the legacy format.
|
||||
func CreateTestChannels(tweaklessCommits bool) (
|
||||
*LightningChannel, *LightningChannel, func(), error) {
|
||||
|
||||
channelCapacity, err := btcutil.NewAmount(10)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
@@ -271,7 +274,7 @@ func CreateTestChannels(tweaklessCommits bool) (*LightningChannel, *LightningCha
|
||||
IdentityPub: aliceKeys[0].PubKey(),
|
||||
FundingOutpoint: *prevOut,
|
||||
ShortChannelID: shortChanID,
|
||||
ChanType: channeldb.SingleFunder,
|
||||
ChanType: channeldb.SingleFunderTweakless,
|
||||
IsInitiator: true,
|
||||
Capacity: channelCapacity,
|
||||
RemoteCurrentRevocation: bobCommitPoint,
|
||||
@@ -289,7 +292,7 @@ func CreateTestChannels(tweaklessCommits bool) (*LightningChannel, *LightningCha
|
||||
IdentityPub: bobKeys[0].PubKey(),
|
||||
FundingOutpoint: *prevOut,
|
||||
ShortChannelID: shortChanID,
|
||||
ChanType: channeldb.SingleFunder,
|
||||
ChanType: channeldb.SingleFunderTweakless,
|
||||
IsInitiator: false,
|
||||
Capacity: channelCapacity,
|
||||
RemoteCurrentRevocation: aliceCommitPoint,
|
||||
@@ -301,6 +304,11 @@ func CreateTestChannels(tweaklessCommits bool) (*LightningChannel, *LightningCha
|
||||
Packager: channeldb.NewChannelPackager(shortChanID),
|
||||
}
|
||||
|
||||
if !tweaklessCommits {
|
||||
aliceChannelState.ChanType = channeldb.SingleFunder
|
||||
bobChannelState.ChanType = channeldb.SingleFunder
|
||||
}
|
||||
|
||||
aliceSigner := &input.MockSigner{Privkeys: aliceKeys}
|
||||
bobSigner := &input.MockSigner{Privkeys: bobKeys}
|
||||
|
||||
|
||||
+6
-1
@@ -106,6 +106,10 @@ type InitFundingReserveMsg struct {
|
||||
// output selected to fund the channel should satisfy.
|
||||
MinConfs int32
|
||||
|
||||
// Tweakless indicates if the channel should use the new tweakless
|
||||
// commitment format or not.
|
||||
Tweakless bool
|
||||
|
||||
// err is a channel in which all errors will be sent across. Will be
|
||||
// nil if this initial set is successful.
|
||||
//
|
||||
@@ -489,6 +493,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,
|
||||
)
|
||||
if err != nil {
|
||||
selected.unlockCoins()
|
||||
@@ -849,7 +854,7 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
// obfuscator then use it to encode the current state number within
|
||||
// both commitment transactions.
|
||||
var stateObfuscator [StateHintSize]byte
|
||||
if chanState.ChanType == channeldb.SingleFunder {
|
||||
if chanState.ChanType.IsSingleFunder() {
|
||||
stateObfuscator = DeriveStateHintObfuscator(
|
||||
ourContribution.PaymentBasePoint.PubKey,
|
||||
theirContribution.PaymentBasePoint.PubKey,
|
||||
|
||||
Reference in new issue
Block a user