diff --git a/common/coin_mvt.c b/common/coin_mvt.c index c28d71f62ced..39d203e003e6 100644 --- a/common/coin_mvt.c +++ b/common/coin_mvt.c @@ -9,12 +9,6 @@ #define EXTERNAL "external" -static const char *mvt_types[] = { "chain_mvt", "channel_mvt" }; -const char *mvt_type_str(enum mvt_type type) -{ - return mvt_types[type]; -} - static const char *mvt_tags[] = { "deposit", "withdrawal", @@ -43,62 +37,134 @@ static const char *mvt_tags[] = { "splice", }; +#define PRIMARY_TAG_BITS ((1ULL << MVT_DEPOSIT) | \ + (1ULL << MVT_WITHDRAWAL) | \ + (1ULL << MVT_PENALTY) | \ + (1ULL << MVT_INVOICE) | \ + (1ULL << MVT_ROUTED) | \ + (1ULL << MVT_PUSHED) | \ + (1ULL << MVT_CHANNEL_OPEN) | \ + (1ULL << MVT_CHANNEL_CLOSE) | \ + (1ULL << MVT_CHANNEL_TO_US) | \ + (1ULL << MVT_HTLC_TIMEOUT) | \ + (1ULL << MVT_HTLC_FULFILL) | \ + (1ULL << MVT_HTLC_TX) | \ + (1ULL << MVT_TO_WALLET) | \ + (1ULL << MVT_ANCHOR) | \ + (1ULL << MVT_TO_THEM) | \ + (1ULL << MVT_PENALIZED) | \ + (1ULL << MVT_STOLEN) | \ + (1ULL << MVT_TO_MINER) | \ + (1ULL << MVT_LEASE_FEE) | \ + (1ULL << MVT_CHANNEL_PROPOSED)) + const char *mvt_tag_str(enum mvt_tag tag) { return mvt_tags[tag]; } -enum mvt_tag *new_tag_arr(const tal_t *ctx, enum mvt_tag tag) +static void tag_set(struct mvt_tags *tags, enum mvt_tag tag) { - enum mvt_tag *tags = tal_arr(ctx, enum mvt_tag, 1); - tags[0] = tag; - return tags; + u64 bitnum = tag; + assert(bitnum < NUM_MVT_TAGS); + /* Not already set! */ + assert((tags->bits & (1ULL << bitnum)) == 0); + tags->bits |= (1ULL << bitnum); +} + +static bool mvt_tags_valid(struct mvt_tags tags) +{ + u64 primaries = (tags.bits & PRIMARY_TAG_BITS); + /* Must have exactly one primary. */ + if (!primaries) + return false; + if ((primaries & (primaries - 1)) != 0) + return false; + return tags.bits < (1ULL << NUM_MVT_TAGS); +} + +void set_mvt_account_id(struct mvt_account_id *acct_id, + const struct channel *channel, + const char *account_name TAKES) +{ + if (channel) { + assert(!account_name); + acct_id->channel = channel; + acct_id->alt_account = NULL; + } else { + acct_id->channel = NULL; + acct_id->alt_account = tal_strdup(acct_id, account_name); + } +} + +struct mvt_account_id *new_mvt_account_id(const tal_t *ctx, + const struct channel *channel, + const char *account_name TAKES) +{ + struct mvt_account_id *acct = tal(ctx, struct mvt_account_id); + set_mvt_account_id(acct, channel, account_name); + return acct; } struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx, - const struct channel_id *cid, + const struct channel *channel, const struct sha256 *payment_hash TAKES, - u64 *part_id TAKES, + const u64 *part_id, + const u64 *group_id, + enum coin_mvt_dir direction, struct amount_msat amount, - const enum mvt_tag *tags TAKES, - bool is_credit, + struct mvt_tags tags, struct amount_msat fees) { struct channel_coin_mvt *mvt = tal(ctx, struct channel_coin_mvt); - mvt->chan_id = *cid; + assert(mvt_tags_valid(tags)); + set_mvt_account_id(&mvt->account, channel, NULL); mvt->payment_hash = tal_dup_or_null(mvt, struct sha256, payment_hash); - mvt->part_id = tal_dup_or_null(mvt, u64, part_id); - mvt->tags = tal_dup_talarr(mvt, enum mvt_tag, tags); + if (!part_id) { + assert(!group_id); + mvt->part_and_group = NULL; + } else { + /* Temporary for non-const */ + struct channel_coin_mvt_id *pg; + mvt->part_and_group = pg = tal(mvt, struct channel_coin_mvt_id); + pg->part_id = *part_id; + pg->group_id = *group_id; + } - if (is_credit) { + mvt->tags = tags; + mvt->fees = fees; + switch (direction) { + case COIN_CREDIT: mvt->credit = amount; mvt->debit = AMOUNT_MSAT(0); - } else { + return mvt; + case COIN_DEBIT: mvt->debit = amount; mvt->credit = AMOUNT_MSAT(0); + return mvt; } - mvt->fees = fees; - - return mvt; + abort(); } static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx, + const struct channel *channel, const char *account_name TAKES, const struct bitcoin_txid *tx_txid, const struct bitcoin_outpoint *outpoint, const struct sha256 *payment_hash TAKES, u32 blockheight, - enum mvt_tag *tags, + struct mvt_tags tags, + enum coin_mvt_dir direction, struct amount_msat amount, - bool is_credit, struct amount_sat output_val, u32 out_count) { struct chain_coin_mvt *mvt = tal(ctx, struct chain_coin_mvt); - mvt->account_name = tal_strdup_or_null(mvt, account_name); + assert(mvt_tags_valid(tags)); + set_mvt_account_id(&mvt->account, channel, account_name); mvt->tx_txid = tx_txid; mvt->outpoint = outpoint; mvt->originating_acct = NULL; @@ -111,40 +177,42 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx, mvt->payment_hash = tal_dup_or_null(mvt, struct sha256, payment_hash); mvt->blockheight = blockheight; - mvt->tags = tal_dup_talarr(mvt, enum mvt_tag, tags); + mvt->tags = tags; + mvt->output_val = output_val; + mvt->output_count = out_count; - if (is_credit) { + switch (direction) { + case COIN_CREDIT: mvt->credit = amount; mvt->debit = AMOUNT_MSAT(0); - } else { + return mvt; + case COIN_DEBIT: mvt->debit = amount; mvt->credit = AMOUNT_MSAT(0); + return mvt; } - - mvt->output_val = output_val; - mvt->output_count = out_count; - - return mvt; + abort(); } static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx, - const char *account_name, + const struct channel *channel, + const char *account_name TAKES, const struct bitcoin_txid *tx_txid, const struct bitcoin_outpoint *outpoint, const struct sha256 *payment_hash TAKES, u32 blockheight, - enum mvt_tag *tags TAKES, - struct amount_sat amt_sat, - bool is_credit) + struct mvt_tags tags, + enum coin_mvt_dir direction, + struct amount_sat amt_sat) { struct amount_msat amt_msat; bool ok; ok = amount_sat_to_msat(&amt_msat, amt_sat); assert(ok); - return new_chain_coin_mvt(ctx, account_name, tx_txid, + return new_chain_coin_mvt(ctx, channel, account_name, tx_txid, outpoint, payment_hash, - blockheight, tags, amt_msat, is_credit, + blockheight, tags, direction, amt_msat, /* All amounts that are sat are * on-chain output values */ amt_sat, 0); @@ -155,30 +223,31 @@ struct chain_coin_mvt *new_onchaind_withdraw(const tal_t *ctx, const struct bitcoin_txid *spend_txid, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_chain_coin_mvt_sat(ctx, NULL, spend_txid, + return new_chain_coin_mvt_sat(ctx, NULL, "", spend_txid, outpoint, NULL, blockheight, - take(new_tag_arr(NULL, tag)), - amount, false); + tags, + COIN_DEBIT, amount); } struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_chain_coin_mvt_sat(ctx, NULL, NULL, + return new_chain_coin_mvt_sat(ctx, NULL, "", NULL, outpoint, NULL, blockheight, - take(new_tag_arr(NULL, tag)), - amount, true); + tags, + COIN_CREDIT, amount); } struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, + const char *alt_account, const struct bitcoin_txid *txid, const struct bitcoin_outpoint *out, u32 blockheight, @@ -188,25 +257,24 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx, bool is_splice) { struct chain_coin_mvt *mvt; - enum mvt_tag *tags = new_tag_arr(NULL, CHANNEL_CLOSE); + struct mvt_tags tags; if (is_splice) - tal_arr_expand(&tags, SPLICE); - - mvt = new_chain_coin_mvt(ctx, NULL, txid, - out, NULL, blockheight, - take(tags), - amount, false, - output_val, - output_count); - if (chan_id) - mvt->account_name = fmt_channel_id(mvt, chan_id); - + tags = mk_mvt_tags(MVT_CHANNEL_CLOSE, MVT_SPLICE); + else + tags = mk_mvt_tags(MVT_CHANNEL_CLOSE); + + mvt = new_chain_coin_mvt(ctx, channel, alt_account, txid, + out, NULL, blockheight, + tags, + COIN_DEBIT, amount, + output_val, + output_count); return mvt; } struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, const struct bitcoin_outpoint *out, const struct node_id *peer_id, const struct amount_msat amount, @@ -215,25 +283,25 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx, bool is_leased) { struct chain_coin_mvt *mvt; - - mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, 0, - take(new_tag_arr(NULL, CHANNEL_PROPOSED)), - amount, true, output_val, 0); - mvt->account_name = fmt_channel_id(mvt, chan_id); - mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); + struct mvt_tags tags = tag_to_mvt_tags(MVT_CHANNEL_PROPOSED); /* If we're the opener, add to the tag list */ if (is_opener) - tal_arr_expand(&mvt->tags, OPENER); + tag_set(&tags, MVT_OPENER); if (is_leased) - tal_arr_expand(&mvt->tags, LEASED); + tag_set(&tags, MVT_LEASED); + + mvt = new_chain_coin_mvt(ctx, channel, NULL, NULL, out, NULL, 0, + tags, + COIN_CREDIT, amount, output_val, 0); + mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); return mvt; } struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, const struct bitcoin_outpoint *out, const struct node_id *peer_id, u32 blockheight, @@ -243,19 +311,20 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, bool is_leased) { struct chain_coin_mvt *mvt; - - mvt = new_chain_coin_mvt(ctx, NULL, NULL, out, NULL, blockheight, - take(new_tag_arr(NULL, CHANNEL_OPEN)), amount, - true, output_val, 0); - mvt->account_name = fmt_channel_id(mvt, chan_id); - mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); + struct mvt_tags tags = tag_to_mvt_tags(MVT_CHANNEL_OPEN); /* If we're the opener, add to the tag list */ if (is_opener) - tal_arr_expand(&mvt->tags, OPENER); + tag_set(&tags, MVT_OPENER); if (is_leased) - tal_arr_expand(&mvt->tags, LEASED); + tag_set(&tags, MVT_LEASED); + + mvt = new_chain_coin_mvt(ctx, channel, NULL, NULL, out, NULL, blockheight, + tags, + COIN_CREDIT, amount, + output_val, 0); + mvt->peer_id = tal_dup(mvt, struct node_id, peer_id); return mvt; } @@ -266,11 +335,11 @@ struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx, struct amount_sat amount, const struct sha256 *payment_hash) { - return new_chain_coin_mvt_sat(ctx, NULL, NULL, + return new_chain_coin_mvt_sat(ctx, NULL, "", NULL, outpoint, payment_hash, blockheight, - take(new_tag_arr(NULL, HTLC_FULFILL)), - amount, true); + tag_to_mvt_tags(MVT_HTLC_FULFILL), + COIN_CREDIT, amount); } @@ -282,24 +351,11 @@ struct chain_coin_mvt *new_onchain_htlc_withdraw(const tal_t *ctx, { /* An onchain htlc fulfillment to peer is a *deposit* of * that output into their (external) account */ - return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL, + return new_chain_coin_mvt_sat(ctx, NULL, EXTERNAL, NULL, outpoint, payment_hash, blockheight, - take(new_tag_arr(NULL, HTLC_FULFILL)), - amount, true); -} - -struct chain_coin_mvt *new_coin_external_spend_tags(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - const struct bitcoin_txid *txid, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags TAKES) -{ - return new_chain_coin_mvt(ctx, EXTERNAL, txid, - outpoint, NULL, blockheight, - take(tags), - AMOUNT_MSAT(0), true, amount, 0); + tag_to_mvt_tags(MVT_HTLC_FULFILL), + COIN_CREDIT, amount); } struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx, @@ -307,64 +363,40 @@ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx, const struct bitcoin_txid *txid, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_coin_external_spend_tags(ctx, outpoint, - txid, blockheight, amount, - new_tag_arr(NULL, tag)); -} - -struct chain_coin_mvt *new_coin_external_deposit_tags(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags TAKES) -{ - return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL, outpoint, NULL, - blockheight, take(tags), - amount, true); + return new_chain_coin_mvt(ctx, NULL, EXTERNAL, txid, + outpoint, NULL, blockheight, + tags, + COIN_CREDIT, AMOUNT_MSAT(0), amount, 0); } - struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_chain_coin_mvt_sat(ctx, EXTERNAL, NULL, outpoint, NULL, - blockheight, take(new_tag_arr(NULL, tag)), - amount, true); + return new_chain_coin_mvt_sat(ctx, NULL, EXTERNAL, NULL, outpoint, NULL, + blockheight, tags, + COIN_CREDIT, amount); } bool chain_mvt_is_external(const struct chain_coin_mvt *mvt) { - return streq(mvt->account_name, EXTERNAL); + return mvt->account.alt_account && streq(mvt->account.alt_account, EXTERNAL); } struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_chain_coin_mvt_sat(ctx, WALLET, NULL, + return new_chain_coin_mvt_sat(ctx, NULL, WALLET, NULL, outpoint, NULL, - blockheight, take(new_tag_arr(NULL, tag)), - amount, true); -} - -struct chain_coin_mvt *new_coin_wallet_deposit_tagged(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags TAKES) -{ - return new_chain_coin_mvt_sat(ctx, WALLET, NULL, - outpoint, NULL, - blockheight, - take(tags), - amount, true); + blockheight, tags, + COIN_CREDIT, amount); } struct chain_coin_mvt *new_coin_wallet_withdraw(const tal_t *ctx, @@ -372,106 +404,66 @@ struct chain_coin_mvt *new_coin_wallet_withdraw(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) { - return new_chain_coin_mvt_sat(ctx, WALLET, spend_txid, + return new_chain_coin_mvt_sat(ctx, NULL, WALLET, spend_txid, outpoint, NULL, - blockheight, take(new_tag_arr(NULL, tag)), - amount, false); + blockheight, tags, + COIN_DEBIT, amount); } struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx, - const struct channel_id *cid, + const struct channel *channel, + enum coin_mvt_dir direction, struct amount_msat amount, - enum mvt_tag tag, - bool is_credit) + struct mvt_tags tags) { - return new_channel_coin_mvt(ctx, cid, NULL, - NULL, amount, - take(new_tag_arr(NULL, tag)), is_credit, + return new_channel_coin_mvt(ctx, channel, NULL, + NULL, NULL, direction, amount, + tags, AMOUNT_MSAT(0)); } -struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, - const struct chain_coin_mvt *chain_mvt, - const char *hrp_name TAKES, - u32 timestamp, - struct node_id *node_id) +const char **mvt_tag_strs(const tal_t *ctx, struct mvt_tags tags) { - struct coin_mvt *mvt = tal(ctx, struct coin_mvt); - - mvt->account_id = tal_strdup(mvt, chain_mvt->account_name); - mvt->originating_acct = - tal_strdup_or_null(mvt, chain_mvt->originating_acct); - mvt->hrp_name = tal_strdup(mvt, hrp_name); - mvt->type = CHAIN_MVT; - - mvt->id.tx_txid = chain_mvt->tx_txid; - mvt->id.outpoint = chain_mvt->outpoint; - mvt->id.payment_hash = chain_mvt->payment_hash; - mvt->tags = tal_steal(mvt, chain_mvt->tags); - mvt->credit = chain_mvt->credit; - mvt->debit = chain_mvt->debit; - - mvt->output_val = tal(mvt, struct amount_sat); - *mvt->output_val = chain_mvt->output_val; - mvt->output_count = chain_mvt->output_count; - mvt->fees = NULL; - - mvt->timestamp = timestamp; - mvt->blockheight = chain_mvt->blockheight; - mvt->version = COIN_MVT_VERSION; - mvt->node_id = node_id; - mvt->peer_id = chain_mvt->peer_id; - - return mvt; + const char **strs = tal_arr(ctx, const char *, 1); + + /* There must be exactly one primary */ + assert(mvt_tags_valid(tags)); + + /* We put the *primary* tag first */ + for (size_t i = 0; i < NUM_MVT_TAGS; i++) { + u64 bit = (u64)1 << i; + if ((bit & tags.bits) == 0) + continue; + if (bit & PRIMARY_TAG_BITS) + strs[0] = mvt_tag_str(i); + else + tal_arr_expand(&strs, mvt_tag_str(i)); + } + return strs; } -struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, - const struct channel_coin_mvt *chan_mvt, - const char *hrp_name TAKES, - u32 timestamp, - const struct node_id *node_id TAKES) +/* Parse a single mvt tag. Returns false or populates *tag */ +bool mvt_tag_parse(const char *buf, size_t len, enum mvt_tag *tag) { - struct coin_mvt *mvt = tal(ctx, struct coin_mvt); - - mvt->account_id = fmt_channel_id(mvt, &chan_mvt->chan_id); - /* channel moves don't have external events! */ - mvt->originating_acct = NULL; - mvt->hrp_name = tal_strdup(mvt, hrp_name); - mvt->type = CHANNEL_MVT; - mvt->id.payment_hash = chan_mvt->payment_hash; - mvt->id.part_id = chan_mvt->part_id; - mvt->id.tx_txid = NULL; - mvt->id.outpoint = NULL; - mvt->tags = tal_steal(mvt, chan_mvt->tags); - mvt->credit = chan_mvt->credit; - mvt->debit = chan_mvt->debit; - mvt->output_val = NULL; - mvt->output_count = 0; - mvt->fees = tal(mvt, struct amount_msat); - *mvt->fees = chan_mvt->fees; - mvt->timestamp = timestamp; - mvt->version = COIN_MVT_VERSION; - mvt->node_id = tal_dup(mvt, struct node_id, node_id); - mvt->peer_id = NULL; + for (size_t i = 0; i < NUM_MVT_TAGS; i++) { + const char *name = mvt_tag_str(i); + if (strlen(name) == len && memcmp(buf, name, len) == 0) { + *tag = i; + return true; + } + } - return mvt; + return false; } +/* This is used solely by onchaind. It always uses alt_account, with "" meaning + * the channel itself. */ void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt) { - if (mvt->account_name) { - towire_bool(pptr, true); - towire_wirestring(pptr, mvt->account_name); - } else - towire_bool(pptr, false); - - if (mvt->originating_acct) { - towire_bool(pptr, true); - towire_wirestring(pptr, mvt->originating_acct); - } else - towire_bool(pptr, false); + towire_wirestring(pptr, mvt->account.alt_account); + assert(!mvt->originating_acct); towire_bitcoin_outpoint(pptr, mvt->outpoint); @@ -488,10 +480,7 @@ void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt) towire_bool(pptr, false); towire_u32(pptr, mvt->blockheight); - towire_u32(pptr, tal_count(mvt->tags)); - for (size_t i = 0; i < tal_count(mvt->tags); i++) - towire_u8(pptr, mvt->tags[i]); - + towire_u64(pptr, mvt->tags.bits); towire_amount_msat(pptr, mvt->credit); towire_amount_msat(pptr, mvt->debit); towire_amount_sat(pptr, mvt->output_val); @@ -506,15 +495,8 @@ void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt) void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_mvt *mvt) { - if (fromwire_bool(cursor, max)) { - mvt->account_name = fromwire_wirestring(mvt, cursor, max); - } else - mvt->account_name = NULL; - - if (fromwire_bool(cursor, max)) { - mvt->originating_acct = fromwire_wirestring(mvt, cursor, max); - } else - mvt->originating_acct = NULL; + set_mvt_account_id(&mvt->account, NULL, take(fromwire_wirestring(NULL, cursor, max))); + mvt->originating_acct = NULL; /* Read into non-const version */ struct bitcoin_outpoint *outpoint @@ -530,17 +512,14 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m mvt->tx_txid = NULL; if (fromwire_bool(cursor, max)) { - mvt->payment_hash = tal(mvt, struct sha256); - fromwire_sha256(cursor, max, mvt->payment_hash); + struct sha256 *ph; + mvt->payment_hash = ph = tal(mvt, struct sha256); + fromwire_sha256(cursor, max, ph); } else mvt->payment_hash = NULL; mvt->blockheight = fromwire_u32(cursor, max); - u32 tags_len = fromwire_u32(cursor, max); - mvt->tags = tal_arr(mvt, enum mvt_tag, tags_len); - for (size_t i = 0; i < tags_len; i++) - mvt->tags[i] = fromwire_u8(cursor, max); - + mvt->tags.bits = fromwire_u64(cursor, max); mvt->credit = fromwire_amount_msat(cursor, max); mvt->debit = fromwire_amount_msat(cursor, max); mvt->output_val = fromwire_amount_sat(cursor, max); @@ -553,3 +532,16 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m } else mvt->peer_id = NULL; } + +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag, ...) +{ + va_list ap; + struct mvt_tags ret = { 0 }; + + tag_set(&ret, tag); + va_start(ap, tag); + while ((tag = va_arg(ap, enum mvt_tag)) != 999) + tag_set(&ret, tag); + va_end(ap); + return ret; +} diff --git a/common/coin_mvt.h b/common/coin_mvt.h index 9b34c69a9a38..518190231e4c 100644 --- a/common/coin_mvt.h +++ b/common/coin_mvt.h @@ -9,65 +9,84 @@ #define COIN_MVT_VERSION 2 #define WALLET "wallet" -enum mvt_type { - CHAIN_MVT = 0, - CHANNEL_MVT = 1, -}; - -#define NUM_MVT_TAGS (SPLICE + 1) enum mvt_tag { - DEPOSIT = 0, - WITHDRAWAL = 1, - PENALTY = 2, - INVOICE = 3, - ROUTED = 4, - PUSHED = 5, - CHANNEL_OPEN = 6, - CHANNEL_CLOSE = 7, - CHANNEL_TO_US = 8, - HTLC_TIMEOUT = 9, - HTLC_FULFILL = 10, - HTLC_TX = 11, - TO_WALLET = 12, - IGNORED = 13, - ANCHOR = 14, - TO_THEM = 15, - PENALIZED = 16, - STOLEN = 17, - TO_MINER = 18, - OPENER = 19, - LEASE_FEE = 20, - LEASED = 21, - STEALABLE = 22, - CHANNEL_PROPOSED = 23, - SPLICE = 24, + MVT_DEPOSIT = 0, + MVT_WITHDRAWAL = 1, + MVT_PENALTY = 2, + MVT_INVOICE = 3, + MVT_ROUTED = 4, + MVT_PUSHED = 5, + MVT_CHANNEL_OPEN = 6, + MVT_CHANNEL_CLOSE = 7, + MVT_CHANNEL_TO_US = 8, + MVT_HTLC_TIMEOUT = 9, + MVT_HTLC_FULFILL = 10, + MVT_HTLC_TX = 11, + MVT_TO_WALLET = 12, + MVT_IGNORED = 13, + MVT_ANCHOR = 14, + MVT_TO_THEM = 15, + MVT_PENALIZED = 16, + MVT_STOLEN = 17, + MVT_TO_MINER = 18, + MVT_OPENER = 19, + MVT_LEASE_FEE = 20, + MVT_LEASED = 21, + MVT_STEALABLE = 22, + MVT_CHANNEL_PROPOSED = 23, + MVT_SPLICE = 24, +#define NUM_MVT_TAGS (MVT_SPLICE + 1) }; -struct channel_coin_mvt { - /* account_id */ - struct channel_id chan_id; +struct mvt_tags { + u64 bits; +}; - /* identifier */ - struct sha256 *payment_hash; +enum coin_mvt_dir { + COIN_CREDIT = 1, + COIN_DEBIT = 2, +}; - /* mutli-part payments may share a payment hash, - * so we should also record a 'part-id' for them */ - u64 *part_id; +struct channel_coin_mvt_id { + /* multi-part payments may share a payment hash, + * so we should also record part-id and group-id for them */ + u64 part_id; + u64 group_id; +}; - /* label / tag array */ - enum mvt_tag *tags; +/* Only one of these is set. */ +struct mvt_account_id { + const struct channel *channel; + const char *alt_account; +}; +struct channel_coin_mvt { + /* Common fields */ + struct mvt_account_id account; + struct mvt_tags tags; /* only one or the other */ struct amount_msat credit; struct amount_msat debit; + /* identifier */ + const struct sha256 *payment_hash; + + /* multi-part payments may share a payment hash, + * so we should also record part-id and group-id for them */ + const struct channel_coin_mvt_id *part_and_group; + /* Fees collected (or paid) on this mvt */ struct amount_msat fees; }; struct chain_coin_mvt { /* account_id */ - const char *account_name; + struct mvt_account_id account; + struct mvt_tags tags; + /* only one or the other */ + struct amount_msat credit; + struct amount_msat debit; + const struct bitcoin_txid *tx_txid; const struct bitcoin_outpoint *outpoint; @@ -76,93 +95,53 @@ struct chain_coin_mvt { const struct node_id *peer_id; /* some on-chain movements have a payment hash */ - struct sha256 *payment_hash; - - /* label / tag array */ - enum mvt_tag *tags; + const struct sha256 *payment_hash; /* block this transaction is confirmed in */ u32 blockheight; - /* only one or the other */ - struct amount_msat credit; - struct amount_msat debit; - /* total value of output (useful for tracking external outs) */ struct amount_sat output_val; /* When we pay to external accounts, it's useful * to track which internal account it originated from */ - const char *originating_acct; + const struct mvt_account_id *originating_acct; /* Number of outputs in spending tx; used by the * `channel_close` event */ u32 output_count; }; -/* differs depending on type!? */ -struct mvt_id { - struct sha256 *payment_hash; - u64 *part_id; - const struct bitcoin_txid *tx_txid; - const struct bitcoin_outpoint *outpoint; -}; - -struct coin_mvt { - /* name of 'account': wallet, external, */ - const char *account_id; - - /* Peer that this event occurred with */ - const struct node_id *peer_id; - - /* if account_id is external, the account this 'impacted' */ - const char *originating_acct; - - /* Chain name: BIP 173, except signet lightning-style: tbs not tb */ - const char *hrp_name; - - /* type of movement: channel or chain */ - enum mvt_type type; - - /* identifier */ - struct mvt_id id; - - /* label / tag array */ - enum mvt_tag *tags; +/* Convenience macro for creating tag bitmaps */ +#define mk_mvt_tags(...) mk_mvt_tags_(__VA_ARGS__, 999) +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag, ...); - /* only one or the other */ - struct amount_msat credit; - struct amount_msat debit; +static inline struct mvt_tags tag_to_mvt_tags(enum mvt_tag tag) +{ + struct mvt_tags tags; + tags.bits = ((u64)1) << tag; + return tags; +} - /* Value of the output. May be different than - * our credit/debit amount, eg channel opens */ - struct amount_sat *output_val; - /* Really only needed for channel closes */ - size_t output_count; +/* Useful constructor for mvt_account_id: exactly one of channel/account_name must be NULL */ +void set_mvt_account_id(struct mvt_account_id *acct_id, + const struct channel *channel, + const char *account_name TAKES); - /* Amount of fees collected/paid by channel mvt */ - struct amount_msat *fees; - - u32 timestamp; - u32 blockheight; - - /* version is a counter of the format of the data payload that - * makes up a coin movement */ - u8 version; - - /* node originating this movement */ - struct node_id *node_id; -}; - -enum mvt_tag *new_tag_arr(const tal_t *ctx, enum mvt_tag tag); +/* Allocating version */ +struct mvt_account_id *new_mvt_account_id(const tal_t *ctx, + const struct channel *channel, + const char *account_name TAKES); +/* Either part_id and group_id both NULL, or neither are */ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx, - const struct channel_id *cid, + const struct channel *channel, const struct sha256 *payment_hash TAKES, - u64 *part_id TAKES, + const u64 *part_id, + const u64 *group_id, + enum coin_mvt_dir direction, struct amount_msat amount, - const enum mvt_tag *tags TAKES, - bool is_credit, + struct mvt_tags tags, struct amount_msat fees) NON_NULL_ARGS(2); @@ -171,18 +150,19 @@ struct chain_coin_mvt *new_onchaind_withdraw(const tal_t *ctx, const struct bitcoin_txid *spend_txid, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) NON_NULL_ARGS(2, 3); struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) NON_NULL_ARGS(2); struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, + const char *alt_account, const struct bitcoin_txid *txid, const struct bitcoin_outpoint *out, u32 blockheight, @@ -190,20 +170,20 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx, const struct amount_sat output_val, u32 output_count, bool is_splice) - NON_NULL_ARGS(3, 4); + NON_NULL_ARGS(4, 5); struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, const struct bitcoin_outpoint *out, const struct node_id *peer_id, const struct amount_msat amount, const struct amount_sat output_val, bool is_opener, bool is_leased) - NON_NULL_ARGS(2, 3); + NON_NULL_ARGS(2, 3, 4); struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, - const struct channel_id *chan_id, + const struct channel *channel, const struct bitcoin_outpoint *out, const struct node_id *peer_id, u32 blockheight, @@ -211,7 +191,7 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, const struct amount_sat output_val, bool is_opener, bool is_leased) - NON_NULL_ARGS(2, 3); + NON_NULL_ARGS(2, 3, 4); struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, @@ -231,30 +211,16 @@ struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) NON_NULL_ARGS(2); -struct chain_coin_mvt *new_coin_wallet_deposit_tagged(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags TAKES) - NON_NULL_ARGS(2); struct chain_coin_mvt *new_coin_wallet_withdraw(const tal_t *ctx, const struct bitcoin_txid *spend_txid, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) - NON_NULL_ARGS(2, 3); - -struct chain_coin_mvt *new_coin_external_spend_tags(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - const struct bitcoin_txid *txid, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags) + struct mvt_tags tags) NON_NULL_ARGS(2, 3); struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx, @@ -262,49 +228,31 @@ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx, const struct bitcoin_txid *txid, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) NON_NULL_ARGS(2, 3); -struct chain_coin_mvt *new_coin_external_deposit_tags(const tal_t *ctx, - const struct bitcoin_outpoint *outpoint, - u32 blockheight, - struct amount_sat amount, - enum mvt_tag *tags) - NON_NULL_ARGS(2, 5); - struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx, const struct bitcoin_outpoint *outpoint, u32 blockheight, struct amount_sat amount, - enum mvt_tag tag) + struct mvt_tags tags) NON_NULL_ARGS(2); struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx, - const struct channel_id *cid, + const struct channel *channel, + enum coin_mvt_dir direction, struct amount_msat amount, - enum mvt_tag tag, - bool is_credit) + struct mvt_tags tags) NON_NULL_ARGS(2); -struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, - const struct chain_coin_mvt *chain_mvt, - const char *hrp_name, - u32 timestamp, - struct node_id *node_id) - NON_NULL_ARGS(2, 3); - -struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, - const struct channel_coin_mvt *chan_mvt, - const char *hrp_name, - u32 timestamp, - const struct node_id *node_id) - NON_NULL_ARGS(2, 3, 5); - /* Is this an xternal account? */ bool chain_mvt_is_external(const struct chain_coin_mvt *mvt); -const char *mvt_type_str(enum mvt_type type); const char *mvt_tag_str(enum mvt_tag tag); +const char **mvt_tag_strs(const tal_t *ctx, struct mvt_tags tags); + +/* Parse a single mvt tag. Returns false or populates *tag */ +bool mvt_tag_parse(const char *buf, size_t len, enum mvt_tag *tag); void towire_chain_coin_mvt(u8 **pptr, const struct chain_coin_mvt *mvt); void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_mvt *mvt); diff --git a/common/json_parse.c b/common/json_parse.c index 1d272b1f0c6c..1fb1fa97b87d 100644 --- a/common/json_parse.c +++ b/common/json_parse.c @@ -630,16 +630,7 @@ bool json_to_channel_id(const char *buffer, const jsmntok_t *tok, bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok, enum mvt_tag *tag) { - enum mvt_tag i_tag; - for (size_t i = 0; i < NUM_MVT_TAGS; i++) { - i_tag = (enum mvt_tag) i; - if (json_tok_streq(buffer, tok, mvt_tag_str(i_tag))) { - *tag = i_tag; - return true; - } - } - - return false; + return mvt_tag_parse(buffer + tok->start, tok->end - tok->start, tag); } bool split_tok(const char *buffer, const jsmntok_t *tok, diff --git a/common/test/run-bigsize.c b/common/test/run-bigsize.c index bd709317e220..9b181261e6c6 100644 --- a/common/test/run-bigsize.c +++ b/common/test/run-bigsize.c @@ -78,9 +78,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for fromwire_u8_array */ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-bolt12-offer-decode.c b/common/test/run-bolt12-offer-decode.c index c88a4afdff40..5296e8fd6c22 100644 --- a/common/test/run-bolt12-offer-decode.c +++ b/common/test/run-bolt12-offer-decode.c @@ -57,9 +57,9 @@ struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max /* Generated stub for merkle_tlv */ void merkle_tlv(const struct tlv_field *fields UNNEEDED, struct sha256 *merkle UNNEEDED) { fprintf(stderr, "merkle_tlv called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-bolt12_decode.c b/common/test/run-bolt12_decode.c index 0faa8ccef1fb..ae4cd8b42888 100644 --- a/common/test/run-bolt12_decode.c +++ b/common/test/run-bolt12_decode.c @@ -102,9 +102,9 @@ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr /* Generated stub for merkle_tlv */ void merkle_tlv(const struct tlv_field *fields UNNEEDED, struct sha256 *merkle UNNEEDED) { fprintf(stderr, "merkle_tlv called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-bolt12_merkle-json.c b/common/test/run-bolt12_merkle-json.c index bf6131ec99c5..4c0910d3f57f 100644 --- a/common/test/run-bolt12_merkle-json.c +++ b/common/test/run-bolt12_merkle-json.c @@ -24,9 +24,9 @@ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, /* Generated stub for fromwire_node_id */ void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "fromwire_node_id called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-bolt12_period.c b/common/test/run-bolt12_period.c index a87ecb169841..514e47fe734f 100644 --- a/common/test/run-bolt12_period.c +++ b/common/test/run-bolt12_period.c @@ -105,9 +105,9 @@ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr /* Generated stub for merkle_tlv */ void merkle_tlv(const struct tlv_field *fields UNNEEDED, struct sha256 *merkle UNNEEDED) { fprintf(stderr, "merkle_tlv called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-codex32.c b/common/test/run-codex32.c index 78a18da7651b..2aed32315799 100644 --- a/common/test/run-codex32.c +++ b/common/test/run-codex32.c @@ -77,9 +77,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for fromwire_u8_array */ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-coin_mvt.c b/common/test/run-coin_mvt.c new file mode 100644 index 000000000000..26128d70bbe9 --- /dev/null +++ b/common/test/run-coin_mvt.c @@ -0,0 +1,196 @@ +#include "config.h" +#include "../coin_mvt.c" +#include +#include +#include + +/* AUTOGENERATED MOCKS START */ +/* Generated stub for amount_asset_is_main */ +bool amount_asset_is_main(struct amount_asset *asset UNNEEDED) +{ fprintf(stderr, "amount_asset_is_main called!\n"); abort(); } +/* Generated stub for amount_asset_to_sat */ +struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED) +{ fprintf(stderr, "amount_asset_to_sat called!\n"); abort(); } +/* Generated stub for amount_feerate */ + bool amount_feerate(u32 *feerate UNNEEDED, struct amount_sat fee UNNEEDED, size_t weight UNNEEDED) +{ fprintf(stderr, "amount_feerate called!\n"); abort(); } +/* Generated stub for amount_sat */ +struct amount_sat amount_sat(u64 satoshis UNNEEDED) +{ fprintf(stderr, "amount_sat called!\n"); abort(); } +/* Generated stub for amount_sat_add */ + bool amount_sat_add(struct amount_sat *val UNNEEDED, + struct amount_sat a UNNEEDED, + struct amount_sat b UNNEEDED) +{ fprintf(stderr, "amount_sat_add called!\n"); abort(); } +/* Generated stub for amount_sat_eq */ +bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED) +{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); } +/* Generated stub for amount_sat_greater_eq */ +bool amount_sat_greater_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED) +{ fprintf(stderr, "amount_sat_greater_eq called!\n"); abort(); } +/* Generated stub for amount_sat_sub */ + bool amount_sat_sub(struct amount_sat *val UNNEEDED, + struct amount_sat a UNNEEDED, + struct amount_sat b UNNEEDED) +{ fprintf(stderr, "amount_sat_sub called!\n"); abort(); } +/* Generated stub for amount_sat_to_asset */ +struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u8 *asset UNNEEDED) +{ fprintf(stderr, "amount_sat_to_asset called!\n"); abort(); } +/* Generated stub for amount_sat_to_msat */ + bool amount_sat_to_msat(struct amount_msat *msat UNNEEDED, + struct amount_sat sat UNNEEDED) +{ fprintf(stderr, "amount_sat_to_msat called!\n"); abort(); } +/* Generated stub for amount_tx_fee */ +struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED) +{ fprintf(stderr, "amount_tx_fee called!\n"); abort(); } +/* Generated stub for fromwire */ +const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED) +{ fprintf(stderr, "fromwire called!\n"); abort(); } +/* Generated stub for fromwire_amount_msat */ +struct amount_msat fromwire_amount_msat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_amount_msat called!\n"); abort(); } +/* Generated stub for fromwire_amount_sat */ +struct amount_sat fromwire_amount_sat(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_amount_sat called!\n"); abort(); } +/* Generated stub for fromwire_bool */ +bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_bool called!\n"); abort(); } +/* Generated stub for fromwire_fail */ +void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_fail called!\n"); abort(); } +/* Generated stub for fromwire_node_id */ +void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED) +{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); } +/* Generated stub for fromwire_secp256k1_ecdsa_signature */ +void fromwire_secp256k1_ecdsa_signature(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, + secp256k1_ecdsa_signature *signature UNNEEDED) +{ fprintf(stderr, "fromwire_secp256k1_ecdsa_signature called!\n"); abort(); } +/* Generated stub for fromwire_sha256 */ +void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sha256 *sha256 UNNEEDED) +{ fprintf(stderr, "fromwire_sha256 called!\n"); abort(); } +/* Generated stub for fromwire_tal_arrn */ +u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED, + const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED) +{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); } +/* Generated stub for fromwire_u32 */ +u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); } +/* Generated stub for fromwire_u64 */ +u64 fromwire_u64(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_u64 called!\n"); abort(); } +/* Generated stub for fromwire_u8 */ +u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } +/* Generated stub for fromwire_u8_array */ +void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) +{ fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } +/* Generated stub for fromwire_wirestring */ +char *fromwire_wirestring(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *max UNNEEDED) +{ fprintf(stderr, "fromwire_wirestring called!\n"); abort(); } +/* Generated stub for towire */ +void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED) +{ fprintf(stderr, "towire called!\n"); abort(); } +/* Generated stub for towire_amount_msat */ +void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED) +{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); } +/* Generated stub for towire_amount_sat */ +void towire_amount_sat(u8 **pptr UNNEEDED, const struct amount_sat sat UNNEEDED) +{ fprintf(stderr, "towire_amount_sat called!\n"); abort(); } +/* Generated stub for towire_bool */ +void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED) +{ fprintf(stderr, "towire_bool called!\n"); abort(); } +/* Generated stub for towire_node_id */ +void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) +{ fprintf(stderr, "towire_node_id called!\n"); abort(); } +/* Generated stub for towire_secp256k1_ecdsa_signature */ +void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED, + const secp256k1_ecdsa_signature *signature UNNEEDED) +{ fprintf(stderr, "towire_secp256k1_ecdsa_signature called!\n"); abort(); } +/* Generated stub for towire_sha256 */ +void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED) +{ fprintf(stderr, "towire_sha256 called!\n"); abort(); } +/* Generated stub for towire_u32 */ +void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED) +{ fprintf(stderr, "towire_u32 called!\n"); abort(); } +/* Generated stub for towire_u64 */ +void towire_u64(u8 **pptr UNNEEDED, u64 v UNNEEDED) +{ fprintf(stderr, "towire_u64 called!\n"); abort(); } +/* Generated stub for towire_u8 */ +void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED) +{ fprintf(stderr, "towire_u8 called!\n"); abort(); } +/* Generated stub for towire_u8_array */ +void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED) +{ fprintf(stderr, "towire_u8_array called!\n"); abort(); } +/* Generated stub for towire_wirestring */ +void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED) +{ fprintf(stderr, "towire_wirestring called!\n"); abort(); } +/* AUTOGENERATED MOCKS END */ + +static bool mvt_tag_is_primary(enum mvt_tag tag) +{ + switch (tag) { + case MVT_DEPOSIT: + return true; + case MVT_WITHDRAWAL: + return true; + case MVT_PENALTY: + return true; + case MVT_INVOICE: + return true; + case MVT_ROUTED: + return true; + case MVT_PUSHED: + return true; + case MVT_CHANNEL_OPEN: + return true; + case MVT_CHANNEL_CLOSE: + return true; + case MVT_CHANNEL_TO_US: + return true; + case MVT_HTLC_TIMEOUT: + return true; + case MVT_HTLC_FULFILL: + return true; + case MVT_HTLC_TX: + return true; + case MVT_TO_WALLET: + return true; + case MVT_IGNORED: + return false; + case MVT_ANCHOR: + return true; + case MVT_TO_THEM: + return true; + case MVT_PENALIZED: + return true; + case MVT_STOLEN: + return true; + case MVT_TO_MINER: + return true; + case MVT_OPENER: + return false; + case MVT_LEASE_FEE: + return true; + case MVT_LEASED: + return false; + case MVT_STEALABLE: + return false; + case MVT_CHANNEL_PROPOSED: + return true; + case MVT_SPLICE: + return false; + } + abort(); +} + +int main(int argc, char *argv[]) +{ + common_setup(argv[0]); + for (size_t i = 0; i < NUM_MVT_TAGS; i++) { + if (mvt_tag_is_primary(i)) + assert((1ULL << i) & PRIMARY_TAG_BITS); + else + assert(((1ULL << i) & PRIMARY_TAG_BITS) == 0); + } + common_shutdown(); +} diff --git a/common/test/run-json_scan.c b/common/test/run-json_scan.c index 46ccee8e9f99..a80dad990606 100644 --- a/common/test/run-json_scan.c +++ b/common/test/run-json_scan.c @@ -72,9 +72,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) /* Generated stub for fromwire_u8_array */ void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED) { fprintf(stderr, "fromwire_u8_array called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for node_id_from_hexstr */ bool node_id_from_hexstr(const char *str UNNEEDED, size_t slen UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "node_id_from_hexstr called!\n"); abort(); } diff --git a/common/test/run-onion-test-vector.c b/common/test/run-onion-test-vector.c index 130de79bb01d..064537109138 100644 --- a/common/test/run-onion-test-vector.c +++ b/common/test/run-onion-test-vector.c @@ -82,9 +82,9 @@ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *record UNNEEDED, struct tlv_field **fields UNNEEDED, const u64 *extra_types UNNEEDED, size_t *err_off UNNEEDED, u64 *err_type UNNEEDED) { fprintf(stderr, "fromwire_tlv called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for new_onionreply */ struct onionreply *new_onionreply(const tal_t *ctx UNNEEDED, const u8 *contents TAKES UNNEEDED) { fprintf(stderr, "new_onionreply called!\n"); abort(); } diff --git a/common/test/run-route_blinding_onion_test.c b/common/test/run-route_blinding_onion_test.c index 9c554ebd1bfa..0dfc0d23ed21 100644 --- a/common/test/run-route_blinding_onion_test.c +++ b/common/test/run-route_blinding_onion_test.c @@ -29,9 +29,9 @@ void fromwire_sciddir_or_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sciddir_or_pubkey *sciddpk UNNEEDED) { fprintf(stderr, "fromwire_sciddir_or_pubkey called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* Generated stub for new_onionreply */ struct onionreply *new_onionreply(const tal_t *ctx UNNEEDED, const u8 *contents TAKES UNNEEDED) { fprintf(stderr, "new_onionreply called!\n"); abort(); } diff --git a/common/test/run-route_blinding_test.c b/common/test/run-route_blinding_test.c index 3358319dfae3..799c540ef9bb 100644 --- a/common/test/run-route_blinding_test.c +++ b/common/test/run-route_blinding_test.c @@ -17,9 +17,6 @@ #include /* AUTOGENERATED MOCKS START */ -/* Generated stub for fmt_channel_id */ -char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) -{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fromwire_channel_id */ bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) diff --git a/common/test/run-splice_script.c b/common/test/run-splice_script.c index 0494adc86a6d..c3bd63fcb2fc 100644 --- a/common/test/run-splice_script.c +++ b/common/test/run-splice_script.c @@ -35,9 +35,9 @@ void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "command_log called!\n"); abort(); } -/* Generated stub for mvt_tag_str */ -const char *mvt_tag_str(enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); } +/* Generated stub for mvt_tag_parse */ +bool mvt_tag_parse(const char *buf UNNEEDED, size_t len UNNEEDED, enum mvt_tag *tag UNNEEDED) +{ fprintf(stderr, "mvt_tag_parse called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ static void set_node_id(struct splice_script_chan *chan, const char *hexstr) diff --git a/db/bindings.c b/db/bindings.c index 9107bc5c28bd..63a224587d86 100644 --- a/db/bindings.c +++ b/db/bindings.c @@ -227,15 +227,15 @@ void db_bind_psbt(struct db_stmt *stmt, const struct wally_psbt *psbt) } void db_bind_amount_msat(struct db_stmt *stmt, - const struct amount_msat *msat) + struct amount_msat msat) { - db_bind_u64(stmt, msat->millisatoshis); /* Raw: low level function */ + db_bind_u64(stmt, msat.millisatoshis); /* Raw: low level function */ } void db_bind_amount_sat(struct db_stmt *stmt, - const struct amount_sat *sat) + struct amount_sat sat) { - db_bind_u64(stmt, sat->satoshis); /* Raw: low level function */ + db_bind_u64(stmt, sat.satoshis); /* Raw: low level function */ } void db_bind_json_escape(struct db_stmt *stmt, diff --git a/db/bindings.h b/db/bindings.h index c4cbe707d921..910b07a319e0 100644 --- a/db/bindings.h +++ b/db/bindings.h @@ -46,9 +46,9 @@ void db_bind_timeabs(struct db_stmt *stmt, struct timeabs t); void db_bind_tx(struct db_stmt *stmt, const struct wally_tx *tx); void db_bind_psbt(struct db_stmt *stmt, const struct wally_psbt *psbt); void db_bind_amount_msat(struct db_stmt *stmt, - const struct amount_msat *msat); + struct amount_msat msat); void db_bind_amount_sat(struct db_stmt *stmt, - const struct amount_sat *sat); + struct amount_sat sat); void db_bind_json_escape(struct db_stmt *stmt, const struct json_escape *esc); void db_bind_onionreply(struct db_stmt *stmt, diff --git a/db/utils.c b/db/utils.c index b73fda3964e3..70389907a251 100644 --- a/db/utils.c +++ b/db/utils.c @@ -153,8 +153,7 @@ bool db_query_prepared_canfail(struct db_stmt *stmt) void db_query_prepared(struct db_stmt *stmt) { if (!db_query_prepared_canfail(stmt)) - db_fatal(stmt->db, "query failed: %s: %s", - stmt->location, stmt->query->query); + db_fatal(stmt->db, "query failed: %s", stmt->error); } bool db_step(struct db_stmt *stmt) diff --git a/doc/developers-guide/deprecated-features.md b/doc/developers-guide/deprecated-features.md index 2ed1fb06e924..1ac420c86865 100644 --- a/doc/developers-guide/deprecated-features.md +++ b/doc/developers-guide/deprecated-features.md @@ -18,6 +18,7 @@ hidden: false | listpeerchannels.max_total_htlc_in_msat | Field | v25.02 | v26.03 | Use our_max_total_htlc_out_msat | | wait.details | Field | v25.05 | v26.06 | Use subsystem-specific object instead | | channel_state_changed.old_state.unknown | Notification Field | v25.05 | v26.03 | Value "unknown" is deprecated: field will be omitted instead | +| coin_movement.tags | Notification Field | v25.09 | v26.09 | Use `primary_tag` (first tag) and `extra_tags` instead | Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported. diff --git a/doc/developers-guide/plugin-development/event-notifications.md b/doc/developers-guide/plugin-development/event-notifications.md index ad6f2756011e..09bbf40d2a36 100644 --- a/doc/developers-guide/plugin-development/event-notifications.md +++ b/doc/developers-guide/plugin-development/event-notifications.md @@ -333,12 +333,14 @@ A notification for topic `coin_movement` is sent to record the movement of coins "vout":1, // (`chain_mvt` only) "payment_hash": "xxx", // (either type, optional on both) "part_id": 0, // (`channel_mvt` only, optional) + "group_id": 0, // (`channel_mvt` only, optional) "credit_msat":2000000000, "debit_msat":0, "output_msat": 2000000000, // ('chain_mvt' only) "output_count": 2, // ('chain_mvt' only, typically only channel closes) "fees_msat": 382, // ('channel_mvt' only) - "tags": ["deposit"], + "primary_tag": "deposit", + "extra_tags": [], "blockheight":102, // 'chain_mvt' only "timestamp":1585948198, "coin_type":"bc" @@ -364,7 +366,7 @@ _Only_ tagged on external events (deposits/withdrawals to an external party). `payment_hash` is the hash of the preimage used to move this payment. Only present for HTLC mediated moves (both `chain_mvt` and `channel_mvt`) A `chain_mvt` will have a `payment_hash` iff it's recording an htlc that was fulfilled onchain. -`part_id` is an identifier for parts of a multi-part payment. useful for aggregating payments for an invoice or to indicate why a payment hash appears multiple times. `channel_mvt` only +`part_id` and `group_id` are identifiers for parts of a multi-part payment. useful for aggregating payments for an invoice or to indicate why a payment hash appears multiple times. `channel_mvt` only `credit` and `debit` are millisatoshi denominated amounts of the fund movement. A 'credit' is funds deposited into an account; a `debit` is funds withdrawn. @@ -375,7 +377,7 @@ _Only_ tagged on external events (deposits/withdrawals to an external party). `fees` is an HTLC annotation for the amount of fees either paid or earned. For "invoice" tagged events, the fees are the total fees paid to send that payment. The end amount can be found by subtracting the total fees from the `debited` amount. For "routed" tagged events, both the debit/credit contain fees. Technically routed debits are the 'fee generating' event, however we include them on routed credits as well. -`tag` is a movement descriptor. Current tags are as follows: +`primary_tag` is a movement descriptor. Current primary tags are as follows: - `deposit`: funds deposited - `withdrawal`: funds withdrawn @@ -390,15 +392,21 @@ _Only_ tagged on external events (deposits/withdrawals to an external party). - `htlc_fulfill`: on-chian htlc fulfill output - `htlc_tx`: on-chain htlc tx has happened - `to_wallet`: output being spent into our wallet -- `ignored`: output is being ignored - `anchor`: an anchor output - `to_them`: output intended to peer's wallet - `penalized`: output we've 'lost' due to a penalty (failed cheat attempt) - `stolen`: output we've 'lost' due to peer's cheat - `to_miner`: output we've burned to miner (OP_RETURN) -- `opener`: tags channel_open, we are the channel opener - `lease_fee`: amount paid as lease fee -- `leased`: tags channel_open, channel contains leased funds +- `channel_proposed`: a zero-conf channel + +`extra_tags` is zero or more additional tags. Current extra tags are as follows: + +- `ignored`: output is being ignored +- `opener`: tags `channel_open` or `channel_proposed`, we are the channel opener +- `stealable`: funds can be taken by the other party +- `leased`: tags `channel_open` or `channel_proposed`, channel contains leased funds +- `splice`: a channel close due to splice operation. `blockheight` is the block the txid is included in. `channel_mvt`s will be null, so will the blockheight for withdrawals to external parties (we issue these events when we send the tx containing them, before they're included in the chain). diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c index 05c0b81aa620..dd22ccadbd64 100644 --- a/lightningd/chaintopology.c +++ b/lightningd/chaintopology.c @@ -882,7 +882,7 @@ static void record_wallet_spend(struct lightningd *ld, notify_chain_mvt(ld, new_coin_wallet_withdraw(tmpctx, txid, outpoint, tx_blockheight, - utxo->amount, WITHDRAWAL)); + utxo->amount, mk_mvt_tags(MVT_WITHDRAWAL))); } /** diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 337f8f21ab38..1d0f6df7966a 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -951,13 +951,15 @@ static void channel_record_splice(struct channel *channel, struct amount_msat orig_our_msats, struct amount_sat orig_funding_sats, struct bitcoin_outpoint *funding, - u32 blockheight, struct bitcoin_txid *txid, const struct channel_inflight *inflight) + u32 blockheight, + const struct bitcoin_txid *txid, + const struct channel_inflight *inflight) { struct chain_coin_mvt *mvt; u32 output_count; output_count = inflight->funding_psbt->num_outputs; - mvt = new_coin_channel_close(tmpctx, &channel->cid, + mvt = new_coin_channel_close(tmpctx, channel, NULL, txid, funding, blockheight, @@ -993,7 +995,7 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p /* If it's not in a block yet, send a proposal */ if (blockheight > 0) mvt = new_coin_channel_open(tmpctx, - &channel->cid, + channel, &channel->funding, &channel->peer->id, blockheight, @@ -1003,7 +1005,7 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p is_leased); else mvt = new_coin_channel_open_proposed(tmpctx, - &channel->cid, + channel, &channel->funding, &channel->peer->id, start_balance, @@ -1016,10 +1018,12 @@ void channel_record_open(struct channel *channel, u32 blockheight, bool record_p /* If we pushed sats, *now* record them */ if (is_pushed && record_push) notify_channel_mvt(channel->peer->ld, - new_coin_channel_push(tmpctx, &channel->cid, + new_coin_channel_push(tmpctx, channel, + channel->opener == REMOTE ? COIN_CREDIT : COIN_DEBIT, channel->push, - is_leased ? LEASE_FEE : PUSHED, - channel->opener == REMOTE)); + is_leased + ? mk_mvt_tags(MVT_LEASE_FEE) + : mk_mvt_tags(MVT_PUSHED))); } void lockin_has_completed(struct channel *channel, bool record_push) diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c index df91cabb6a1b..68bf42d9e25b 100644 --- a/lightningd/coin_mvts.c +++ b/lightningd/coin_mvts.c @@ -6,42 +6,20 @@ #include -void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt) -{ - const struct coin_mvt *cm; - u32 timestamp; - - timestamp = time_now().ts.tv_sec; - cm = finalize_channel_mvt(mvt, mvt, chainparams->lightning_hrp, - timestamp, &ld->our_nodeid); - - notify_coin_mvt(ld, cm); -} - -void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt) -{ - const struct coin_mvt *cm; - u32 timestamp; - - timestamp = time_now().ts.tv_sec; - cm = finalize_chain_mvt(mvt, mvt, chainparams->lightning_hrp, - timestamp, &ld->our_nodeid); - notify_coin_mvt(ld, cm); -} - struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx, - struct htlc_in *hin, - struct channel *channel) + const struct htlc_in *hin, + const struct channel *channel) { - return new_channel_coin_mvt(ctx, &channel->cid, - &hin->payment_hash, NULL, - hin->msat, new_tag_arr(ctx, INVOICE), - true, AMOUNT_MSAT(0)); + return new_channel_coin_mvt(ctx, channel, + &hin->payment_hash, NULL, NULL, + COIN_CREDIT, hin->msat, + mk_mvt_tags(MVT_INVOICE), + AMOUNT_MSAT(0)); } struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx, - struct htlc_in *hin, - struct channel *channel) + const struct htlc_in *hin, + const struct channel *channel) { struct amount_msat fees_collected; @@ -52,30 +30,34 @@ struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx, hin->payload->amt_to_forward)) return NULL; - return new_channel_coin_mvt(ctx, &channel->cid, - &hin->payment_hash, NULL, - hin->msat, new_tag_arr(ctx, ROUTED), - true, fees_collected); + return new_channel_coin_mvt(ctx, channel, + &hin->payment_hash, NULL, NULL, + COIN_CREDIT, hin->msat, + mk_mvt_tags(MVT_ROUTED), + fees_collected); } struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx, - struct htlc_out *hout, - struct channel *channel) + const struct htlc_out *hout, + const struct channel *channel) { - return new_channel_coin_mvt(ctx, &channel->cid, - &hout->payment_hash, &hout->partid, - hout->msat, new_tag_arr(ctx, INVOICE), - false, hout->fees); + return new_channel_coin_mvt(ctx, channel, + &hout->payment_hash, + &hout->partid, + &hout->groupid, + COIN_DEBIT, hout->msat, + mk_mvt_tags(MVT_INVOICE), + hout->fees); } struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx, - struct htlc_out *hout, - struct channel *channel) + const struct htlc_out *hout, + const struct channel *channel) { - return new_channel_coin_mvt(ctx, &channel->cid, - &hout->payment_hash, NULL, - hout->msat, new_tag_arr(ctx, ROUTED), - false, + return new_channel_coin_mvt(ctx, channel, + &hout->payment_hash, NULL, NULL, + COIN_DEBIT, hout->msat, + mk_mvt_tags(MVT_ROUTED), hout->fees); } diff --git a/lightningd/coin_mvts.h b/lightningd/coin_mvts.h index 90db53178c74..8d7613d822e3 100644 --- a/lightningd/coin_mvts.h +++ b/lightningd/coin_mvts.h @@ -20,21 +20,18 @@ struct balance_snapshot { struct account_balance **accts; }; -void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt); -void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt); - struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx, - struct htlc_in *hin, - struct channel *channel); + const struct htlc_in *hin, + const struct channel *channel); struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx, - struct htlc_in *hin, - struct channel *channel); + const struct htlc_in *hin, + const struct channel *channel); struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx, - struct htlc_out *hout, - struct channel *channel); + const struct htlc_out *hout, + const struct channel *channel); struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx, - struct htlc_out *hout, - struct channel *channel); + const struct htlc_out *hout, + const struct channel *channel); void send_account_balance_snapshot(struct lightningd *ld); #endif /* LIGHTNING_LIGHTNINGD_COIN_MVTS_H */ diff --git a/lightningd/notification.c b/lightningd/notification.c index 1e4a58aa5474..cd04ee219805 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -445,90 +445,129 @@ void notify_sendpay_failure(struct lightningd *ld, notify_send(ld, n); } -static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type, - const struct mvt_id *id) -{ - switch (mvt_type) { - case CHAIN_MVT: - /* some 'journal entries' don't have a txid */ - if (id->tx_txid) - json_add_string(stream, "txid", - fmt_bitcoin_txid(tmpctx, - id->tx_txid)); - /* some chain ledger entries aren't associated with a utxo - * e.g. journal updates (due to penalty/state loss) and - * chain_fee entries */ - if (id->outpoint) { - json_add_string(stream, "utxo_txid", - fmt_bitcoin_txid(tmpctx, - &id->outpoint->txid)); - json_add_u32(stream, "vout", id->outpoint->n); - } - - /* on-chain htlcs include a payment hash */ - if (id->payment_hash) - json_add_sha256(stream, "payment_hash", id->payment_hash); - return; - case CHANNEL_MVT: - /* push funding / leases don't have a payment_hash */ - if (id->payment_hash) - json_add_sha256(stream, "payment_hash", id->payment_hash); - if (id->part_id) - json_add_u64(stream, "part_id", *id->part_id); - return; - } - abort(); -} - -static void coin_movement_notification_serialize(struct json_stream *stream, - const struct coin_mvt *mvt) -{ - json_add_num(stream, "version", mvt->version); - json_add_node_id(stream, "node_id", mvt->node_id); - if (mvt->peer_id) - json_add_node_id(stream, "peer_id", mvt->peer_id); - json_add_string(stream, "type", mvt_type_str(mvt->type)); - json_add_string(stream, "account_id", mvt->account_id); - if (mvt->originating_acct) - json_add_string(stream, "originating_account", - mvt->originating_acct); - json_mvt_id(stream, mvt->type, &mvt->id); - json_add_amount_msat(stream, "credit_msat", mvt->credit); - json_add_amount_msat(stream, "debit_msat", mvt->debit); - - /* Only chain movements */ - if (mvt->output_val) - json_add_amount_sat_msat(stream, - "output_msat", *mvt->output_val); - if (mvt->output_count > 0) - json_add_num(stream, "output_count", - mvt->output_count); - - if (mvt->fees) { - json_add_amount_msat(stream, "fees_msat", *mvt->fees); +static void json_add_mvt_account_id(struct json_stream *stream, + const char *fieldname, + const struct mvt_account_id *account_id) +{ + if (account_id->channel) + json_add_channel_id(stream, fieldname, &account_id->channel->cid); + else + json_add_string(stream, fieldname, account_id->alt_account); +} + +static void add_movement_tags(struct json_stream *stream, + struct lightningd *ld, + const struct mvt_tags tags) +{ + const char **tagstrs = mvt_tag_strs(tmpctx, tags); + + if (lightningd_deprecated_out_ok(ld, ld->deprecated_ok, + "coin_movement", "tags", + "v25.05", "v26.09")) { + json_array_start(stream, "tags"); + for (size_t i = 0; i < tal_count(tagstrs); i++) + json_add_string(stream, NULL, tagstrs[i]); + json_array_end(stream); } - json_array_start(stream, "tags"); - for (size_t i = 0; i < tal_count(mvt->tags); i++) - json_add_string(stream, NULL, mvt_tag_str(mvt->tags[i])); + json_add_string(stream, "primary_tag", tagstrs[0]); + json_array_start(stream, "extra_tags"); + for (size_t i = 1; i < tal_count(tagstrs); i++) + json_add_string(stream, NULL, tagstrs[i]); json_array_end(stream); +} - if (mvt->type == CHAIN_MVT) - json_add_u32(stream, "blockheight", mvt->blockheight); +static void chain_movement_notification_serialize(struct json_stream *stream, + struct lightningd *ld, + const struct chain_coin_mvt *chain_mvt) +{ + json_add_num(stream, "version", COIN_MVT_VERSION); + json_add_string(stream, "type", "chain_mvt"); + json_add_node_id(stream, "node_id", &ld->our_nodeid); + if (chain_mvt->peer_id) + json_add_node_id(stream, "peer_id", chain_mvt->peer_id); + json_add_mvt_account_id(stream, "account_id", &chain_mvt->account); + + if (chain_mvt->originating_acct) + json_add_mvt_account_id(stream, "originating_account", chain_mvt->originating_acct); + + /* some 'journal entries' don't have a txid */ + if (chain_mvt->tx_txid) + json_add_string(stream, "txid", + fmt_bitcoin_txid(tmpctx, + chain_mvt->tx_txid)); + /* some chain ledger entries aren't associated with a utxo + * e.g. journal updates (due to penalty/state loss) and + * chain_fee entries */ + if (chain_mvt->outpoint) { + json_add_string(stream, "utxo_txid", + fmt_bitcoin_txid(tmpctx, + &chain_mvt->outpoint->txid)); + json_add_u32(stream, "vout", chain_mvt->outpoint->n); + } - json_add_u32(stream, "timestamp", mvt->timestamp); - json_add_string(stream, "coin_type", mvt->hrp_name); + /* on-chain htlcs include a payment hash */ + if (chain_mvt->payment_hash) + json_add_sha256(stream, "payment_hash", chain_mvt->payment_hash); + json_add_amount_msat(stream, "credit_msat", chain_mvt->credit); + json_add_amount_msat(stream, "debit_msat", chain_mvt->debit); + + json_add_amount_sat_msat(stream, + "output_msat", chain_mvt->output_val); + if (chain_mvt->output_count > 0) + json_add_num(stream, "output_count", chain_mvt->output_count); + + add_movement_tags(stream, ld, chain_mvt->tags); + + json_add_u32(stream, "blockheight", chain_mvt->blockheight); + json_add_u32(stream, "timestamp", time_now().ts.tv_sec); + json_add_string(stream, "coin_type", chainparams->lightning_hrp); +} + +static void channel_movement_notification_serialize(struct json_stream *stream, + struct lightningd *ld, + const struct channel_coin_mvt *chan_mvt) +{ + json_add_num(stream, "version", COIN_MVT_VERSION); + json_add_string(stream, "type", "channel_mvt"); + json_add_node_id(stream, "node_id", &ld->our_nodeid); + json_add_mvt_account_id(stream, "account_id", &chan_mvt->account); + /* push funding / leases don't have a payment_hash */ + if (chan_mvt->payment_hash) + json_add_sha256(stream, "payment_hash", chan_mvt->payment_hash); + if (chan_mvt->part_and_group) { + json_add_u64(stream, "part_id", chan_mvt->part_and_group->part_id); + json_add_u64(stream, "group_id", chan_mvt->part_and_group->group_id); + } + json_add_amount_msat(stream, "credit_msat", chan_mvt->credit); + json_add_amount_msat(stream, "debit_msat", chan_mvt->debit); + json_add_amount_msat(stream, "fees_msat", chan_mvt->fees); + + add_movement_tags(stream, ld, chan_mvt->tags); + + json_add_u32(stream, "timestamp", time_now().ts.tv_sec); + json_add_string(stream, "coin_type", chainparams->lightning_hrp); } REGISTER_NOTIFICATION(coin_movement); -void notify_coin_mvt(struct lightningd *ld, - const struct coin_mvt *mvt) +void notify_channel_mvt(struct lightningd *ld, + const struct channel_coin_mvt *chan_mvt) +{ + struct jsonrpc_notification *n = notify_start(ld, "coin_movement"); + if (!n) + return; + channel_movement_notification_serialize(n->stream, ld, chan_mvt); + notify_send(ld, n); +} + +void notify_chain_mvt(struct lightningd *ld, + const struct chain_coin_mvt *chain_mvt) { struct jsonrpc_notification *n = notify_start(ld, "coin_movement"); if (!n) return; - coin_movement_notification_serialize(n->stream, mvt); + chain_movement_notification_serialize(n->stream, ld, chain_mvt); notify_send(ld, n); } diff --git a/lightningd/notification.h b/lightningd/notification.h index 8f37cb70b838..c90f01605069 100644 --- a/lightningd/notification.h +++ b/lightningd/notification.h @@ -83,8 +83,11 @@ void notify_sendpay_failure(struct lightningd *ld, const struct routing_failure *fail, const char *errmsg); -void notify_coin_mvt(struct lightningd *ld, - const struct coin_mvt *mvt); +void notify_channel_mvt(struct lightningd *ld, + const struct channel_coin_mvt *chan_mvt); + +void notify_chain_mvt(struct lightningd *ld, + const struct chain_coin_mvt *chain_mvt); void notify_balance_snapshot(struct lightningd *ld, const struct balance_snapshot *snap); diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 0fe32e4d920e..e536e5323caa 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -345,13 +346,14 @@ static void handle_onchain_log_coin_move(struct channel *channel, const u8 *msg) return; } - /* Any 'ignored' payments get registered to the wallet */ - if (!mvt->account_name) - mvt->account_name = fmt_channel_id(mvt, - &channel->cid); - else - mvt->originating_acct = fmt_channel_id(mvt, - &channel->cid); + /* onchaind uses an empty string to mean "this channel" */ + if (streq(mvt->account.alt_account, "")) { + tal_free(mvt->account.alt_account); + set_mvt_account_id(&mvt->account, channel, NULL); + } else { + mvt->originating_acct = new_mvt_account_id(mvt, channel, NULL); + } + notify_chain_mvt(channel->peer->ld, mvt); tal_free(mvt); } @@ -576,9 +578,8 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg) csv_lock); mvt = new_coin_wallet_deposit(msg, &outpoint, blockheight, - amount, DEPOSIT); - mvt->originating_acct = fmt_channel_id(mvt, - &channel->cid); + amount, mk_mvt_tags(MVT_DEPOSIT)); + mvt->originating_acct = new_mvt_account_id(mvt, channel, NULL); notify_chain_mvt(channel->peer->ld, mvt); } diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index fc4a7063dcde..10d56f8a962e 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 3ded3c1be4dd..2aa0702cc844 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -225,55 +225,36 @@ static void send_coin_mvt(struct chain_coin_mvt *mvt TAKES) static void record_channel_withdrawal(const struct bitcoin_txid *tx_txid, struct tracked_output *out, u32 blockheight, - enum mvt_tag tag) + struct mvt_tags tags) { send_coin_mvt(take(new_onchaind_withdraw(NULL, &out->outpoint, tx_txid, - blockheight, out->sat, tag))); + blockheight, out->sat, tags))); } static void record_external_spend(const struct bitcoin_txid *txid, struct tracked_output *out, u32 blockheight, - enum mvt_tag tag) + struct mvt_tags tags) { send_coin_mvt(take(new_coin_external_spend(NULL, &out->outpoint, txid, blockheight, - out->sat, tag))); -} - -static void record_external_spend_tags(const struct bitcoin_txid *txid, - struct tracked_output *out, - u32 blockheight, - enum mvt_tag *tags TAKES) -{ - send_coin_mvt(take(new_coin_external_spend_tags(NULL, &out->outpoint, - txid, blockheight, - out->sat, tags))); + out->sat, tags))); } static void record_external_output(const struct bitcoin_outpoint *out, struct amount_sat amount, u32 blockheight, - enum mvt_tag tag) + struct mvt_tags tags) { send_coin_mvt(take(new_coin_external_deposit(NULL, out, blockheight, - amount, tag))); + amount, tags))); } static void record_external_deposit(const struct tracked_output *out, u32 blockheight, - enum mvt_tag tag) + struct mvt_tags tags) { - record_external_output(&out->outpoint, out->sat, blockheight, tag); -} - -static void record_external_deposit_tags(const struct tracked_output *out, - u32 blockheight, - enum mvt_tag *tags TAKES) -{ - send_coin_mvt(take(new_coin_external_deposit_tags(NULL, &out->outpoint, - blockheight, out->sat, - tags))); + record_external_output(&out->outpoint, out->sat, blockheight, tags); } static void record_mutual_close(const struct tx_parts *tx, @@ -295,19 +276,19 @@ static void record_mutual_close(const struct tx_parts *tx, record_external_output(&out, amount_sat(tx->outputs[i]->satoshi), blockheight, - TO_THEM); + mk_mvt_tags(MVT_TO_THEM)); break; } } static void record_channel_deposit(struct tracked_output *out, - u32 blockheight, enum mvt_tag tag) + u32 blockheight, struct mvt_tags tags) { send_coin_mvt(take(new_onchaind_deposit(NULL, &out->outpoint, blockheight, out->sat, - tag))); + tags))); } static void record_to_us_htlc_fulfilled(struct tracked_output *out, @@ -333,13 +314,11 @@ static void record_to_them_htlc_fulfilled(struct tracked_output *out, static void record_anchor(struct tracked_output *out) { - enum mvt_tag *tags = new_tag_arr(NULL, ANCHOR); - tal_arr_expand(&tags, IGNORED); - send_coin_mvt(take(new_coin_wallet_deposit_tagged(NULL, + send_coin_mvt(take(new_coin_wallet_deposit(NULL, &out->outpoint, out->tx_blockheight, out->sat, - tags))); + mk_mvt_tags(MVT_ANCHOR, MVT_IGNORED)))); } static void record_coin_movements(struct tracked_output *out, @@ -355,10 +334,10 @@ static void record_coin_movements(struct tracked_output *out, * AND so we can accurately calculate our on-chain fee burden */ if (out->tx_type == OUR_HTLC_TIMEOUT_TX || out->tx_type == OUR_HTLC_SUCCESS_TX) - record_channel_deposit(out, out->tx_blockheight, HTLC_TX); + record_channel_deposit(out, out->tx_blockheight, mk_mvt_tags(MVT_HTLC_TX)); if (out->resolved->tx_type == OUR_HTLC_TIMEOUT_TO_US) - record_channel_deposit(out, out->tx_blockheight, HTLC_TIMEOUT); + record_channel_deposit(out, out->tx_blockheight, mk_mvt_tags(MVT_HTLC_TIMEOUT)); /* there is a case where we've fulfilled an htlc onchain, * in which case we log a deposit to the channel */ @@ -371,20 +350,20 @@ static void record_coin_movements(struct tracked_output *out, if (out->tx_type == OUR_UNILATERAL) { if (out->output_type == DELAYED_OUTPUT_TO_US) record_channel_deposit(out, out->tx_blockheight, - CHANNEL_TO_US); + mk_mvt_tags(MVT_CHANNEL_TO_US)); else if (out->output_type == OUR_HTLC) { record_channel_deposit(out, out->tx_blockheight, - HTLC_TIMEOUT); + mk_mvt_tags(MVT_HTLC_TIMEOUT)); record_channel_withdrawal(txid, out, blockheight, - HTLC_TIMEOUT); + mk_mvt_tags(MVT_HTLC_TIMEOUT)); } else if (out->output_type == THEIR_HTLC) record_channel_withdrawal(txid, out, blockheight, - HTLC_FULFILL); + mk_mvt_tags(MVT_HTLC_FULFILL)); } if (out->tx_type == THEIR_REVOKED_UNILATERAL || out->resolved->tx_type == OUR_PENALTY_TX) - record_channel_deposit(out, out->tx_blockheight, PENALTY); + record_channel_deposit(out, out->tx_blockheight, mk_mvt_tags(MVT_PENALTY)); if (out->resolved->tx_type == OUR_DELAYED_RETURN_TO_WALLET || out->resolved->tx_type == THEIR_HTLC_FULFILL_TO_US @@ -393,9 +372,9 @@ static void record_coin_movements(struct tracked_output *out, || out->resolved->tx_type == OUR_PENALTY_TX) { /* penalty rbf cases, the amount might be zero */ if (amount_sat_is_zero(out->sat)) - record_channel_withdrawal(txid, out, blockheight, TO_MINER); + record_channel_withdrawal(txid, out, blockheight, mk_mvt_tags(MVT_TO_MINER)); else - record_channel_withdrawal(txid, out, blockheight, TO_WALLET); + record_channel_withdrawal(txid, out, blockheight, mk_mvt_tags(MVT_TO_WALLET)); } } @@ -1229,24 +1208,19 @@ static bool output_spent(struct tracked_output ***outs, case DELAYED_OUTPUT_TO_US: unknown_spend(out, tx_parts); record_external_deposit(out, out->tx_blockheight, - PENALIZED); + mk_mvt_tags(MVT_PENALIZED)); break; case THEIR_HTLC: if (out->tx_type == THEIR_REVOKED_UNILATERAL) { - enum mvt_tag *tags; - tags = new_tag_arr(NULL, HTLC_TIMEOUT); - tal_arr_expand(&tags, STEALABLE); - - record_external_deposit_tags(out, out->tx_blockheight, - /* This takes tags */ - tal_dup_talarr(NULL, - enum mvt_tag, - tags)); - record_external_spend_tags(&tx_parts->txid, - out, - tx_blockheight, - tags); + struct mvt_tags tags = mk_mvt_tags(MVT_HTLC_TIMEOUT, MVT_STEALABLE); + + record_external_deposit(out, out->tx_blockheight, + tags); + record_external_spend(&tx_parts->txid, + out, + tx_blockheight, + tags); /* we've actually got a 'new' output here */ steal_htlc_tx(out, outs, tx_parts, @@ -1283,13 +1257,10 @@ static bool output_spent(struct tracked_output ***outs, record_to_them_htlc_fulfilled(out, out->tx_blockheight); if (out->tx_type == THEIR_REVOKED_UNILATERAL) { - enum mvt_tag *tags = new_tag_arr(NULL, - HTLC_FULFILL); - tal_arr_expand(&tags, STEALABLE); - record_external_spend_tags(&tx_parts->txid, - out, - tx_blockheight, - tags); + record_external_spend(&tx_parts->txid, + out, + tx_blockheight, + mk_mvt_tags(MVT_HTLC_FULFILL, MVT_STEALABLE)); steal_htlc_tx(out, outs, tx_parts, tx_blockheight, OUR_HTLC_FULFILL_TO_THEM, @@ -1297,7 +1268,7 @@ static bool output_spent(struct tracked_output ***outs, } else { record_external_spend(&tx_parts->txid, out, tx_blockheight, - HTLC_FULFILL); + mk_mvt_tags(MVT_HTLC_FULFILL)); /* BOLT #5: * * ## HTLC Output Handling: Local Commitment, @@ -1326,7 +1297,7 @@ static bool output_spent(struct tracked_output ***outs, resolved_by_other(out, &tx_parts->txid, THEIR_DELAYED_CHEAT); - record_external_deposit(out, out->tx_blockheight, STOLEN); + record_external_deposit(out, out->tx_blockheight, mk_mvt_tags(MVT_STOLEN)); break; /* Um, we don't track these! */ case OUTPUT_TO_THEM: @@ -1430,7 +1401,7 @@ static void tx_new_depth(struct tracked_output **outs, if (outs[i]->proposal->tx_type == THEIR_HTLC_TIMEOUT_TO_THEM) record_external_deposit(outs[i], outs[i]->tx_blockheight, - HTLC_TIMEOUT); + mk_mvt_tags(MVT_HTLC_TIMEOUT)); } } } @@ -2310,7 +2281,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, OUTPUT_TO_THEM, NULL, NULL, NULL); ignore_output(out); - record_external_deposit(out, tx_blockheight, TO_THEM); + record_external_deposit(out, tx_blockheight, mk_mvt_tags(MVT_TO_THEM)); script[REMOTE] = NULL; continue; } @@ -2339,7 +2310,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, ANCHOR_TO_THEM, NULL, NULL, NULL); ignore_output(out); - record_external_deposit(out, tx_blockheight, ANCHOR); + record_external_deposit(out, tx_blockheight, mk_mvt_tags(MVT_ANCHOR)); anchor[REMOTE] = NULL; continue; } @@ -2413,7 +2384,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, ignore_output(out); record_external_deposit(out, tx_blockheight, - TO_THEM); + mk_mvt_tags(MVT_TO_THEM)); script[REMOTE] = NULL; found = true; break; @@ -2428,7 +2399,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, record_external_output(&outpoint, amt, tx_blockheight, - PENALTY); + mk_mvt_tags(MVT_PENALTY)); status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not find resolution for output %zu", i); @@ -2823,7 +2794,7 @@ static void handle_their_cheat(const struct tx_parts *tx, ANCHOR_TO_THEM, NULL, NULL, NULL); ignore_output(out); - record_external_deposit(out, tx_blockheight, ANCHOR); + record_external_deposit(out, tx_blockheight, mk_mvt_tags(MVT_ANCHOR)); anchor[REMOTE] = NULL; continue; } @@ -2893,7 +2864,7 @@ static void handle_their_cheat(const struct tx_parts *tx, if (!found) { record_external_output(&outpoint, amt, tx_blockheight, - PENALTY); + mk_mvt_tags(MVT_PENALTY)); status_broken("Could not find resolution" " for output %zu: did" " *we* cheat?", i); @@ -3120,7 +3091,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, DELAYED_OUTPUT_TO_THEM, NULL, NULL, NULL); ignore_output(out); - record_external_deposit(out, tx_blockheight, TO_THEM); + record_external_deposit(out, tx_blockheight, mk_mvt_tags(MVT_TO_THEM)); continue; } if (anchor[LOCAL] @@ -3150,7 +3121,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, NULL, NULL, NULL); ignore_output(out); anchor[REMOTE] = NULL; - record_external_deposit(out, tx_blockheight, ANCHOR); + record_external_deposit(out, tx_blockheight, mk_mvt_tags(MVT_ANCHOR)); continue; } @@ -3215,7 +3186,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, ignore_output(out); record_external_deposit(out, tx_blockheight, - TO_THEM); + mk_mvt_tags(MVT_TO_THEM)); found = true; break; } @@ -3226,7 +3197,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, record_external_output(&outpoint, amt, tx_blockheight, - PENALTY); + mk_mvt_tags(MVT_PENALTY)); status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not find resolution for output %zu", i); @@ -3362,7 +3333,7 @@ static void handle_unknown_commitment(const struct tx_parts *tx, record_external_output(&outpoint, amt, tx_blockheight, - PENALTY); + mk_mvt_tags(MVT_PENALTY)); } if (to_us_output == -1) { @@ -3465,7 +3436,7 @@ int main(int argc, char *argv[]) FUNDING_OUTPUT, NULL, NULL, NULL); /* Record funding output spent */ - send_coin_mvt(take(new_coin_channel_close(NULL, NULL, &tx->txid, + send_coin_mvt(take(new_coin_channel_close(NULL, NULL, "", &tx->txid, &funding, tx_blockheight, our_msat, funding_sats, diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index 30a31b0b89f4..539fb0883ec7 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -101,9 +101,13 @@ struct htable *memleak_start(const tal_t *ctx UNNEEDED) /* Generated stub for memleak_status_broken */ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "memleak_status_broken called!\n"); abort(); } +/* Generated stub for mk_mvt_tags_ */ +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag UNNEEDED, ...) +{ fprintf(stderr, "mk_mvt_tags_ called!\n"); abort(); } /* Generated stub for new_coin_channel_close */ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED, - const struct channel_id *chan_id UNNEEDED, + const struct channel *channel UNNEEDED, + const char *alt_account UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_outpoint *out UNNEEDED, u32 blockheight UNNEEDED, @@ -118,43 +122,26 @@ struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_external_deposit called!\n"); abort(); } -/* Generated stub for new_coin_external_deposit_tags */ -struct chain_coin_mvt *new_coin_external_deposit_tags(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags) - -{ fprintf(stderr, "new_coin_external_deposit_tags called!\n"); abort(); } /* Generated stub for new_coin_external_spend */ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_external_spend called!\n"); abort(); } -/* Generated stub for new_coin_external_spend_tags */ -struct chain_coin_mvt *new_coin_external_spend_tags(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags) - -{ fprintf(stderr, "new_coin_external_spend_tags called!\n"); abort(); } -/* Generated stub for new_coin_wallet_deposit_tagged */ -struct chain_coin_mvt *new_coin_wallet_deposit_tagged(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags TAKES) +/* Generated stub for new_coin_wallet_deposit */ +struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED, + const struct bitcoin_outpoint *outpoint UNNEEDED, + u32 blockheight UNNEEDED, + struct amount_sat amount UNNEEDED, + struct mvt_tags tags) -{ fprintf(stderr, "new_coin_wallet_deposit_tagged called!\n"); abort(); } +{ fprintf(stderr, "new_coin_wallet_deposit called!\n"); abort(); } /* Generated stub for new_onchain_htlc_deposit */ struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, @@ -176,7 +163,7 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_onchaind_deposit called!\n"); abort(); } /* Generated stub for new_onchaind_withdraw */ @@ -185,12 +172,9 @@ struct chain_coin_mvt *new_onchaind_withdraw(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *spend_txid UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_onchaind_withdraw called!\n"); abort(); } -/* Generated stub for new_tag_arr */ -enum mvt_tag *new_tag_arr(const tal_t *ctx UNNEEDED, enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "new_tag_arr called!\n"); abort(); } /* Generated stub for notleak_ */ void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index ac714fcd4ca3..ae9422880a20 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -151,9 +151,13 @@ struct htable *memleak_start(const tal_t *ctx UNNEEDED) /* Generated stub for memleak_status_broken */ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "memleak_status_broken called!\n"); abort(); } +/* Generated stub for mk_mvt_tags_ */ +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag UNNEEDED, ...) +{ fprintf(stderr, "mk_mvt_tags_ called!\n"); abort(); } /* Generated stub for new_coin_channel_close */ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED, - const struct channel_id *chan_id UNNEEDED, + const struct channel *channel UNNEEDED, + const char *alt_account UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, const struct bitcoin_outpoint *out UNNEEDED, u32 blockheight UNNEEDED, @@ -168,43 +172,26 @@ struct chain_coin_mvt *new_coin_external_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_external_deposit called!\n"); abort(); } -/* Generated stub for new_coin_external_deposit_tags */ -struct chain_coin_mvt *new_coin_external_deposit_tags(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags) - -{ fprintf(stderr, "new_coin_external_deposit_tags called!\n"); abort(); } /* Generated stub for new_coin_external_spend */ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_external_spend called!\n"); abort(); } -/* Generated stub for new_coin_external_spend_tags */ -struct chain_coin_mvt *new_coin_external_spend_tags(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags) - -{ fprintf(stderr, "new_coin_external_spend_tags called!\n"); abort(); } -/* Generated stub for new_coin_wallet_deposit_tagged */ -struct chain_coin_mvt *new_coin_wallet_deposit_tagged(const tal_t *ctx UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - enum mvt_tag *tags TAKES) +/* Generated stub for new_coin_wallet_deposit */ +struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED, + const struct bitcoin_outpoint *outpoint UNNEEDED, + u32 blockheight UNNEEDED, + struct amount_sat amount UNNEEDED, + struct mvt_tags tags) -{ fprintf(stderr, "new_coin_wallet_deposit_tagged called!\n"); abort(); } +{ fprintf(stderr, "new_coin_wallet_deposit called!\n"); abort(); } /* Generated stub for new_onchain_htlc_deposit */ struct chain_coin_mvt *new_onchain_htlc_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, @@ -226,7 +213,7 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_onchaind_deposit called!\n"); abort(); } /* Generated stub for new_onchaind_withdraw */ @@ -235,12 +222,9 @@ struct chain_coin_mvt *new_onchaind_withdraw(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *spend_txid UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_onchaind_withdraw called!\n"); abort(); } -/* Generated stub for new_tag_arr */ -enum mvt_tag *new_tag_arr(const tal_t *ctx UNNEEDED, enum mvt_tag tag UNNEEDED) -{ fprintf(stderr, "new_tag_arr called!\n"); abort(); } /* Generated stub for notleak_ */ void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED) { fprintf(stderr, "notleak_ called!\n"); abort(); } diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c index a218ac0e575b..08822e1c519f 100644 --- a/plugins/bkpr/bookkeeper.c +++ b/plugins/bkpr/bookkeeper.c @@ -757,7 +757,7 @@ static bool new_missed_channel_account(struct command *cmd, acct->name); chain_ev = tal(cmd, struct chain_event); - chain_ev->tag = mvt_tag_str(CHANNEL_OPEN); + chain_ev->tag = mvt_tag_str(MVT_CHANNEL_OPEN); chain_ev->debit = AMOUNT_MSAT(0); ok = amount_msat_add(&chain_ev->output_value, amt, remote_amt); @@ -777,7 +777,7 @@ static bool new_missed_channel_account(struct command *cmd, /* Update the account info too */ tags = tal_arr(chain_ev, enum mvt_tag, 1); - tags[0] = CHANNEL_OPEN; + tags[0] = MVT_CHANNEL_OPEN; is_opener = streq(opener, "local"); @@ -787,9 +787,9 @@ static bool new_missed_channel_account(struct command *cmd, &is_leased); if (is_leased) - tal_arr_expand(&tags, LEASED); + tal_arr_expand(&tags, MVT_LEASED); if (is_opener) - tal_arr_expand(&tags, OPENER); + tal_arr_expand(&tags, MVT_OPENER); chain_ev->credit = amt; db_begin_transaction(db); @@ -816,7 +816,7 @@ static bool new_missed_channel_account(struct command *cmd, chan_tag = tal_fmt(tmpctx, "%s", mvt_tag_str( is_leased ? - LEASE_FEE : PUSHED)); + MVT_LEASE_FEE : MVT_PUSHED)); chan_ev = new_channel_event(tmpctx, chan_tag, push_credit, @@ -1456,7 +1456,7 @@ listpeerchannels_done(struct command *cmd, plugin_err(cmd->plugin, "%s", err); if (info->ev->payment_id && - streq(info->ev->tag, mvt_tag_str(INVOICE))) { + streq(info->ev->tag, mvt_tag_str(MVT_INVOICE))) { return lookup_invoice_desc(cmd, info->ev->credit, info->ev->payment_id); } @@ -1573,9 +1573,9 @@ parse_and_log_chain_move(struct command *cmd, e->stealable = false; e->splice_close = false; for (size_t i = 0; i < tal_count(tags); i++) { - e->ignored |= tags[i] == IGNORED; - e->stealable |= tags[i] == STEALABLE; - e->splice_close |= tags[i] == SPLICE; + e->ignored |= tags[i] == MVT_IGNORED; + e->stealable |= tags[i] == MVT_STEALABLE; + e->splice_close |= tags[i] == MVT_SPLICE; } db_begin_transaction(db); @@ -1674,7 +1674,7 @@ parse_and_log_chain_move(struct command *cmd, /* Check for invoice desc data, necessary */ if (e->payment_id) { for (size_t i = 0; i < tal_count(tags); i++) { - if (tags[i] != INVOICE) + if (tags[i] != MVT_INVOICE) continue; return lookup_invoice_desc(cmd, e->credit, @@ -1748,7 +1748,7 @@ parse_and_log_channel_move(struct command *cmd, /* Check for invoice desc data, necessary */ if (e->payment_id) { for (size_t i = 0; i < tal_count(tags); i++) { - if (tags[i] != INVOICE) + if (tags[i] != MVT_INVOICE) continue; /* We only do rebalance checks for debits, @@ -1772,16 +1772,20 @@ static char *parse_tags(const tal_t *ctx, enum mvt_tag **tags) { size_t i; - const jsmntok_t *tag_tok, - *tags_tok = json_get_member(buf, tok, "tags"); - - if (tags_tok == NULL || tags_tok->type != JSMN_ARRAY) - return "Invalid/missing 'tags' field"; - - *tags = tal_arr(ctx, enum mvt_tag, tags_tok->size); - json_for_each_arr(i, tag_tok, tags_tok) { - if (!json_to_coin_mvt_tag(buf, tag_tok, &(*tags)[i])) - return "Unable to parse 'tags'"; + const jsmntok_t *extras_tok, + *tag_tok = json_get_member(buf, tok, "primary_tag"); + + if (tag_tok == NULL) + return "missing 'primary_tag' field"; + *tags = tal_arr(ctx, enum mvt_tag, 1); + if (!json_to_coin_mvt_tag(buf, tag_tok, &(*tags)[0])) + return "Unable to parse 'primary_tag'"; + + extras_tok = json_get_member(buf, tok, "extra_tags"); + tal_resize(tags, 1 + extras_tok->size); + json_for_each_arr(i, tag_tok, extras_tok) { + if (!json_to_coin_mvt_tag(buf, tag_tok, &(*tags)[i + 1])) + return "Unable to parse 'extra_tags'"; } return NULL; diff --git a/plugins/bkpr/incomestmt.c b/plugins/bkpr/incomestmt.c index 5bcf6a1028fc..74faa71e0917 100644 --- a/plugins/bkpr/incomestmt.c +++ b/plugins/bkpr/incomestmt.c @@ -164,7 +164,7 @@ static struct income_event *maybe_chain_income(const tal_t *ctx, ev->debit, ev->credit); /* Also, really a withdrawal.. phh */ - iev->tag = tal_strdup(iev, mvt_tag_str(WITHDRAWAL)); + iev->tag = tal_strdup(iev, mvt_tag_str(MVT_WITHDRAWAL)); return iev; } @@ -533,7 +533,7 @@ static void cointrack_entry(const tal_t *ctx, FILE *csvf, struct income_event *e /* "Fee Amount,Fee Currency," */ if (!amount_msat_is_zero(ev->fees) - && streq(ev->tag, mvt_tag_str(INVOICE))) { + && streq(ev->tag, mvt_tag_str(MVT_INVOICE))) { fprintf(csvf, "%s", fmt_amount_msat_btc(ctx, ev->fees, false)); fprintf(csvf, ","); fprintf(csvf, "%s", convert_asset_type(ev)); @@ -606,7 +606,7 @@ static void koinly_entry(const tal_t *ctx, FILE *csvf, struct income_event *ev) /* "Fee Amount,Fee Currency," */ if (!amount_msat_is_zero(ev->fees) - && streq(ev->tag, mvt_tag_str(INVOICE))) { + && streq(ev->tag, mvt_tag_str(MVT_INVOICE))) { fprintf(csvf, "%s", fmt_amount_msat_btc(ctx, ev->fees, false)); fprintf(csvf, ","); fprintf(csvf, "%s", convert_asset_type(ev)); diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c index 363a401de588..49ff194c9f01 100644 --- a/plugins/bkpr/recorder.c +++ b/plugins/bkpr/recorder.c @@ -453,7 +453,7 @@ static struct txo_set *find_txo_set(const tal_t *ctx, if (pr) { /* Disappear "channel_proposed" events */ if (streq(pr->txo->tag, - mvt_tag_str(CHANNEL_PROPOSED))) + mvt_tag_str(MVT_CHANNEL_PROPOSED))) pr = tal_free(pr); else tal_arr_expand(&txos->pairs, pr); @@ -577,7 +577,7 @@ struct account *find_close_account(const tal_t *ctx, /* ignore splicing 'close' events */ " AND e.spliced = 0 ")); - db_bind_text(stmt, mvt_tag_str(CHANNEL_CLOSE)); + db_bind_text(stmt, mvt_tag_str(MVT_CHANNEL_CLOSE)); db_bind_txid(stmt, txid); db_query_prepared(stmt); @@ -1445,13 +1445,13 @@ void maybe_update_account(struct db *db, for (size_t i = 0; i < tal_count(tags); i++) { switch (tags[i]) { - case CHANNEL_PROPOSED: - case CHANNEL_OPEN: + case MVT_CHANNEL_PROPOSED: + case MVT_CHANNEL_OPEN: updated = true; acct->open_event_db_id = tal(acct, u64); *acct->open_event_db_id = e->db_id; break; - case CHANNEL_CLOSE: + case MVT_CHANNEL_CLOSE: /* Splices dont count as closes */ if (e->splice_close) break; @@ -1459,34 +1459,34 @@ void maybe_update_account(struct db *db, acct->closed_event_db_id = tal(acct, u64); *acct->closed_event_db_id = e->db_id; break; - case LEASED: + case MVT_LEASED: updated = true; acct->leased = true; break; - case OPENER: + case MVT_OPENER: updated = true; acct->we_opened = true; break; - case DEPOSIT: - case WITHDRAWAL: - case PENALTY: - case INVOICE: - case ROUTED: - case PUSHED: - case CHANNEL_TO_US: - case HTLC_TIMEOUT: - case HTLC_FULFILL: - case HTLC_TX: - case TO_WALLET: - case IGNORED: - case ANCHOR: - case TO_THEM: - case PENALIZED: - case STOLEN: - case TO_MINER: - case LEASE_FEE: - case STEALABLE: - case SPLICE: + case MVT_DEPOSIT: + case MVT_WITHDRAWAL: + case MVT_PENALTY: + case MVT_INVOICE: + case MVT_ROUTED: + case MVT_PUSHED: + case MVT_CHANNEL_TO_US: + case MVT_HTLC_TIMEOUT: + case MVT_HTLC_FULFILL: + case MVT_HTLC_TX: + case MVT_TO_WALLET: + case MVT_IGNORED: + case MVT_ANCHOR: + case MVT_TO_THEM: + case MVT_PENALIZED: + case MVT_STOLEN: + case MVT_TO_MINER: + case MVT_LEASE_FEE: + case MVT_STEALABLE: + case MVT_SPLICE: /* Ignored */ break; } @@ -1565,9 +1565,9 @@ void log_channel_event(struct db *db, db_bind_u64(stmt, acct->db_id); db_bind_text(stmt, e->tag); - db_bind_amount_msat(stmt, &e->credit); - db_bind_amount_msat(stmt, &e->debit); - db_bind_amount_msat(stmt, &e->fees); + db_bind_amount_msat(stmt, e->credit); + db_bind_amount_msat(stmt, e->debit); + db_bind_amount_msat(stmt, e->fees); db_bind_text(stmt, e->currency); if (e->payment_id) db_bind_sha256(stmt, e->payment_id); @@ -1720,8 +1720,8 @@ static void insert_chain_fees_diff(struct db *db, db_bind_u64(stmt, acct_id); db_bind_txid(stmt, txid); - db_bind_amount_msat(stmt, &credit); - db_bind_amount_msat(stmt, &debit); + db_bind_amount_msat(stmt, credit); + db_bind_amount_msat(stmt, debit); db_bind_text(stmt, currency); db_bind_u64(stmt, timestamp); db_bind_int(stmt, ++update_count); @@ -1893,7 +1893,7 @@ void maybe_record_rebalance(struct db *db, " AND e.rebalance_id IS NULL")); db_bind_sha256(stmt, out->payment_id); - db_bind_amount_msat(stmt, &credit); + db_bind_amount_msat(stmt, credit); db_query_prepared(stmt); if (!db_step(stmt)) { @@ -2207,9 +2207,9 @@ bool log_chain_event(struct db *db, else db_bind_null(stmt); db_bind_text(stmt, e->tag); - db_bind_amount_msat(stmt, &e->credit); - db_bind_amount_msat(stmt, &e->debit); - db_bind_amount_msat(stmt, &e->output_value); + db_bind_amount_msat(stmt, e->credit); + db_bind_amount_msat(stmt, e->debit); + db_bind_amount_msat(stmt, e->output_value); db_bind_text(stmt, e->currency); db_bind_u64(stmt, e->timestamp); db_bind_int(stmt, e->blockheight); diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c index 10ba59aea78f..2441e73c76be 100644 --- a/plugins/bkpr/test/run-bkpr_db.c +++ b/plugins/bkpr/test/run-bkpr_db.c @@ -51,9 +51,6 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED, /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } -/* Generated stub for fmt_channel_id */ -char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) -{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c index 16cd8e9b7877..1594ea992a88 100644 --- a/plugins/bkpr/test/run-recorder.c +++ b/plugins/bkpr/test/run-recorder.c @@ -57,9 +57,6 @@ bool deprecated_ok_(bool deprecated_apis UNNEEDED, /* Generated stub for first_fee_state */ enum htlc_state first_fee_state(enum side opener UNNEEDED) { fprintf(stderr, "first_fee_state called!\n"); abort(); } -/* Generated stub for fmt_channel_id */ -char *fmt_channel_id(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED) -{ fprintf(stderr, "fmt_channel_id called!\n"); abort(); } /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } @@ -555,7 +552,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx, struct plugin *p) blockheight, 'X', 0, '*'); log_chain_event(db, acct, ev); - tags[0] = CHANNEL_OPEN; + tags[0] = MVT_CHANNEL_OPEN; maybe_update_account(db, acct, ev, tags, 0, NULL); ev = make_chain_event(ctx, "channel_close", @@ -567,7 +564,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx, struct plugin *p) log_chain_event(db, acct, ev); /* Update the account to have the right info! */ - tags[0] = CHANNEL_CLOSE; + tags[0] = MVT_CHANNEL_CLOSE; maybe_update_account(db, acct, ev, tags, close_output_count, NULL); log_chain_event(db, acct, @@ -1374,8 +1371,8 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) tags = tal_arr(ctx, enum mvt_tag, 2); /* should not update the account info */ - tags[0] = PUSHED; - tags[1] = PENALTY; + tags[0] = MVT_PUSHED; + tags[1] = MVT_PENALTY; maybe_update_account(db, acct, ev1, tags, 0, peer_id); acct2 = find_account(ctx, db, "wallet"); accountseq(acct, acct2); @@ -1383,8 +1380,8 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) /* channel_open -> open event db updated */ CHECK(!acct->leased); CHECK(acct->open_event_db_id == NULL); - tags[0] = CHANNEL_OPEN; - tags[1] = LEASED; + tags[0] = MVT_CHANNEL_OPEN; + tags[1] = MVT_LEASED; maybe_update_account(db, acct, ev1, tags, 2, peer_id); acct2 = find_account(ctx, db, "wallet"); accountseq(acct, acct2); @@ -1392,8 +1389,8 @@ static bool test_account_crud(const tal_t *ctx, struct plugin *p) CHECK(acct->open_event_db_id != NULL); CHECK(acct->closed_count == 2); - tags[0] = CHANNEL_CLOSE; - tags[1] = OPENER; + tags[0] = MVT_CHANNEL_CLOSE; + tags[1] = MVT_OPENER; CHECK(acct->closed_event_db_id == NULL); CHECK(!acct->we_opened); maybe_update_account(db, acct, ev1, tags, 0, NULL); diff --git a/tests/utils.py b/tests/utils.py index 5b682c6c3e10..9ac65199cd7a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -88,7 +88,9 @@ def move_matches(exp, mv): return False if Millisatoshi(mv['debit_msat']) != Millisatoshi(exp['debit_msat']): return False - if mv['tags'] != exp['tags']: + if mv['primary_tag'] != exp['primary_tag']: + return False + if mv['extra_tags'] != exp['extra_tags']: return False if 'fees_msat' in exp: if 'fees_msat' not in mv: @@ -144,7 +146,7 @@ def check_coin_moves(n, account_id, expected_moves, chainparams): .format(mv['type'], Millisatoshi(mv['credit_msat']).millisatoshis, Millisatoshi(mv['debit_msat']).millisatoshis, - mv['tags'], + [mv['primary_tag']] + mv['extra_tags'], mv['fees_msat'] if 'fees_msat' in mv else '')) if mv['version'] != 2: raise ValueError(f'version not 2 {mv}') @@ -261,6 +263,9 @@ def matchup_events(u_set, evs, chans, tag_list): if len(u_set) == 0: raise ValueError(f"utxo-set is empty. exp {evs}, actual {u_set}") + def get_tags(utxo): + return [utxo['primary_tag']] + utxo['extra_tags'] + txid = u_set[0][0]['utxo_txid'] # Stash the set for logging at end, if error _u_set = u_set @@ -277,7 +282,7 @@ def matchup_events(u_set, evs, chans, tag_list): else: acct = ev[0] - if u[0]['account_id'] != acct or u[0]['tags'] != ev[1]: + if u[0]['account_id'] != acct or get_tags(u[0]) != ev[1]: continue if ev[2] is None: @@ -289,7 +294,7 @@ def matchup_events(u_set, evs, chans, tag_list): # ugly hack to annotate two possible futures for a utxo if type(ev[2]) is tuple: - tag = u[1]['tags'] if u[1] else u[1] + tag = get_tags(u[1]) if u[1] else u[1] if tag not in [x[0] for x in ev[2]]: raise ValueError(f"Unable to find {tag} in event set {ev}") if not u[1]: @@ -297,14 +302,14 @@ def matchup_events(u_set, evs, chans, tag_list): u_set.remove(u) break for x in ev[2]: - if x[0] == u[1]['tags'] and 'to_miner' not in u[1]['tags']: + if x[0] == get_tags(u[1]) and 'to_miner' not in get_tags(u[1]): # Save the 'spent to' txid in the tag-list tag_list[x[1]] = u[1]['txid'] else: - if ev[2] != u[1]['tags']: + if ev[2] != get_tags(u[1]): raise ValueError(f"tags dont' match. exp {ev}, actual ({u[1]}) full utxo info: {u}") # Save the 'spent to' txid in the tag-list - if 'to_miner' not in u[1]['tags']: + if 'to_miner' not in get_tags(u[1]): tag_list[ev[3]] = u[1]['txid'] found = True diff --git a/wallet/invoices.c b/wallet/invoices.c index c8364fe32653..8122cac51c5a 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -308,7 +308,7 @@ bool invoices_create(struct invoices *invoices, db_bind_preimage(stmt, r); db_bind_int(stmt, UNPAID); if (msat) - db_bind_amount_msat(stmt, msat); + db_bind_amount_msat(stmt, *msat); else db_bind_null(stmt); db_bind_json_escape(stmt, label); @@ -623,7 +623,7 @@ bool invoices_resolve(struct invoices *invoices, " WHERE id=?;")); db_bind_int(stmt, PAID); db_bind_u64(stmt, pay_index); - db_bind_amount_msat(stmt, &received); + db_bind_amount_msat(stmt, received); db_bind_u64(stmt, paid_timestamp); if (outpoint) { db_bind_txid(stmt, &outpoint->txid); diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index 7c18dede5127..c73321bd5d85 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -164,6 +164,9 @@ void logv(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const s void memleak_scan_outpointfilter(struct htable *memtable UNNEEDED, const struct outpointfilter *opf UNNEEDED) { fprintf(stderr, "memleak_scan_outpointfilter called!\n"); abort(); } +/* Generated stub for mk_mvt_tags_ */ +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag UNNEEDED, ...) +{ fprintf(stderr, "mk_mvt_tags_ called!\n"); abort(); } /* Generated stub for new_channel */ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED, /* NULL or stolen */ @@ -252,7 +255,7 @@ struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_wallet_deposit called!\n"); abort(); } /* Generated stub for new_inflight */ @@ -288,7 +291,8 @@ struct peer *new_peer(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED, bool connected_incoming UNNEEDED) { fprintf(stderr, "new_peer called!\n"); abort(); } /* Generated stub for notify_chain_mvt */ -void notify_chain_mvt(struct lightningd *ld UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED) +void notify_chain_mvt(struct lightningd *ld UNNEEDED, + const struct chain_coin_mvt *chain_mvt UNNEEDED) { fprintf(stderr, "notify_chain_mvt called!\n"); abort(); } /* Generated stub for notify_forward_event */ void notify_forward_event(struct lightningd *ld UNNEEDED, diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 5787f640c25f..87e2cdee5e1d 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -655,32 +655,35 @@ void logv(struct logger *logger UNNEEDED, enum log_level level UNNEEDED, const s void memleak_scan_outpointfilter(struct htable *memtable UNNEEDED, const struct outpointfilter *opf UNNEEDED) { fprintf(stderr, "memleak_scan_outpointfilter called!\n"); abort(); } +/* Generated stub for mk_mvt_tags_ */ +struct mvt_tags mk_mvt_tags_(enum mvt_tag tag UNNEEDED, ...) +{ fprintf(stderr, "mk_mvt_tags_ called!\n"); abort(); } /* Generated stub for new_channel_mvt_invoice_hin */ struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx UNNEEDED, - struct htlc_in *hin UNNEEDED, - struct channel *channel UNNEEDED) + const struct htlc_in *hin UNNEEDED, + const struct channel *channel UNNEEDED) { fprintf(stderr, "new_channel_mvt_invoice_hin called!\n"); abort(); } /* Generated stub for new_channel_mvt_invoice_hout */ struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx UNNEEDED, - struct htlc_out *hout UNNEEDED, - struct channel *channel UNNEEDED) + const struct htlc_out *hout UNNEEDED, + const struct channel *channel UNNEEDED) { fprintf(stderr, "new_channel_mvt_invoice_hout called!\n"); abort(); } /* Generated stub for new_channel_mvt_routed_hin */ struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx UNNEEDED, - struct htlc_in *hin UNNEEDED, - struct channel *channel UNNEEDED) + const struct htlc_in *hin UNNEEDED, + const struct channel *channel UNNEEDED) { fprintf(stderr, "new_channel_mvt_routed_hin called!\n"); abort(); } /* Generated stub for new_channel_mvt_routed_hout */ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx UNNEEDED, - struct htlc_out *hout UNNEEDED, - struct channel *channel UNNEEDED) + const struct htlc_out *hout UNNEEDED, + const struct channel *channel UNNEEDED) { fprintf(stderr, "new_channel_mvt_routed_hout called!\n"); abort(); } /* Generated stub for new_coin_wallet_deposit */ struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED, const struct bitcoin_outpoint *outpoint UNNEEDED, u32 blockheight UNNEEDED, struct amount_sat amount UNNEEDED, - enum mvt_tag tag) + struct mvt_tags tags) { fprintf(stderr, "new_coin_wallet_deposit called!\n"); abort(); } /* Generated stub for new_global_subd */ @@ -701,10 +704,12 @@ struct uncommitted_channel *new_uncommitted_channel(struct peer *peer UNNEEDED) bool node_announcement_same(const u8 *nann1 UNNEEDED, const u8 *nann2 UNNEEDED) { fprintf(stderr, "node_announcement_same called!\n"); abort(); } /* Generated stub for notify_chain_mvt */ -void notify_chain_mvt(struct lightningd *ld UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED) +void notify_chain_mvt(struct lightningd *ld UNNEEDED, + const struct chain_coin_mvt *chain_mvt UNNEEDED) { fprintf(stderr, "notify_chain_mvt called!\n"); abort(); } /* Generated stub for notify_channel_mvt */ -void notify_channel_mvt(struct lightningd *ld UNNEEDED, const struct channel_coin_mvt *mvt UNNEEDED) +void notify_channel_mvt(struct lightningd *ld UNNEEDED, + const struct channel_coin_mvt *chan_mvt UNNEEDED) { fprintf(stderr, "notify_channel_mvt called!\n"); abort(); } /* Generated stub for notify_channel_open_failed */ void notify_channel_open_failed(struct lightningd *ld UNNEEDED, diff --git a/wallet/wallet.c b/wallet/wallet.c index 75f3b6fae18a..64168b5225d0 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -291,7 +291,7 @@ static bool wallet_add_utxo(struct wallet *w, ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); db_bind_txid(stmt, &utxo->outpoint.txid); db_bind_int(stmt, utxo->outpoint.n); - db_bind_amount_sat(stmt, &utxo->amount); + db_bind_amount_sat(stmt, utxo->amount); db_bind_int(stmt, wallet_output_type_in_db(type)); db_bind_int(stmt, OUTPUT_STATE_AVAILABLE); db_bind_int(stmt, utxo->keyindex); @@ -922,7 +922,7 @@ bool wallet_add_onchaind_utxo(struct wallet *w, ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); db_bind_txid(stmt, &outpoint->txid); db_bind_int(stmt, outpoint->n); - db_bind_amount_sat(stmt, &amount); + db_bind_amount_sat(stmt, amount); db_bind_int(stmt, wallet_output_type_in_db(WALLET_OUTPUT_P2WPKH)); db_bind_int(stmt, OUTPUT_STATE_AVAILABLE); db_bind_int(stmt, 0); @@ -1422,8 +1422,8 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight) db_bind_txid(stmt, &inflight->funding->outpoint.txid); db_bind_int(stmt, inflight->funding->outpoint.n); db_bind_int(stmt, inflight->funding->feerate); - db_bind_amount_sat(stmt, &inflight->funding->total_funds); - db_bind_amount_sat(stmt, &inflight->funding->our_funds); + db_bind_amount_sat(stmt, inflight->funding->total_funds); + db_bind_amount_sat(stmt, inflight->funding->our_funds); db_bind_psbt(stmt, inflight->funding_psbt); db_bind_int(stmt, inflight->remote_tx_sigs ? 1 : 0); if (inflight->last_tx) { @@ -1440,8 +1440,8 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight) db_bind_int(stmt, inflight->lease_chan_max_ppt); db_bind_int(stmt, inflight->lease_expiry); db_bind_int(stmt, inflight->lease_blockheight_start); - db_bind_amount_msat(stmt, &inflight->lease_fee); - db_bind_amount_sat(stmt, &inflight->lease_amt); + db_bind_amount_msat(stmt, inflight->lease_fee); + db_bind_amount_sat(stmt, inflight->lease_amt); } else { db_bind_null(stmt); db_bind_null(stmt); @@ -2356,7 +2356,7 @@ static void wallet_channel_stats_incr_x(struct wallet *w, struct db_stmt *stmt; stmt = db_prepare_v2(w->db, query); - db_bind_amount_msat(stmt, &msat); + db_bind_amount_msat(stmt, msat); db_bind_u64(stmt, cdbid); db_exec_prepared_v2(take(stmt)); @@ -2446,13 +2446,13 @@ static void wallet_channel_config_save(struct wallet *w, " max_accepted_htlcs=?," " max_dust_htlc_exposure_msat=?" " WHERE id=?;")); - db_bind_amount_sat(stmt, &cc->dust_limit); - db_bind_amount_msat(stmt, &cc->max_htlc_value_in_flight); - db_bind_amount_sat(stmt, &cc->channel_reserve); - db_bind_amount_msat(stmt, &cc->htlc_minimum); + db_bind_amount_sat(stmt, cc->dust_limit); + db_bind_amount_msat(stmt, cc->max_htlc_value_in_flight); + db_bind_amount_sat(stmt, cc->channel_reserve); + db_bind_amount_msat(stmt, cc->htlc_minimum); db_bind_int(stmt, cc->to_self_delay); db_bind_int(stmt, cc->max_accepted_htlcs); - db_bind_amount_msat(stmt, &cc->max_dust_htlc_exposure_msat); + db_bind_amount_msat(stmt, cc->max_dust_htlc_exposure_msat); db_bind_u64(stmt, cc->id); db_exec_prepared_v2(take(stmt)); } @@ -2593,11 +2593,11 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_sha256d(stmt, &chan->funding.txid.shad); db_bind_int(stmt, chan->funding.n); - db_bind_amount_sat(stmt, &chan->funding_sats); - db_bind_amount_sat(stmt, &chan->our_funds); + db_bind_amount_sat(stmt, chan->funding_sats); + db_bind_amount_sat(stmt, chan->our_funds); db_bind_int(stmt, chan->remote_channel_ready); - db_bind_amount_msat(stmt, &chan->push); - db_bind_amount_msat(stmt, &chan->our_msat); + db_bind_amount_msat(stmt, chan->push); + db_bind_amount_msat(stmt, chan->our_msat); db_bind_talarr(stmt, chan->shutdown_scriptpubkey[REMOTE]); db_bind_u64(stmt, chan->final_key_idx); @@ -2612,8 +2612,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_int(stmt, chan->last_was_revoke); db_bind_int(stmt, chan->min_possible_feerate); db_bind_int(stmt, chan->max_possible_feerate); - db_bind_amount_msat(stmt, &chan->msat_to_us_min); - db_bind_amount_msat(stmt, &chan->msat_to_us_max); + db_bind_amount_msat(stmt, chan->msat_to_us_min); + db_bind_amount_msat(stmt, chan->msat_to_us_max); db_bind_int(stmt, chan->feerate_base); db_bind_int(stmt, chan->feerate_ppm); db_bind_talarr(stmt, chan->remote_upfront_shutdown_script); @@ -2641,8 +2641,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_null(stmt); db_bind_null(stmt); } - db_bind_amount_msat(stmt, &chan->htlc_minimum_msat); - db_bind_amount_msat(stmt, &chan->htlc_maximum_msat); + db_bind_amount_msat(stmt, chan->htlc_minimum_msat); + db_bind_amount_msat(stmt, chan->htlc_maximum_msat); if (chan->alias[LOCAL] != NULL) db_bind_short_channel_id(stmt, *chan->alias[LOCAL]); @@ -2660,8 +2660,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_int(stmt, peer_update->fee_base); db_bind_int(stmt, peer_update->fee_ppm); db_bind_int(stmt, peer_update->cltv_delta); - db_bind_amount_msat(stmt, &peer_update->htlc_minimum_msat); - db_bind_amount_msat(stmt, &peer_update->htlc_maximum_msat); + db_bind_amount_msat(stmt, peer_update->htlc_minimum_msat); + db_bind_amount_msat(stmt, peer_update->htlc_maximum_msat); } else { db_bind_null(stmt); db_bind_null(stmt); @@ -3123,7 +3123,7 @@ static void got_utxo(struct wallet *w, mvt = new_coin_wallet_deposit(tmpctx, &utxo->outpoint, *blockheight, utxo->amount, - DEPOSIT); + mk_mvt_tags(MVT_DEPOSIT)); notify_chain_mvt(w->ld, mvt); } @@ -3208,7 +3208,7 @@ void wallet_htlc_save_in(struct wallet *wallet, db_bind_u64(stmt, chan->dbid); db_bind_u64(stmt, in->key.id); db_bind_int(stmt, DIRECTION_INCOMING); - db_bind_amount_msat(stmt, &in->msat); + db_bind_amount_msat(stmt, in->msat); db_bind_int(stmt, in->cltv_expiry); db_bind_sha256(stmt, &in->payment_hash); @@ -3282,7 +3282,7 @@ void wallet_htlc_save_out(struct wallet *wallet, db_bind_u64(stmt, out->in->dbid); else db_bind_null(stmt); - db_bind_amount_msat(stmt, &out->msat); + db_bind_amount_msat(stmt, out->msat); db_bind_int(stmt, out->cltv_expiry); db_bind_sha256(stmt, &out->payment_hash); @@ -3304,7 +3304,7 @@ void wallet_htlc_save_out(struct wallet *wallet, db_bind_u64(stmt, out->groupid); } - db_bind_amount_msat(stmt, &out->fees); + db_bind_amount_msat(stmt, out->fees); db_bind_u64(stmt, min_u64(chan->next_index[LOCAL]-1, chan->next_index[REMOTE]-1)); @@ -3813,7 +3813,7 @@ struct wallet_payment *wallet_add_payment(const tal_t *ctx, else db_bind_null(stmt); - db_bind_amount_msat(stmt, &payment->msatoshi); + db_bind_amount_msat(stmt, payment->msatoshi); db_bind_int(stmt, payment->timestamp); if (payment->path_secrets != NULL) @@ -3830,7 +3830,7 @@ struct wallet_payment *wallet_add_payment(const tal_t *ctx, db_bind_null(stmt); } - db_bind_amount_msat(stmt, &payment->msatoshi_sent); + db_bind_amount_msat(stmt, payment->msatoshi_sent); if (payment->label != NULL) db_bind_text(stmt, payment->label); @@ -3842,7 +3842,7 @@ struct wallet_payment *wallet_add_payment(const tal_t *ctx, else db_bind_null(stmt); - db_bind_amount_msat(stmt, &payment->total_msat); + db_bind_amount_msat(stmt, payment->total_msat); db_bind_u64(stmt, payment->partid); if (payment->local_invreq_id != NULL) @@ -4737,7 +4737,7 @@ void wallet_utxoset_add(struct wallet *w, db_bind_null(stmt); db_bind_int(stmt, txindex); db_bind_blob(stmt, scriptpubkey, scriptpubkey_len); - db_bind_amount_sat(stmt, &sat); + db_bind_amount_sat(stmt, sat); db_exec_prepared_v2(take(stmt)); outpointfilter_add(w->utxoset_outpoints, outpoint); @@ -4775,7 +4775,7 @@ void wallet_filteredblock_add(struct wallet *w, const struct filteredblock *fb) db_bind_null(stmt); db_bind_int(stmt, o->txindex); db_bind_talarr(stmt, o->scriptPubKey); - db_bind_amount_sat(stmt, &o->amount); + db_bind_amount_sat(stmt, o->amount); db_exec_prepared_v2(take(stmt)); outpointfilter_add(w->utxoset_outpoints, &o->outpoint); @@ -5170,10 +5170,10 @@ static bool wallet_forwarded_payment_update(struct wallet *w, " WHERE in_htlc_id=? AND in_channel_scid=?")); /* This may not work so don't increment index yet! */ db_bind_u64(stmt, w->ld->indexes[WAIT_SUBSYSTEM_FORWARD].i[WAIT_INDEX_UPDATED] + 1); - db_bind_amount_msat(stmt, &in->msat); + db_bind_amount_msat(stmt, in->msat); if (out) { - db_bind_amount_msat(stmt, &out->msat); + db_bind_amount_msat(stmt, out->msat); } else { db_bind_null(stmt); } @@ -5285,9 +5285,9 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, db_bind_short_channel_id(stmt, *scid_out); else db_bind_null(stmt); - db_bind_amount_msat(stmt, &in->msat); + db_bind_amount_msat(stmt, in->msat); if (out) - db_bind_amount_msat(stmt, &out->msat); + db_bind_amount_msat(stmt, out->msat); else db_bind_null(stmt); @@ -5721,7 +5721,7 @@ void wallet_penalty_base_add(struct wallet *w, u64 chan_id, db_bind_u64(stmt, pb->commitment_num); db_bind_txid(stmt, &pb->txid); db_bind_int(stmt, pb->outnum); - db_bind_amount_sat(stmt, &pb->amount); + db_bind_amount_sat(stmt, pb->amount); db_exec_prepared_v2(take(stmt)); } @@ -6703,7 +6703,7 @@ void wallet_set_local_anchor(struct wallet *w, db_bind_u64(stmt, remote_index); db_bind_txid(stmt, &anchor->anchor_point.txid); db_bind_int(stmt, anchor->anchor_point.n); - db_bind_amount_sat(stmt, &anchor->commitment_fee); + db_bind_amount_sat(stmt, anchor->commitment_fee); db_bind_int(stmt, anchor->commitment_weight); db_exec_prepared_v2(stmt); tal_free(stmt); diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 29beb0aaaf6f..db49c8315364 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -17,10 +17,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -946,9 +946,10 @@ static void maybe_notify_new_external_send(struct lightningd *ld, mvt = new_coin_external_deposit(NULL, &outpoint, 0, amount, - DEPOSIT); + mk_mvt_tags(MVT_DEPOSIT)); + + mvt->originating_acct = new_mvt_account_id(mvt, NULL, WALLET); - mvt->originating_acct = WALLET; notify_chain_mvt(ld, mvt); tal_free(mvt); }