wallet: Set the fee to 0 when forward doesn't have out channel with LOCAL_FAILED status

This commit is contained in:
trueptolemy 2019-06-25 00:54:33 +08:00 committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent 2255dd4dda
commit ab60bcab7c

View File

@ -2753,13 +2753,8 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
cur->status = sqlite3_column_int(stmt, 0); cur->status = sqlite3_column_int(stmt, 0);
cur->msat_in = sqlite3_column_amount_msat(stmt, 1); cur->msat_in = sqlite3_column_amount_msat(stmt, 1);
if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) {
cur->msat_out = sqlite3_column_amount_msat(stmt, 2); cur->msat_out = sqlite3_column_amount_msat(stmt, 2);
else {
assert(cur->status == FORWARD_LOCAL_FAILED);
cur->msat_out = AMOUNT_MSAT(0);
}
if (!amount_msat_sub(&cur->fee, cur->msat_in, cur->msat_out)) { if (!amount_msat_sub(&cur->fee, cur->msat_in, cur->msat_out)) {
log_broken(w->log, "Forwarded in %s less than out %s!", log_broken(w->log, "Forwarded in %s less than out %s!",
type_to_string(tmpctx, struct amount_msat, type_to_string(tmpctx, struct amount_msat,
@ -2768,6 +2763,14 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
&cur->msat_out)); &cur->msat_out));
cur->fee = AMOUNT_MSAT(0); cur->fee = AMOUNT_MSAT(0);
} }
}
else {
assert(cur->status == FORWARD_LOCAL_FAILED);
cur->msat_out = AMOUNT_MSAT(0);
/* For this case, this forward_payment doesn't have out channel,
* so the fee should be set as 0.*/
cur->fee = AMOUNT_MSAT(0);
}
if (sqlite3_column_type(stmt, 3) != SQLITE_NULL) { if (sqlite3_column_type(stmt, 3) != SQLITE_NULL) {
cur->payment_hash = tal(ctx, struct sha256_double); cur->payment_hash = tal(ctx, struct sha256_double);
@ -2795,7 +2798,8 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
} }
if (sqlite3_column_type(stmt, 8) != SQLITE_NULL) { if (sqlite3_column_type(stmt, 8) != SQLITE_NULL) {
assert(cur->status == FORWARD_FAILED || cur->status == FORWARD_LOCAL_FAILED); assert(cur->status == FORWARD_FAILED ||
cur->status == FORWARD_LOCAL_FAILED);
cur->failcode = sqlite3_column_int(stmt, 8); cur->failcode = sqlite3_column_int(stmt, 8);
} else { } else {
cur->failcode = 0; cur->failcode = 0;