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.
This commit is contained in:
niftynei
2021-12-01 10:34:58 -06:00
committed by Rusty Russell
parent 8098a4cd21
commit 4506f639fa
10 changed files with 11 additions and 74 deletions

View File

@@ -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;
}

View File

@@ -5,7 +5,7 @@
#include <common/amount.h>
#include <common/channel_id.h>
#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);

View File

@@ -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,

View File

@@ -3,25 +3,15 @@
#include <lightningd/coin_mvts.h>
#include <lightningd/notification.h>
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;
}

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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);

View File

@@ -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(); }

View File

@@ -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):

View File

@@ -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]