@@ -90,6 +90,7 @@ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char
90
90
/* AUTOGENERATED MOCKS END */
91
91
92
92
static sqlite3 * bkpr_db ;
93
+ static struct command * cmd ;
93
94
94
95
/* Stolen from old plugins/bkpr/db.c */
95
96
struct migration {
@@ -734,8 +735,8 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
734
735
memset (& txid , '1' , sizeof (struct bitcoin_txid ));
735
736
736
737
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" );
739
740
db_commit_transaction (db );
740
741
741
742
@@ -753,7 +754,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
753
754
AMOUNT_MSAT (1000 ),
754
755
blockheight ,
755
756
'X' , 0 , '1' ));
756
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
757
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
757
758
758
759
log_chain_event (bkpr , wal_acct ,
759
760
make_chain_event (ctx , "deposit" ,
@@ -762,7 +763,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
762
763
AMOUNT_MSAT (200 ),
763
764
blockheight ,
764
765
'1' , 1 , '*' ));
765
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
766
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
766
767
767
768
log_chain_event (bkpr , ext_acct ,
768
769
make_chain_event (ctx , "deposit" ,
@@ -771,7 +772,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
771
772
AMOUNT_MSAT (700 ),
772
773
blockheight ,
773
774
'1' , 0 , '*' ));
774
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
775
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
775
776
db_commit_transaction (db );
776
777
777
778
ofs = list_chain_fees (ctx , bkpr );
@@ -815,9 +816,9 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
815
816
acct -> peer_id = & peer_id ;
816
817
817
818
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" );
821
822
db_commit_transaction (db );
822
823
823
824
/* Close a channel */
@@ -845,7 +846,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
845
846
'X' , 0 , '*' );
846
847
log_chain_event (bkpr , acct , ev );
847
848
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 );
849
850
850
851
ev = make_chain_event (ctx , "channel_close" ,
851
852
AMOUNT_MSAT (0 ),
@@ -857,7 +858,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
857
858
858
859
/* Update the account to have the right info! */
859
860
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 );
861
862
862
863
log_chain_event (bkpr , acct ,
863
864
make_chain_event (ctx , "delayed_to_us" ,
@@ -867,7 +868,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
867
868
blockheight ,
868
869
'1' , 1 , '*' ));
869
870
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 );
871
872
872
873
log_chain_event (bkpr , wal_acct ,
873
874
make_chain_event (ctx , "anchor" ,
@@ -884,7 +885,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
884
885
blockheight ,
885
886
'1' , 4 , '*' ));
886
887
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 );
888
889
889
890
/* Should be no fees yet */
890
891
ofs = list_chain_fees (ctx , bkpr );
@@ -907,7 +908,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
907
908
'1' , 3 , '*' ));
908
909
909
910
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 );
911
912
db_commit_transaction (db );
912
913
913
914
/* txid 2222 */
@@ -928,10 +929,10 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
928
929
blockheight + 1 ,
929
930
'2' , 0 , '*' ));
930
931
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 );
932
933
CHECK (acct -> onchain_resolved_block == 0 );
933
934
934
- assert (account_onchain_closeheight (bkpr , NULL , acct ) == 0 );
935
+ assert (account_onchain_closeheight (bkpr , cmd , acct ) == 0 );
935
936
CHECK (acct -> onchain_resolved_block == 0 );
936
937
db_commit_transaction (db );
937
938
@@ -953,7 +954,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
953
954
'4' , 0 , '*' ));
954
955
955
956
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 );
957
958
958
959
/* txid 3333 */
959
960
log_chain_event (bkpr , acct ,
@@ -964,7 +965,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
964
965
blockheight + 2 ,
965
966
'1' , 2 , '3' ));
966
967
967
- assert (account_onchain_closeheight (bkpr , NULL , acct ) == 0 );
968
+ assert (account_onchain_closeheight (bkpr , cmd , acct ) == 0 );
968
969
CHECK (acct -> onchain_resolved_block == 0 );
969
970
970
971
log_chain_event (bkpr , acct ,
@@ -976,7 +977,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
976
977
'3' , 0 , '*' ));
977
978
978
979
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 );
980
981
981
982
log_chain_event (bkpr , acct ,
982
983
make_chain_event (ctx , "to_wallet" ,
@@ -987,7 +988,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
987
988
'3' , 0 , '4' ));
988
989
989
990
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 );
991
992
992
993
db_commit_transaction (db );
993
994
@@ -1001,9 +1002,9 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
1001
1002
/* Now we update the channel's onchain fees */
1002
1003
CHECK (acct -> onchain_resolved_block == 0 );
1003
1004
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 ));
1005
1006
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 );
1007
1008
CHECK_MSG (!err , err );
1008
1009
db_commit_transaction (db );
1009
1010
ofs = account_get_chain_fees (tmpctx , bkpr , acct -> name );
@@ -1076,10 +1077,10 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
1076
1077
acct2 -> peer_id = & peer_id ;
1077
1078
1078
1079
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" );
1083
1084
db_commit_transaction (db );
1084
1085
1085
1086
/* Assumption that we rely on later */
@@ -1117,7 +1118,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
1117
1118
AMOUNT_MSAT (500 ),
1118
1119
blockheight ,
1119
1120
'A' , 0 , '*' ));
1120
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1121
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
1121
1122
1122
1123
log_chain_event (bkpr , acct2 ,
1123
1124
make_chain_event (ctx , "deposit" ,
@@ -1126,7 +1127,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
1126
1127
AMOUNT_MSAT (1000 ),
1127
1128
blockheight ,
1128
1129
'A' , 1 , '*' ));
1129
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1130
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
1130
1131
1131
1132
log_chain_event (bkpr , wal_acct ,
1132
1133
make_chain_event (ctx , "deposit" ,
@@ -1135,9 +1136,9 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
1135
1136
AMOUNT_MSAT (2200 ),
1136
1137
blockheight ,
1137
1138
'A' , 2 , '*' ));
1138
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1139
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
1139
1140
1140
- maybe_update_onchain_fees (ctx , NULL , bkpr , & txid );
1141
+ maybe_update_onchain_fees (ctx , cmd , bkpr , & txid );
1141
1142
db_commit_transaction (db );
1142
1143
1143
1144
/* Expect: 5 onchain fee records, totaling to 151/150msat ea,
@@ -1196,9 +1197,9 @@ static bool test_channel_rebalances(const tal_t *ctx)
1196
1197
1197
1198
db_begin_transaction (db );
1198
1199
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" );
1202
1203
1203
1204
/* Simulate a rebalance of 100msats, w/ a 12msat fee */
1204
1205
ev1 = make_channel_event (ctx , "invoice" ,
@@ -1224,29 +1225,29 @@ static bool test_channel_rebalances(const tal_t *ctx)
1224
1225
db_commit_transaction (db );
1225
1226
1226
1227
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 );
1228
1229
CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1229
1230
1230
- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct2 );
1231
+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct2 );
1231
1232
CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1232
1233
1233
- chan_evs = account_get_channel_events (ctx , bkpr , NULL , acct3 );
1234
+ chan_evs = account_get_channel_events (ctx , bkpr , cmd , acct3 );
1234
1235
CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1235
1236
1236
- maybe_record_rebalance (NULL , bkpr , ev2 );
1237
+ maybe_record_rebalance (cmd , bkpr , ev2 );
1237
1238
CHECK (find_rebalance (bkpr , ev2 -> db_id ) != NULL );
1238
1239
1239
1240
/* 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 );
1241
1242
CHECK (tal_count (chan_evs ) == 1 && find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1242
1243
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 );
1244
1245
CHECK (tal_count (chan_evs ) == 1 && find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1245
1246
CHECK (* find_rebalance (bkpr , chan_evs [0 ]-> db_id ) == ev1 -> db_id );
1246
1247
CHECK (* find_rebalance (bkpr , ev1 -> db_id ) == chan_evs [0 ]-> db_id );
1247
1248
1248
1249
/* 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 );
1250
1251
CHECK (tal_count (chan_evs ) == 1 && !find_rebalance (bkpr , chan_evs [0 ]-> db_id ));
1251
1252
1252
1253
/* Did we get an accurate rebalances entry? */
@@ -1279,8 +1280,8 @@ static bool test_channel_event_crud(const tal_t *ctx)
1279
1280
acct2 = new_account (bkpr -> accounts , tal_fmt (ctx , ACCOUNT_NAME_WALLET ));
1280
1281
acct2 -> peer_id = & peer_id ;
1281
1282
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" );
1284
1285
db_commit_transaction (db );
1285
1286
1286
1287
ev1 = tal (ctx , struct channel_event );
@@ -1329,7 +1330,7 @@ static bool test_channel_event_crud(const tal_t *ctx)
1329
1330
db_commit_transaction (db );
1330
1331
1331
1332
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 );
1333
1334
db_commit_transaction (db );
1334
1335
1335
1336
CHECK (streq (acct -> name , chan_evs [0 ]-> acct_name ));
@@ -1358,8 +1359,8 @@ static bool test_chain_event_crud(const tal_t *ctx)
1358
1359
acct2 = new_account (bkpr -> accounts , tal_fmt (ctx , ACCOUNT_NAME_WALLET ));
1359
1360
acct2 -> peer_id = & peer_id ;
1360
1361
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" );
1363
1364
db_commit_transaction (db );
1364
1365
1365
1366
/* This event spends the second inserted event */
@@ -1504,8 +1505,8 @@ static bool test_account_balances(const tal_t *ctx)
1504
1505
ok = account_get_balance (bkpr , acct -> name , & balance );
1505
1506
CHECK (ok );
1506
1507
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" );
1509
1510
1510
1511
/* +1000btc */
1511
1512
log_chain_event (bkpr , acct ,
@@ -1575,7 +1576,7 @@ static bool test_account_crud(const tal_t *ctx)
1575
1576
CHECK (!acct -> is_wallet );
1576
1577
1577
1578
db_begin_transaction (db );
1578
- account_datastore_set (NULL , acct , "must-create" );
1579
+ account_datastore_set (cmd , acct , "must-create" );
1579
1580
db_commit_transaction (db );
1580
1581
1581
1582
acct_list = list_accounts (ctx , bkpr );
@@ -1586,7 +1587,7 @@ static bool test_account_crud(const tal_t *ctx)
1586
1587
CHECK (acct -> is_wallet );
1587
1588
1588
1589
db_begin_transaction (db );
1589
- account_datastore_set (NULL , acct , "must-create" );
1590
+ account_datastore_set (cmd , acct , "must-create" );
1590
1591
db_commit_transaction (db );
1591
1592
1592
1593
acct_list = list_accounts (ctx , bkpr );
@@ -1622,7 +1623,7 @@ static bool test_account_crud(const tal_t *ctx)
1622
1623
/* should not update the account info */
1623
1624
tags [0 ] = MVT_PUSHED ;
1624
1625
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 );
1626
1627
acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
1627
1628
accountseq (acct , acct2 );
1628
1629
@@ -1631,7 +1632,7 @@ static bool test_account_crud(const tal_t *ctx)
1631
1632
CHECK (acct -> open_event_db_id == NULL );
1632
1633
tags [0 ] = MVT_CHANNEL_OPEN ;
1633
1634
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 );
1635
1636
acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
1636
1637
accountseq (acct , acct2 );
1637
1638
CHECK (acct -> leased );
@@ -1642,7 +1643,7 @@ static bool test_account_crud(const tal_t *ctx)
1642
1643
tags [1 ] = MVT_OPENER ;
1643
1644
CHECK (acct -> closed_event_db_id == NULL );
1644
1645
CHECK (!acct -> we_opened );
1645
- maybe_update_account (NULL , acct , ev1 , tags , 0 , NULL );
1646
+ maybe_update_account (cmd , acct , ev1 , tags , 0 , NULL );
1646
1647
acct2 = find_account (bkpr , ACCOUNT_NAME_WALLET );
1647
1648
accountseq (acct , acct2 );
1648
1649
CHECK (acct -> closed_event_db_id != NULL );
@@ -1660,6 +1661,8 @@ int main(int argc, char *argv[])
1660
1661
common_setup (argv [0 ]);
1661
1662
1662
1663
if (HAVE_SQLITE3 ) {
1664
+ /* UBSan insists cmd isn't NULL */
1665
+ cmd = tal (tmpctx , struct command );
1663
1666
ok &= test_account_crud (tmpctx );
1664
1667
ok &= test_channel_event_crud (tmpctx );
1665
1668
ok &= test_chain_event_crud (tmpctx );
0 commit comments