@@ -90,6 +90,7 @@ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char
9090/* AUTOGENERATED MOCKS END */
9191
9292static sqlite3 * bkpr_db ;
93+ static struct command * cmd ;
9394
9495/* Stolen from old plugins/bkpr/db.c */
9596struct migration {
@@ -734,8 +735,8 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
734735 memset (& txid , '1' , sizeof (struct bitcoin_txid ));
735736
736737 db_begin_transaction (db );
737- account_datastore_set (NULL , wal_acct , "must-create" );
738- account_datastore_set (NULL , ext_acct , "must-create" );
738+ account_datastore_set (cmd , wal_acct , "must-create" );
739+ account_datastore_set (cmd , ext_acct , "must-create" );
739740 db_commit_transaction (db );
740741
741742
@@ -753,7 +754,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
753754 AMOUNT_MSAT (1000 ),
754755 blockheight ,
755756 'X' , 0 , '1' ));
756- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
757+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
757758
758759 log_chain_event (bkpr , wal_acct ,
759760 make_chain_event (ctx , "deposit" ,
@@ -762,7 +763,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
762763 AMOUNT_MSAT (200 ),
763764 blockheight ,
764765 '1' , 1 , '*' ));
765- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
766+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
766767
767768 log_chain_event (bkpr , ext_acct ,
768769 make_chain_event (ctx , "deposit" ,
@@ -771,7 +772,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
771772 AMOUNT_MSAT (700 ),
772773 blockheight ,
773774 '1' , 0 , '*' ));
774- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
775+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
775776 db_commit_transaction (db );
776777
777778 ofs = list_chain_fees (ctx , bkpr );
@@ -815,9 +816,9 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
815816 acct -> peer_id = & peer_id ;
816817
817818 db_begin_transaction (db );
818- account_datastore_set (NULL , wal_acct , "must-create" );
819- account_datastore_set (NULL , ext_acct , "must-create" );
820- account_datastore_set (NULL , acct , "must-create" );
819+ account_datastore_set (cmd , wal_acct , "must-create" );
820+ account_datastore_set (cmd , ext_acct , "must-create" );
821+ account_datastore_set (cmd , acct , "must-create" );
821822 db_commit_transaction (db );
822823
823824 /* Close a channel */
@@ -845,7 +846,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
845846 'X' , 0 , '*' );
846847 log_chain_event (bkpr , acct , ev );
847848 tags [0 ] = MVT_CHANNEL_OPEN ;
848- maybe_update_account (NULL , acct , ev , tags , 0 , NULL );
849+ maybe_update_account (cmd , acct , ev , tags , 0 , NULL );
849850
850851 ev = make_chain_event (ctx , "channel_close" ,
851852 AMOUNT_MSAT (0 ),
@@ -857,7 +858,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
857858
858859 /* Update the account to have the right info! */
859860 tags [0 ] = MVT_CHANNEL_CLOSE ;
860- maybe_update_account (NULL , acct , ev , tags , close_output_count , NULL );
861+ maybe_update_account (cmd , acct , ev , tags , close_output_count , NULL );
861862
862863 log_chain_event (bkpr , acct ,
863864 make_chain_event (ctx , "delayed_to_us" ,
@@ -867,7 +868,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
867868 blockheight ,
868869 '1' , 1 , '*' ));
869870 memset (& txid , '1' , sizeof (struct bitcoin_txid ));
870- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
871+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
871872
872873 log_chain_event (bkpr , wal_acct ,
873874 make_chain_event (ctx , "anchor" ,
@@ -884,7 +885,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
884885 blockheight ,
885886 '1' , 4 , '*' ));
886887 memset (& txid , '1' , sizeof (struct bitcoin_txid ));
887- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
888+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
888889
889890 /* Should be no fees yet */
890891 ofs = list_chain_fees (ctx , bkpr );
@@ -907,7 +908,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
907908 '1' , 3 , '*' ));
908909
909910 memset (& txid , '1' , sizeof (struct bitcoin_txid ));
910- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
911+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
911912 db_commit_transaction (db );
912913
913914 /* txid 2222 */
@@ -928,10 +929,10 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
928929 blockheight + 1 ,
929930 '2' , 0 , '*' ));
930931 memset (& txid , '2' , sizeof (struct bitcoin_txid ));
931- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
932+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
932933 CHECK (acct -> onchain_resolved_block == 0 );
933934
934- assert (account_onchain_closeheight (bkpr , NULL , acct ) == 0 );
935+ assert (account_onchain_closeheight (bkpr , cmd , acct ) == 0 );
935936 CHECK (acct -> onchain_resolved_block == 0 );
936937 db_commit_transaction (db );
937938
@@ -953,7 +954,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
953954 '4' , 0 , '*' ));
954955
955956 memset (& txid , '4' , sizeof (struct bitcoin_txid ));
956- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
957+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
957958
958959 /* txid 3333 */
959960 log_chain_event (bkpr , acct ,
@@ -964,7 +965,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
964965 blockheight + 2 ,
965966 '1' , 2 , '3' ));
966967
967- assert (account_onchain_closeheight (bkpr , NULL , acct ) == 0 );
968+ assert (account_onchain_closeheight (bkpr , cmd , acct ) == 0 );
968969 CHECK (acct -> onchain_resolved_block == 0 );
969970
970971 log_chain_event (bkpr , acct ,
@@ -976,7 +977,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
976977 '3' , 0 , '*' ));
977978
978979 memset (& txid , '3' , sizeof (struct bitcoin_txid ));
979- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
980+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
980981
981982 log_chain_event (bkpr , acct ,
982983 make_chain_event (ctx , "to_wallet" ,
@@ -987,7 +988,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
987988 '3' , 0 , '4' ));
988989
989990 memset (& txid , '4' , sizeof (struct bitcoin_txid ));
990- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
991+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
991992
992993 db_commit_transaction (db );
993994
@@ -1001,9 +1002,9 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
10011002 /* Now we update the channel's onchain fees */
10021003 CHECK (acct -> onchain_resolved_block == 0 );
10031004 db_begin_transaction (db );
1004- account_update_closeheight (NULL , acct , account_onchain_closeheight (bkpr , NULL , acct ));
1005+ account_update_closeheight (cmd , acct , account_onchain_closeheight (bkpr , cmd , acct ));
10051006 CHECK (acct -> onchain_resolved_block == blockheight + 2 );
1006- err = update_channel_onchain_fees (ctx , NULL , bkpr , acct );
1007+ err = update_channel_onchain_fees (ctx , cmd , bkpr , acct );
10071008 CHECK_MSG (!err , err );
10081009 db_commit_transaction (db );
10091010 ofs = account_get_chain_fees (tmpctx , bkpr , acct -> name );
@@ -1076,10 +1077,10 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
10761077 acct2 -> peer_id = & peer_id ;
10771078
10781079 db_begin_transaction (db );
1079- account_datastore_set (NULL , wal_acct , "must-create" );
1080- account_datastore_set (NULL , ext_acct , "must-create" );
1081- account_datastore_set (NULL , acct , "must-create" );
1082- account_datastore_set (NULL , acct2 , "must-create" );
1080+ account_datastore_set (cmd , wal_acct , "must-create" );
1081+ account_datastore_set (cmd , ext_acct , "must-create" );
1082+ account_datastore_set (cmd , acct , "must-create" );
1083+ account_datastore_set (cmd , acct2 , "must-create" );
10831084 db_commit_transaction (db );
10841085
10851086 /* Assumption that we rely on later */
@@ -1117,7 +1118,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
11171118 AMOUNT_MSAT (500 ),
11181119 blockheight ,
11191120 'A' , 0 , '*' ));
1120- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1121+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
11211122
11221123 log_chain_event (bkpr , acct2 ,
11231124 make_chain_event (ctx , "deposit" ,
@@ -1126,7 +1127,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
11261127 AMOUNT_MSAT (1000 ),
11271128 blockheight ,
11281129 'A' , 1 , '*' ));
1129- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1130+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
11301131
11311132 log_chain_event (bkpr , wal_acct ,
11321133 make_chain_event (ctx , "deposit" ,
@@ -1135,9 +1136,9 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
11351136 AMOUNT_MSAT (2200 ),
11361137 blockheight ,
11371138 'A' , 2 , '*' ));
1138- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1139+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
11391140
1140- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1141+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
11411142 db_commit_transaction (db );
11421143
11431144 /* Expect: 5 onchain fee records, totaling to 151/150msat ea,
@@ -1196,9 +1197,9 @@ static bool test_channel_rebalances(const tal_t *ctx)
11961197
11971198 db_begin_transaction (db );
11981199
1199- account_datastore_set (NULL , acct1 , "must-create" );
1200- account_datastore_set (NULL , acct2 , "must-create" );
1201- account_datastore_set (NULL , acct3 , "must-create" );
1200+ account_datastore_set (cmd , acct1 , "must-create" );
1201+ account_datastore_set (cmd , acct2 , "must-create" );
1202+ account_datastore_set (cmd , acct3 , "must-create" );
12021203
12031204 /* Simulate a rebalance of 100msats, w/ a 12msat fee */
12041205 ev1 = make_channel_event (ctx , "invoice" ,
@@ -1224,29 +1225,29 @@ static bool test_channel_rebalances(const tal_t *ctx)
12241225 db_commit_transaction (db );
12251226
12261227 db_begin_transaction (db );
1227- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct1 );
1228+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct1 );
12281229 CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12291230
1230- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct2 );
1231+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct2 );
12311232 CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12321233
1233- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct3 );
1234+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct3 );
12341235 CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12351236
1236- maybe_record_rebalance (NULL , bkpr , ev2 );
1237+ maybe_record_rebalance (cmd , bkpr , ev2 );
12371238 CHECK (find_rebalance (bkpr , ev2 -> db_id ) != NULL );
12381239
12391240 /* Both events should be marked as rebalance */
1240- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct1 );
1241+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct1 );
12411242 CHECK (tal_count (chan_evs ) == 1 && find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12421243 ev1 = chan_evs [0 ];
1243- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct2 );
1244+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct2 );
12441245 CHECK (tal_count (chan_evs ) == 1 && find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12451246 CHECK (* find_rebalance (bkpr , chan_evs [0 ]-> db_id ) == ev1 -> db_id );
12461247 CHECK (* find_rebalance (bkpr , ev1 -> db_id ) == chan_evs [0 ]-> db_id );
12471248
12481249 /* Third event is not a rebalance though */
1249- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct3 );
1250+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct3 );
12501251 CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
12511252
12521253 /* Did we get an accurate rebalances entry? */
@@ -1279,8 +1280,8 @@ static bool test_channel_event_crud(const tal_t *ctx)
12791280 acct2 = new_account (bkpr -> accounts , tal_fmt (ctx , ACCOUNT_NAME_WALLET ));
12801281 acct2 -> peer_id = & peer_id ;
12811282 db_begin_transaction (db );
1282- account_datastore_set (NULL , acct , "must-create" );
1283- account_datastore_set (NULL , acct2 , "must-create" );
1283+ account_datastore_set (cmd , acct , "must-create" );
1284+ account_datastore_set (cmd , acct2 , "must-create" );
12841285 db_commit_transaction (db );
12851286
12861287 ev1 = tal (ctx , struct channel_event );
@@ -1329,7 +1330,7 @@ static bool test_channel_event_crud(const tal_t *ctx)
13291330 db_commit_transaction (db );
13301331
13311332 db_begin_transaction (db );
1332- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct );
1333+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct );
13331334 db_commit_transaction (db );
13341335
13351336 CHECK (streq (acct -> name , chan_evs [0 ]-> acct_name ));
@@ -1358,8 +1359,8 @@ static bool test_chain_event_crud(const tal_t *ctx)
13581359 acct2 = new_account (bkpr -> accounts , tal_fmt (ctx , ACCOUNT_NAME_WALLET ));
13591360 acct2 -> peer_id = & peer_id ;
13601361 db_begin_transaction (db );
1361- account_datastore_set (NULL , acct , "must-create" );
1362- account_datastore_set (NULL , acct2 , "must-create" );
1362+ account_datastore_set (cmd , acct , "must-create" );
1363+ account_datastore_set (cmd , acct2 , "must-create" );
13631364 db_commit_transaction (db );
13641365
13651366 /* This event spends the second inserted event */
@@ -1504,8 +1505,8 @@ static bool test_account_balances(const tal_t *ctx)
15041505 ok = account_get_balance (bkpr , acct -> name , & balance );
15051506 CHECK (ok );
15061507
1507- account_datastore_set (NULL , acct , "must-create" );
1508- account_datastore_set (NULL , acct2 , "must-create" );
1508+ account_datastore_set (cmd , acct , "must-create" );
1509+ account_datastore_set (cmd , acct2 , "must-create" );
15091510
15101511 /* +1000btc */
15111512 log_chain_event (bkpr , acct ,
@@ -1575,7 +1576,7 @@ static bool test_account_crud(const tal_t *ctx)
15751576 CHECK (!acct -> is_wallet );
15761577
15771578 db_begin_transaction (db );
1578- account_datastore_set (NULL , acct , "must-create" );
1579+ account_datastore_set (cmd , acct , "must-create" );
15791580 db_commit_transaction (db );
15801581
15811582 acct_list = list_accounts (ctx , bkpr );
@@ -1586,7 +1587,7 @@ static bool test_account_crud(const tal_t *ctx)
15861587 CHECK (acct -> is_wallet );
15871588
15881589 db_begin_transaction (db );
1589- account_datastore_set (NULL , acct , "must-create" );
1590+ account_datastore_set (cmd , acct , "must-create" );
15901591 db_commit_transaction (db );
15911592
15921593 acct_list = list_accounts (ctx , bkpr );
@@ -1622,7 +1623,7 @@ static bool test_account_crud(const tal_t *ctx)
16221623 /* should not update the account info */
16231624 tags [0 ] = MVT_PUSHED ;
16241625 tags [1 ] = MVT_PENALTY ;
1625- maybe_update_account (NULL , acct , ev1 , tags , 0 , peer_id );
1626+ maybe_update_account (cmd , acct , ev1 , tags , 0 , peer_id );
16261627 acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
16271628 accountseq (acct , acct2 );
16281629
@@ -1631,7 +1632,7 @@ static bool test_account_crud(const tal_t *ctx)
16311632 CHECK (acct -> open_event_db_id == NULL );
16321633 tags [0 ] = MVT_CHANNEL_OPEN ;
16331634 tags [1 ] = MVT_LEASED ;
1634- maybe_update_account (NULL , acct , ev1 , tags , 2 , peer_id );
1635+ maybe_update_account (cmd , acct , ev1 , tags , 2 , peer_id );
16351636 acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
16361637 accountseq (acct , acct2 );
16371638 CHECK (acct -> leased );
@@ -1642,7 +1643,7 @@ static bool test_account_crud(const tal_t *ctx)
16421643 tags [1 ] = MVT_OPENER ;
16431644 CHECK (acct -> closed_event_db_id == NULL );
16441645 CHECK (!acct -> we_opened );
1645- maybe_update_account (NULL , acct , ev1 , tags , 0 , NULL );
1646+ maybe_update_account (cmd , acct , ev1 , tags , 0 , NULL );
16461647 acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
16471648 accountseq (acct , acct2 );
16481649 CHECK (acct -> closed_event_db_id != NULL );
@@ -1660,6 +1661,8 @@ int main(int argc, char *argv[])
16601661 common_setup (argv [0 ]);
16611662
16621663 if (HAVE_SQLITE3 ) {
1664+ /* UBSan insists cmd isn't NULL */
1665+ cmd = tal (tmpctx , struct command );
16631666 ok &= test_account_crud (tmpctx );
16641667 ok &= test_channel_event_crud (tmpctx );
16651668 ok &= test_chain_event_crud (tmpctx );
0 commit comments