lnwallet/channel_test: convert tests to new channel API for persistence

This commit is contained in:
Conner Fromknecht 2018-02-27 19:33:11 -08:00
parent aeecb9cdf5
commit 5539e23b05
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF
1 changed files with 151 additions and 122 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/binary"
"io"
"io/ioutil"
"os"
"reflect"
"runtime"
@ -104,7 +105,7 @@ func forceStateTransition(chanA, chanB *LightningChannel) error {
return err
}
if _, err := chanA.ReceiveRevocation(bobRevocation); err != nil {
if _, _, _, err := chanA.ReceiveRevocation(bobRevocation); err != nil {
return err
}
if err := chanA.ReceiveNewCommitment(bobSig, bobHtlcSigs); err != nil {
@ -115,7 +116,7 @@ func forceStateTransition(chanA, chanB *LightningChannel) error {
if err != nil {
return err
}
if _, err := chanB.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := chanB.ReceiveRevocation(aliceRevocation); err != nil {
return err
}
@ -451,7 +452,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// First Alice adds the outgoing HTLC to her local channel's state
// update log. Then Alice sends this wire message over to Bob who adds
// this htlc to his remote state update log.
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
@ -497,10 +498,17 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// Alice then processes this revocation, sending her own revocation for
// her prior commitment transaction. Alice shouldn't have any HTLCs to
// forward since she's sending an outgoing HTLC.
if htlcs, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
fwdPkg, _, _, err := aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to process bob's revocation: %v", err)
} else if len(htlcs) != 0 {
t.Fatalf("alice forwards %v htlcs, should forward none: ", len(htlcs))
}
if len(fwdPkg.Adds) != 0 {
t.Fatalf("alice forwards %v add htlcs, should forward none",
len(fwdPkg.Adds))
}
if len(fwdPkg.SettleFails) != 0 {
t.Fatalf("alice forwards %v settle/fail htlcs, "+
"should forward none", len(fwdPkg.SettleFails))
}
// Alice then processes bob's signature, and since she just received
@ -521,11 +529,17 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// is fully locked in within both commitment transactions. Bob should
// also be able to forward an HTLC now that the HTLC has been locked
// into both commitment transactions.
if htlcs, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
fwdPkg, _, _, err = bobChannel.ReceiveRevocation(aliceRevocation)
if err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
} else if len(htlcs) != 1 {
t.Fatalf("bob should be able to forward an HTLC, instead can "+
"forward %v", len(htlcs))
}
if len(fwdPkg.Adds) != 1 {
t.Fatalf("bob forwards %v add htlcs, should only forward one",
len(fwdPkg.Adds))
}
if len(fwdPkg.SettleFails) != 0 {
t.Fatalf("bob forwards %v settle/fail htlcs, "+
"should forward none", len(fwdPkg.SettleFails))
}
// At this point, both sides should have the proper number of satoshis
@ -582,7 +596,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// HTLC once he learns of the preimage.
var preimage [32]byte
copy(preimage[:], paymentPreimage)
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex)
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -610,12 +624,19 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
t.Fatalf("alice unable to sign new commitment: %v", err)
}
if htlcs, err := bobChannel.ReceiveRevocation(aliceRevocation2); err != nil {
fwdPkg, _, _, err = bobChannel.ReceiveRevocation(aliceRevocation2)
if err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
} else if len(htlcs) != 0 {
t.Fatalf("bob shouldn't forward any HTLCs after outgoing settle, "+
"instead can forward: %v", spew.Sdump(htlcs))
}
if len(fwdPkg.Adds) != 0 {
t.Fatalf("bob forwards %v add htlcs, should forward none",
len(fwdPkg.Adds))
}
if len(fwdPkg.SettleFails) != 0 {
t.Fatalf("bob forwards %v settle/fail htlcs, "+
"should forward none", len(fwdPkg.SettleFails))
}
err = bobChannel.ReceiveNewCommitment(aliceSig2, aliceHtlcSigs2)
if err != nil {
t.Fatalf("bob unable to process alice's new commitment: %v", err)
@ -625,14 +646,20 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
if err != nil {
t.Fatalf("bob unable to revoke commitment: %v", err)
}
if htlcs, err := aliceChannel.ReceiveRevocation(bobRevocation2); err != nil {
fwdPkg, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation2)
if err != nil {
t.Fatalf("alice unable to process bob's revocation: %v", err)
} else if len(htlcs) != 1 {
}
if len(fwdPkg.Adds) != 0 {
// Alice should now be able to forward the settlement HTLC to
// any down stream peers.
t.Fatalf("alice should be able to forward a single HTLC, "+
"instead can forward %v: %v", len(htlcs), spew.Sdump(htlcs))
t.Fatalf("alice should be forwarding an add HTLC, "+
"instead forwarding %v: %v", len(fwdPkg.Adds),
spew.Sdump(fwdPkg.Adds))
}
if len(fwdPkg.SettleFails) != 1 {
t.Fatalf("alice should be forwarding one settle/fails HTLC, "+
"instead forwarding: %v", len(fwdPkg.SettleFails))
}
// At this point, Bob should have 6 BTC settled, with Alice still having
@ -733,7 +760,7 @@ func TestCheckCommitTxSize(t *testing.T) {
for i := 0; i <= 10; i++ {
htlc, _ := createHTLC(i, lnwire.MilliSatoshi(1e7))
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -752,7 +779,7 @@ func TestCheckCommitTxSize(t *testing.T) {
for i := 10; i >= 0; i-- {
_, preimage := createHTLC(i, lnwire.MilliSatoshi(1e7))
err := bobChannel.SettleHTLC(preimage, uint64(i))
err := bobChannel.SettleHTLC(preimage, uint64(i), nil, nil, nil)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -856,7 +883,7 @@ func TestForceClose(t *testing.T) {
// We'll ensure that the HTLC amount is above Alice's dust limit.
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
htlcAlice, _ := createHTLC(0, htlcAmount)
if _, err := aliceChannel.AddHTLC(htlcAlice); err != nil {
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlcAlice); err != nil {
@ -867,7 +894,7 @@ func TestForceClose(t *testing.T) {
// have both an incoming and outgoing HTLC on her commitment
// transaction.
htlcBob, preimageBob := createHTLC(0, htlcAmount)
if _, err := bobChannel.AddHTLC(htlcBob); err != nil {
if _, err := bobChannel.AddHTLC(htlcBob, nil); err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
if _, err := aliceChannel.ReceiveHTLC(htlcBob); err != nil {
@ -1154,7 +1181,7 @@ func TestForceCloseDustOutput(t *testing.T) {
// Have Bobs' to-self output be below her dust limit and check
// ForceCloseSummary again on both peers.
htlc, preimage := createHTLC(0, bobAmount-htlcAmount)
bobHtlcIndex, err := bobChannel.AddHTLC(htlc)
bobHtlcIndex, err := bobChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
@ -1167,7 +1194,7 @@ func TestForceCloseDustOutput(t *testing.T) {
}
// Settle HTLC and sign new commitment.
err = aliceChannel.SettleHTLC(preimage, aliceHtlcIndex)
err = aliceChannel.SettleHTLC(preimage, aliceHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1261,7 +1288,7 @@ func TestDustHTLCFees(t *testing.T) {
// This HTLC amount should be lower than the dust limits of both nodes.
htlcAmount := lnwire.NewMSatFromSatoshis(100)
htlc, _ := createHTLC(0, htlcAmount)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -1340,7 +1367,7 @@ func TestHTLCDustLimit(t *testing.T) {
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
htlc, preimage := createHTLC(0, htlcAmount)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
@ -1374,7 +1401,7 @@ func TestHTLCDustLimit(t *testing.T) {
}
// Settle HTLC and create a new commitment state.
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex)
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1436,7 +1463,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
htlcAmount := lnwire.NewMSatFromSatoshis(htlcSat)
htlc, preimage := createHTLC(0, htlcAmount)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("alice unable to add htlc: %v", err)
}
@ -1447,7 +1474,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
if err := forceStateTransition(aliceChannel, bobChannel); err != nil {
t.Fatalf("state transition error: %v", err)
}
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex)
err = bobChannel.SettleHTLC(preimage, bobHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1507,7 +1534,7 @@ func TestStateUpdatePersistence(t *testing.T) {
OnionBlob: fakeOnionBlob,
}
if _, err := aliceChannel.AddHTLC(h); err != nil {
if _, err := aliceChannel.AddHTLC(h, nil); err != nil {
t.Fatalf("unable to add alice's htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(h); err != nil {
@ -1521,7 +1548,7 @@ func TestStateUpdatePersistence(t *testing.T) {
Expiry: uint32(10),
OnionBlob: fakeOnionBlob,
}
if _, err := bobChannel.AddHTLC(bobh); err != nil {
if _, err := bobChannel.AddHTLC(bobh, nil); err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
if _, err := aliceChannel.ReceiveHTLC(bobh); err != nil {
@ -1697,7 +1724,7 @@ func TestStateUpdatePersistence(t *testing.T) {
// Now settle all the HTLCs, then force a state update. The state
// update should succeed as both sides have identical.
for i := 0; i < 3; i++ {
err := bobChannelNew.SettleHTLC(alicePreimage, uint64(i))
err := bobChannelNew.SettleHTLC(alicePreimage, uint64(i), nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc #%v: %v", i, err)
}
@ -1706,7 +1733,7 @@ func TestStateUpdatePersistence(t *testing.T) {
t.Fatalf("unable to settle htlc#%v: %v", i, err)
}
}
err = aliceChannelNew.SettleHTLC(bobPreimage, 0)
err = aliceChannelNew.SettleHTLC(bobPreimage, 0, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -1749,14 +1776,14 @@ func TestStateUpdatePersistence(t *testing.T) {
// has been persisted properly. If we instruct Alice to add a new HTLC,
// it should have an index of 3. If we instruct Bob to do the
// same, it should have an index of 1.
aliceHtlcIndex, err := aliceChannel.AddHTLC(bobh)
aliceHtlcIndex, err := aliceChannel.AddHTLC(bobh, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if aliceHtlcIndex != 3 {
t.Fatalf("wrong htlc index: expected %v, got %v", 3, aliceHtlcIndex)
}
bobHtlcIndex, err := bobChannel.AddHTLC(bobh)
bobHtlcIndex, err := bobChannel.AddHTLC(bobh, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
@ -1789,7 +1816,7 @@ func TestCancelHTLC(t *testing.T) {
Expiry: 10,
}
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("unable to add alice htlc: %v", err)
}
@ -1814,7 +1841,7 @@ func TestCancelHTLC(t *testing.T) {
// Now, with the HTLC committed on both sides, trigger a cancellation
// from Bob to Alice, removing the HTLC.
err = bobChannel.FailHTLC(bobHtlcIndex, []byte("failreason"))
err = bobChannel.FailHTLC(bobHtlcIndex, []byte("failreason"), nil, nil, nil)
if err != nil {
t.Fatalf("unable to cancel HTLC: %v", err)
}
@ -2099,7 +2126,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
// First Alice adds the outgoing HTLC to her local channel's state
// update log. Then Alice sends this wire message over to Bob who
// adds this htlc to his remote state update log.
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -2152,7 +2179,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
// Alice receives the revocation of the old one, and can now assume
// that Bob's received everything up to the signature she sent,
// including the HTLC and fee update.
if _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
if _, _, _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
t.Fatalf("alice unable to process bob's revocation: %v", err)
}
@ -2179,7 +2206,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
}
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
@ -2211,7 +2238,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
// First Alice adds the outgoing HTLC to her local channel's state
// update log. Then Alice sends this wire message over to Bob who
// adds this htlc to his remote state update log.
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -2247,7 +2274,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
}
// Bob receives the revocation of the old commitment
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("alice unable to process bob's revocation: %v", err)
}
@ -2291,7 +2318,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
// Alice receives revocation from Bob, and can now be sure that Bob
// received the two updates, and they are considered locked in.
if _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
if _, _, _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
@ -2318,7 +2345,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
}
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
}
@ -2432,7 +2459,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
// Alice receives the revocation of the old one, and can now assume that
// Bob's received everything up to the signature she sent, including the
// HTLC and fee update.
if _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
if _, _, _, err := aliceChannel.ReceiveRevocation(bobRevocation); err != nil {
t.Fatalf("alice unable to process bob's revocation: %v", err)
}
@ -2458,7 +2485,7 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
}
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
}
@ -2486,7 +2513,7 @@ func TestAddHTLCNegativeBalance(t *testing.T) {
htlcAmt := lnwire.NewMSatFromSatoshis(btcutil.SatoshiPerBitcoin)
for i := 0; i < numHTLCs; i++ {
htlc, _ := createHTLC(i, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
}
@ -2496,7 +2523,7 @@ func TestAddHTLCNegativeBalance(t *testing.T) {
// has to pay a commitment fee).
htlcAmt = lnwire.NewMSatFromSatoshis(2 * btcutil.SatoshiPerBitcoin)
htlc, _ := createHTLC(numHTLCs+1, htlcAmt)
_, err = aliceChannel.AddHTLC(htlc)
_, err = aliceChannel.AddHTLC(htlc, nil)
if err != ErrBelowChanReserve {
t.Fatalf("expected balance below channel reserve, instead "+
"got: %v", err)
@ -2516,7 +2543,7 @@ func assertNoChanSyncNeeded(t *testing.T, aliceChannel *LightningChannel,
t.Fatalf("line #%v: unable to produce chan sync msg: %v",
line, err)
}
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceChanSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceChanSyncMsg)
if err != nil {
t.Fatalf("line #%v: unable to process ChannelReestablish "+
"msg: %v", line, err)
@ -2531,7 +2558,7 @@ func assertNoChanSyncNeeded(t *testing.T, aliceChannel *LightningChannel,
t.Fatalf("line #%v: unable to produce chan sync msg: %v",
line, err)
}
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(bobChanSyncMsg)
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(bobChanSyncMsg)
if err != nil {
t.Fatalf("line #%v: unable to process ChannelReestablish "+
"msg: %v", line, err)
@ -2572,7 +2599,7 @@ func TestChanSyncFullySynced(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(5),
}
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
@ -2592,7 +2619,7 @@ func TestChanSyncFullySynced(t *testing.T) {
// If bob settles the HTLC, and then initiates a state transition, they
// should both still think that they're in sync.
err = bobChannel.SettleHTLC(paymentPreimage, bobHtlcIndex)
err = bobChannel.SettleHTLC(paymentPreimage, bobHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -2696,7 +2723,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
OnionBlob: fakeOnionBlob,
}
htlcIndex, err := bobChannel.AddHTLC(h)
htlcIndex, err := bobChannel.AddHTLC(h, nil)
if err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
@ -2720,7 +2747,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
// Next, Alice's settles all 3 HTLC's from Bob, and also adds a new
// HTLC of her own.
for i := 0; i < 3; i++ {
err := aliceChannel.SettleHTLC(bobPreimage, uint64(i))
err := aliceChannel.SettleHTLC(bobPreimage, uint64(i), nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -2739,7 +2766,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
Expiry: uint32(10),
OnionBlob: fakeOnionBlob,
}
aliceHtlcIndex, err := aliceChannel.AddHTLC(aliceHtlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(aliceHtlc, nil)
if err != nil {
t.Fatalf("unable to add alice's htlc: %v", err)
}
@ -2772,7 +2799,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
// needs to retransmit the exact commitment that we failed to send
// above.
assertAliceCommitRetransmit := func() {
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(
bobSyncMsg,
)
if err != nil {
@ -2848,7 +2875,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
// From Bob's Pov he has nothing else to send, so he should conclude he
// has no further action remaining.
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -2884,7 +2911,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
if err != nil {
t.Fatalf("bob unable to sign commitment: %v", err)
}
_, err = aliceChannel.ReceiveRevocation(bobRevocation)
_, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to recv revocation: %v", err)
}
@ -2896,7 +2923,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
if err != nil {
t.Fatalf("alice unable to revoke commitment: %v", err)
}
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to recv revocation: %v", err)
}
@ -2943,7 +2970,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
// We'll conclude the test by having Bob settle Alice's HTLC, then
// initiate a state transition.
err = bobChannel.SettleHTLC(alicePreimage, bobHtlcIndex)
err = bobChannel.SettleHTLC(alicePreimage, bobHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -3008,7 +3035,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(10),
}
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc)
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc, nil)
if err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
@ -3022,7 +3049,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
// Next, Alice will settle that single HTLC, the _begin_ the start of a
// state transition.
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex)
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -3054,7 +3081,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
t.Fatalf("bob unable to sign commitment: %v", err)
}
_, err = aliceChannel.ReceiveRevocation(bobRevocation)
_, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to recv revocation: %v", err)
}
@ -3083,7 +3110,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
}
assertAliceOwesRevoke := func() {
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3112,7 +3139,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
}
// From Bob's PoV he shouldn't think that he owes Alice any messages.
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3137,7 +3164,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
// TODO(roasbeef): restart bob too???
// We'll continue by then allowing bob to process Alice's revocation message.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to recv revocation: %v", err)
}
@ -3152,7 +3179,7 @@ func TestChanSyncOweRevocation(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(10),
}
if _, err := aliceChannel.AddHTLC(aliceHtlc); err != nil {
if _, err := aliceChannel.AddHTLC(aliceHtlc, nil); err != nil {
t.Fatalf("unable to add alice's htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(aliceHtlc); err != nil {
@ -3194,7 +3221,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(10),
}
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc)
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc, nil)
if err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
@ -3208,7 +3235,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
// Next, Alice will settle that incoming HTLC, then we'll start the
// core of the test itself.
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex)
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -3251,7 +3278,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
t.Fatalf("unable to produce chan sync msg: %v", err)
}
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3261,7 +3288,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
}
assertBobSendsRevokeAndCommit := func() {
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3316,7 +3343,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
// We'll now finish the state transition by having Alice process both
// messages, and send her final revocation.
_, err = aliceChannel.ReceiveRevocation(bobRevocation)
_, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to recv revocation: %v", err)
}
@ -3328,7 +3355,7 @@ func TestChanSyncOweRevocationAndCommit(t *testing.T) {
if err != nil {
t.Fatalf("alice unable to revoke commitment: %v", err)
}
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to recv revocation: %v", err)
}
}
@ -3363,7 +3390,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(10),
}
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc)
bobHtlcIndex, err := bobChannel.AddHTLC(bobHtlc, nil)
if err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
@ -3377,7 +3404,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
// Next, Alice will settle that incoming HTLC, then we'll start the
// core of the test itself.
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex)
err = aliceChannel.SettleHTLC(bobPreimage, aliceHtlcIndex, nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -3417,7 +3444,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
t.Fatalf("unable to produce chan sync msg: %v", err)
}
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(bobSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3430,7 +3457,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
// send his RevokeAndAck message again. Additionally, the CommitSig
// message that he sends should be sufficient to finalize the state
// transition.
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3501,7 +3528,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
// Now, we'll continue the exchange, sending Bob's revocation and
// signature message to Alice, ending with Alice sending her revocation
// message to Bob.
_, err = aliceChannel.ReceiveRevocation(bobRevocation)
_, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to recv revocation: %v", err)
}
@ -3515,7 +3542,7 @@ func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
if err != nil {
t.Fatalf("alice unable to revoke commitment: %v", err)
}
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to recv revocation: %v", err)
}
}
@ -3607,7 +3634,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
}
// Bob should detect that he doesn't need to send anything to Alice.
bobMsgsToSend, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg)
if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err)
}
@ -3620,7 +3647,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
// When Alice processes Bob's chan sync message, she should realize
// that she needs to first send a new UpdateFee message, and also a
// CommitSig.
aliceMsgsToSend, err := aliceChannel.ProcessChanSyncMsg(
aliceMsgsToSend, _, _, err := aliceChannel.ProcessChanSyncMsg(
bobSyncMsg,
)
if err != nil {
@ -3686,7 +3713,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
if err != nil {
t.Fatalf("bob unable to sign commitment: %v", err)
}
_, err = aliceChannel.ReceiveRevocation(bobRevocation)
_, _, _, err = aliceChannel.ReceiveRevocation(bobRevocation)
if err != nil {
t.Fatalf("alice unable to recv revocation: %v", err)
}
@ -3698,7 +3725,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
if err != nil {
t.Fatalf("alice unable to revoke commitment: %v", err)
}
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
if _, _, _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to recv revocation: %v", err)
}
@ -3720,7 +3747,7 @@ func TestChannelRetransmissionFeeUpdate(t *testing.T) {
Amount: lnwire.NewMSatFromSatoshis(20000),
Expiry: uint32(10),
}
if _, err := bobChannel.AddHTLC(bobHtlc); err != nil {
if _, err := bobChannel.AddHTLC(bobHtlc, nil); err != nil {
t.Fatalf("unable to add bob's htlc: %v", err)
}
if _, err := aliceChannel.ReceiveHTLC(bobHtlc); err != nil {
@ -3756,11 +3783,11 @@ func TestChanSyncUnableToSync(t *testing.T) {
NextLocalCommitHeight: 1000,
RemoteCommitTailHeight: 9000,
}
_, err = bobChannel.ProcessChanSyncMsg(badChanSync)
_, _, _, err = bobChannel.ProcessChanSyncMsg(badChanSync)
if err != ErrCannotSyncCommitChains {
t.Fatalf("expected error instead have: %v", err)
}
_, err = aliceChannel.ProcessChanSyncMsg(badChanSync)
_, _, _, err = aliceChannel.ProcessChanSyncMsg(badChanSync)
if err != ErrCannotSyncCommitChains {
t.Fatalf("expected error instead have: %v", err)
}
@ -3803,7 +3830,7 @@ func TestChanSyncInvalidLastSecret(t *testing.T) {
Amount: htlcAmt,
Expiry: uint32(5),
}
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -3842,7 +3869,7 @@ func TestChanSyncInvalidLastSecret(t *testing.T) {
// Alice's former self should conclude that she possibly lost data as
// Bob is sending a valid commit secret for the latest state.
_, err = aliceOld.ProcessChanSyncMsg(bobChanSync)
_, _, _, err = aliceOld.ProcessChanSyncMsg(bobChanSync)
if err != ErrCommitSyncDataLoss {
t.Fatalf("wrong error, expected ErrCommitSyncDataLoss "+
"instead got: %v", err)
@ -3850,7 +3877,7 @@ func TestChanSyncInvalidLastSecret(t *testing.T) {
// Bob should conclude that he should force close the channel, as Alice
// cannot continue operation.
_, err = bobChannel.ProcessChanSyncMsg(aliceChanSync)
_, _, _, err = bobChannel.ProcessChanSyncMsg(aliceChanSync)
if err != ErrInvalidLastCommitSecret {
t.Fatalf("wrong error, expected ErrInvalidLastCommitSecret, "+
"instead got: %v", err)
@ -3913,7 +3940,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
alicePreimages := make([][32]byte, numHtlcs)
for i := 0; i < numHtlcs; i++ {
htlc, preImage := createHTLC(i, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -3931,7 +3958,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
htlcAmt = lnwire.NewMSatFromSatoshis(30000)
for i := 0; i < numHtlcs; i++ {
htlc, preImage := createHTLC(numHtlcs+i, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -3947,7 +3974,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
// the update log).
for i := 0; i < (numHtlcs*2)-1; i++ {
preImage := alicePreimages[i]
err := bobChannel.SettleHTLC(preImage, uint64(i))
err := bobChannel.SettleHTLC(preImage, uint64(i), nil, nil, nil)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -3958,7 +3985,7 @@ func TestChanAvailableBandwidth(t *testing.T) {
}
htlcIndex := uint64((numHtlcs * 2) - 1)
err = bobChannel.FailHTLC(htlcIndex, []byte("f"))
err = bobChannel.FailHTLC(htlcIndex, []byte("f"), nil, nil, nil)
if err != nil {
t.Fatalf("unable to cancel HTLC: %v", err)
}
@ -4025,14 +4052,14 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
// state transition.
var htlcAmt lnwire.MilliSatoshi = 100000
htlc, _ := createHTLC(0, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != 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)
if _, err := aliceChannel.AddHTLC(htlc2); err != nil {
if _, err := aliceChannel.AddHTLC(htlc2, nil); err != nil {
t.Fatalf("unable to add htlc2: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc2); err != nil {
@ -4059,7 +4086,7 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
}
// Alice should detect that she doesn't need to forward any HTLC's.
aliceHtlcsToForward, err := aliceChannel.ReceiveRevocation(
_, aliceHtlcsToForward, _, err := aliceChannel.ReceiveRevocation(
bobRevocation,
)
if err != nil {
@ -4081,7 +4108,7 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
// Bob on the other hand, should detect that he now has 2 incoming
// HTLC's that he can forward along.
bobHtlcsToForward, err := bobChannel.ReceiveRevocation(aliceRevocation)
_, bobHtlcsToForward, _, err := bobChannel.ReceiveRevocation(aliceRevocation)
if err != nil {
t.Fatal(err)
}
@ -4103,7 +4130,7 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
// With both nodes restarted, Bob will now attempt to cancel one of
// Alice's HTLC's.
err = bobChannel.FailHTLC(htlc2.ID, []byte("failreason"))
err = bobChannel.FailHTLC(htlc2.ID, []byte("failreason"), nil, nil, nil)
if err != nil {
t.Fatalf("unable to cancel HTLC: %v", err)
}
@ -4134,7 +4161,7 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
// At this point, Bob receives the revocation from Alice, which is now
// his signal to examine all the HTLC's that have been locked in to
// process.
bobHtlcsToForward, err = bobChannel.ReceiveRevocation(aliceRevocation)
_, bobHtlcsToForward, _, err = bobChannel.ReceiveRevocation(aliceRevocation)
if err != nil {
t.Fatal(err)
}
@ -4165,7 +4192,7 @@ func TestInvalidCommitSigError(t *testing.T) {
// Alice to Bob.
var htlcAmt lnwire.MilliSatoshi = 100000
htlc, _ := createHTLC(0, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4212,14 +4239,14 @@ func TestChannelUnilateralCloseHtlcResolution(t *testing.T) {
// initiating enough state transitions to lock both of them in.
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
htlcAlice, _ := createHTLC(0, htlcAmount)
if _, err := aliceChannel.AddHTLC(htlcAlice); err != nil {
if _, err := aliceChannel.AddHTLC(htlcAlice, nil); err != 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)
if _, err := bobChannel.AddHTLC(htlcBob); err != nil {
if _, err := bobChannel.AddHTLC(htlcBob, nil); err != nil {
t.Fatalf("bob unable to add htlc: %v", err)
}
if _, err := aliceChannel.ReceiveHTLC(htlcBob); err != nil {
@ -4369,7 +4396,7 @@ func TestDesyncHTLCs(t *testing.T) {
// First add one HTLC of value 4.1 BTC.
htlcAmt := lnwire.NewMSatFromSatoshis(4.1 * btcutil.SatoshiPerBitcoin)
htlc, _ := createHTLC(0, htlcAmt)
aliceIndex, err := aliceChannel.AddHTLC(htlc)
aliceIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
@ -4384,7 +4411,8 @@ func TestDesyncHTLCs(t *testing.T) {
}
// Now let let Bob fail this HTLC.
if err := bobChannel.FailHTLC(bobIndex, []byte("failreason")); err != nil {
err = bobChannel.FailHTLC(bobIndex, []byte("failreason"), nil, nil, nil)
if err != nil {
t.Fatalf("unable to cancel HTLC: %v", err)
}
if err := aliceChannel.ReceiveFailHTLC(aliceIndex, []byte("bad")); err != nil {
@ -4401,8 +4429,9 @@ func TestDesyncHTLCs(t *testing.T) {
// balance is unavailable.
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
htlc, _ = createHTLC(1, htlcAmt)
if _, err = aliceChannel.AddHTLC(htlc); err != ErrBelowChanReserve {
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
if _, err = aliceChannel.AddHTLC(htlc, nil); err != ErrBelowChanReserve {
t.Fatalf("expected ErrInsufficientBalance, instead received: %v",
err)
}
// Now do a state transition, which will ACK the FailHTLC, making Alice
@ -4410,7 +4439,7 @@ func TestDesyncHTLCs(t *testing.T) {
if err := forceStateTransition(aliceChannel, bobChannel); err != nil {
t.Fatalf("unable to complete state update: %v", err)
}
if _, err = aliceChannel.AddHTLC(htlc); err != nil {
if _, err = aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
}
@ -4452,7 +4481,7 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
// Send the maximum allowed number of HTLCs.
for i := 0; i < numHTLCs; i++ {
htlc, _ := createHTLC(i, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4462,7 +4491,7 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
// The next HTLC should fail with ErrMaxHTLCNumber.
htlc, _ := createHTLC(numHTLCs, htlcAmt)
_, err = aliceChannel.AddHTLC(htlc)
_, err = aliceChannel.AddHTLC(htlc, nil)
if err != ErrMaxHTLCNumber {
t.Fatalf("expected ErrMaxHTLCNumber, instead received: %v", err)
}
@ -4509,7 +4538,7 @@ func TestMaxPendingAmount(t *testing.T) {
htlcAmt := lnwire.NewMSatFromSatoshis(1.5 * btcutil.SatoshiPerBitcoin)
for i := 0; i < numHTLCs; i++ {
htlc, _ := createHTLC(i, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4521,7 +4550,7 @@ func TestMaxPendingAmount(t *testing.T) {
// SHOULD trigger Alice's ErrMaxPendingAmount error.
htlcAmt = lnwire.NewMSatFromSatoshis(0.1 * btcutil.SatoshiPerBitcoin)
htlc, _ := createHTLC(numHTLCs, htlcAmt)
_, err = aliceChannel.AddHTLC(htlc)
_, err = aliceChannel.AddHTLC(htlc, nil)
if err != ErrMaxPendingAmount {
t.Fatalf("expected ErrMaxPendingAmount, instead received: %v", err)
}
@ -4590,7 +4619,7 @@ func TestChanReserve(t *testing.T) {
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
htlc, _ := createHTLC(aliceIndex, htlcAmt)
aliceIndex++
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4611,7 +4640,7 @@ func TestChanReserve(t *testing.T) {
// Bob: 5.5
htlc, _ = createHTLC(bobIndex, htlcAmt)
bobIndex++
_, err := bobChannel.AddHTLC(htlc)
_, err := bobChannel.AddHTLC(htlc, nil)
if err != ErrBelowChanReserve {
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
}
@ -4643,7 +4672,7 @@ func TestChanReserve(t *testing.T) {
// The first HTLC should successfully be sent.
htlc, _ = createHTLC(aliceIndex, htlcAmt)
aliceIndex++
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4657,7 +4686,7 @@ func TestChanReserve(t *testing.T) {
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
htlc, _ = createHTLC(aliceIndex, htlcAmt)
aliceIndex++
_, err = aliceChannel.AddHTLC(htlc)
_, err = aliceChannel.AddHTLC(htlc, nil)
if err != ErrBelowChanReserve {
t.Fatalf("expected ErrBelowChanReserve, instead received: %v", err)
}
@ -4687,7 +4716,7 @@ func TestChanReserve(t *testing.T) {
htlcAmt = lnwire.NewMSatFromSatoshis(2 * btcutil.SatoshiPerBitcoin)
htlc, preimage := createHTLC(aliceIndex, htlcAmt)
aliceIndex++
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc)
aliceHtlcIndex, err := aliceChannel.AddHTLC(htlc, nil)
if err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
@ -4695,7 +4724,7 @@ func TestChanReserve(t *testing.T) {
if err != nil {
t.Fatalf("unable to recv htlc: %v", err)
}
if err := bobChannel.SettleHTLC(preimage, bobHtlcIndex); err != nil {
if err := bobChannel.SettleHTLC(preimage, bobHtlcIndex, nil, nil, nil); err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
if err := aliceChannel.ReceiveHTLCSettle(preimage, aliceHtlcIndex); err != nil {
@ -4708,7 +4737,7 @@ func TestChanReserve(t *testing.T) {
htlcAmt = lnwire.NewMSatFromSatoshis(1 * btcutil.SatoshiPerBitcoin)
htlc, _ = createHTLC(bobIndex, htlcAmt)
bobIndex++
if _, err := bobChannel.AddHTLC(htlc); err != nil {
if _, err := bobChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := aliceChannel.ReceiveHTLC(htlc); err != nil {
@ -4746,7 +4775,7 @@ func TestMinHTLC(t *testing.T) {
// ErrBelowMinHTLC.
htlcAmt := lnwire.NewMSatFromSatoshis(0.5 * btcutil.SatoshiPerBitcoin)
htlc, _ := createHTLC(0, htlcAmt)
if _, err := aliceChannel.AddHTLC(htlc); err != nil {
if _, err := aliceChannel.AddHTLC(htlc, nil); err != nil {
t.Fatalf("unable to add htlc: %v", err)
}
if _, err := bobChannel.ReceiveHTLC(htlc); err != nil {
@ -4757,7 +4786,7 @@ func TestMinHTLC(t *testing.T) {
// an ErrBelowMinHTLC error.
amt := minValue - 100
htlc, _ = createHTLC(1, amt)
_, err = aliceChannel.AddHTLC(htlc)
_, err = aliceChannel.AddHTLC(htlc, nil)
if err != ErrBelowMinHTLC {
t.Fatalf("expected ErrBelowMinHTLC, instead received: %v", err)
}