|
|
@ -19,7 +19,6 @@ import (
|
|
|
|
"github.com/lightninglabs/loop/utils"
|
|
|
|
"github.com/lightninglabs/loop/utils"
|
|
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
|
|
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
|
|
|
"github.com/lightningnetwork/lnd/input"
|
|
|
|
"github.com/lightningnetwork/lnd/input"
|
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
@ -48,15 +47,22 @@ var destAddr = func() btcutil.Address {
|
|
|
|
return addr
|
|
|
|
return addr
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var htlcKeys = func() loopdb.HtlcKeys {
|
|
|
|
var senderKey, receiverKey [33]byte
|
|
|
|
var senderKey, receiverKey [33]byte
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
// Generate keys.
|
|
|
|
// Generate keys.
|
|
|
|
_, senderPubKey := test.CreateKey(1)
|
|
|
|
_, senderPubKey := test.CreateKey(1)
|
|
|
|
copy(senderKey[:], senderPubKey.SerializeCompressed())
|
|
|
|
copy(senderKey[:], senderPubKey.SerializeCompressed())
|
|
|
|
_, receiverPubKey := test.CreateKey(2)
|
|
|
|
_, receiverPubKey := test.CreateKey(2)
|
|
|
|
copy(receiverKey[:], receiverPubKey.SerializeCompressed())
|
|
|
|
copy(receiverKey[:], receiverPubKey.SerializeCompressed())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return loopdb.HtlcKeys{
|
|
|
|
|
|
|
|
SenderScriptKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverScriptKey: receiverKey,
|
|
|
|
|
|
|
|
SenderInternalPubKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverInternalPubKey: receiverKey,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
func testVerifySchnorrSig(pubKey *btcec.PublicKey, hash, sig []byte) error {
|
|
|
|
func testVerifySchnorrSig(pubKey *btcec.PublicKey, hash, sig []byte) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -127,8 +133,8 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -149,10 +155,13 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
@ -175,6 +184,9 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
return len(batcher.batches) == 1
|
|
|
|
return len(batcher.batches) == 1
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Create a second sweep request that has a timeout distance less than
|
|
|
|
// Create a second sweep request that has a timeout distance less than
|
|
|
|
// our configured threshold.
|
|
|
|
// our configured threshold.
|
|
|
|
sweepReq2 := SweepRequest{
|
|
|
|
sweepReq2 := SweepRequest{
|
|
|
@ -191,12 +203,16 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
@ -205,6 +221,13 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
|
|
|
|
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tick tock next block.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Batcher should not create a second batch as timeout distance is small
|
|
|
|
// Batcher should not create a second batch as timeout distance is small
|
|
|
|
// enough.
|
|
|
|
// enough.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -227,12 +250,16 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
AmountRequested: 333,
|
|
|
|
AmountRequested: 333,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq3.SwapHash, swap3)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq3.SwapHash, swap3)
|
|
|
@ -251,6 +278,9 @@ func testSweepBatcherBatchCreation(t *testing.T, store testStore,
|
|
|
|
// primary sweep's spend.
|
|
|
|
// primary sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
// Verify that each batch has the correct number of sweeps
|
|
|
|
// Verify that each batch has the correct number of sweeps
|
|
|
|
// in it.
|
|
|
|
// in it.
|
|
|
@ -321,16 +351,7 @@ func testFeeBumping(t *testing.T, store testStore,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 1_000_000,
|
|
|
|
AmountRequested: 1_000_000,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
HtlcKeys: loopdb.HtlcKeys{
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
SenderScriptKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverScriptKey: receiverKey,
|
|
|
|
|
|
|
|
SenderInternalPubKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverInternalPubKey: receiverKey,
|
|
|
|
|
|
|
|
ClientScriptKeyLocator: keychain.KeyLocator{
|
|
|
|
|
|
|
|
Family: 1,
|
|
|
|
|
|
|
|
Index: 2,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
@ -385,8 +406,8 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -407,7 +428,10 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
SweepConfTarget: 111,
|
|
|
@ -445,6 +469,9 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
|
|
|
|
// The primary sweep id should be that of the first inserted sweep.
|
|
|
|
// The primary sweep id should be that of the first inserted sweep.
|
|
|
|
require.Equal(t, batch.primarySweepID, sweepReq1.SwapHash)
|
|
|
|
require.Equal(t, batch.primarySweepID, sweepReq1.SwapHash)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
@ -454,6 +481,9 @@ func testSweepBatcherSimpleLifecycle(t *testing.T, store testStore,
|
|
|
|
return batch.currentHeight == 601
|
|
|
|
return batch.currentHeight == 601
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Create the spending tx that will trigger the spend monitor of the
|
|
|
|
// Create the spending tx that will trigger the spend monitor of the
|
|
|
|
// batch.
|
|
|
|
// batch.
|
|
|
|
spendingTx := &wire.MsgTx{
|
|
|
|
spendingTx := &wire.MsgTx{
|
|
|
@ -525,8 +555,8 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -548,6 +578,8 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
@ -572,6 +604,8 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
@ -599,6 +633,8 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 333,
|
|
|
|
AmountRequested: 333,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
@ -619,10 +655,29 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
// registered.
|
|
|
|
// registered.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the second sweep.
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add next block to trigger batch publishing.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the third sweep.
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq3))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq3))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add next block to trigger batch publishing.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(602)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Batcher should create a batch for the sweeps.
|
|
|
|
// Batcher should create a batch for the sweeps.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
return len(batcher.batches) == 1
|
|
|
|
return len(batcher.batches) == 1
|
|
|
@ -674,7 +729,7 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
SpendingTx: spendingTx,
|
|
|
|
SpendingTx: spendingTx,
|
|
|
|
SpenderTxHash: &spendingTxHash,
|
|
|
|
SpenderTxHash: &spendingTxHash,
|
|
|
|
SpenderInputIndex: 0,
|
|
|
|
SpenderInputIndex: 0,
|
|
|
|
SpendingHeight: 601,
|
|
|
|
SpendingHeight: 603,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send the spending notification to the mock channel.
|
|
|
|
// Send the spending notification to the mock channel.
|
|
|
@ -706,6 +761,15 @@ func testSweepBatcherSweepReentry(t *testing.T, store testStore,
|
|
|
|
Tx: spendingTx,
|
|
|
|
Tx: spendingTx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
// Here is a race condition, which is unlikely to cause a crash: if we
|
|
|
|
|
|
|
|
// wait for publish tx before sending a conf notification (previous
|
|
|
|
|
|
|
|
// action), then conf notification can go to the second batch (since
|
|
|
|
|
|
|
|
// the mock does not have a way to direct a notification to proper
|
|
|
|
|
|
|
|
// subscriber) and the first batch does not exit, waiting for the
|
|
|
|
|
|
|
|
// confirmation forever.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Eventually the batch receives the confirmation notification,
|
|
|
|
// Eventually the batch receives the confirmation notification,
|
|
|
|
// gracefully exits and the batcher deletes it.
|
|
|
|
// gracefully exits and the batcher deletes it.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -743,8 +807,8 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -765,10 +829,13 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IsExternalAddr: true,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
@ -788,6 +855,9 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Insert the same swap twice, this should be a noop.
|
|
|
|
// Insert the same swap twice, this should be a noop.
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq1))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq1))
|
|
|
|
|
|
|
|
|
|
|
@ -807,13 +877,16 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
IsExternalAddr: true,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
@ -832,6 +905,9 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for second batch to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Create a third sweep request that has more timeout distance than
|
|
|
|
// Create a third sweep request that has more timeout distance than
|
|
|
|
// the default.
|
|
|
|
// the default.
|
|
|
|
sweepReq3 := SweepRequest{
|
|
|
|
sweepReq3 := SweepRequest{
|
|
|
@ -847,14 +923,17 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
swap3 := &loopdb.LoopOutContract{
|
|
|
|
swap3 := &loopdb.LoopOutContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
AmountRequested: 333,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
IsExternalAddr: true,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq3.SwapHash, swap3)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq3.SwapHash, swap3)
|
|
|
@ -873,6 +952,9 @@ func testSweepBatcherNonWalletAddr(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published for 3rd batch.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
// Verify that each batch has the correct number of sweeps
|
|
|
|
// Verify that each batch has the correct number of sweeps
|
|
|
|
// in it.
|
|
|
|
// in it.
|
|
|
@ -919,8 +1001,8 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -941,10 +1023,12 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq1.SwapHash, swap1)
|
|
|
@ -967,12 +1051,15 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 1,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
Preimage: lntypes.Preimage{2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq2.SwapHash, swap2)
|
|
|
@ -995,12 +1082,15 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 3,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance - 3,
|
|
|
|
AmountRequested: 333,
|
|
|
|
AmountRequested: 333,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
Preimage: lntypes.Preimage{3},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1024,12 +1114,15 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 1,
|
|
|
|
AmountRequested: 444,
|
|
|
|
AmountRequested: 444,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{4},
|
|
|
|
Preimage: lntypes.Preimage{4},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq4.SwapHash, swap4)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq4.SwapHash, swap4)
|
|
|
@ -1052,12 +1145,15 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 5,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 5,
|
|
|
|
AmountRequested: 555,
|
|
|
|
AmountRequested: 555,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{5},
|
|
|
|
Preimage: lntypes.Preimage{5},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq5.SwapHash, swap5)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq5.SwapHash, swap5)
|
|
|
@ -1080,12 +1176,15 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 6,
|
|
|
|
CltvExpiry: 111 + defaultMaxTimeoutDistance + 6,
|
|
|
|
AmountRequested: 666,
|
|
|
|
AmountRequested: 666,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
|
|
|
|
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
// Make preimage unique to pass SQL constraints.
|
|
|
|
Preimage: lntypes.Preimage{6},
|
|
|
|
Preimage: lntypes.Preimage{6},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
IsExternalAddr: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1106,6 +1205,9 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Insert the same swap twice, this should be a noop.
|
|
|
|
// Insert the same swap twice, this should be a noop.
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq1))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq1))
|
|
|
|
|
|
|
|
|
|
|
@ -1117,6 +1219,14 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
return len(batcher.batches) == 1
|
|
|
|
return len(batcher.batches) == 1
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
}, test.Timeout, eventuallyCheckFrequency)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Publish a block to trigger batch 1 republishing.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx for the first batch to be published (2 sweeps).
|
|
|
|
|
|
|
|
tx := <-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
require.Equal(t, 2, len(tx.TxIn))
|
|
|
|
|
|
|
|
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq3))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq3))
|
|
|
|
|
|
|
|
|
|
|
|
// Batcher should create a second batch as this sweep pays to a non
|
|
|
|
// Batcher should create a second batch as this sweep pays to a non
|
|
|
@ -1129,6 +1239,10 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx for the second batch to be published (1 sweep).
|
|
|
|
|
|
|
|
tx = <-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(tx.TxIn))
|
|
|
|
|
|
|
|
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq4))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq4))
|
|
|
|
|
|
|
|
|
|
|
|
// Batcher should create a third batch as timeout distance is greater
|
|
|
|
// Batcher should create a third batch as timeout distance is greater
|
|
|
@ -1141,8 +1255,21 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx for the third batch to be published (1 sweep).
|
|
|
|
|
|
|
|
tx = <-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(tx.TxIn))
|
|
|
|
|
|
|
|
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq5))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq5))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Publish a block to trigger batch 3 republishing.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for 3 txs for the 3 batches.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Batcher should not create a fourth batch as timeout distance is small
|
|
|
|
// Batcher should not create a fourth batch as timeout distance is small
|
|
|
|
// enough for it to join the last batch.
|
|
|
|
// enough for it to join the last batch.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -1161,6 +1288,10 @@ func testSweepBatcherComposite(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx for the 4th batch to be published (1 sweep).
|
|
|
|
|
|
|
|
tx = <-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
require.Equal(t, 1, len(tx.TxIn))
|
|
|
|
|
|
|
|
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
// Verify that each batch has the correct number of sweeps in
|
|
|
|
// Verify that each batch has the correct number of sweeps in
|
|
|
|
// it.
|
|
|
|
// it.
|
|
|
@ -1264,8 +1395,8 @@ func testRestoringEmptyBatch(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
@ -1294,10 +1425,12 @@ func testRestoringEmptyBatch(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq.SwapHash, swap)
|
|
|
|
err = store.CreateLoopOut(ctx, sweepReq.SwapHash, swap)
|
|
|
@ -1311,6 +1444,9 @@ func testRestoringEmptyBatch(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Once batcher receives sweep request it will eventually spin up a
|
|
|
|
// Once batcher receives sweep request it will eventually spin up a
|
|
|
|
// batch.
|
|
|
|
// batch.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -1433,8 +1569,8 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
@ -1471,9 +1607,12 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: shortCltv,
|
|
|
|
CltvExpiry: shortCltv,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1495,9 +1634,12 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: longCltv,
|
|
|
|
CltvExpiry: longCltv,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1511,11 +1653,17 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
// primary sweep's spend.
|
|
|
|
// primary sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Deliver the second sweep. It will go to a separate batch,
|
|
|
|
// Deliver the second sweep. It will go to a separate batch,
|
|
|
|
// since CltvExpiry values are distant enough.
|
|
|
|
// since CltvExpiry values are distant enough.
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
require.NoError(t, batcher.AddSweep(&sweepReq2))
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Once batcher receives sweep request it will eventually spin up
|
|
|
|
// Once batcher receives sweep request it will eventually spin up
|
|
|
|
// batches.
|
|
|
|
// batches.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -1536,9 +1684,12 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: shortCltv,
|
|
|
|
CltvExpiry: shortCltv,
|
|
|
|
AmountRequested: 222,
|
|
|
|
AmountRequested: 222,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
|
|
|
|
SweepConfTarget: 111,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
store.putLoopOutSwap(sweepReq2.SwapHash, loopOut2)
|
|
|
|
store.putLoopOutSwap(sweepReq2.SwapHash, loopOut2)
|
|
|
@ -1580,6 +1731,14 @@ func testHandleSweepTwice(t *testing.T, backend testStore,
|
|
|
|
require.Equal(t, 1, len(batch.sweeps))
|
|
|
|
require.Equal(t, 1, len(batch.sweeps))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Publish a block to trigger batch 2 republishing.
|
|
|
|
|
|
|
|
err = lnd.NotifyHeight(601)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for txs to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Now make the batcher quit by canceling the context.
|
|
|
|
// Now make the batcher quit by canceling the context.
|
|
|
|
cancel()
|
|
|
|
cancel()
|
|
|
|
wg.Wait()
|
|
|
|
wg.Wait()
|
|
|
@ -1601,8 +1760,8 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
@ -1631,6 +1790,8 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
SwapContract: loopdb.SwapContract{
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
@ -1649,6 +1810,9 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
|
|
|
// sweep's spend.
|
|
|
|
// sweep's spend.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Once batcher receives sweep request it will eventually spin up a
|
|
|
|
// Once batcher receives sweep request it will eventually spin up a
|
|
|
|
// batch.
|
|
|
|
// batch.
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
require.Eventually(t, func() bool {
|
|
|
@ -1688,8 +1852,8 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
|
|
|
|
|
|
|
|
|
|
|
// Now launch it again.
|
|
|
|
// Now launch it again.
|
|
|
|
batcher = NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher = NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
|
|
wg.Add(1)
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
@ -1725,6 +1889,9 @@ func testRestoringPreservesConfTarget(t *testing.T, store testStore,
|
|
|
|
// Expect registration for spend notification.
|
|
|
|
// Expect registration for spend notification.
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
<-lnd.RegisterSpendChannel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for tx to be published.
|
|
|
|
|
|
|
|
<-lnd.TxPublishChannel
|
|
|
|
|
|
|
|
|
|
|
|
// Now make the batcher quit by canceling the context.
|
|
|
|
// Now make the batcher quit by canceling the context.
|
|
|
|
cancel()
|
|
|
|
cancel()
|
|
|
|
wg.Wait()
|
|
|
|
wg.Wait()
|
|
|
@ -1772,12 +1939,7 @@ func testSweepFetcher(t *testing.T, store testStore,
|
|
|
|
CltvExpiry: 222,
|
|
|
|
CltvExpiry: 222,
|
|
|
|
AmountRequested: amt,
|
|
|
|
AmountRequested: amt,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
HtlcKeys: loopdb.HtlcKeys{
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
SenderScriptKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverScriptKey: receiverKey,
|
|
|
|
|
|
|
|
SenderInternalPubKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverInternalPubKey: receiverKey,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
|
SwapInvoice: swapInvoice,
|
|
|
@ -1795,12 +1957,7 @@ func testSweepFetcher(t *testing.T, store testStore,
|
|
|
|
SwapInvoicePaymentAddr: *swapPaymentAddr,
|
|
|
|
SwapInvoicePaymentAddr: *swapPaymentAddr,
|
|
|
|
MinFeeRate: feeRate,
|
|
|
|
MinFeeRate: feeRate,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
HTLCKeys: loopdb.HtlcKeys{
|
|
|
|
HTLCKeys: htlcKeys,
|
|
|
|
SenderScriptKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverScriptKey: receiverKey,
|
|
|
|
|
|
|
|
SenderInternalPubKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverInternalPubKey: receiverKey,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
HTLC: *htlc,
|
|
|
|
HTLC: *htlc,
|
|
|
|
HTLCSuccessEstimator: htlc.AddSuccessToEstimator,
|
|
|
|
HTLCSuccessEstimator: htlc.AddSuccessToEstimator,
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
@ -1912,8 +2069,8 @@ func testSweepBatcherCloseDuringAdding(t *testing.T, store testStore,
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
batcher := NewBatcher(lnd.WalletKit, lnd.ChainNotifier, lnd.Signer,
|
|
|
|
testMuSig2SignSweep, nil, lnd.ChainParams, batcherStore,
|
|
|
|
testMuSig2SignSweep, testVerifySchnorrSig, lnd.ChainParams,
|
|
|
|
sweepStore)
|
|
|
|
batcherStore, sweepStore)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
err := batcher.Run(ctx)
|
|
|
|
checkBatcherError(t, err)
|
|
|
|
checkBatcherError(t, err)
|
|
|
@ -2041,12 +2198,7 @@ func testCustomSignMuSig2(t *testing.T, store testStore,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
CltvExpiry: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
AmountRequested: 111,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
ProtocolVersion: loopdb.ProtocolVersionMuSig2,
|
|
|
|
HtlcKeys: loopdb.HtlcKeys{
|
|
|
|
HtlcKeys: htlcKeys,
|
|
|
|
SenderScriptKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverScriptKey: receiverKey,
|
|
|
|
|
|
|
|
SenderInternalPubKey: senderKey,
|
|
|
|
|
|
|
|
ReceiverInternalPubKey: receiverKey,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
DestAddr: destAddr,
|
|
|
|
DestAddr: destAddr,
|
|
|
|