lnwallet: modify SettleHTLC to return value of HTLC settled

This commit adds an additional return value to SettleHTLC in order to
make way for an upcoming change to modify the way bandwidth status from
the link to the switch is reported.
This commit is contained in:
Olaoluwa Osuntokun 2017-09-24 20:17:09 -07:00
parent 2bf8d1b3fb
commit f576a74bf6
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 13 additions and 11 deletions

@ -3049,15 +3049,17 @@ 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.
func (lc *LightningChannel) SettleHTLC(preimage [32]byte) (uint64, error) {
// is invalid, an error is returned. Additionally, the value of the settled
// HTLC is also returned.
func (lc *LightningChannel) SettleHTLC(preimage [32]byte) (uint64,
lnwire.MilliSatoshi, error) {
lc.Lock()
defer lc.Unlock()
paymentHash := sha256.Sum256(preimage[:])
targetHTLCs, ok := lc.rHashMap[paymentHash]
if !ok {
return 0, fmt.Errorf("invalid payment hash(%v)",
return 0, 0, fmt.Errorf("invalid payment hash(%v)",
hex.EncodeToString(paymentHash[:]))
}
targetHTLC := targetHTLCs[0]
@ -3079,7 +3081,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte) (uint64, error) {
}
lc.availableLocalBalance += pd.Amount
return targetHTLC.Index, nil
return targetHTLC.Index, targetHTLC.Amount, nil
}
// ReceiveHTLCSettle attempts to settle an existing outgoing HTLC indexed by an

@ -562,7 +562,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
// HTLC once he learns of the preimage.
var preimage [32]byte
copy(preimage[:], paymentPreimage)
settleIndex, err := bobChannel.SettleHTLC(preimage)
settleIndex, _, err := bobChannel.SettleHTLC(preimage)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -730,7 +730,7 @@ func TestCheckCommitTxSize(t *testing.T) {
for i := 10; i >= 1; i-- {
_, preimage := createHTLC(i, lnwire.MilliSatoshi(1e7))
settleIndex, err := bobChannel.SettleHTLC(preimage)
settleIndex, _, err := bobChannel.SettleHTLC(preimage)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -924,7 +924,7 @@ func TestForceClose(t *testing.T) {
}
// Settle HTLC and sign new commitment.
settleIndex, err := aliceChannel.SettleHTLC(preimage)
settleIndex, _, err := aliceChannel.SettleHTLC(preimage)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1126,7 +1126,7 @@ func TestHTLCDustLimit(t *testing.T) {
}
// Settle HTLC and create a new commitment state.
settleIndex, err := bobChannel.SettleHTLC(preimage)
settleIndex, _, err := bobChannel.SettleHTLC(preimage)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1190,7 +1190,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
if err := forceStateTransition(aliceChannel, bobChannel); err != nil {
t.Fatalf("state transition error: %v", err)
}
settleIndex, err := bobChannel.SettleHTLC(preimage)
settleIndex, _, err := bobChannel.SettleHTLC(preimage)
if err != nil {
t.Fatalf("bob unable to settle inbound htlc: %v", err)
}
@ -1438,7 +1438,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++ {
settleIndex, err := bobChannelNew.SettleHTLC(alicePreimage)
settleIndex, _, err := bobChannelNew.SettleHTLC(alicePreimage)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}
@ -1447,7 +1447,7 @@ func TestStateUpdatePersistence(t *testing.T) {
t.Fatalf("unable to settle htlc: %v", err)
}
}
settleIndex, err := aliceChannelNew.SettleHTLC(bobPreimage)
settleIndex, _, err := aliceChannelNew.SettleHTLC(bobPreimage)
if err != nil {
t.Fatalf("unable to settle htlc: %v", err)
}