lnwallet: modify ReceiveFailHTLC to return value of HTLC failed

This commit is contained in:
Olaoluwa Osuntokun committed 2017-09-24 20:17:53 -07:00
1 parent f576a74bf6
commit 9164cc218a
2 files changed
+14 -10

No files matched your search

+6 -4
View File
@@ -3152,14 +3152,15 @@ func (lc *LightningChannel) FailHTLC(rHash [32]byte) (uint64, error) {
// ReceiveFailHTLC attempts to cancel a targeted HTLC by its log index,
// inserting an entry which will remove the target log entry within the next
// commitment update. This method should be called in response to the upstream
// party cancelling an outgoing HTLC.
func (lc *LightningChannel) ReceiveFailHTLC(logIndex uint64) error {
// party cancelling an outgoing HTLC. The value of the failed HTLC is returned
// along with an error indicating success.
func (lc *LightningChannel) ReceiveFailHTLC(logIndex uint64) (lnwire.MilliSatoshi, error) {
lc.Lock()
defer lc.Unlock()
htlc := lc.localUpdateLog.lookup(logIndex)
if htlc == nil {
return fmt.Errorf("unable to find HTLC to fail")
return 0, fmt.Errorf("unable to find HTLC to fail")
}
pd := &PaymentDescriptor{
@@ -3172,7 +3173,8 @@ func (lc *LightningChannel) ReceiveFailHTLC(logIndex uint64) error {
lc.remoteUpdateLog.appendUpdate(pd)
lc.availableLocalBalance += pd.Amount
return nil
return htlc.Amount, nil
}
// ChannelPoint returns the outpoint of the original funding transaction which
+8 -6
View File
@@ -506,7 +506,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// 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 {
t.Fatalf("bob unable to process alive's revocation: %v", err)
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))
@@ -1538,7 +1538,7 @@ func TestCancelHTLC(t *testing.T) {
if err != nil {
t.Fatalf("unable to cancel HTLC: %v", err)
}
if err := aliceChannel.ReceiveFailHTLC(htlcCancelIndex); err != nil {
if _, err := aliceChannel.ReceiveFailHTLC(htlcCancelIndex); err != nil {
t.Fatalf("unable to recv htlc cancel: %v", err)
}
@@ -1891,7 +1891,7 @@ func TestUpdateFeeSenderCommits(t *testing.T) {
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alive's revocation: %v", err)
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
}
@@ -2003,7 +2003,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
// Alice receives revokation 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 {
t.Fatalf("bob unable to process alive's revocation: %v", err)
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
// Alice will receive the signature from Bob, which will cover what was
@@ -2030,7 +2030,7 @@ func TestUpdateFeeReceiverCommits(t *testing.T) {
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alive's revocation: %v", err)
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
}
@@ -2170,7 +2170,9 @@ func TestUpdateFeeMultipleUpdates(t *testing.T) {
// Bob receives revocation from Alice.
if _, err := bobChannel.ReceiveRevocation(aliceRevocation); err != nil {
t.Fatalf("bob unable to process alive's revocation: %v", err)
t.Fatalf("bob unable to process alice's revocation: %v", err)
}
}
// TestAddHTLCNegativeBalance tests that if enough HTLC's are added to the
// state machine to drive the balance to zero, then the next HTLC attempted to