channeldb+routing: store all payment htlcs

This commit converts the database structure of a payment so that it can
not just store the last htlc attempt, but all attempts that have been
made. This is a preparation for mpp sending.

In addition to that, we now also persist the fail time of an htlc. In a
later commit, the full failure reason will be added as well.

A key change is made to the control tower interface. Previously the
control tower wasn't aware of individual htlc outcomes. The payment
remained in-flight with the latest attempt recorded, but an outcome was
only set when the payment finished. With this commit, the outcome of
every htlc is expected by the control tower and recorded in the
database.

Co-authored-by: Johan T. Halseth <johanth@gmail.com>
This commit is contained in:
Joost Jager
2020-02-20 18:08:01 +01:00
parent 8558534417
commit 48c0e42c26
10 changed files with 550 additions and 274 deletions

View File

@@ -67,9 +67,10 @@ func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
}
a := &HTLCAttemptInfo{
AttemptID: 44,
SessionKey: priv,
Route: testRoute,
AttemptID: 44,
SessionKey: priv,
Route: testRoute,
AttemptTime: time.Unix(100, 0),
}
return c, a
}
@@ -113,29 +114,30 @@ func TestSentPaymentSerialization(t *testing.T) {
t.Fatalf("unable to serialize info: %v", err)
}
newAttemptInfo, err := deserializeHTLCAttemptInfo(&b)
newWireInfo, err := deserializeHTLCAttemptInfo(&b)
if err != nil {
t.Fatalf("unable to deserialize info: %v", err)
}
newWireInfo.AttemptID = s.AttemptID
// First we verify all the records match up porperly, as they aren't
// able to be properly compared using reflect.DeepEqual.
err = assertRouteEqual(&s.Route, &newAttemptInfo.Route)
err = assertRouteEqual(&s.Route, &newWireInfo.Route)
if err != nil {
t.Fatalf("Routes do not match after "+
"serialization/deserialization: %v", err)
}
// Clear routes to allow DeepEqual to compare the remaining fields.
newAttemptInfo.Route = route.Route{}
newWireInfo.Route = route.Route{}
s.Route = route.Route{}
if !reflect.DeepEqual(s, newAttemptInfo) {
if !reflect.DeepEqual(s, newWireInfo) {
s.SessionKey.Curve = nil
newAttemptInfo.SessionKey.Curve = nil
newWireInfo.SessionKey.Curve = nil
t.Fatalf("Payments do not match after "+
"serialization/deserialization %v vs %v",
spew.Sdump(s), spew.Sdump(newAttemptInfo),
spew.Sdump(s), spew.Sdump(newWireInfo),
)
}
}