mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-20 10:39:01 +01:00
Merge pull request #778 from cfromknecht/switch-wallet-api
Switch Persistence [2.5/4]: Establish Switch-Sphinx-Wallet APIs for Switch Persistence
This commit is contained in:
commit
7a14b6bb32
@ -970,7 +970,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
|
||||
// Send one HTLC to Bob and perform a state transition to lock it in.
|
||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||
htlc, _ := createHTLC(0, htlcAmount)
|
||||
if _, err := alice.AddHTLC(htlc); err != nil {
|
||||
if _, err := alice.AddHTLC(htlc, nil); err != nil {
|
||||
t.Fatalf("alice unable to add htlc: %v", err)
|
||||
}
|
||||
if _, err := bob.ReceiveHTLC(htlc); err != nil {
|
||||
@ -990,7 +990,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
|
||||
// Now send another HTLC and perform a state transition, this ensures
|
||||
// Alice is ahead of the state Bob will broadcast.
|
||||
htlc2, _ := createHTLC(1, htlcAmount)
|
||||
if _, err := alice.AddHTLC(htlc2); err != nil {
|
||||
if _, err := alice.AddHTLC(htlc2, nil); err != nil {
|
||||
t.Fatalf("alice unable to add htlc: %v", err)
|
||||
}
|
||||
if _, err := bob.ReceiveHTLC(htlc2); err != nil {
|
||||
@ -1058,7 +1058,7 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||
// Send one HTLC to Bob and perform a state transition to lock it in.
|
||||
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
|
||||
htlc, _ := createHTLC(0, htlcAmount)
|
||||
if _, err := alice.AddHTLC(htlc); err != nil {
|
||||
if _, err := alice.AddHTLC(htlc, nil); err != nil {
|
||||
t.Fatalf("alice unable to add htlc: %v", err)
|
||||
}
|
||||
if _, err := bob.ReceiveHTLC(htlc); err != nil {
|
||||
@ -1078,7 +1078,7 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||
// Now send another HTLC and perform a state transition, this ensures
|
||||
// Alice is ahead of the state Bob will broadcast.
|
||||
htlc2, _ := createHTLC(1, htlcAmount)
|
||||
if _, err := alice.AddHTLC(htlc2); err != nil {
|
||||
if _, err := alice.AddHTLC(htlc2, nil); err != nil {
|
||||
t.Fatalf("alice unable to add htlc: %v", err)
|
||||
}
|
||||
if _, err := bob.ReceiveHTLC(htlc2); err != nil {
|
||||
@ -1554,7 +1554,7 @@ func forceStateTransition(chanA, chanB *lnwallet.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 {
|
||||
@ -1565,7 +1565,7 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := chanB.ReceiveRevocation(aliceRevocation); err != nil {
|
||||
if _, _, _, err := chanB.ReceiveRevocation(aliceRevocation); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ func (l *channelLink) syncChanStates() error {
|
||||
// We've just received a ChnSync message from the remote party,
|
||||
// so we'll process the message in order to determine if we
|
||||
// need to re-transmit any messages to the remote party.
|
||||
msgsToReSend, err = l.channel.ProcessChanSyncMsg(remoteChanSyncMsg)
|
||||
msgsToReSend, _, _, err = l.channel.ProcessChanSyncMsg(remoteChanSyncMsg)
|
||||
if err != nil {
|
||||
// TODO(roasbeef): check concrete type of error, act
|
||||
// accordingly
|
||||
@ -580,7 +580,7 @@ func (l *channelLink) syncChanStates() error {
|
||||
// remote party.
|
||||
var p [32]byte
|
||||
copy(p[:], preimage)
|
||||
err := l.channel.SettleHTLC(p, htlc.HtlcIndex)
|
||||
err := l.channel.SettleHTLC(p, htlc.HtlcIndex, nil, nil, nil)
|
||||
if err != nil {
|
||||
l.fail("unable to settle htlc: %v", err)
|
||||
return err
|
||||
@ -819,7 +819,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
||||
// so we add the new HTLC to our local log, then update the
|
||||
// commitment chains.
|
||||
htlc.ChanID = l.ChanID()
|
||||
index, err := l.channel.AddHTLC(htlc)
|
||||
index, err := l.channel.AddHTLC(htlc, nil)
|
||||
if err != nil {
|
||||
switch err {
|
||||
|
||||
@ -910,7 +910,13 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
||||
// An HTLC we forward to the switch has just settled somewhere
|
||||
// upstream. Therefore we settle the HTLC within the our local
|
||||
// state machine.
|
||||
err := l.channel.SettleHTLC(htlc.PaymentPreimage, pkt.incomingHTLCID)
|
||||
err := l.channel.SettleHTLC(
|
||||
htlc.PaymentPreimage,
|
||||
pkt.incomingHTLCID,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
// TODO(roasbeef): broadcast on-chain
|
||||
l.fail("unable to settle incoming HTLC: %v", err)
|
||||
@ -931,7 +937,13 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
|
||||
case *lnwire.UpdateFailHTLC:
|
||||
// An HTLC cancellation has been triggered somewhere upstream,
|
||||
// we'll remove then HTLC from our local state machine.
|
||||
err := l.channel.FailHTLC(pkt.incomingHTLCID, htlc.Reason)
|
||||
err := l.channel.FailHTLC(
|
||||
pkt.incomingHTLCID,
|
||||
htlc.Reason,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("unable to cancel HTLC: %v", err)
|
||||
return
|
||||
@ -1129,7 +1141,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
// We've received a revocation from the remote chain, if valid,
|
||||
// this moves the remote chain forward, and expands our
|
||||
// revocation window.
|
||||
htlcs, err := l.channel.ReceiveRevocation(msg)
|
||||
_, adds, settleFails, err := l.channel.ReceiveRevocation(msg)
|
||||
if err != nil {
|
||||
l.fail("unable to accept revocation: %v", err)
|
||||
return
|
||||
@ -1139,6 +1151,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
// commitment transactions they might be safely propagated over
|
||||
// htlc switch or settled if our node was last node in htlc
|
||||
// path.
|
||||
htlcs := append(settleFails, adds...)
|
||||
htlcsToForward := l.processLockedInHtlcs(htlcs)
|
||||
go func() {
|
||||
log.Debugf("ChannelPoint(%v) forwarding %v HTLC's",
|
||||
@ -1646,7 +1659,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
}
|
||||
|
||||
preimage := invoice.Terms.PaymentPreimage
|
||||
err = l.channel.SettleHTLC(preimage, pd.HtlcIndex)
|
||||
err = l.channel.SettleHTLC(preimage, pd.HtlcIndex, nil, nil, nil)
|
||||
if err != nil {
|
||||
l.fail("unable to settle htlc: %v", err)
|
||||
return nil
|
||||
@ -1868,7 +1881,7 @@ func (l *channelLink) sendHTLCError(htlcIndex uint64,
|
||||
return
|
||||
}
|
||||
|
||||
err = l.channel.FailHTLC(htlcIndex, reason)
|
||||
err = l.channel.FailHTLC(htlcIndex, reason, nil, nil, nil)
|
||||
if err != nil {
|
||||
log.Errorf("unable cancel htlc: %v", err)
|
||||
return
|
||||
@ -1887,7 +1900,7 @@ func (l *channelLink) sendMalformedHTLCError(htlcIndex uint64,
|
||||
code lnwire.FailCode, onionBlob []byte) {
|
||||
|
||||
shaOnionBlob := sha256.Sum256(onionBlob)
|
||||
err := l.channel.MalformedFailHTLC(htlcIndex, code, shaOnionBlob)
|
||||
err := l.channel.MalformedFailHTLC(htlcIndex, code, shaOnionBlob, nil)
|
||||
if err != nil {
|
||||
log.Errorf("unable cancel htlc: %v", err)
|
||||
return
|
||||
|
@ -1555,7 +1555,7 @@ func handleStateUpdate(link *channelLink,
|
||||
if !ok {
|
||||
return fmt.Errorf("expected RevokeAndAck got %T", msg)
|
||||
}
|
||||
_, err = remoteChannel.ReceiveRevocation(revoke)
|
||||
_, _, _, err = remoteChannel.ReceiveRevocation(revoke)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to receive "+
|
||||
"revocation: %v", err)
|
||||
@ -1609,7 +1609,7 @@ func updateState(batchTick chan time.Time, link *channelLink,
|
||||
return fmt.Errorf("expected RevokeAndAck got %T",
|
||||
msg)
|
||||
}
|
||||
_, err = remoteChannel.ReceiveRevocation(revoke)
|
||||
_, _, _, err = remoteChannel.ReceiveRevocation(revoke)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to receive "+
|
||||
"revocation: %v", err)
|
||||
@ -1743,7 +1743,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
||||
// If we now send in a valid HTLC settle for the prior HTLC we added,
|
||||
// then the bandwidth should remain unchanged as the remote party will
|
||||
// gain additional channel balance.
|
||||
err = bobChannel.SettleHTLC(invoice.Terms.PaymentPreimage, bobIndex)
|
||||
err = bobChannel.SettleHTLC(invoice.Terms.PaymentPreimage, bobIndex, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to settle htlc: %v", err)
|
||||
}
|
||||
@ -1807,7 +1807,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
||||
// With that processed, we'll now generate an HTLC fail (sent by the
|
||||
// remote peer) to cancel the HTLC we just added. This should return us
|
||||
// back to the bandwidth of the link right before the HTLC was sent.
|
||||
err = bobChannel.FailHTLC(bobIndex, []byte("nop"))
|
||||
err = bobChannel.FailHTLC(bobIndex, []byte("nop"), nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fail htlc: %v", err)
|
||||
}
|
||||
@ -1852,7 +1852,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
||||
t.Fatalf("unable to add invoice to registry: %v", err)
|
||||
}
|
||||
|
||||
bobIndex, err = bobChannel.AddHTLC(htlc)
|
||||
bobIndex, err = bobChannel.AddHTLC(htlc, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to add htlc: %v", err)
|
||||
}
|
||||
@ -1931,7 +1931,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
|
||||
// HTLC we add, hence it should have an ID of 1 (Alice's channel
|
||||
// link will set this automatically for her side).
|
||||
htlc.ID = 1
|
||||
bobIndex, err = bobChannel.AddHTLC(htlc)
|
||||
bobIndex, err = bobChannel.AddHTLC(htlc, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to add htlc: %v", err)
|
||||
}
|
||||
@ -2132,7 +2132,7 @@ func TestChannelLinkBandwidthConsistencyOverflow(t *testing.T) {
|
||||
// will simply transfer over funds to the remote party. However, the
|
||||
// size of the overflow queue should be decreasing
|
||||
for i := 0; i < numOverFlowHTLCs; i++ {
|
||||
err = bobChannel.SettleHTLC(preImages[i], uint64(i))
|
||||
err = bobChannel.SettleHTLC(preImages[i], uint64(i), nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to settle htlc: %v", err)
|
||||
}
|
||||
@ -2280,7 +2280,7 @@ func TestChannelLinkBandwidthChanReserve(t *testing.T) {
|
||||
// If we now send in a valid HTLC settle for the prior HTLC we added,
|
||||
// then the bandwidth should remain unchanged as the remote party will
|
||||
// gain additional channel balance.
|
||||
err = bobChannel.SettleHTLC(invoice.Terms.PaymentPreimage, bobIndex)
|
||||
err = bobChannel.SettleHTLC(invoice.Terms.PaymentPreimage, bobIndex, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to settle htlc: %v", err)
|
||||
}
|
||||
|
@ -224,21 +224,21 @@ type PaymentDescriptor struct {
|
||||
// link's commitment txn.
|
||||
DestRef *channeldb.SettleFailRef
|
||||
|
||||
// OpenCircuitRef references the incoming Chan/HTLC ID of an Add HTLC
|
||||
// OpenCircuitKey references the incoming Chan/HTLC ID of an Add HTLC
|
||||
// packet delivered by the switch.
|
||||
//
|
||||
// NOTE: This field is only populated for payment descriptors in the
|
||||
// *local* update log, and if the Add packet was delivered by the
|
||||
// switch.
|
||||
OpenCircuitRef *channeldb.CircuitKey
|
||||
OpenCircuitKey *channeldb.CircuitKey
|
||||
|
||||
// ClosedCircuitRef references the incoming Chan/HTLC ID of the Add HTLC
|
||||
// ClosedCircuitKey references the incoming Chan/HTLC ID of the Add HTLC
|
||||
// that opened the circuit.
|
||||
//
|
||||
// NOTE: This field is only populated for payment descriptors in the
|
||||
// *local* update log, and if settle/fails have a committed circuit in
|
||||
// the circuit map.
|
||||
ClosedCircuitRef *channeldb.CircuitKey
|
||||
ClosedCircuitKey *channeldb.CircuitKey
|
||||
|
||||
// localOutputIndex is the output index of this HTLc output in the
|
||||
// commitment transaction of the local node.
|
||||
@ -327,12 +327,9 @@ type PaymentDescriptor struct {
|
||||
//
|
||||
// NOTE: The provided `logUpdates` MUST corresponding exactly to either the Adds
|
||||
// or SettleFails in this channel's forwarding package at `height`.
|
||||
func (lc *LightningChannel) PayDescsFromRemoteLogUpdates(height uint64,
|
||||
func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
|
||||
logUpdates []channeldb.LogUpdate) []*PaymentDescriptor {
|
||||
|
||||
lc.RLock()
|
||||
defer lc.RUnlock()
|
||||
|
||||
// Allocate enough space to hold all of the payment descriptors we will
|
||||
// reconstruct, and also the list of pointers that will be returned to
|
||||
// the caller.
|
||||
@ -373,7 +370,7 @@ func (lc *LightningChannel) PayDescsFromRemoteLogUpdates(height uint64,
|
||||
ParentIndex: wireMsg.ID,
|
||||
EntryType: Settle,
|
||||
DestRef: &channeldb.SettleFailRef{
|
||||
Source: lc.ShortChanID(),
|
||||
Source: chanID,
|
||||
Height: height,
|
||||
Index: uint16(i),
|
||||
},
|
||||
@ -385,7 +382,7 @@ func (lc *LightningChannel) PayDescsFromRemoteLogUpdates(height uint64,
|
||||
EntryType: Fail,
|
||||
FailReason: wireMsg.Reason[:],
|
||||
DestRef: &channeldb.SettleFailRef{
|
||||
Source: lc.ShortChanID(),
|
||||
Source: chanID,
|
||||
Height: height,
|
||||
Index: uint16(i),
|
||||
},
|
||||
@ -398,7 +395,7 @@ func (lc *LightningChannel) PayDescsFromRemoteLogUpdates(height uint64,
|
||||
FailCode: wireMsg.FailureCode,
|
||||
ShaOnionBlob: wireMsg.ShaOnionBlob,
|
||||
DestRef: &channeldb.SettleFailRef{
|
||||
Source: lc.ShortChanID(),
|
||||
Source: chanID,
|
||||
Height: height,
|
||||
Index: uint16(i),
|
||||
},
|
||||
@ -2741,9 +2738,9 @@ func (lc *LightningChannel) createCommitDiff(
|
||||
|
||||
// Gather any references for circuits opened by this Add
|
||||
// HTLC.
|
||||
if pd.OpenCircuitRef != nil {
|
||||
if pd.OpenCircuitKey != nil {
|
||||
openCircuitKeys = append(openCircuitKeys,
|
||||
*pd.OpenCircuitRef)
|
||||
*pd.OpenCircuitKey)
|
||||
}
|
||||
|
||||
logUpdates = append(logUpdates, logUpdate)
|
||||
@ -2784,9 +2781,9 @@ func (lc *LightningChannel) createCommitDiff(
|
||||
if pd.DestRef != nil {
|
||||
settleFailRefs = append(settleFailRefs, *pd.DestRef)
|
||||
}
|
||||
if pd.ClosedCircuitRef != nil {
|
||||
if pd.ClosedCircuitKey != nil {
|
||||
closedCircuitKeys = append(closedCircuitKeys,
|
||||
*pd.ClosedCircuitRef)
|
||||
*pd.ClosedCircuitKey)
|
||||
}
|
||||
|
||||
logUpdates = append(logUpdates, logUpdate)
|
||||
@ -2991,8 +2988,16 @@ func (lc *LightningChannel) SignNextCommitment() (lnwire.Sig, []lnwire.Sig, erro
|
||||
// have not received
|
||||
// * RevokeAndAck: if we sent a revocation message that they claim to have
|
||||
// not received
|
||||
//
|
||||
// If we detect a scenario where we need to send a CommitSig+Updates, this
|
||||
// method also returns two sets channeldb.CircuitKeys identifying the circuits
|
||||
// that were opened and closed, respectively, as a result of signing the
|
||||
// previous commitment txn. This allows the link to clear its mailbox of those
|
||||
// circuits in case they are still in memory, and ensure the switch's circuit
|
||||
// map has been updated by deleting the closed circuits.
|
||||
func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
msg *lnwire.ChannelReestablish) ([]lnwire.Message, error) {
|
||||
msg *lnwire.ChannelReestablish) ([]lnwire.Message, []channeldb.CircuitKey,
|
||||
[]channeldb.CircuitKey, error) {
|
||||
|
||||
// We owe them a commitment if they have an un-acked commitment and the
|
||||
// tip of their chain (from our Pov) is equal to what they think their
|
||||
@ -3011,11 +3016,9 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// batch of messages which when applied will kick start the chain
|
||||
// resync.
|
||||
var (
|
||||
updates []lnwire.Message
|
||||
// TODO(conner): uncomment after API exposes these return
|
||||
// variables, this permits compilation in the meantime
|
||||
//openedCircuits []channeldb.CircuitKey
|
||||
//closedCircuits []channeldb.CircuitKey
|
||||
updates []lnwire.Message
|
||||
openedCircuits []channeldb.CircuitKey
|
||||
closedCircuits []channeldb.CircuitKey
|
||||
)
|
||||
|
||||
// If the remote party included the optional fields, then we'll verify
|
||||
@ -3030,7 +3033,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
msg.RemoteCommitTailHeight - 1,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
commitSecretCorrect = bytes.Equal(
|
||||
heightSecret[:], msg.LastRemoteCommitSecret[:],
|
||||
@ -3045,7 +3048,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// In this case, we'll return an error to indicate the remote
|
||||
// node sent us the wrong values. This will let the caller act
|
||||
// accordingly.
|
||||
return nil, ErrInvalidLastCommitSecret
|
||||
return nil, nil, nil, ErrInvalidLastCommitSecret
|
||||
}
|
||||
|
||||
switch {
|
||||
@ -3057,7 +3060,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
localChainTail.height - 1,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
updates = append(updates, revocationMsg)
|
||||
|
||||
@ -3092,7 +3095,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// Otherwise, this is an error and we'll treat it as
|
||||
// such.
|
||||
default:
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -3105,17 +3108,17 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// In this case, we've likely lost data and shouldn't proceed
|
||||
// with channel updates. So we'll return the appropriate error
|
||||
// to signal to the caller the current state.
|
||||
return nil, ErrCommitSyncDataLoss
|
||||
return nil, nil, nil, ErrCommitSyncDataLoss
|
||||
|
||||
// If we don't owe them a revocation, and the height of our commitment
|
||||
// chain reported by the remote party is not equal to our chain tail,
|
||||
// then we cannot sync.
|
||||
case !oweRevocation && localChainTail.height != msg.RemoteCommitTailHeight:
|
||||
if err := lc.channelState.MarkBorked(); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return nil, ErrCannotSyncCommitChains
|
||||
return nil, nil, nil, ErrCannotSyncCommitChains
|
||||
}
|
||||
|
||||
// If we owe them a commitment, then we'll read from disk our
|
||||
@ -3126,7 +3129,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// our states.
|
||||
commitDiff, err := lc.channelState.RemoteCommitChainTip()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
// Next, we'll need to send over any updates we sent as part of
|
||||
@ -3140,23 +3143,21 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
||||
// commitment chain with our local version of their chain.
|
||||
updates = append(updates, commitDiff.CommitSig)
|
||||
|
||||
// TODO(conner): uncomment after API exposes these return
|
||||
// variables, this permits compilation in the meantime
|
||||
//openedCircuits = commitDiff.OpenedCircuitKeys
|
||||
//closedCircuits = commitDiff.ClosedCircuitKeys
|
||||
openedCircuits = commitDiff.OpenedCircuitKeys
|
||||
closedCircuits = commitDiff.ClosedCircuitKeys
|
||||
|
||||
} else if remoteChainTip.height+1 != msg.NextLocalCommitHeight {
|
||||
if err := lc.channelState.MarkBorked(); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
// If we don't owe them a commitment, yet the tip of their
|
||||
// chain isn't one more than the next local commit height they
|
||||
// report, we'll fail the channel.
|
||||
return nil, ErrCannotSyncCommitChains
|
||||
return nil, nil, nil, ErrCannotSyncCommitChains
|
||||
}
|
||||
|
||||
return updates, nil
|
||||
return updates, openedCircuits, closedCircuits, nil
|
||||
}
|
||||
|
||||
// ChanSyncMsg returns the ChannelReestablish message that should be sent upon
|
||||
@ -3859,10 +3860,17 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck, []c
|
||||
// revocation either during the initial session negotiation wherein revocation
|
||||
// windows are extended, or in response to a state update that we initiate. If
|
||||
// successful, then the remote commitment chain is advanced by a single
|
||||
// commitment, and a log compaction is attempted. In addition, a slice of
|
||||
// HTLC's which can be forwarded upstream are returned.
|
||||
// commitment, and a log compaction is attempted.
|
||||
//
|
||||
// The returned values correspond to:
|
||||
// 1. The forwarding package corresponding to the remote commitment height
|
||||
// that was revoked.
|
||||
// 2. The PaymentDescriptor of any Add HTLCs that were locked in by this
|
||||
// revocation.
|
||||
// 3. The PaymentDescriptor of any Settle/Fail HTLCs that were locked in by
|
||||
// this revocation.
|
||||
func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
[]*PaymentDescriptor, error) {
|
||||
*channeldb.FwdPkg, []*PaymentDescriptor, []*PaymentDescriptor, error) {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
@ -3871,10 +3879,10 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
store := lc.channelState.RevocationStore
|
||||
revocation, err := chainhash.NewHash(revMsg.Revocation[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if err := store.AddNextEntry(revocation); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
// Verify that if we use the commitment point computed based off of the
|
||||
@ -3883,7 +3891,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
currentCommitPoint := lc.channelState.RemoteCurrentRevocation
|
||||
derivedCommitPoint := ComputeCommitmentPoint(revMsg.Revocation[:])
|
||||
if !derivedCommitPoint.IsEqual(currentCommitPoint) {
|
||||
return nil, fmt.Errorf("revocation key mismatch")
|
||||
return nil, nil, nil, fmt.Errorf("revocation key mismatch")
|
||||
}
|
||||
|
||||
// Now that we've verified that the prior commitment has been properly
|
||||
@ -4048,7 +4056,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
// commitment chain.
|
||||
err = lc.channelState.AdvanceCommitChainTail(fwdPkg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
// Since they revoked the current lowest height in their commitment
|
||||
@ -4061,10 +4069,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
compactLogs(lc.localUpdateLog, lc.remoteUpdateLog,
|
||||
localChainTail, remoteChainTail)
|
||||
|
||||
htlcsToForward := append(settleFailsToForward,
|
||||
addsToForward...)
|
||||
|
||||
return htlcsToForward, nil
|
||||
return fwdPkg, addsToForward, settleFailsToForward, nil
|
||||
}
|
||||
|
||||
// LoadFwdPkgs loads any pending log updates from disk and returns the payment
|
||||
@ -4116,19 +4121,26 @@ func (lc *LightningChannel) InitNextRevocation(revKey *btcec.PublicKey) error {
|
||||
|
||||
// AddHTLC adds an HTLC to the state machine's local update log. This method
|
||||
// should be called when preparing to send an outgoing HTLC.
|
||||
func (lc *LightningChannel) AddHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, error) {
|
||||
//
|
||||
// The additional openKey argument corresponds to the incoming CircuitKey of the
|
||||
// committed circuit for this HTLC. This value should never be nil.
|
||||
//
|
||||
// NOTE: It is okay for sourceRef to be nil when unit testing the wallet.
|
||||
func (lc *LightningChannel) AddHTLC(htlc *lnwire.UpdateAddHTLC,
|
||||
openKey *channeldb.CircuitKey) (uint64, error) {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
EntryType: Add,
|
||||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
HtlcIndex: lc.localUpdateLog.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
EntryType: Add,
|
||||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
HtlcIndex: lc.localUpdateLog.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
OpenCircuitKey: openKey,
|
||||
}
|
||||
|
||||
// Make sure adding this HTLC won't violate any of the constraints we
|
||||
@ -4176,9 +4188,29 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
|
||||
// SettleHTLC attempts to settle an existing outstanding received HTLC. The
|
||||
// remote log index of the HTLC settled is returned in order to facilitate
|
||||
// creating the corresponding wire message. In the case the supplied preimage
|
||||
// is invalid, an error is returned. Additionally, the value of the settled
|
||||
// HTLC is also returned.
|
||||
func (lc *LightningChannel) SettleHTLC(preimage [32]byte, htlcIndex uint64) error {
|
||||
// is invalid, an error is returned.
|
||||
//
|
||||
// The additional arguments correspond to:
|
||||
// * sourceRef: specifies the location of the Add HTLC within a forwarding
|
||||
// package that this HTLC is settling. Every Settle fails exactly one Add,
|
||||
// so this should never be empty in practice.
|
||||
//
|
||||
// * destRef: specifies the location of the Settle HTLC within another
|
||||
// channel's forwarding package. This value can be nil if the corresponding
|
||||
// Add HTLC was never locked into an outgoing commitment txn, or this
|
||||
// HTLC does not originate as a response from the peer on the outgoing
|
||||
// link, e.g. on-chain resolutions.
|
||||
//
|
||||
// * closeKey: identifies the circuit that should be deleted after this Settle
|
||||
// HTLC is included in a commitment txn. This value should only be nil if
|
||||
// the HTLC was settled locally before committing a circuit to the circuit
|
||||
// map.
|
||||
//
|
||||
// NOTE: It is okay for sourceRef, destRef, and closeKey to be nil when unit
|
||||
// testing the wallet.
|
||||
func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
||||
htlcIndex uint64, sourceRef *channeldb.AddRef,
|
||||
destRef *channeldb.SettleFailRef, closeKey *channeldb.CircuitKey) error {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
@ -4195,11 +4227,14 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte, htlcIndex uint64) erro
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
Amount: htlc.Amount,
|
||||
RPreimage: preimage,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
ParentIndex: htlcIndex,
|
||||
EntryType: Settle,
|
||||
Amount: htlc.Amount,
|
||||
RPreimage: preimage,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
ParentIndex: htlcIndex,
|
||||
EntryType: Settle,
|
||||
SourceRef: sourceRef,
|
||||
DestRef: destRef,
|
||||
ClosedCircuitKey: closeKey,
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendUpdate(pd)
|
||||
@ -4243,7 +4278,28 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
||||
// entry which will remove the target log entry within the next commitment
|
||||
// update. This method is intended to be called in order to cancel in
|
||||
// _incoming_ HTLC.
|
||||
func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte) error {
|
||||
//
|
||||
// The additional arguments correspond to:
|
||||
// * sourceRef: specifies the location of the Add HTLC within a forwarding
|
||||
// package that this HTLC is failing. Every Fail fails exactly one Add, so
|
||||
// this should never be empty in practice.
|
||||
//
|
||||
// * destRef: specifies the location of the Fail HTLC within another channel's
|
||||
// forwarding package. This value can be nil if the corresponding Add HTLC
|
||||
// was never locked into an outgoing commitment txn, or this HTLC does not
|
||||
// originate as a response from the peer on the outgoing link, e.g.
|
||||
// on-chain resolutions.
|
||||
//
|
||||
// * closeKey: identifies the circuit that should be deleted after this Fail
|
||||
// HTLC is included in a commitment txn. This value should only be nil if
|
||||
// the HTLC was failed locally before committing a circuit to the circuit
|
||||
// map.
|
||||
//
|
||||
// NOTE: It is okay for sourceRef, destRef, and closeKey to be nil when unit
|
||||
// testing the wallet.
|
||||
func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
||||
sourceRef *channeldb.AddRef, destRef *channeldb.SettleFailRef,
|
||||
closeKey *channeldb.CircuitKey) error {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
@ -4255,12 +4311,15 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte) error {
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
Amount: htlc.Amount,
|
||||
RHash: htlc.RHash,
|
||||
ParentIndex: htlcIndex,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
EntryType: Fail,
|
||||
FailReason: reason,
|
||||
Amount: htlc.Amount,
|
||||
RHash: htlc.RHash,
|
||||
ParentIndex: htlcIndex,
|
||||
LogIndex: lc.localUpdateLog.logIndex,
|
||||
EntryType: Fail,
|
||||
FailReason: reason,
|
||||
SourceRef: sourceRef,
|
||||
DestRef: destRef,
|
||||
ClosedCircuitKey: closeKey,
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendUpdate(pd)
|
||||
@ -4272,8 +4331,15 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte) error {
|
||||
// inserting an entry which will remove the target log entry within the next
|
||||
// commitment update. This method is intended to be called in order to cancel
|
||||
// in _incoming_ HTLC.
|
||||
//
|
||||
// The additional sourceRef specifies the location of the Add HTLC within a
|
||||
// forwarding package that this HTLC is failing. This value should never be
|
||||
// empty.
|
||||
//
|
||||
// NOTE: It is okay for sourceRef to be nil when unit testing the wallet.
|
||||
func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
||||
failCode lnwire.FailCode, shaOnionBlob [sha256.Size]byte) error {
|
||||
failCode lnwire.FailCode, shaOnionBlob [sha256.Size]byte,
|
||||
sourceRef *channeldb.AddRef) error {
|
||||
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
@ -4292,6 +4358,7 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
||||
EntryType: MalformedFail,
|
||||
FailCode: failCode,
|
||||
ShaOnionBlob: shaOnionBlob,
|
||||
SourceRef: sourceRef,
|
||||
}
|
||||
|
||||
lc.localUpdateLog.appendUpdate(pd)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user