mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
lnwallet: refactor test code for HTLC add and recv
This commit is contained in:
parent
b3f953b1c4
commit
22deba3d26
1 changed files with 75 additions and 327 deletions
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/fn"
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
|
@ -49,6 +50,18 @@ func createHTLC(id int, amount lnwire.MilliSatoshi) (*lnwire.UpdateAddHTLC, [32]
|
||||||
}, returnPreimage
|
}, returnPreimage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addAndReceiveHTLC adds an HTLC as local to the first channel, and as remote
|
||||||
|
// to a second channel. The HTLC ID is not modified.
|
||||||
|
func addAndReceiveHTLC(t *testing.T, channel1, channel2 *LightningChannel,
|
||||||
|
htlc *lnwire.UpdateAddHTLC, openKey *models.CircuitKey) {
|
||||||
|
|
||||||
|
_, err := channel1.AddHTLC(htlc, openKey)
|
||||||
|
require.NoErrorf(t, err, "channel 1 unable to add htlc: %v", err)
|
||||||
|
|
||||||
|
_, err = channel2.ReceiveHTLC(htlc)
|
||||||
|
require.NoErrorf(t, err, "channel 2 unable to recv htlc: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
func assertOutputExistsByValue(t *testing.T, commitTx *wire.MsgTx,
|
func assertOutputExistsByValue(t *testing.T, commitTx *wire.MsgTx,
|
||||||
value btcutil.Amount) {
|
value btcutil.Amount) {
|
||||||
|
|
||||||
|
@ -437,10 +450,7 @@ func TestChannelZeroAddLocalHeight(t *testing.T) {
|
||||||
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
||||||
|
|
||||||
// -----add----->
|
// -----add----->
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Force a state transition to lock in this add on both commitments.
|
// Force a state transition to lock in this add on both commitments.
|
||||||
// -----sig----->
|
// -----sig----->
|
||||||
|
@ -486,10 +496,7 @@ func TestChannelZeroAddLocalHeight(t *testing.T) {
|
||||||
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
||||||
|
|
||||||
// <----add-----
|
// <----add-----
|
||||||
_, err = bobChannel.AddHTLC(htlc2, nil)
|
addAndReceiveHTLC(t, bobChannel, newAliceChannel, htlc2, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = newAliceChannel.ReceiveHTLC(htlc2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Bob should now send a commitment signature to Alice.
|
// Bob should now send a commitment signature to Alice.
|
||||||
// <----sig-----
|
// <----sig-----
|
||||||
|
@ -546,12 +553,7 @@ func TestCheckCommitTxSize(t *testing.T) {
|
||||||
for i := 0; i <= 10; i++ {
|
for i := 0; i <= 10; i++ {
|
||||||
htlc, _ := createHTLC(i, lnwire.MilliSatoshi(1e7))
|
htlc, _ := createHTLC(i, lnwire.MilliSatoshi(1e7))
|
||||||
|
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("bob unable to receive htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete state update: %v", err)
|
t.Fatalf("unable to complete state update: %v", err)
|
||||||
|
@ -626,12 +628,7 @@ func testCommitHTLCSigTieBreak(t *testing.T, restart bool) {
|
||||||
Expiry: uint32(numHtlcs - i),
|
Expiry: uint32(numHtlcs - i),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("bob unable to receive htlc: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Have Alice initiate the first half of the commitment dance. The
|
// Have Alice initiate the first half of the commitment dance. The
|
||||||
|
@ -937,23 +934,13 @@ func testForceClose(t *testing.T, testCase *forceCloseTestCase) {
|
||||||
// We'll ensure that the HTLC amount is above Alice's dust limit.
|
// We'll ensure that the HTLC amount is above Alice's dust limit.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We'll also a distinct HTLC from Bob -> Alice. This way, Alice will
|
// We'll also a distinct HTLC from Bob -> Alice. This way, Alice will
|
||||||
// have both an incoming and outgoing HTLC on her commitment
|
// have both an incoming and outgoing HTLC on her commitment
|
||||||
// transaction.
|
// transaction.
|
||||||
htlcBob, preimageBob := createHTLC(0, htlcAmount)
|
htlcBob, preimageBob := createHTLC(0, htlcAmount)
|
||||||
if _, err := bobChannel.AddHTLC(htlcBob, nil); err != nil {
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlcBob, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := aliceChannel.ReceiveHTLC(htlcBob); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, we'll perform two state transitions to ensure that both HTLC's
|
// Next, we'll perform two state transitions to ensure that both HTLC's
|
||||||
// get fully locked-in.
|
// get fully locked-in.
|
||||||
|
@ -1407,12 +1394,7 @@ func TestDustHTLCFees(t *testing.T) {
|
||||||
// This HTLC amount should be lower than the dust limits of both nodes.
|
// This HTLC amount should be lower than the dust limits of both nodes.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(100)
|
htlcAmount := lnwire.NewMSatFromSatoshis(100)
|
||||||
htlc, _ := createHTLC(0, htlcAmount)
|
htlc, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("bob unable to receive htlc: %v", err)
|
|
||||||
}
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("Can't update the channel state: %v", err)
|
t.Fatalf("Can't update the channel state: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -1565,14 +1547,9 @@ func TestHTLCSigNumber(t *testing.T) {
|
||||||
for i, htlcSat := range htlcValues {
|
for i, htlcSat := range htlcValues {
|
||||||
htlcMsat := lnwire.NewMSatFromSatoshis(htlcSat)
|
htlcMsat := lnwire.NewMSatFromSatoshis(htlcSat)
|
||||||
htlc, _ := createHTLC(i, htlcMsat)
|
htlc, _ := createHTLC(i, htlcMsat)
|
||||||
_, err := aliceChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(
|
||||||
if err != nil {
|
t, aliceChannel, bobChannel, htlc, nil,
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
)
|
||||||
}
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("bob unable to receive htlc: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return aliceChannel, bobChannel
|
return aliceChannel, bobChannel
|
||||||
|
@ -1806,12 +1783,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||||
OnionBlob: fakeOnionBlob,
|
OnionBlob: fakeOnionBlob,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := aliceChannel.AddHTLC(h, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, h, nil)
|
||||||
t.Fatalf("unable to add alice's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(h); err != nil {
|
|
||||||
t.Fatalf("unable to recv alice's htlc: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rHash := sha256.Sum256(bobPreimage[:])
|
rHash := sha256.Sum256(bobPreimage[:])
|
||||||
bobh := &lnwire.UpdateAddHTLC{
|
bobh := &lnwire.UpdateAddHTLC{
|
||||||
|
@ -1820,12 +1792,7 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||||
Expiry: uint32(10),
|
Expiry: uint32(10),
|
||||||
OnionBlob: fakeOnionBlob,
|
OnionBlob: fakeOnionBlob,
|
||||||
}
|
}
|
||||||
if _, err := bobChannel.AddHTLC(bobh, nil); err != nil {
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, bobh, nil)
|
||||||
t.Fatalf("unable to add bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := aliceChannel.ReceiveHTLC(bobh); err != nil {
|
|
||||||
t.Fatalf("unable to recv bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also add a fee update to the update logs.
|
// Also add a fee update to the update logs.
|
||||||
fee := chainfee.SatPerKWeight(333)
|
fee := chainfee.SatPerKWeight(333)
|
||||||
|
@ -2494,12 +2461,7 @@ func TestUpdateFeeConcurrentSig(t *testing.T) {
|
||||||
// First Alice adds the outgoing HTLC to her local channel's state
|
// First Alice adds the outgoing HTLC to her local channel's state
|
||||||
// update log. Then Alice sends this wire message over to Bob who
|
// update log. Then Alice sends this wire message over to Bob who
|
||||||
// adds this htlc to his remote state update log.
|
// adds this htlc to his remote state update log.
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate Alice sending update fee message to bob.
|
// Simulate Alice sending update fee message to bob.
|
||||||
fee := chainfee.SatPerKWeight(333)
|
fee := chainfee.SatPerKWeight(333)
|
||||||
|
@ -2569,12 +2531,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
|
||||||
// First Alice adds the outgoing HTLC to her local channel's state
|
// First Alice adds the outgoing HTLC to her local channel's state
|
||||||
// update log. Then Alice sends this wire message over to Bob who
|
// update log. Then Alice sends this wire message over to Bob who
|
||||||
// adds this htlc to his remote state update log.
|
// adds this htlc to his remote state update log.
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate Alice sending update fee message to bob.
|
// Simulate Alice sending update fee message to bob.
|
||||||
fee := chainfee.SatPerKWeight(333)
|
fee := chainfee.SatPerKWeight(333)
|
||||||
|
@ -2678,12 +2635,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
|
||||||
// First Alice adds the outgoing HTLC to her local channel's state
|
// First Alice adds the outgoing HTLC to her local channel's state
|
||||||
// update log. Then Alice sends this wire message over to Bob who
|
// update log. Then Alice sends this wire message over to Bob who
|
||||||
// adds this htlc to his remote state update log.
|
// adds this htlc to his remote state update log.
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate Alice sending update fee message to bob
|
// Simulate Alice sending update fee message to bob
|
||||||
fee := chainfee.SatPerKWeight(333)
|
fee := chainfee.SatPerKWeight(333)
|
||||||
|
@ -3882,12 +3834,7 @@ func testChanSyncOweRevocation(t *testing.T, chanType channeldb.ChannelType) {
|
||||||
Amount: htlcAmt,
|
Amount: htlcAmt,
|
||||||
Expiry: uint32(10),
|
Expiry: uint32(10),
|
||||||
}
|
}
|
||||||
if _, err := aliceChannel.AddHTLC(aliceHtlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, aliceHtlc, nil)
|
||||||
t.Fatalf("unable to add alice's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(aliceHtlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv alice's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete alice's state transition: %v", err)
|
t.Fatalf("unable to complete alice's state transition: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -4168,10 +4115,7 @@ func testChanSyncOweRevocationAndCommitForceTransition(t *testing.T,
|
||||||
Expiry: uint32(10),
|
Expiry: uint32(10),
|
||||||
ID: 1,
|
ID: 1,
|
||||||
}
|
}
|
||||||
_, err = bobChannel.AddHTLC(bobHtlc[1], nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, bobHtlc[1], nil)
|
||||||
require.NoError(t, err, "unable to add bob's htlc")
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(bobHtlc[1])
|
|
||||||
require.NoError(t, err, "unable to recv bob's htlc")
|
|
||||||
|
|
||||||
// Bob signs the new state update, and sends the signature to Alice.
|
// Bob signs the new state update, and sends the signature to Alice.
|
||||||
bobNewCommit, err := bobChannel.SignNextCommitment()
|
bobNewCommit, err := bobChannel.SignNextCommitment()
|
||||||
|
@ -4404,14 +4348,7 @@ func TestChanSyncFailure(t *testing.T) {
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
|
|
||||||
_, err := bobChannel.AddHTLC(bobHtlc, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, bobHtlc, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to add bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(bobHtlc)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to recv bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
err = ForceStateTransition(bobChannel, aliceChannel)
|
err = ForceStateTransition(bobChannel, aliceChannel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to complete bob's state "+
|
t.Fatalf("unable to complete bob's state "+
|
||||||
|
@ -4437,14 +4374,7 @@ func TestChanSyncFailure(t *testing.T) {
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
|
|
||||||
_, err := bobChannel.AddHTLC(bobHtlc, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, bobHtlc, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to add bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(bobHtlc)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to recv bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4787,12 +4717,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
|
||||||
Amount: lnwire.NewMSatFromSatoshis(20000),
|
Amount: lnwire.NewMSatFromSatoshis(20000),
|
||||||
Expiry: uint32(10),
|
Expiry: uint32(10),
|
||||||
}
|
}
|
||||||
if _, err := bobChannel.AddHTLC(bobHtlc, nil); err != nil {
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, bobHtlc, nil)
|
||||||
t.Fatalf("unable to add bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := aliceChannel.ReceiveHTLC(bobHtlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv bob's htlc: %v", err)
|
|
||||||
}
|
|
||||||
if err := ForceStateTransition(bobChannel, aliceChannel); err != nil {
|
if err := ForceStateTransition(bobChannel, aliceChannel); err != nil {
|
||||||
t.Fatalf("unable to complete bob's state transition: %v", err)
|
t.Fatalf("unable to complete bob's state transition: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -4864,12 +4789,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
||||||
var htlcs []*lnwire.UpdateAddHTLC
|
var htlcs []*lnwire.UpdateAddHTLC
|
||||||
for i := 0; i < numHTLCs; i++ {
|
for i := 0; i < numHTLCs; i++ {
|
||||||
htlc, _ := createHTLC(i, htlcAmt)
|
htlc, _ := createHTLC(i, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
htlcs = append(htlcs, htlc)
|
htlcs = append(htlcs, htlc)
|
||||||
|
|
||||||
if i%5 != 0 {
|
if i%5 != 0 {
|
||||||
|
@ -4978,12 +4898,7 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) {
|
||||||
// Finally, to trigger a compactLogs execution, we'll add a new HTLC,
|
// Finally, to trigger a compactLogs execution, we'll add a new HTLC,
|
||||||
// then force a state transition.
|
// then force a state transition.
|
||||||
htlc, _ := createHTLC(numHTLCs, htlcAmt)
|
htlc, _ := createHTLC(numHTLCs, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete bob's state transition: %v", err)
|
t.Fatalf("unable to complete bob's state transition: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -5077,12 +4992,7 @@ func TestChanSyncInvalidLastSecret(t *testing.T) {
|
||||||
Amount: htlcAmt,
|
Amount: htlcAmt,
|
||||||
Expiry: uint32(5),
|
Expiry: uint32(5),
|
||||||
}
|
}
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then we'll initiate a state transition to lock in this new HTLC.
|
// Then we'll initiate a state transition to lock in this new HTLC.
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
|
@ -5204,12 +5114,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
|
||||||
alicePreimages := make([][32]byte, numHtlcs)
|
alicePreimages := make([][32]byte, numHtlcs)
|
||||||
for i := 0; i < numHtlcs; i++ {
|
for i := 0; i < numHtlcs; i++ {
|
||||||
htlc, preImage := createHTLC(i, dustAmt)
|
htlc, preImage := createHTLC(i, dustAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
alicePreimages[i] = preImage
|
alicePreimages[i] = preImage
|
||||||
}
|
}
|
||||||
|
@ -5222,12 +5127,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
|
||||||
htlcAmt := lnwire.NewMSatFromSatoshis(30000)
|
htlcAmt := lnwire.NewMSatFromSatoshis(30000)
|
||||||
for i := 0; i < numHtlcs; i++ {
|
for i := 0; i < numHtlcs; i++ {
|
||||||
htlc, preImage := createHTLC(numHtlcs+i, htlcAmt)
|
htlc, preImage := createHTLC(numHtlcs+i, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
alicePreimages = append(alicePreimages, preImage)
|
alicePreimages = append(alicePreimages, preImage)
|
||||||
}
|
}
|
||||||
|
@ -5496,13 +5396,7 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
htlc, preImage := createHTLC(int(htlcIndex), htlcAmt)
|
htlc, preImage := createHTLC(int(htlcIndex), htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete alice's state "+
|
t.Fatalf("unable to complete alice's state "+
|
||||||
"transition: %v", err)
|
"transition: %v", err)
|
||||||
|
@ -5637,19 +5531,10 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
|
||||||
// a state transition.
|
// a state transition.
|
||||||
var htlcAmt lnwire.MilliSatoshi = 100000
|
var htlcAmt lnwire.MilliSatoshi = 100000
|
||||||
htlc, _ := createHTLC(0, htlcAmt)
|
htlc, _ := createHTLC(0, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
htlc2, _ := createHTLC(1, htlcAmt)
|
htlc2, _ := createHTLC(1, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc2, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc2, nil)
|
||||||
t.Fatalf("unable to add htlc2: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc2); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc2: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We'll now manually initiate a state transition between Alice and
|
// We'll now manually initiate a state transition between Alice and
|
||||||
// bob.
|
// bob.
|
||||||
|
@ -5955,12 +5840,7 @@ func TestInvalidCommitSigError(t *testing.T) {
|
||||||
// Alice to Bob.
|
// Alice to Bob.
|
||||||
var htlcAmt lnwire.MilliSatoshi = 100000
|
var htlcAmt lnwire.MilliSatoshi = 100000
|
||||||
htlc, _ := createHTLC(0, htlcAmt)
|
htlc, _ := createHTLC(0, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alice will now attempt to initiate a state transition.
|
// Alice will now attempt to initiate a state transition.
|
||||||
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
||||||
|
@ -6005,19 +5885,9 @@ func TestChannelUnilateralCloseHtlcResolution(t *testing.T) {
|
||||||
// initiating enough state transitions to lock both of them in.
|
// initiating enough state transitions to lock both of them in.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
htlcBob, preimageBob := createHTLC(0, htlcAmount)
|
htlcBob, preimageBob := createHTLC(0, htlcAmount)
|
||||||
if _, err := bobChannel.AddHTLC(htlcBob, nil); err != nil {
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlcBob, nil)
|
||||||
t.Fatalf("bob unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := aliceChannel.ReceiveHTLC(htlcBob); err != nil {
|
|
||||||
t.Fatalf("alice unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("Can't update the channel state: %v", err)
|
t.Fatalf("Can't update the channel state: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -6162,12 +6032,7 @@ func TestChannelUnilateralClosePendingCommit(t *testing.T) {
|
||||||
// create a new state transition.
|
// create a new state transition.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// With the HTLC added, we'll now manually initiate a state transition
|
// With the HTLC added, we'll now manually initiate a state transition
|
||||||
// from Alice to Bob.
|
// from Alice to Bob.
|
||||||
|
@ -6363,12 +6228,7 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
|
||||||
// Send the maximum allowed number of HTLCs.
|
// Send the maximum allowed number of HTLCs.
|
||||||
for i := 0; i < numHTLCs; i++ {
|
for i := 0; i < numHTLCs; i++ {
|
||||||
htlc, _ := createHTLC(i, htlcAmt)
|
htlc, _ := createHTLC(i, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just assign htlcID to the last received HTLC.
|
// Just assign htlcID to the last received HTLC.
|
||||||
htlcID = htlc.ID
|
htlcID = htlc.ID
|
||||||
|
@ -6407,12 +6267,7 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
|
||||||
// failed. We use numHTLCs here since the previous AddHTLC with this index
|
// failed. We use numHTLCs here since the previous AddHTLC with this index
|
||||||
// failed.
|
// failed.
|
||||||
htlc, _ = createHTLC(numHTLCs, htlcAmt)
|
htlc, _ = createHTLC(numHTLCs, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a commitment to Bob's commitment chain.
|
// Add a commitment to Bob's commitment chain.
|
||||||
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
||||||
|
@ -6488,12 +6343,7 @@ func TestMaxAsynchronousHtlcs(t *testing.T) {
|
||||||
// Send the maximum allowed number of HTLCs minus one.
|
// Send the maximum allowed number of HTLCs minus one.
|
||||||
for i := 0; i < numHTLCs-1; i++ {
|
for i := 0; i < numHTLCs-1; i++ {
|
||||||
htlc, _ := createHTLC(i, htlcAmt)
|
htlc, _ := createHTLC(i, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just assign htlcID to the last received HTLC.
|
// Just assign htlcID to the last received HTLC.
|
||||||
htlcID = htlc.ID
|
htlcID = htlc.ID
|
||||||
|
@ -6505,12 +6355,7 @@ func TestMaxAsynchronousHtlcs(t *testing.T) {
|
||||||
|
|
||||||
// Send an HTLC to Bob so that Bob's commitment transaction is full.
|
// Send an HTLC to Bob so that Bob's commitment transaction is full.
|
||||||
htlc, _ := createHTLC(numHTLCs-1, htlcAmt)
|
htlc, _ := createHTLC(numHTLCs-1, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fail back an HTLC and sign a commitment as in steps 1 & 2.
|
// Fail back an HTLC and sign a commitment as in steps 1 & 2.
|
||||||
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil)
|
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil)
|
||||||
|
@ -6549,12 +6394,7 @@ func TestMaxAsynchronousHtlcs(t *testing.T) {
|
||||||
|
|
||||||
// Send the final Add which should succeed as in step 6.
|
// Send the final Add which should succeed as in step 6.
|
||||||
htlc, _ = createHTLC(numHTLCs, htlcAmt)
|
htlc, _ = createHTLC(numHTLCs, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Receiving the commitment should succeed as in step 7 since space was
|
// Receiving the commitment should succeed as in step 7 since space was
|
||||||
// made.
|
// made.
|
||||||
|
@ -6595,12 +6435,7 @@ func TestMaxPendingAmount(t *testing.T) {
|
||||||
htlcAmt := lnwire.NewMSatFromSatoshis(1.5 * btcutil.SatoshiPerBitcoin)
|
htlcAmt := lnwire.NewMSatFromSatoshis(1.5 * btcutil.SatoshiPerBitcoin)
|
||||||
for i := 0; i < numHTLCs; i++ {
|
for i := 0; i < numHTLCs; i++ {
|
||||||
htlc, _ := createHTLC(i, htlcAmt)
|
htlc, _ := createHTLC(i, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We finally add one more HTLC of 0.1 BTC to Alice's commitment. This
|
// We finally add one more HTLC of 0.1 BTC to Alice's commitment. This
|
||||||
|
@ -6702,12 +6537,7 @@ func TestChanReserve(t *testing.T) {
|
||||||
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
|
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
|
||||||
htlc, _ := createHTLC(aliceIndex, htlcAmt)
|
htlc, _ := createHTLC(aliceIndex, htlcAmt)
|
||||||
aliceIndex++
|
aliceIndex++
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force a state transition, making sure this HTLC is considered valid
|
// Force a state transition, making sure this HTLC is considered valid
|
||||||
// even though the channel reserves are not met.
|
// even though the channel reserves are not met.
|
||||||
|
@ -6754,12 +6584,7 @@ func TestChanReserve(t *testing.T) {
|
||||||
// The first HTLC should successfully be sent.
|
// The first HTLC should successfully be sent.
|
||||||
htlc, _ = createHTLC(aliceIndex, htlcAmt)
|
htlc, _ = createHTLC(aliceIndex, htlcAmt)
|
||||||
aliceIndex++
|
aliceIndex++
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a second HTLC of 1 BTC. This should fail because it will take
|
// Add a second HTLC of 1 BTC. This should fail because it will take
|
||||||
// Alice's balance all the way down to her channel reserve, but since
|
// Alice's balance all the way down to her channel reserve, but since
|
||||||
|
@ -6825,12 +6650,7 @@ func TestChanReserve(t *testing.T) {
|
||||||
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
|
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
|
||||||
htlc, _ = createHTLC(bobIndex, htlcAmt)
|
htlc, _ = createHTLC(bobIndex, htlcAmt)
|
||||||
bobIndex++
|
bobIndex++
|
||||||
if _, err := bobChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := aliceChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do a last state transition, which should succeed.
|
// Do a last state transition, which should succeed.
|
||||||
if err := ForceStateTransition(bobChannel, aliceChannel); err != nil {
|
if err := ForceStateTransition(bobChannel, aliceChannel); err != nil {
|
||||||
|
@ -6958,12 +6778,7 @@ func TestMinHTLC(t *testing.T) {
|
||||||
// ErrBelowMinHTLC.
|
// ErrBelowMinHTLC.
|
||||||
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
|
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
|
||||||
htlc, _ := createHTLC(0, htlcAmt)
|
htlc, _ := createHTLC(0, htlcAmt)
|
||||||
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
t.Fatalf("unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
|
|
||||||
t.Fatalf("unable to recv htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We add an HTLC below the min value, this should result in
|
// We add an HTLC below the min value, this should result in
|
||||||
// an ErrBelowMinHTLC error.
|
// an ErrBelowMinHTLC error.
|
||||||
|
@ -7205,12 +7020,7 @@ func TestChannelRestoreUpdateLogs(t *testing.T) {
|
||||||
// Bob's commit, but not on Alice's.
|
// Bob's commit, but not on Alice's.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let Alice sign a new state, which will include the HTLC just sent.
|
// Let Alice sign a new state, which will include the HTLC just sent.
|
||||||
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
||||||
|
@ -7454,11 +7264,7 @@ func TestDuplicateFailRejection(t *testing.T) {
|
||||||
// parties.
|
// parties.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlcAlice)
|
|
||||||
require.NoError(t, err, "unable to recv htlc")
|
|
||||||
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete state update: %v", err)
|
t.Fatalf("unable to complete state update: %v", err)
|
||||||
|
@ -7521,11 +7327,7 @@ func TestDuplicateSettleRejection(t *testing.T) {
|
||||||
// parties.
|
// parties.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||||
htlcAlice, alicePreimage := createHTLC(0, htlcAmount)
|
htlcAlice, alicePreimage := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlcAlice)
|
|
||||||
require.NoError(t, err, "unable to recv htlc")
|
|
||||||
|
|
||||||
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
if err := ForceStateTransition(aliceChannel, bobChannel); err != nil {
|
||||||
t.Fatalf("unable to complete state update: %v", err)
|
t.Fatalf("unable to complete state update: %v", err)
|
||||||
|
@ -7629,12 +7431,7 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
|
||||||
// We'll send an HtLC from Alice to Bob.
|
// We'll send an HtLC from Alice to Bob.
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(100000000)
|
htlcAmount := lnwire.NewMSatFromSatoshis(100000000)
|
||||||
htlcAlice, _ := createHTLC(0, htlcAmount)
|
htlcAlice, _ := createHTLC(0, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let Alice sign a new state, which will include the HTLC just sent.
|
// Let Alice sign a new state, which will include the HTLC just sent.
|
||||||
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
aliceNewCommit, err := aliceChannel.SignNextCommitment()
|
||||||
|
@ -7698,12 +7495,7 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
|
||||||
// existing HTLCs (the HTLC with index 0) keep getting the add heights
|
// existing HTLCs (the HTLC with index 0) keep getting the add heights
|
||||||
// restored properly.
|
// restored properly.
|
||||||
htlcAlice, _ = createHTLC(1, htlcAmount)
|
htlcAlice, _ = createHTLC(1, htlcAmount)
|
||||||
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlcAlice, nil)
|
||||||
t.Fatalf("alice unable to add htlc: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
|
|
||||||
t.Fatalf("bob unable to recv add htlc: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a new signature from Alice to Bob, making Alice have a pending
|
// Send a new signature from Alice to Bob, making Alice have a pending
|
||||||
// remote commitment.
|
// remote commitment.
|
||||||
|
@ -9088,10 +8880,7 @@ func TestChannelUnsignedAckedFailure(t *testing.T) {
|
||||||
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
||||||
|
|
||||||
// -----add----->
|
// -----add----->
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Force a state transition to lock in this add on both commitments.
|
// Force a state transition to lock in this add on both commitments.
|
||||||
// -----sig----->
|
// -----sig----->
|
||||||
|
@ -9151,10 +8940,7 @@ func TestChannelUnsignedAckedFailure(t *testing.T) {
|
||||||
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
||||||
|
|
||||||
// <----add------
|
// <----add------
|
||||||
_, err = bobChannel.AddHTLC(htlc2, nil)
|
addAndReceiveHTLC(t, bobChannel, newAliceChannel, htlc2, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = newAliceChannel.ReceiveHTLC(htlc2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Bob sends the final signature to Alice and Alice should not
|
// Bob sends the final signature to Alice and Alice should not
|
||||||
// reject it, given that we properly restore the unsigned acked
|
// reject it, given that we properly restore the unsigned acked
|
||||||
|
@ -9198,10 +8984,7 @@ func TestChannelLocalUnsignedUpdatesFailure(t *testing.T) {
|
||||||
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
htlc, _ := createHTLC(0, lnwire.MilliSatoshi(500000))
|
||||||
|
|
||||||
// <----add-----
|
// <----add-----
|
||||||
_, err = bobChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Force a state transition to lock in this add on both commitments.
|
// Force a state transition to lock in this add on both commitments.
|
||||||
// <----sig-----
|
// <----sig-----
|
||||||
|
@ -9285,10 +9068,7 @@ func TestChannelSignedAckRegression(t *testing.T) {
|
||||||
htlc, preimage := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
htlc, preimage := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
||||||
|
|
||||||
// <----add------
|
// <----add------
|
||||||
_, err = bobChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Force a state transition to lock in the HTLC.
|
// Force a state transition to lock in the HTLC.
|
||||||
// <----sig------
|
// <----sig------
|
||||||
|
@ -9327,10 +9107,7 @@ func TestChannelSignedAckRegression(t *testing.T) {
|
||||||
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
htlc2, _ := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
||||||
|
|
||||||
// -----add---->
|
// -----add---->
|
||||||
_, err = aliceChannel.AddHTLC(htlc2, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc2, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// -----sig---->
|
// -----sig---->
|
||||||
aliceNewCommit, err = aliceChannel.SignNextCommitment()
|
aliceNewCommit, err = aliceChannel.SignNextCommitment()
|
||||||
|
@ -9427,10 +9204,7 @@ func TestIsChannelClean(t *testing.T) {
|
||||||
// sends an htlc.
|
// sends an htlc.
|
||||||
// ---add--->
|
// ---add--->
|
||||||
htlc, preimage := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
htlc, preimage := createHTLC(0, lnwire.MilliSatoshi(5000000))
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
assertCleanOrDirty(false, aliceChannel, bobChannel, t)
|
assertCleanOrDirty(false, aliceChannel, bobChannel, t)
|
||||||
|
|
||||||
// Assert that the channel remains dirty until the HTLC is completely
|
// Assert that the channel remains dirty until the HTLC is completely
|
||||||
|
@ -9608,10 +9382,7 @@ func testGetDustSum(t *testing.T, chantype channeldb.ChannelType) {
|
||||||
htlc1Amt := lnwire.MilliSatoshi(700_000)
|
htlc1Amt := lnwire.MilliSatoshi(700_000)
|
||||||
htlc1, preimage1 := createHTLC(0, htlc1Amt)
|
htlc1, preimage1 := createHTLC(0, htlc1Amt)
|
||||||
|
|
||||||
_, err = bobChannel.AddHTLC(htlc1, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc1, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Assert that GetDustSum from Alice's perspective does not consider
|
// Assert that GetDustSum from Alice's perspective does not consider
|
||||||
// the HTLC dust on her commitment, but does on Bob's commitment.
|
// the HTLC dust on her commitment, but does on Bob's commitment.
|
||||||
|
@ -9651,10 +9422,7 @@ func testGetDustSum(t *testing.T, chantype channeldb.ChannelType) {
|
||||||
htlc2Amt := lnwire.MilliSatoshi(100_000)
|
htlc2Amt := lnwire.MilliSatoshi(100_000)
|
||||||
htlc2, _ := createHTLC(0, htlc2Amt)
|
htlc2, _ := createHTLC(0, htlc2Amt)
|
||||||
|
|
||||||
_, err = aliceChannel.AddHTLC(htlc2, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc2, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Assert that GetDustSum from Alice's perspective includes the new
|
// Assert that GetDustSum from Alice's perspective includes the new
|
||||||
// HTLC as dust on both commitments.
|
// HTLC as dust on both commitments.
|
||||||
|
@ -9702,10 +9470,7 @@ func testGetDustSum(t *testing.T, chantype channeldb.ChannelType) {
|
||||||
htlc3Amt := lnwire.MilliSatoshi(400_000)
|
htlc3Amt := lnwire.MilliSatoshi(400_000)
|
||||||
htlc3, _ := createHTLC(1, htlc3Amt)
|
htlc3, _ := createHTLC(1, htlc3Amt)
|
||||||
|
|
||||||
_, err = aliceChannel.AddHTLC(htlc3, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc3, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc3)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Assert that this new HTLC is not counted on Alice's local commitment
|
// Assert that this new HTLC is not counted on Alice's local commitment
|
||||||
// in the dust sum. Bob's commitment should count it.
|
// in the dust sum. Bob's commitment should count it.
|
||||||
|
@ -10707,11 +10472,7 @@ func TestAsynchronousSendingWithFeeBuffer(t *testing.T) {
|
||||||
aliceChannel.channelState.LocalChanCfg.DustLimit + htlcFee,
|
aliceChannel.channelState.LocalChanCfg.DustLimit + htlcFee,
|
||||||
)
|
)
|
||||||
htlc3, _ := createHTLC(1, htlcAmt3)
|
htlc3, _ := createHTLC(1, htlcAmt3)
|
||||||
_, err = bobChannel.AddHTLC(htlc3, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc3, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc3)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = ForceStateTransition(bobChannel, aliceChannel)
|
err = ForceStateTransition(bobChannel, aliceChannel)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -10817,10 +10578,7 @@ func TestEnforceFeeBuffer(t *testing.T) {
|
||||||
// --------------- |-----rev------>
|
// --------------- |-----rev------>
|
||||||
htlc1, _ := createHTLC(0, lnwire.NewMSatFromSatoshis(htlcAmt1))
|
htlc1, _ := createHTLC(0, lnwire.NewMSatFromSatoshis(htlcAmt1))
|
||||||
|
|
||||||
_, err = aliceChannel.AddHTLC(htlc1, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc1, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = ForceStateTransition(aliceChannel, bobChannel)
|
err = ForceStateTransition(aliceChannel, bobChannel)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -10834,10 +10592,7 @@ func TestEnforceFeeBuffer(t *testing.T) {
|
||||||
htlcAmt2 := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcent)
|
htlcAmt2 := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcent)
|
||||||
htlc2, _ := createHTLC(0, htlcAmt2)
|
htlc2, _ := createHTLC(0, htlcAmt2)
|
||||||
|
|
||||||
_, err = bobChannel.AddHTLC(htlc2, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc2, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc2)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = ForceStateTransition(bobChannel, aliceChannel)
|
err = ForceStateTransition(bobChannel, aliceChannel)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -10857,10 +10612,7 @@ func TestEnforceFeeBuffer(t *testing.T) {
|
||||||
// <----rev------- |---------------
|
// <----rev------- |---------------
|
||||||
htlc4, _ := createHTLC(1, htlcAmt2)
|
htlc4, _ := createHTLC(1, htlcAmt2)
|
||||||
|
|
||||||
_, err = bobChannel.AddHTLC(htlc4, nil)
|
addAndReceiveHTLC(t, bobChannel, aliceChannel, htlc4, nil)
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = aliceChannel.ReceiveHTLC(htlc4)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
err = ForceStateTransition(bobChannel, aliceChannel)
|
err = ForceStateTransition(bobChannel, aliceChannel)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -10900,11 +10652,7 @@ func TestBlindingPointPersistence(t *testing.T) {
|
||||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](blinding),
|
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](blinding),
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err = aliceChannel.AddHTLC(htlc, nil)
|
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
|
||||||
|
|
||||||
require.NoError(t, err)
|
|
||||||
_, err = bobChannel.ReceiveHTLC(htlc)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Now, Alice will send a new commitment to Bob, which will persist our
|
// Now, Alice will send a new commitment to Bob, which will persist our
|
||||||
// pending HTLC to disk.
|
// pending HTLC to disk.
|
||||||
|
|
Loading…
Add table
Reference in a new issue