Merge pull request #3390 from joostjager/invoice-circuits

channeldb+cnct+invoices: track invoice htlcs
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2019-09-04 19:51:37 -07:00
commit 7eca7b02a6
26 files changed
+1993 -1010

No files matched your search

+2
View File
@@ -394,6 +394,8 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
Memo: []byte(invoice.Memo),
Receipt: invoice.Receipt,
PaymentRequest: []byte(payReqString),
FinalCltvDelta: int32(payReq.MinFinalCLTVExpiry()),
Expiry: payReq.Expiry(),
Terms: channeldb.ContractTerm{
Value: amtMSat,
PaymentPreimage: paymentPreimage,
+35 -9
View File
@@ -36,13 +36,6 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
settleDate = invoice.SettleDate.Unix()
}
// Expiry time will default to 3600 seconds if not specified
// explicitly.
expiry := int64(decoded.Expiry().Seconds())
// The expiry will default to 9 blocks if not specified explicitly.
cltvExpiry := decoded.MinFinalCLTVExpiry()
// Convert between the `lnrpc` and `routing` types.
routeHints := CreateRPCRouteHints(decoded.RouteHints)
@@ -67,6 +60,38 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
invoice.Terms.State)
}
rpcHtlcs := make([]*lnrpc.InvoiceHTLC, 0, len(invoice.Htlcs))
for key, htlc := range invoice.Htlcs {
var state lnrpc.InvoiceHTLCState
switch htlc.State {
case channeldb.HtlcStateAccepted:
state = lnrpc.InvoiceHTLCState_ACCEPTED
case channeldb.HtlcStateSettled:
state = lnrpc.InvoiceHTLCState_SETTLED
case channeldb.HtlcStateCancelled:
state = lnrpc.InvoiceHTLCState_CANCELLED
default:
return nil, fmt.Errorf("unknown state %v", htlc.State)
}
rpcHtlc := lnrpc.InvoiceHTLC{
ChanId: key.ChanID.ToUint64(),
HtlcIndex: key.HtlcID,
AcceptHeight: int32(htlc.AcceptHeight),
AcceptTime: htlc.AcceptTime.Unix(),
ExpiryHeight: int32(htlc.Expiry),
AmtMsat: uint64(htlc.Amt),
State: state,
}
// Only report resolved times if htlc is resolved.
if htlc.State != channeldb.HtlcStateAccepted {
rpcHtlc.ResolveTime = htlc.ResolveTime.Unix()
}
rpcHtlcs = append(rpcHtlcs, &rpcHtlc)
}
rpcInvoice := &lnrpc.Invoice{
Memo: string(invoice.Memo[:]),
Receipt: invoice.Receipt[:],
@@ -77,8 +102,8 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
Settled: isSettled,
PaymentRequest: paymentRequest,
DescriptionHash: descHash,
Expiry: expiry,
CltvExpiry: cltvExpiry,
Expiry: int64(invoice.Expiry.Seconds()),
CltvExpiry: uint64(invoice.FinalCltvDelta),
FallbackAddr: fallbackAddr,
RouteHints: routeHints,
AddIndex: invoice.AddIndex,
@@ -88,6 +113,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
AmtPaidMsat: int64(invoice.AmtPaid),
AmtPaid: int64(invoice.AmtPaid),
State: state,
Htlcs: rpcHtlcs,
}
if preimage != channeldb.UnknownPreimage {
+697 -546
View File
File diff suppressed because it is too large. Load diff
+36
View File
@@ -2117,6 +2117,42 @@ message Invoice {
The state the invoice is in.
*/
InvoiceState state = 21 [json_name = "state"];
/// List of HTLCs paying to this invoice [EXPERIMENTAL].
repeated InvoiceHTLC htlcs = 22 [json_name = "htlcs"];
}
enum InvoiceHTLCState {
ACCEPTED = 0;
SETTLED = 1;
CANCELLED = 2;
}
/// Details of an HTLC that paid to an invoice
message InvoiceHTLC {
/// Short channel id over which the htlc was received.
uint64 chan_id = 1 [json_name = "chan_id"];
/// Index identifying the htlc on the channel.
uint64 htlc_index = 2 [json_name = "htlc_index"];
/// The amount of the htlc in msat.
uint64 amt_msat = 3 [json_name = "amt_msat"];
/// Block height at which this htlc was accepted.
int32 accept_height = 4 [json_name = "accept_height"];
/// Time at which this htlc was accepted.
int64 accept_time = 5 [json_name = "accept_time"];
/// Time at which this htlc was settled or cancelled.
int64 resolve_time = 6 [json_name = "resolve_time"];
/// Block height at which this htlc expires.
int32 expiry_height = 7 [json_name = "expiry_height"];
/// Current state the htlc is in.
InvoiceHTLCState state = 8 [json_name = "state"];
}
message AddInvoiceResponse {
+61
View File
@@ -2489,9 +2489,70 @@
"state": {
"$ref": "#/definitions/InvoiceInvoiceState",
"description": "*\nThe state the invoice is in."
},
"htlcs": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcInvoiceHTLC"
},
"description": "/ List of HTLCs paying to this invoice [EXPERIMENTAL]."
}
}
},
"lnrpcInvoiceHTLC": {
"type": "object",
"properties": {
"chan_id": {
"type": "string",
"format": "uint64",
"description": "/ Short channel id over which the htlc was received."
},
"htlc_index": {
"type": "string",
"format": "uint64",
"description": "/ Index identifying the htlc on the channel."
},
"amt_msat": {
"type": "string",
"format": "uint64",
"description": "/ The amount of the htlc in msat."
},
"accept_height": {
"type": "integer",
"format": "int32",
"description": "/ Block height at which this htlc was accepted."
},
"accept_time": {
"type": "string",
"format": "int64",
"description": "/ Time at which this htlc was accepted."
},
"resolve_time": {
"type": "string",
"format": "int64",
"description": "/ Time at which this htlc was settled or cancelled."
},
"expiry_height": {
"type": "integer",
"format": "int32",
"description": "/ Block height at which this htlc expires."
},
"state": {
"$ref": "#/definitions/lnrpcInvoiceHTLCState",
"description": "/ Current state the htlc is in."
}
},
"title": "/ Details of an HTLC that paid to an invoice"
},
"lnrpcInvoiceHTLCState": {
"type": "string",
"enum": [
"ACCEPTED",
"SETTLED",
"CANCELLED"
],
"default": "ACCEPTED"
},
"lnrpcLightningAddress": {
"type": "object",
"properties": {