Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions plugins/bkpr/bookkeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,10 @@ parse_and_log_chain_move(struct command *cmd,
if (e->origin_acct)
find_or_create_account(cmd, bkpr, e->origin_acct);

/* Make this visible for queries (we expect increasing!) */
assert(e->db_id > bkpr->chainmoves_index);
/* Make this visible for queries (we expect increasing!). If we raced, this is not true. */
if (e->db_id <= bkpr->chainmoves_index)
return;

bkpr->chainmoves_index = e->db_id;

/* This event *might* have implications for account;
Expand Down Expand Up @@ -1336,8 +1338,9 @@ parse_and_log_channel_move(struct command *cmd,
" but no account exists %s",
acct_name);

/* Make this visible for queries (we expect increasing!) */
assert(e->db_id > bkpr->channelmoves_index);
/* Make this visible for queries (we expect increasing!). If we raced, this is not true. */
if (e->db_id <= bkpr->channelmoves_index)
return;
bkpr->channelmoves_index = e->db_id;

/* Check for invoice desc data, necessary */
Expand Down
15 changes: 15 additions & 0 deletions tests/test_bookkeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,3 +1193,18 @@ def test_listincome_timebox(node_factory, bitcoind):

incomes = l1.rpc.bkpr_listincome(end_time=first_one)['income_events']
assert [i for i in incomes if i['timestamp'] > first_one] == []


@unittest.skipIf(TEST_NETWORK != 'regtest', "Snapshots are bitcoin regtest.")
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "uses snapshots")
def test_bkpr_parallel(node_factory, bitcoind, executor):
"""Bookkeeper could crash with parallel requests"""
bitcoind.generate_block(1)
l1 = node_factory.get_node(dbfile="l1-before-moves-in-db.sqlite3.xz",
options={'database-upgrade': True})

fut1 = executor.submit(l1.rpc.bkpr_listincome)
fut2 = executor.submit(l1.rpc.bkpr_listincome)

fut1.result()
fut2.result()
Loading