mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
bkpr: use pointer for payment_id for channel events
sometimes these are null!
This commit is contained in:
parent
8ec35b7eb1
commit
d943e5e85c
4 changed files with 38 additions and 15 deletions
|
@ -204,7 +204,7 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
|
||||||
ev.fees = AMOUNT_MSAT(0);
|
ev.fees = AMOUNT_MSAT(0);
|
||||||
ev.currency = s.coin_type;
|
ev.currency = s.coin_type;
|
||||||
ev.part_id = 0;
|
ev.part_id = 0;
|
||||||
memset(&ev.payment_id, 0, sizeof(struct sha256));
|
ev.payment_id = NULL;
|
||||||
/* Use current time for this */
|
/* Use current time for this */
|
||||||
ev.timestamp = time_now().ts.tv_sec;
|
ev.timestamp = time_now().ts.tv_sec;
|
||||||
|
|
||||||
|
@ -323,11 +323,12 @@ static const char *parse_and_log_channel_move(struct command *cmd,
|
||||||
struct account *acct;
|
struct account *acct;
|
||||||
const char *err;
|
const char *err;
|
||||||
|
|
||||||
|
e->payment_id = tal(e, struct sha256);
|
||||||
err = json_scan(tmpctx, buf, params,
|
err = json_scan(tmpctx, buf, params,
|
||||||
"{coin_movement:{payment_hash:%}}",
|
"{coin_movement:{payment_hash:%}}",
|
||||||
JSON_SCAN(json_to_sha256, &e->payment_id));
|
JSON_SCAN(json_to_sha256, e->payment_id));
|
||||||
if (err)
|
if (err)
|
||||||
memset(&e->payment_id, 0, sizeof(struct sha256));
|
e->payment_id = tal_free(e->payment_id);
|
||||||
|
|
||||||
err = json_scan(tmpctx, buf, params,
|
err = json_scan(tmpctx, buf, params,
|
||||||
"{coin_movement:{part_id:%}}",
|
"{coin_movement:{part_id:%}}",
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct channel_event {
|
||||||
const char *currency;
|
const char *currency;
|
||||||
|
|
||||||
/* Payment identifier (typically the preimage hash) */
|
/* Payment identifier (typically the preimage hash) */
|
||||||
struct sha256 payment_id;
|
struct sha256 *payment_id;
|
||||||
|
|
||||||
/* Some payments share a payment_id, and are differentiable via id */
|
/* Some payments share a payment_id, and are differentiable via id */
|
||||||
u32 part_id;
|
u32 part_id;
|
||||||
|
|
|
@ -84,7 +84,11 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt
|
||||||
db_col_amount_msat(stmt, "fees", &e->fees);
|
db_col_amount_msat(stmt, "fees", &e->fees);
|
||||||
|
|
||||||
e->currency = db_col_strdup(e, stmt, "currency");
|
e->currency = db_col_strdup(e, stmt, "currency");
|
||||||
db_col_sha256(stmt, "payment_id", &e->payment_id);
|
if (!db_col_is_null(stmt, "payment_id")) {
|
||||||
|
e->payment_id = tal(e, struct sha256);
|
||||||
|
db_col_sha256(stmt, "payment_id", e->payment_id);
|
||||||
|
} else
|
||||||
|
e->payment_id = NULL;
|
||||||
e->part_id = db_col_int(stmt, "part_id");
|
e->part_id = db_col_int(stmt, "part_id");
|
||||||
e->timestamp = db_col_u64(stmt, "timestamp");
|
e->timestamp = db_col_u64(stmt, "timestamp");
|
||||||
|
|
||||||
|
@ -629,7 +633,10 @@ void log_channel_event(struct db *db,
|
||||||
db_bind_amount_msat(stmt, 3, &e->debit);
|
db_bind_amount_msat(stmt, 3, &e->debit);
|
||||||
db_bind_amount_msat(stmt, 4, &e->fees);
|
db_bind_amount_msat(stmt, 4, &e->fees);
|
||||||
db_bind_text(stmt, 5, e->currency);
|
db_bind_text(stmt, 5, e->currency);
|
||||||
db_bind_sha256(stmt, 6, &e->payment_id);
|
if (e->payment_id)
|
||||||
|
db_bind_sha256(stmt, 6, e->payment_id);
|
||||||
|
else
|
||||||
|
db_bind_null(stmt, 6);
|
||||||
db_bind_int(stmt, 7, e->part_id);
|
db_bind_int(stmt, 7, e->part_id);
|
||||||
db_bind_u64(stmt, 8, e->timestamp);
|
db_bind_u64(stmt, 8, e->timestamp);
|
||||||
|
|
||||||
|
@ -956,7 +963,11 @@ void log_chain_event(struct db *db,
|
||||||
db_bind_int(stmt, 7, e->blockheight);
|
db_bind_int(stmt, 7, e->blockheight);
|
||||||
db_bind_txid(stmt, 8, &e->outpoint.txid);
|
db_bind_txid(stmt, 8, &e->outpoint.txid);
|
||||||
db_bind_int(stmt, 9, e->outpoint.n);
|
db_bind_int(stmt, 9, e->outpoint.n);
|
||||||
db_bind_sha256(stmt, 10, e->payment_id);
|
|
||||||
|
if (e->payment_id)
|
||||||
|
db_bind_sha256(stmt, 10, e->payment_id);
|
||||||
|
else
|
||||||
|
db_bind_null(stmt, 10);
|
||||||
|
|
||||||
if (e->spending_txid)
|
if (e->spending_txid)
|
||||||
db_bind_txid(stmt, 11, e->spending_txid);
|
db_bind_txid(stmt, 11, e->spending_txid);
|
||||||
|
|
|
@ -259,7 +259,9 @@ static bool channel_events_eq(struct channel_event *e1, struct channel_event *e2
|
||||||
CHECK(amount_msat_eq(e1->debit, e2->debit));
|
CHECK(amount_msat_eq(e1->debit, e2->debit));
|
||||||
CHECK(amount_msat_eq(e1->fees, e2->fees));
|
CHECK(amount_msat_eq(e1->fees, e2->fees));
|
||||||
CHECK(streq(e1->currency, e2->currency));
|
CHECK(streq(e1->currency, e2->currency));
|
||||||
CHECK(sha256_eq(&e1->payment_id, &e2->payment_id));
|
CHECK((e1->payment_id != NULL) == (e2->payment_id != NULL));
|
||||||
|
if (e1->payment_id)
|
||||||
|
CHECK(sha256_eq(e1->payment_id, e2->payment_id));
|
||||||
CHECK(e1->part_id == e2->part_id);
|
CHECK(e1->part_id == e2->part_id);
|
||||||
CHECK(e1->timestamp == e2->timestamp);
|
CHECK(e1->timestamp == e2->timestamp);
|
||||||
|
|
||||||
|
@ -298,7 +300,8 @@ static struct channel_event *make_channel_event(const tal_t *ctx,
|
||||||
{
|
{
|
||||||
struct channel_event *ev = tal(ctx, struct channel_event);
|
struct channel_event *ev = tal(ctx, struct channel_event);
|
||||||
|
|
||||||
memset(&ev->payment_id, payment_char, sizeof(struct sha256));
|
ev->payment_id = tal(ev, struct sha256);
|
||||||
|
memset(ev->payment_id, payment_char, sizeof(struct sha256));
|
||||||
ev->credit = credit;
|
ev->credit = credit;
|
||||||
ev->debit = debit;
|
ev->debit = debit;
|
||||||
ev->fees = AMOUNT_MSAT(104);
|
ev->fees = AMOUNT_MSAT(104);
|
||||||
|
@ -707,32 +710,35 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p)
|
||||||
db_commit_transaction(db);
|
db_commit_transaction(db);
|
||||||
CHECK_MSG(!db_err, db_err);
|
CHECK_MSG(!db_err, db_err);
|
||||||
|
|
||||||
memset(&ev1.payment_id, 'B', sizeof(struct sha256));
|
ev1.payment_id = tal(ctx, struct sha256);
|
||||||
|
memset(ev1.payment_id, 'B', sizeof(struct sha256));
|
||||||
ev1.credit = AMOUNT_MSAT(100);
|
ev1.credit = AMOUNT_MSAT(100);
|
||||||
ev1.debit = AMOUNT_MSAT(102);
|
ev1.debit = AMOUNT_MSAT(102);
|
||||||
ev1.fees = AMOUNT_MSAT(104);
|
ev1.fees = AMOUNT_MSAT(104);
|
||||||
ev1.currency = "btc";
|
ev1.currency = "btc";
|
||||||
ev1.timestamp = 1919191;
|
ev1.timestamp = 11111;
|
||||||
ev1.part_id = 19;
|
ev1.part_id = 19;
|
||||||
|
|
||||||
/* Passing unknown tags in should be ok */
|
/* Passing unknown tags in should be ok */
|
||||||
ev1.tag = "hello";
|
ev1.tag = "hello";
|
||||||
|
|
||||||
memset(&ev2.payment_id, 'C', sizeof(struct sha256));
|
ev2.payment_id = tal(ctx, struct sha256);
|
||||||
|
memset(ev2.payment_id, 'C', sizeof(struct sha256));
|
||||||
ev2.credit = AMOUNT_MSAT(200);
|
ev2.credit = AMOUNT_MSAT(200);
|
||||||
ev2.debit = AMOUNT_MSAT(202);
|
ev2.debit = AMOUNT_MSAT(202);
|
||||||
ev2.fees = AMOUNT_MSAT(204);
|
ev2.fees = AMOUNT_MSAT(204);
|
||||||
ev2.currency = "brct";
|
ev2.currency = "brct";
|
||||||
ev2.timestamp = 1818181;
|
ev2.timestamp = 22222;
|
||||||
ev2.part_id = 0;
|
ev2.part_id = 0;
|
||||||
ev2.tag = tal_fmt(ctx, "deposit");
|
ev2.tag = tal_fmt(ctx, "deposit");
|
||||||
|
|
||||||
memset(&ev3.payment_id, 'D', sizeof(struct sha256));
|
ev3.payment_id = tal(ctx, struct sha256);
|
||||||
|
memset(ev3.payment_id, 'D', sizeof(struct sha256));
|
||||||
ev3.credit = AMOUNT_MSAT(300);
|
ev3.credit = AMOUNT_MSAT(300);
|
||||||
ev3.debit = AMOUNT_MSAT(302);
|
ev3.debit = AMOUNT_MSAT(302);
|
||||||
ev3.fees = AMOUNT_MSAT(304);
|
ev3.fees = AMOUNT_MSAT(304);
|
||||||
ev3.currency = "brct";
|
ev3.currency = "brct";
|
||||||
ev3.timestamp = 1717171;
|
ev3.timestamp = 33333;
|
||||||
ev3.part_id = 5;
|
ev3.part_id = 5;
|
||||||
ev3.tag = tal_fmt(ctx, "routed");
|
ev3.tag = tal_fmt(ctx, "routed");
|
||||||
|
|
||||||
|
@ -742,6 +748,11 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p)
|
||||||
|
|
||||||
/* log a channel event to a different acct */
|
/* log a channel event to a different acct */
|
||||||
log_channel_event(db, acct2, &ev3);
|
log_channel_event(db, acct2, &ev3);
|
||||||
|
|
||||||
|
/* log a channel event without a payment id */
|
||||||
|
ev3.payment_id = NULL;
|
||||||
|
log_channel_event(db, acct2, &ev3);
|
||||||
|
|
||||||
db_commit_transaction(db);
|
db_commit_transaction(db);
|
||||||
CHECK_MSG(!db_err, db_err);
|
CHECK_MSG(!db_err, db_err);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue