From 4506f639fa68e0b194017fcb9026877f4e5fe230 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 1 Dec 2021 10:34:58 -0600 Subject: [PATCH] coin_moves: remove 'index' for moves; bump version Get rid of the 'movement_idx', since we replay events now. Since we're removing a field from the 'coin_movement' event emission, we bump the version type. Changelog-Updated: `coin_movements` events have been revamped and are now on version 2. --- common/coin_mvt.c | 8 ++----- common/coin_mvt.h | 11 +++------ doc/PLUGINS.md | 5 +---- lightningd/coin_mvts.c | 32 +++------------------------ lightningd/coin_mvts.h | 2 -- lightningd/lightningd.c | 4 ---- lightningd/notification.c | 1 - lightningd/test/run-find_my_abspath.c | 3 --- tests/test_plugin.py | 4 +--- tests/utils.py | 15 +------------ 10 files changed, 11 insertions(+), 74 deletions(-) diff --git a/common/coin_mvt.c b/common/coin_mvt.c index 1f93435e1..a9bb5dee6 100644 --- a/common/coin_mvt.c +++ b/common/coin_mvt.c @@ -306,8 +306,7 @@ struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, const struct chain_coin_mvt *chain_mvt, const char *bip173_name, u32 timestamp, - struct node_id *node_id, - s64 count) + struct node_id *node_id) { struct coin_mvt *mvt = tal(ctx, struct coin_mvt); @@ -330,7 +329,6 @@ struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, mvt->blockheight = chain_mvt->blockheight; mvt->version = COIN_MVT_VERSION; mvt->node_id = node_id; - mvt->counter = count; return mvt; } @@ -338,8 +336,7 @@ struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, const struct channel_coin_mvt *chan_mvt, const char *bip173_name, - u32 timestamp, struct node_id *node_id, - s64 count) + u32 timestamp, struct node_id *node_id) { struct coin_mvt *mvt = tal(ctx, struct coin_mvt); @@ -360,7 +357,6 @@ struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, mvt->blockheight = 0; mvt->version = COIN_MVT_VERSION; mvt->node_id = node_id; - mvt->counter = count; return mvt; } diff --git a/common/coin_mvt.h b/common/coin_mvt.h index 04383c6e6..e76a6679b 100644 --- a/common/coin_mvt.h +++ b/common/coin_mvt.h @@ -5,7 +5,7 @@ #include #include -#define COIN_MVT_VERSION 1 +#define COIN_MVT_VERSION 2 #define COIN_MVT_ACCT_WALLET "wallet" @@ -123,9 +123,6 @@ struct coin_mvt { /* node originating this movement */ struct node_id *node_id; - - /* id of this movement (on this node) */ - u64 counter; }; struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx, @@ -222,14 +219,12 @@ struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, const struct chain_coin_mvt *chain_mvt, const char *bip173_name, u32 timestamp, - struct node_id *node_id, - s64 mvt_count); + struct node_id *node_id); struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, const struct channel_coin_mvt *chan_mvt, const char *bip173_name, - u32 timestamp, struct node_id *node_id, - s64 mvt_count); + u32 timestamp, struct node_id *node_id); const char *mvt_type_str(enum mvt_type type); const char *mvt_tag_str(enum mvt_tag tag); diff --git a/doc/PLUGINS.md b/doc/PLUGINS.md index b88d6140b..e925e319d 100644 --- a/doc/PLUGINS.md +++ b/doc/PLUGINS.md @@ -697,9 +697,8 @@ i.e. only definitively resolved HTLCs or confirmed bitcoin transactions. ```json { "coin_movement": { - "version":1, + "version":2, "node_id":"03a7103a2322b811f7369cbb27fb213d30bbc0b012082fed3cad7e4498da2dc56b", - "movement_idx":0, "type":"chain_mvt", "account_id":"wallet", "txid":"0159693d8f3876b4def468b208712c630309381e9d106a9836fa0a9571a28722", // (`chain_mvt` type only, mandatory) @@ -722,8 +721,6 @@ notification adheres to. `node_id` specifies the node issuing the coin movement. -`movement_idx` is an increment-only counter for coin moves emitted by this node. - `type` marks the underlying mechanism which moved these coins. There are two 'types' of `coin_movements`: - `channel_mvt`s, which occur as a result of htlcs being resolved and, diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c index b827310d9..d83550327 100644 --- a/lightningd/coin_mvts.c +++ b/lightningd/coin_mvts.c @@ -3,25 +3,15 @@ #include #include -static s64 update_count(struct lightningd *ld) -{ - s64 count; - count = ++ld->coin_moves_count; - db_set_intvar(ld->wallet->db, "coin_moves_count", count); - - return count; -} - void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt) { const struct coin_mvt *cm; u32 timestamp; - s64 count; timestamp = time_now().ts.tv_sec; - count = update_count(ld); cm = finalize_channel_mvt(mvt, mvt, chainparams->lightning_hrp, - timestamp, &ld->id, count); + timestamp, &ld->id); + notify_coin_mvt(ld, cm); } @@ -29,12 +19,10 @@ void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt) { const struct coin_mvt *cm; u32 timestamp; - s64 count; timestamp = time_now().ts.tv_sec; - count = update_count(ld); cm = finalize_chain_mvt(mvt, mvt, chainparams->onchain_hrp, - timestamp, &ld->id, count); + timestamp, &ld->id); notify_coin_mvt(ld, cm); } @@ -77,17 +65,3 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx, hout->msat, ROUTED, false); } - -void coin_mvts_init_count(struct lightningd *ld) -{ - s64 count; - db_begin_transaction(ld->wallet->db); - count = db_get_intvar(ld->wallet->db, - "coin_moves_count", -1); - db_commit_transaction(ld->wallet->db); - if (count == -1) - fatal("Something went wrong attempting to fetch" - "the latest `coin_moves_count` from the intvars " - "table"); - ld->coin_moves_count = count; -} diff --git a/lightningd/coin_mvts.h b/lightningd/coin_mvts.h index 30f89c28f..0ebce3d7d 100644 --- a/lightningd/coin_mvts.h +++ b/lightningd/coin_mvts.h @@ -21,6 +21,4 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx, struct htlc_out *hout, struct channel *channel); -/* Initialize the coin movement counter on lightningd */ -void coin_mvts_init_count(struct lightningd *ld); #endif /* LIGHTNING_LIGHTNINGD_COIN_MVTS_H */ diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 9c0d120a6..4adb6632a 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -1000,10 +1000,6 @@ int main(int argc, char *argv[]) * states, invoices, payments, blocks and bitcoin transactions. */ ld->wallet = wallet_new(ld, ld->timers, bip32_base); - /*~ We keep track of how many 'coin moves' we've ever made. - * Initialize the starting value from the database here. */ - coin_mvts_init_count(ld); - /*~ We keep a filter of scriptpubkeys we're interested in. */ ld->owned_txfilter = txfilter_new(ld); diff --git a/lightningd/notification.c b/lightningd/notification.c index de7d1e64e..3ca5deec2 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -465,7 +465,6 @@ static void coin_movement_notification_serialize(struct json_stream *stream, json_object_start(stream, "coin_movement"); json_add_num(stream, "version", mvt->version); json_add_node_id(stream, "node_id", mvt->node_id); - json_add_u64(stream, "movement_idx", mvt->counter); json_add_string(stream, "type", mvt_type_str(mvt->type)); json_add_string(stream, "account_id", mvt->account_id); json_mvt_id(stream, mvt->type, &mvt->id); diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 24e53c97a..f7896a0c1 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -19,9 +19,6 @@ void begin_topology(struct chain_topology *topo UNNEEDED) void channel_notify_new_block(struct lightningd *ld UNNEEDED, u32 block_height UNNEEDED) { fprintf(stderr, "channel_notify_new_block called!\n"); abort(); } -/* Generated stub for coin_mvts_init_count */ -void coin_mvts_init_count(struct lightningd *ld UNNEEDED) -{ fprintf(stderr, "coin_mvts_init_count called!\n"); abort(); } /* Generated stub for connectd_activate */ void connectd_activate(struct lightningd *ld UNNEEDED) { fprintf(stderr, "connectd_activate called!\n"); abort(); } diff --git a/tests/test_plugin.py b/tests/test_plugin.py index c4c24f738..b4cbf7508 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -9,8 +9,7 @@ from utils import ( DEVELOPER, only_one, sync_blockheight, TIMEOUT, wait_for, TEST_NETWORK, DEPRECATED_APIS, expected_peer_features, expected_node_features, expected_channel_features, account_balance, - check_coin_moves, first_channel_id, check_coin_moves_idx, - EXPERIMENTAL_DUAL_FUND + check_coin_moves, first_channel_id, EXPERIMENTAL_DUAL_FUND ) import ast @@ -1986,7 +1985,6 @@ def test_coin_movement_notices(node_factory, bitcoind, chainparams): # Verify we recorded all the movements we expect check_coin_moves(l2, chanid_1, l1_l2_mvts, chainparams) check_coin_moves(l2, chanid_3, l2_l3_mvts, chainparams) - check_coin_moves_idx(l2) def test_3847_repro(node_factory, bitcoind): diff --git a/tests/utils.py b/tests/utils.py index 74bf7d2b3..4c5c83464 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -99,7 +99,7 @@ def check_coin_moves(n, account_id, expected_moves, chainparams): Millisatoshi(mv['credit']).millisatoshis, Millisatoshi(mv['debit']).millisatoshis, mv['tag'])) - assert mv['version'] == 1 + assert mv['version'] == 2 assert mv['node_id'] == node_id assert mv['timestamp'] > 0 assert mv['coin_type'] == chainparams['bip173_prefix'] @@ -129,19 +129,6 @@ def check_coin_moves(n, account_id, expected_moves, chainparams): assert acct_moves == [] -def check_coin_moves_idx(n): - """ Just check that the counter increments smoothly""" - moves = n.rpc.call('listcoinmoves_plugin')['coin_moves'] - idx = 0 - for m in moves: - c_idx = m['movement_idx'] - # verify that the index count increments smoothly here, also - if c_idx == 0 and idx == 0: - continue - assert c_idx == idx + 1 - idx = c_idx - - def account_balance(n, account_id): moves = dedupe_moves(n.rpc.call('listcoinmoves_plugin')['coin_moves']) chan_moves = [m for m in moves if m['account_id'] == account_id]