@ -11,6 +11,8 @@ static void db_log_(struct log *log, enum log_level level, const char *fmt, ...)
# include "wallet/wallet.c"
# include "lightningd/htlc_end.c"
# include "lightningd/peer_control.c"
# include "lightningd/channel.c"
# include "wallet/db.c"
@ -23,7 +25,167 @@ static void db_log_(struct log *log, enum log_level level, const char *fmt, ...)
# include <stdio.h>
# include <unistd.h>
bool deprecated_apis = true ;
/* AUTOGENERATED MOCKS START */
/* Generated stub for bip32_pubkey */
bool bip32_pubkey ( const struct ext_key * bip32_base UNNEEDED ,
struct pubkey * pubkey UNNEEDED , u32 index UNNEEDED )
{ fprintf ( stderr , " bip32_pubkey called! \n " ) ; abort ( ) ; }
/* Generated stub for bitcoind_gettxout */
void bitcoind_gettxout ( struct bitcoind * bitcoind UNNEEDED ,
const struct bitcoin_txid * txid UNNEEDED , const u32 outnum UNNEEDED ,
void ( * cb ) ( struct bitcoind * bitcoind UNNEEDED ,
const struct bitcoin_tx_output * txout UNNEEDED ,
void * arg ) UNNEEDED ,
void * arg UNNEEDED )
{ fprintf ( stderr , " bitcoind_gettxout called! \n " ) ; abort ( ) ; }
/* Generated stub for broadcast_tx */
void broadcast_tx ( struct chain_topology * topo UNNEEDED ,
struct peer * peer UNNEEDED , const struct bitcoin_tx * tx UNNEEDED ,
void ( * failed ) ( struct peer * peer UNNEEDED ,
int exitstatus UNNEEDED ,
const char * err ) )
{ fprintf ( stderr , " broadcast_tx called! \n " ) ; abort ( ) ; }
/* Generated stub for build_utxos */
const struct utxo * * build_utxos ( const tal_t * ctx UNNEEDED ,
struct lightningd * ld UNNEEDED , u64 satoshi_out UNNEEDED ,
u32 feerate_per_kw UNNEEDED , u64 dust_limit UNNEEDED ,
size_t outputscriptlen UNNEEDED ,
u64 * change_satoshis UNNEEDED , u32 * change_keyindex UNNEEDED )
{ fprintf ( stderr , " build_utxos called! \n " ) ; abort ( ) ; }
/* Generated stub for channel_wire_type_name */
const char * channel_wire_type_name ( int e UNNEEDED )
{ fprintf ( stderr , " channel_wire_type_name called! \n " ) ; abort ( ) ; }
/* Generated stub for closing_wire_type_name */
const char * closing_wire_type_name ( int e UNNEEDED )
{ fprintf ( stderr , " closing_wire_type_name called! \n " ) ; abort ( ) ; }
/* Generated stub for command_fail */
void command_fail ( struct command * cmd UNNEEDED , const char * fmt UNNEEDED , . . . )
{ fprintf ( stderr , " command_fail called! \n " ) ; abort ( ) ; }
/* Generated stub for command_still_pending */
void command_still_pending ( struct command * cmd UNNEEDED )
{ fprintf ( stderr , " command_still_pending called! \n " ) ; abort ( ) ; }
/* Generated stub for command_success */
void command_success ( struct command * cmd UNNEEDED , struct json_result * response UNNEEDED )
{ fprintf ( stderr , " command_success called! \n " ) ; abort ( ) ; }
/* Generated stub for derive_basepoints */
bool derive_basepoints ( const struct privkey * seed UNNEEDED ,
struct pubkey * funding_pubkey UNNEEDED ,
struct basepoints * basepoints UNNEEDED ,
struct secrets * secrets UNNEEDED ,
struct sha256 * shaseed UNNEEDED )
{ fprintf ( stderr , " derive_basepoints called! \n " ) ; abort ( ) ; }
/* Generated stub for extract_channel_id */
bool extract_channel_id ( const u8 * in_pkt UNNEEDED , struct channel_id * channel_id UNNEEDED )
{ fprintf ( stderr , " extract_channel_id called! \n " ) ; abort ( ) ; }
/* Generated stub for find_htlc_out_by_ripemd */
struct htlc_out * find_htlc_out_by_ripemd ( const struct peer * peer UNNEEDED ,
const struct ripemd160 * ripemd160 UNNEEDED )
{ fprintf ( stderr , " find_htlc_out_by_ripemd called! \n " ) ; abort ( ) ; }
/* Generated stub for find_txwatch */
struct txwatch * find_txwatch ( struct chain_topology * topo UNNEEDED ,
const struct bitcoin_txid * txid UNNEEDED ,
const struct peer * peer UNNEEDED )
{ fprintf ( stderr , " find_txwatch called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_channel_got_funding_locked */
bool fromwire_channel_got_funding_locked ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct pubkey * next_per_commit_point UNNEEDED )
{ fprintf ( stderr , " fromwire_channel_got_funding_locked called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_channel_got_shutdown */
bool fromwire_channel_got_shutdown ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , u8 * * scriptpubkey UNNEEDED )
{ fprintf ( stderr , " fromwire_channel_got_shutdown called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_channel_shutdown_complete */
bool fromwire_channel_shutdown_complete ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED )
{ fprintf ( stderr , " fromwire_channel_shutdown_complete called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_closing_complete */
bool fromwire_closing_complete ( const void * p UNNEEDED , size_t * plen UNNEEDED , u64 * gossip_index UNNEEDED )
{ fprintf ( stderr , " fromwire_closing_complete called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_closing_received_signature */
bool fromwire_closing_received_signature ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , secp256k1_ecdsa_signature * signature UNNEEDED , struct bitcoin_tx * * tx UNNEEDED )
{ fprintf ( stderr , " fromwire_closing_received_signature called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossipctl_release_peer_reply */
bool fromwire_gossipctl_release_peer_reply ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct wireaddr * addr UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED , u8 * * gfeatures UNNEEDED , u8 * * lfeatures UNNEEDED )
{ fprintf ( stderr , " fromwire_gossipctl_release_peer_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossipctl_release_peer_replyfail */
bool fromwire_gossipctl_release_peer_replyfail ( const void * p UNNEEDED , size_t * plen UNNEEDED )
{ fprintf ( stderr , " fromwire_gossipctl_release_peer_replyfail called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossip_getpeers_reply */
bool fromwire_gossip_getpeers_reply ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct pubkey * * id UNNEEDED , struct wireaddr * * addr UNNEEDED )
{ fprintf ( stderr , " fromwire_gossip_getpeers_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossip_peer_already_connected */
bool fromwire_gossip_peer_already_connected ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct pubkey * id UNNEEDED )
{ fprintf ( stderr , " fromwire_gossip_peer_already_connected called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossip_peer_connected */
bool fromwire_gossip_peer_connected ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct pubkey * id UNNEEDED , struct wireaddr * addr UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED , u8 * * gfeatures UNNEEDED , u8 * * lfeatures UNNEEDED )
{ fprintf ( stderr , " fromwire_gossip_peer_connected called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_gossip_peer_connection_failed */
bool fromwire_gossip_peer_connection_failed ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct pubkey * id UNNEEDED , u32 * timeout UNNEEDED , u32 * attempts UNNEEDED , bool * addr_unknown UNNEEDED )
{ fprintf ( stderr , " fromwire_gossip_peer_connection_failed called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_hsm_client_hsmfd_reply */
bool fromwire_hsm_client_hsmfd_reply ( const void * p UNNEEDED , size_t * plen UNNEEDED )
{ fprintf ( stderr , " fromwire_hsm_client_hsmfd_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_hsm_sign_funding_reply */
bool fromwire_hsm_sign_funding_reply ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct bitcoin_tx * * tx UNNEEDED )
{ fprintf ( stderr , " fromwire_hsm_sign_funding_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_add_utxo */
bool fromwire_onchain_add_utxo ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct bitcoin_txid * prev_out_tx UNNEEDED , u32 * prev_out_index UNNEEDED , struct pubkey * per_commit_point UNNEEDED , u64 * value UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_add_utxo called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_broadcast_tx */
bool fromwire_onchain_broadcast_tx ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct bitcoin_tx * * tx UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_broadcast_tx called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_extracted_preimage */
bool fromwire_onchain_extracted_preimage ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct preimage * preimage UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_extracted_preimage called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_htlc_timeout */
bool fromwire_onchain_htlc_timeout ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct htlc_stub * htlc UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_htlc_timeout called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_init_reply */
bool fromwire_onchain_init_reply ( const void * p UNNEEDED , size_t * plen UNNEEDED , u8 * state UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_init_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_missing_htlc_output */
bool fromwire_onchain_missing_htlc_output ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct htlc_stub * htlc UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_missing_htlc_output called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_onchain_unwatch_tx */
bool fromwire_onchain_unwatch_tx ( const void * p UNNEEDED , size_t * plen UNNEEDED , struct bitcoin_txid * txid UNNEEDED )
{ fprintf ( stderr , " fromwire_onchain_unwatch_tx called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_opening_fundee_reply */
bool fromwire_opening_fundee_reply ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct channel_config * their_config UNNEEDED , struct bitcoin_tx * * first_commit UNNEEDED , secp256k1_ecdsa_signature * first_commit_sig UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED , struct pubkey * revocation_basepoint UNNEEDED , struct pubkey * payment_basepoint UNNEEDED , struct pubkey * htlc_basepoint UNNEEDED , struct pubkey * delayed_payment_basepoint UNNEEDED , struct pubkey * their_per_commit_point UNNEEDED , struct pubkey * remote_fundingkey UNNEEDED , struct bitcoin_txid * funding_txid UNNEEDED , u16 * funding_txout UNNEEDED , u64 * funding_satoshis UNNEEDED , u64 * push_msat UNNEEDED , u8 * channel_flags UNNEEDED , u32 * feerate_per_kw UNNEEDED , u8 * * funding_signed_msg UNNEEDED )
{ fprintf ( stderr , " fromwire_opening_fundee_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_opening_funder_reply */
bool fromwire_opening_funder_reply ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct channel_config * their_config UNNEEDED , struct bitcoin_tx * * first_commit UNNEEDED , secp256k1_ecdsa_signature * first_commit_sig UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED , struct pubkey * revocation_basepoint UNNEEDED , struct pubkey * payment_basepoint UNNEEDED , struct pubkey * htlc_basepoint UNNEEDED , struct pubkey * delayed_payment_basepoint UNNEEDED , struct pubkey * their_per_commit_point UNNEEDED , u32 * minimum_depth UNNEEDED , struct pubkey * remote_fundingkey UNNEEDED , struct bitcoin_txid * funding_txid UNNEEDED , u32 * feerate_per_kw UNNEEDED )
{ fprintf ( stderr , " fromwire_opening_funder_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for fromwire_opening_negotiation_failed */
bool fromwire_opening_negotiation_failed ( const tal_t * ctx UNNEEDED , const void * p UNNEEDED , size_t * plen UNNEEDED , struct crypto_state * crypto_state UNNEEDED , u64 * gossip_index UNNEEDED , wirestring * * msg UNNEEDED )
{ fprintf ( stderr , " fromwire_opening_negotiation_failed called! \n " ) ; abort ( ) ; }
/* Generated stub for funding_tx */
struct bitcoin_tx * funding_tx ( const tal_t * ctx UNNEEDED ,
u16 * outnum UNNEEDED ,
const struct utxo * * utxomap UNNEEDED ,
u64 funding_satoshis UNNEEDED ,
const struct pubkey * local_fundingkey UNNEEDED ,
const struct pubkey * remote_fundingkey UNNEEDED ,
u64 change_satoshis UNNEEDED ,
const struct pubkey * changekey UNNEEDED ,
const struct ext_key * bip32_base UNNEEDED )
{ fprintf ( stderr , " funding_tx called! \n " ) ; abort ( ) ; }
/* Generated stub for get_block_height */
u32 get_block_height ( const struct chain_topology * topo UNNEEDED )
{ fprintf ( stderr , " get_block_height called! \n " ) ; abort ( ) ; }
/* Generated stub for get_chainparams */
struct chainparams * get_chainparams ( const struct lightningd * ld UNNEEDED )
{ fprintf ( stderr , " get_chainparams called! \n " ) ; abort ( ) ; }
/* Generated stub for get_feerate */
u32 get_feerate ( const struct chain_topology * topo UNNEEDED , enum feerate feerate UNNEEDED )
{ fprintf ( stderr , " get_feerate called! \n " ) ; abort ( ) ; }
/* Generated stub for get_supported_global_features */
u8 * get_supported_global_features ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " get_supported_global_features called! \n " ) ; abort ( ) ; }
/* Generated stub for get_supported_local_features */
u8 * get_supported_local_features ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " get_supported_local_features called! \n " ) ; abort ( ) ; }
/* Generated stub for hsm_sync_read */
u8 * hsm_sync_read ( const tal_t * ctx UNNEEDED , struct lightningd * ld UNNEEDED )
{ fprintf ( stderr , " hsm_sync_read called! \n " ) ; abort ( ) ; }
/* Generated stub for invoices_create */
const struct invoice * invoices_create ( struct invoices * invoices UNNEEDED ,
u64 * msatoshi TAKES UNNEEDED ,
@ -74,8 +236,292 @@ void invoices_waitone(const tal_t *ctx UNNEEDED,
void ( * cb ) ( const struct invoice * UNNEEDED , void * ) UNNEEDED ,
void * cbarg UNNEEDED )
{ fprintf ( stderr , " invoices_waitone called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_bool */
void json_add_bool ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
bool value UNNEEDED )
{ fprintf ( stderr , " json_add_bool called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_hex */
void json_add_hex ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
const void * data UNNEEDED , size_t len UNNEEDED )
{ fprintf ( stderr , " json_add_hex called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_log */
void json_add_log ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
const struct log_book * lr UNNEEDED , enum log_level minlevel UNNEEDED )
{ fprintf ( stderr , " json_add_log called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_num */
void json_add_num ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
unsigned int value UNNEEDED )
{ fprintf ( stderr , " json_add_num called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_pubkey */
void json_add_pubkey ( struct json_result * response UNNEEDED ,
const char * fieldname UNNEEDED ,
const struct pubkey * key UNNEEDED )
{ fprintf ( stderr , " json_add_pubkey called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_short_channel_id */
void json_add_short_channel_id ( struct json_result * response UNNEEDED ,
const char * fieldname UNNEEDED ,
const struct short_channel_id * id UNNEEDED )
{ fprintf ( stderr , " json_add_short_channel_id called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_string */
void json_add_string ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED , const char * value UNNEEDED )
{ fprintf ( stderr , " json_add_string called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_txid */
void json_add_txid ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
const struct bitcoin_txid * txid UNNEEDED )
{ fprintf ( stderr , " json_add_txid called! \n " ) ; abort ( ) ; }
/* Generated stub for json_add_u64 */
void json_add_u64 ( struct json_result * result UNNEEDED , const char * fieldname UNNEEDED ,
uint64_t value UNNEEDED )
{ fprintf ( stderr , " json_add_u64 called! \n " ) ; abort ( ) ; }
/* Generated stub for json_array_end */
void json_array_end ( struct json_result * ptr UNNEEDED )
{ fprintf ( stderr , " json_array_end called! \n " ) ; abort ( ) ; }
/* Generated stub for json_array_start */
void json_array_start ( struct json_result * ptr UNNEEDED , const char * fieldname UNNEEDED )
{ fprintf ( stderr , " json_array_start called! \n " ) ; abort ( ) ; }
/* Generated stub for json_get_params */
bool json_get_params ( struct command * cmd UNNEEDED ,
const char * buffer UNNEEDED , const jsmntok_t param [ ] UNNEEDED , . . . )
{ fprintf ( stderr , " json_get_params called! \n " ) ; abort ( ) ; }
/* Generated stub for json_object_end */
void json_object_end ( struct json_result * ptr UNNEEDED )
{ fprintf ( stderr , " json_object_end called! \n " ) ; abort ( ) ; }
/* Generated stub for json_object_start */
void json_object_start ( struct json_result * ptr UNNEEDED , const char * fieldname UNNEEDED )
{ fprintf ( stderr , " json_object_start called! \n " ) ; abort ( ) ; }
/* Generated stub for json_tok_bool */
bool json_tok_bool ( const char * buffer UNNEEDED , const jsmntok_t * tok UNNEEDED , bool * b UNNEEDED )
{ fprintf ( stderr , " json_tok_bool called! \n " ) ; abort ( ) ; }
/* Generated stub for json_tok_loglevel */
bool json_tok_loglevel ( const char * buffer UNNEEDED , const jsmntok_t * tok UNNEEDED ,
enum log_level * level UNNEEDED )
{ fprintf ( stderr , " json_tok_loglevel called! \n " ) ; abort ( ) ; }
/* Generated stub for json_tok_number */
bool json_tok_number ( const char * buffer UNNEEDED , const jsmntok_t * tok UNNEEDED ,
unsigned int * num UNNEEDED )
{ fprintf ( stderr , " json_tok_number called! \n " ) ; abort ( ) ; }
/* Generated stub for json_tok_pubkey */
bool json_tok_pubkey ( const char * buffer UNNEEDED , const jsmntok_t * tok UNNEEDED ,
struct pubkey * pubkey UNNEEDED )
{ fprintf ( stderr , " json_tok_pubkey called! \n " ) ; abort ( ) ; }
/* Generated stub for json_tok_u64 */
bool json_tok_u64 ( const char * buffer UNNEEDED , const jsmntok_t * tok UNNEEDED ,
uint64_t * num UNNEEDED )
{ fprintf ( stderr , " json_tok_u64 called! \n " ) ; abort ( ) ; }
/* Generated stub for locate_tx */
struct txlocator * locate_tx ( const void * ctx UNNEEDED , const struct chain_topology * topo UNNEEDED , const struct bitcoin_txid * txid UNNEEDED )
{ fprintf ( stderr , " locate_tx called! \n " ) ; abort ( ) ; }
/* Generated stub for log_add */
void log_add ( struct log * log UNNEEDED , const char * fmt UNNEEDED , . . . )
{ fprintf ( stderr , " log_add called! \n " ) ; abort ( ) ; }
/* Generated stub for log_io */
void log_io ( struct log * log UNNEEDED , enum log_level dir UNNEEDED , const char * comment UNNEEDED ,
const void * data UNNEEDED , size_t len UNNEEDED )
{ fprintf ( stderr , " log_io called! \n " ) ; abort ( ) ; }
/* Generated stub for logv_add */
void logv_add ( struct log * log UNNEEDED , const char * fmt UNNEEDED , va_list ap UNNEEDED )
{ fprintf ( stderr , " logv_add called! \n " ) ; abort ( ) ; }
/* Generated stub for new_json_result */
struct json_result * new_json_result ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " new_json_result called! \n " ) ; abort ( ) ; }
/* Generated stub for new_peer_subd */
struct subd * new_peer_subd ( struct lightningd * ld UNNEEDED ,
const char * name UNNEEDED ,
struct peer * peer UNNEEDED ,
const char * ( * msgname ) ( int msgtype ) UNNEEDED ,
unsigned int ( * msgcb ) ( struct subd * UNNEEDED , const u8 * UNNEEDED ,
const int * fds ) UNNEEDED ,
. . . )
{ fprintf ( stderr , " new_peer_subd called! \n " ) ; abort ( ) ; }
/* Generated stub for null_response */
struct json_result * null_response ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " null_response called! \n " ) ; abort ( ) ; }
/* Generated stub for onchain_failed_our_htlc */
void onchain_failed_our_htlc ( const struct peer * peer UNNEEDED ,
const struct htlc_stub * htlc UNNEEDED ,
const char * why UNNEEDED )
{ fprintf ( stderr , " onchain_failed_our_htlc called! \n " ) ; abort ( ) ; }
/* Generated stub for onchain_fulfilled_htlc */
void onchain_fulfilled_htlc ( struct peer * peer UNNEEDED , const struct preimage * preimage UNNEEDED )
{ fprintf ( stderr , " onchain_fulfilled_htlc called! \n " ) ; abort ( ) ; }
/* Generated stub for onchain_wire_type_name */
const char * onchain_wire_type_name ( int e UNNEEDED )
{ fprintf ( stderr , " onchain_wire_type_name called! \n " ) ; abort ( ) ; }
/* Generated stub for opening_wire_type_name */
const char * opening_wire_type_name ( int e UNNEEDED )
{ fprintf ( stderr , " opening_wire_type_name called! \n " ) ; abort ( ) ; }
/* Generated stub for peer_got_commitsig */
void peer_got_commitsig ( struct peer * peer UNNEEDED , const u8 * msg UNNEEDED )
{ fprintf ( stderr , " peer_got_commitsig called! \n " ) ; abort ( ) ; }
/* Generated stub for peer_got_revoke */
void peer_got_revoke ( struct peer * peer UNNEEDED , const u8 * msg UNNEEDED )
{ fprintf ( stderr , " peer_got_revoke called! \n " ) ; abort ( ) ; }
/* Generated stub for peer_htlcs */
void peer_htlcs ( const tal_t * ctx UNNEEDED ,
const struct peer * peer UNNEEDED ,
struct added_htlc * * htlcs UNNEEDED ,
enum htlc_state * * htlc_states UNNEEDED ,
struct fulfilled_htlc * * fulfilled_htlcs UNNEEDED ,
enum side * * fulfilled_sides UNNEEDED ,
const struct failed_htlc * * * failed_htlcs UNNEEDED ,
enum side * * failed_sides UNNEEDED )
{ fprintf ( stderr , " peer_htlcs called! \n " ) ; abort ( ) ; }
/* Generated stub for peer_sending_commitsig */
void peer_sending_commitsig ( struct peer * peer UNNEEDED , const u8 * msg UNNEEDED )
{ fprintf ( stderr , " peer_sending_commitsig called! \n " ) ; abort ( ) ; }
/* Generated stub for sanitize_error */
char * sanitize_error ( const tal_t * ctx UNNEEDED , const u8 * errmsg UNNEEDED ,
struct channel_id * channel_id UNNEEDED )
{ fprintf ( stderr , " sanitize_error called! \n " ) ; abort ( ) ; }
/* Generated stub for subd_release_peer */
void subd_release_peer ( struct subd * owner UNNEEDED , struct peer * peer UNNEEDED )
{ fprintf ( stderr , " subd_release_peer called! \n " ) ; abort ( ) ; }
/* Generated stub for subd_req_ */
void subd_req_ ( const tal_t * ctx UNNEEDED ,
struct subd * sd UNNEEDED ,
const u8 * msg_out UNNEEDED ,
int fd_out UNNEEDED , size_t num_fds_in UNNEEDED ,
void ( * replycb ) ( struct subd * UNNEEDED , const u8 * UNNEEDED , const int * UNNEEDED , void * ) UNNEEDED ,
void * replycb_data UNNEEDED )
{ fprintf ( stderr , " subd_req_ called! \n " ) ; abort ( ) ; }
/* Generated stub for subd_send_fd */
void subd_send_fd ( struct subd * sd UNNEEDED , int fd UNNEEDED )
{ fprintf ( stderr , " subd_send_fd called! \n " ) ; abort ( ) ; }
/* Generated stub for subd_send_msg */
void subd_send_msg ( struct subd * sd UNNEEDED , const u8 * msg_out UNNEEDED )
{ fprintf ( stderr , " subd_send_msg called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_channel_dev_reenable_commit */
u8 * towire_channel_dev_reenable_commit ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " towire_channel_dev_reenable_commit called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_channel_funding_announce_depth */
u8 * towire_channel_funding_announce_depth ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " towire_channel_funding_announce_depth called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_channel_funding_locked */
u8 * towire_channel_funding_locked ( const tal_t * ctx UNNEEDED , const struct short_channel_id * short_channel_id UNNEEDED )
{ fprintf ( stderr , " towire_channel_funding_locked called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_channel_init */
u8 * towire_channel_init ( const tal_t * ctx UNNEEDED , const struct bitcoin_blkid * chain_hash UNNEEDED , const struct bitcoin_txid * funding_txid UNNEEDED , u16 funding_txout UNNEEDED , u64 funding_satoshi UNNEEDED , const struct channel_config * our_config UNNEEDED , const struct channel_config * their_config UNNEEDED , const u32 feerate_per_kw [ 2 ] UNNEEDED , u32 feerate_min UNNEEDED , u32 feerate_max UNNEEDED , const secp256k1_ecdsa_signature * first_commit_sig UNNEEDED , const struct crypto_state * crypto_state UNNEEDED , u64 gossip_index UNNEEDED , const struct pubkey * remote_fundingkey UNNEEDED , const struct pubkey * remote_revocation_basepoint UNNEEDED , const struct pubkey * remote_payment_basepoint UNNEEDED , const struct pubkey * remote_htlc_basepoint UNNEEDED , const struct pubkey * remote_delayed_payment_basepoint UNNEEDED , const struct pubkey * remote_per_commit UNNEEDED , const struct pubkey * old_remote_per_commit UNNEEDED , enum side funder UNNEEDED , u32 fee_base UNNEEDED , u32 fee_proportional UNNEEDED , u64 local_msatoshi UNNEEDED , const struct privkey * seed UNNEEDED , const struct pubkey * local_node_id UNNEEDED , const struct pubkey * remote_node_id UNNEEDED , u32 commit_msec UNNEEDED , u16 cltv_delta UNNEEDED , bool last_was_revoke UNNEEDED , const struct changed_htlc * last_sent_commit UNNEEDED , u64 next_index_local UNNEEDED , u64 next_index_remote UNNEEDED , u64 revocations_received UNNEEDED , u64 next_htlc_id UNNEEDED , const struct added_htlc * htlcs UNNEEDED , const enum htlc_state * htlc_states UNNEEDED , const struct fulfilled_htlc * fulfilled UNNEEDED , const enum side * fulfilled_sides UNNEEDED , const struct failed_htlc * * failed UNNEEDED , const enum side * failed_sides UNNEEDED , bool local_funding_locked UNNEEDED , bool remote_funding_locked UNNEEDED , const struct short_channel_id * funding_short_id UNNEEDED , bool reestablish UNNEEDED , const u8 * shutdown_scriptpubkey UNNEEDED , bool remote_shutdown_received UNNEEDED , u8 flags UNNEEDED , const u8 * init_peer_pkt UNNEEDED )
{ fprintf ( stderr , " towire_channel_init called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_channel_send_shutdown */
u8 * towire_channel_send_shutdown ( const tal_t * ctx UNNEEDED , const u8 * scriptpubkey UNNEEDED )
{ fprintf ( stderr , " towire_channel_send_shutdown called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_closing_init */
u8 * towire_closing_init ( const tal_t * ctx UNNEEDED , const struct crypto_state * crypto_state UNNEEDED , u64 gossip_index UNNEEDED , const struct privkey * seed UNNEEDED , const struct bitcoin_txid * funding_txid UNNEEDED , u16 funding_txout UNNEEDED , u64 funding_satoshi UNNEEDED , const struct pubkey * remote_fundingkey UNNEEDED , enum side funder UNNEEDED , u64 local_msatoshi UNNEEDED , u64 remote_msatoshi UNNEEDED , u64 our_dust_limit UNNEEDED , u64 min_fee_satoshi UNNEEDED , u64 fee_limit_satoshi UNNEEDED , u64 initial_fee_satoshi UNNEEDED , const u8 * local_scriptpubkey UNNEEDED , const u8 * remote_scriptpubkey UNNEEDED , bool reconnected UNNEEDED , u64 next_index_local UNNEEDED , u64 next_index_remote UNNEEDED , u64 revocations_received UNNEEDED , bool deprecated_api UNNEEDED )
{ fprintf ( stderr , " towire_closing_init called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_closing_received_signature_reply */
u8 * towire_closing_received_signature_reply ( const tal_t * ctx UNNEEDED )
{ fprintf ( stderr , " towire_closing_received_signature_reply called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_error */
u8 * towire_error ( const tal_t * ctx UNNEEDED , const struct channel_id * channel_id UNNEEDED , const u8 * data UNNEEDED )
{ fprintf ( stderr , " towire_error called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_errorfmt */
u8 * towire_errorfmt ( const tal_t * ctx UNNEEDED ,
const struct channel_id * channel UNNEEDED ,
const char * fmt UNNEEDED , . . . )
{ fprintf ( stderr , " towire_errorfmt called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossipctl_hand_back_peer */
u8 * towire_gossipctl_hand_back_peer ( const tal_t * ctx UNNEEDED , const struct pubkey * id UNNEEDED , const struct crypto_state * crypto_state UNNEEDED , u64 gossip_index UNNEEDED , const u8 * msg UNNEEDED )
{ fprintf ( stderr , " towire_gossipctl_hand_back_peer called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossipctl_peer_addrhint */
u8 * towire_gossipctl_peer_addrhint ( const tal_t * ctx UNNEEDED , const struct pubkey * id UNNEEDED , const struct wireaddr * addr UNNEEDED )
{ fprintf ( stderr , " towire_gossipctl_peer_addrhint called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossipctl_reach_peer */
u8 * towire_gossipctl_reach_peer ( const tal_t * ctx UNNEEDED , const struct pubkey * id UNNEEDED )
{ fprintf ( stderr , " towire_gossipctl_reach_peer called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossipctl_release_peer */
u8 * towire_gossipctl_release_peer ( const tal_t * ctx UNNEEDED , const struct pubkey * id UNNEEDED )
{ fprintf ( stderr , " towire_gossipctl_release_peer called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossip_disable_channel */
u8 * towire_gossip_disable_channel ( const tal_t * ctx UNNEEDED , const struct short_channel_id * short_channel_id UNNEEDED , u8 direction UNNEEDED , bool active UNNEEDED )
{ fprintf ( stderr , " towire_gossip_disable_channel called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_gossip_getpeers_request */
u8 * towire_gossip_getpeers_request ( const tal_t * ctx UNNEEDED , const struct pubkey * id UNNEEDED )
{ fprintf ( stderr , " towire_gossip_getpeers_request called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_hsm_client_hsmfd */
u8 * towire_hsm_client_hsmfd ( const tal_t * ctx UNNEEDED , const struct pubkey * pubkey UNNEEDED , u64 capabilities UNNEEDED )
{ fprintf ( stderr , " towire_hsm_client_hsmfd called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_hsm_sign_funding */
u8 * towire_hsm_sign_funding ( const tal_t * ctx UNNEEDED , u64 satoshi_out UNNEEDED , u64 change_out UNNEEDED , u32 change_keyindex UNNEEDED , const struct pubkey * our_pubkey UNNEEDED , const struct pubkey * their_pubkey UNNEEDED , const struct utxo * * inputs UNNEEDED )
{ fprintf ( stderr , " towire_hsm_sign_funding called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_onchain_depth */
u8 * towire_onchain_depth ( const tal_t * ctx UNNEEDED , const struct bitcoin_txid * txid UNNEEDED , u32 depth UNNEEDED )
{ fprintf ( stderr , " towire_onchain_depth called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_onchain_htlc */
u8 * towire_onchain_htlc ( const tal_t * ctx UNNEEDED , const struct htlc_stub * htlc UNNEEDED , bool tell_if_missing UNNEEDED , bool tell_immediately UNNEEDED )
{ fprintf ( stderr , " towire_onchain_htlc called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_onchain_init */
u8 * towire_onchain_init ( const tal_t * ctx UNNEEDED , const struct privkey * seed UNNEEDED , const struct shachain * shachain UNNEEDED , u64 funding_amount_satoshi UNNEEDED , const struct pubkey * old_remote_per_commitment_point UNNEEDED , const struct pubkey * remote_per_commitment_point UNNEEDED , u32 local_to_self_delay UNNEEDED , u32 remote_to_self_delay UNNEEDED , u32 feerate_per_kw UNNEEDED , u64 local_dust_limit_satoshi UNNEEDED , const struct pubkey * remote_revocation_basepoint UNNEEDED , const struct bitcoin_txid * our_broadcast_txid UNNEEDED , const u8 * local_scriptpubkey UNNEEDED , const u8 * remote_scriptpubkey UNNEEDED , const struct pubkey * ourwallet_pubkey UNNEEDED , enum side funder UNNEEDED , const struct pubkey * remote_payment_basepoint UNNEEDED , const struct pubkey * remote_htlc_basepoint UNNEEDED , const struct pubkey * remote_delayed_payment_basepoint UNNEEDED , const struct bitcoin_tx * tx UNNEEDED , u32 tx_blockheight UNNEEDED , u32 reasonable_depth UNNEEDED , const secp256k1_ecdsa_signature * htlc_signature UNNEEDED , u64 num_htlcs UNNEEDED )
{ fprintf ( stderr , " towire_onchain_init called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_onchain_known_preimage */
u8 * towire_onchain_known_preimage ( const tal_t * ctx UNNEEDED , const struct preimage * preimage UNNEEDED )
{ fprintf ( stderr , " towire_onchain_known_preimage called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_onchain_spent */
u8 * towire_onchain_spent ( const tal_t * ctx UNNEEDED , const struct bitcoin_tx * tx UNNEEDED , u32 input_num UNNEEDED , u32 blockheight UNNEEDED )
{ fprintf ( stderr , " towire_onchain_spent called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_opening_fundee */
u8 * towire_opening_fundee ( const tal_t * ctx UNNEEDED , u32 minimum_depth UNNEEDED , u32 min_feerate UNNEEDED , u32 max_feerate UNNEEDED , const u8 * msg UNNEEDED )
{ fprintf ( stderr , " towire_opening_fundee called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_opening_funder */
u8 * towire_opening_funder ( const tal_t * ctx UNNEEDED , u64 funding_satoshis UNNEEDED , u64 push_msat UNNEEDED , u32 feerate_per_kw UNNEEDED , u32 max_minimum_depth UNNEEDED , u64 change_satoshis UNNEEDED , u32 change_keyindex UNNEEDED , u8 channel_flags UNNEEDED , const struct utxo * * inputs UNNEEDED , const struct ext_key * bip32 UNNEEDED )
{ fprintf ( stderr , " towire_opening_funder called! \n " ) ; abort ( ) ; }
/* Generated stub for towire_opening_init */
u8 * towire_opening_init ( const tal_t * ctx UNNEEDED , u32 network_index UNNEEDED , const struct channel_config * our_config UNNEEDED , u32 max_to_self_delay UNNEEDED , u64 min_effective_htlc_capacity_msat UNNEEDED , const struct crypto_state * crypto_state UNNEEDED , u64 gossip_index UNNEEDED , const struct privkey * seed UNNEEDED )
{ fprintf ( stderr , " towire_opening_init called! \n " ) ; abort ( ) ; }
/* Generated stub for txfilter_add_scriptpubkey */
void txfilter_add_scriptpubkey ( struct txfilter * filter UNNEEDED , u8 * script UNNEEDED )
{ fprintf ( stderr , " txfilter_add_scriptpubkey called! \n " ) ; abort ( ) ; }
/* Generated stub for unsupported_features */
bool unsupported_features ( const u8 * gfeatures UNNEEDED , const u8 * lfeatures UNNEEDED )
{ fprintf ( stderr , " unsupported_features called! \n " ) ; abort ( ) ; }
/* Generated stub for update_per_commit_point */
void update_per_commit_point ( struct peer * peer UNNEEDED ,
const struct pubkey * per_commitment_point UNNEEDED )
{ fprintf ( stderr , " update_per_commit_point called! \n " ) ; abort ( ) ; }
/* Generated stub for watch_tx_ */
struct txwatch * watch_tx_ ( const tal_t * ctx UNNEEDED ,
struct chain_topology * topo UNNEEDED ,
struct peer * peer UNNEEDED ,
const struct bitcoin_tx * tx UNNEEDED ,
enum watch_result ( * cb ) ( struct peer * peer UNNEEDED ,
const struct bitcoin_tx * UNNEEDED ,
unsigned int depth UNNEEDED ,
void * ) UNNEEDED ,
void * cbdata UNNEEDED )
{ fprintf ( stderr , " watch_tx_ called! \n " ) ; abort ( ) ; }
/* Generated stub for watch_txid_ */
struct txwatch * watch_txid_ ( const tal_t * ctx UNNEEDED ,
struct chain_topology * topo UNNEEDED ,
struct peer * peer UNNEEDED ,
const struct bitcoin_txid * txid UNNEEDED ,
enum watch_result ( * cb ) ( struct peer * peer UNNEEDED ,
const struct bitcoin_tx * UNNEEDED ,
unsigned int depth UNNEEDED ,
void * ) UNNEEDED ,
void * cbdata UNNEEDED )
{ fprintf ( stderr , " watch_txid_ called! \n " ) ; abort ( ) ; }
/* Generated stub for watch_txo_ */
struct txowatch * watch_txo_ ( const tal_t * ctx UNNEEDED ,
struct chain_topology * topo UNNEEDED ,
struct peer * peer UNNEEDED ,
const struct bitcoin_txid * txid UNNEEDED ,
unsigned int output UNNEEDED ,
enum watch_result ( * cb ) ( struct peer * peer UNNEEDED ,
const struct bitcoin_tx * tx UNNEEDED ,
size_t input_num UNNEEDED ,
const struct block * block UNNEEDED ,
void * ) UNNEEDED ,
void * cbdata UNNEEDED )
{ fprintf ( stderr , " watch_txo_ called! \n " ) ; abort ( ) ; }
/* Generated stub for wire_sync_write */
bool wire_sync_write ( int fd UNNEEDED , const void * msg TAKES UNNEEDED )
{ fprintf ( stderr , " wire_sync_write called! \n " ) ; abort ( ) ; }
/* AUTOGENERATED MOCKS END */
# if DEVELOPER
bool dev_disconnect_permanent ( struct lightningd * ld UNNEEDED )
{ fprintf ( stderr , " dev_disconnect_permanent called! \n " ) ; abort ( ) ; }
# endif
static char * wallet_err ;
static void wallet_fatal ( const char * fmt , . . . )
{
@ -95,6 +541,40 @@ static void wallet_fatal(const char *fmt, ...)
# define transaction_wrap(db, ...) \
( db_begin_transaction ( db ) , __VA_ARGS__ , db_commit_transaction ( db ) , wallet_err = = NULL )
enum log_level get_log_level ( struct log_book * lr UNNEEDED )
{
return LOG_DBG ;
}
struct log * new_log ( const tal_t * ctx UNNEEDED , struct log_book * record UNNEEDED , const char * fmt UNNEEDED , . . . )
{
return NULL ;
}
struct log_book * new_log_book ( const tal_t * ctx UNNEEDED ,
size_t max_mem UNNEEDED ,
enum log_level printlevel UNNEEDED )
{
return NULL ;
}
void set_log_outfn_ ( struct log_book * lr UNNEEDED ,
void ( * print ) ( const char * prefix UNNEEDED ,
enum log_level level UNNEEDED ,
bool continued UNNEEDED ,
const struct timeabs * time UNNEEDED ,
const char * str UNNEEDED ,
const u8 * io UNNEEDED ,
void * arg ) UNNEEDED ,
void * arg UNNEEDED )
{
}
const char * log_prefix ( const struct log * log UNNEEDED )
{
return " " ;
}
/**
* mempat - - Set the memory to a pattern
*
@ -109,7 +589,7 @@ static void mempat(void *dst, size_t len)
p [ i ] = n % 251 ; /* Prime */
}
static struct wallet * create_test_wallet ( const tal_t * ctx )
static struct wallet * create_test_wallet ( struct lightningd * ld , const tal_t * ctx )
{
char filename [ ] = " /tmp/ldb-XXXXXX " ;
int fd = mkstemp ( filename ) ;
@ -121,6 +601,7 @@ static struct wallet *create_test_wallet(const tal_t *ctx)
ltmp = tal_tmpctx ( ctx ) ;
list_head_init ( & w - > unstored_payments ) ;
w - > ld = ld ;
CHECK_MSG ( w - > db , " Failed opening the db " ) ;
db_migrate ( w - > db , w - > log ) ;
@ -272,29 +753,30 @@ static bool bitcoin_tx_eq(const struct bitcoin_tx *tx1,
return eq ;
}
static bool channelseq ( struct wallet_ channel * c1 , struct wallet_ channel * c2 )
static bool channelseq ( struct channel * c1 , struct channel * c2 )
{
struct peer * p1 = c1 - > peer , * p2 = c2 - > peer ;
struct channel_info * ci1 = p 1- > channel_info , * ci2 = p 2- > channel_info ;
struct changed_htlc * lc1 = p 1- > last_sent_commit , * lc2 = p 2- > last_sent_commit ;
CHECK ( c1 - > id = = c2 - > id ) ;
struct channel_info * ci1 = c 1- > channel_info , * ci2 = c 2- > channel_info ;
struct changed_htlc * lc1 = c 1- > last_sent_commit , * lc2 = c 2- > last_sent_commit ;
CHECK ( c1 - > db id = = c2 - > db id) ;
CHECK ( c1 - > first_blocknum = = c2 - > first_blocknum ) ;
CHECK ( c1 - > peer - > dbid = = c2 - > peer - > dbid ) ;
CHECK ( p1 - > their_shachain . id = = p2 - > their_shachain . id ) ;
CHECK ( c1 - > peer = = c2 - > peer ) ;
CHECK ( c1 - > their_shachain . id = = c2 - > their_shachain . id ) ;
CHECK_MSG ( pubkey_eq ( & p1 - > id , & p2 - > id ) , " NodeIDs do not match " ) ;
CHECK ( ( p 1- > scid = = NULL & & p 2- > scid = = NULL ) | | short_channel_id_eq ( p 1- > scid , p 2- > scid ) ) ;
CHECK ( ( p 1- > our_msatoshi = = NULL ) = = ( p 2- > our_msatoshi = = NULL ) ) ;
if ( p 1- > our_msatoshi )
CHECK ( * p 1- > our_msatoshi = = * p 2- > our_msatoshi ) ;
CHECK ( ( p 1- > remote_shutdown_scriptpubkey = = NULL & & p 2- > remote_shutdown_scriptpubkey = = NULL ) | | memeq (
p 1- > remote_shutdown_scriptpubkey ,
tal_len ( p 1- > remote_shutdown_scriptpubkey ) ,
p 2- > remote_shutdown_scriptpubkey ,
tal_len ( p 2- > remote_shutdown_scriptpubkey ) ) ) ;
CHECK ( ( p 1- > funding_txid = = NULL & & p 2- > funding_txid = = NULL ) | | memeq (
p 1- > funding_txid ,
CHECK ( ( c 1- > scid = = NULL & & c 2- > scid = = NULL ) | | short_channel_id_eq ( c 1- > scid , c 2- > scid ) ) ;
CHECK ( ( c 1- > our_msatoshi = = NULL ) = = ( c 2- > our_msatoshi = = NULL ) ) ;
if ( c 1- > our_msatoshi )
CHECK ( * c 1- > our_msatoshi = = * c 2- > our_msatoshi ) ;
CHECK ( ( c 1- > remote_shutdown_scriptpubkey = = NULL & & c 2- > remote_shutdown_scriptpubkey = = NULL ) | | memeq (
c 1- > remote_shutdown_scriptpubkey ,
tal_len ( c 1- > remote_shutdown_scriptpubkey ) ,
c 2- > remote_shutdown_scriptpubkey ,
tal_len ( c 2- > remote_shutdown_scriptpubkey ) ) ) ;
CHECK ( ( c 1- > funding_txid = = NULL & & c 2- > funding_txid = = NULL ) | | memeq (
c 1- > funding_txid ,
sizeof ( struct sha256_double ) ,
p 2- > funding_txid ,
c 2- > funding_txid ,
sizeof ( struct sha256_double ) ) ) ;
CHECK ( ( ci1 ! = NULL ) = = ( ci2 ! = NULL ) ) ;
if ( ci1 ) {
@ -307,54 +789,55 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2)
CHECK ( ci1 - > their_config . id ! = 0 & & ci1 - > their_config . id = = ci2 - > their_config . id ) ;
}
CHECK ( p 1- > our_config . id ! = 0 & & p 1- > our_config . id = = p 2- > our_config . id ) ;
CHECK ( c 1- > our_config . id ! = 0 & & c 1- > our_config . id = = c 2- > our_config . id ) ;
CHECK ( ( lc1 ! = NULL ) = = ( lc2 ! = NULL ) ) ;
if ( lc1 ) {
CHECK ( lc1 - > newstate = = lc2 - > newstate ) ;
CHECK ( lc1 - > id = = lc2 - > id ) ;
}
CHECK ( ( p 1- > last_tx ! = NULL ) = = ( p 2- > last_tx ! = NULL ) ) ;
if ( p 1- > last_tx ) {
CHECK ( bitcoin_tx_eq ( p 1- > last_tx , p 2- > last_tx ) ) ;
CHECK ( ( c 1- > last_tx ! = NULL ) = = ( c 2- > last_tx ! = NULL ) ) ;
if ( c 1- > last_tx ) {
CHECK ( bitcoin_tx_eq ( c 1- > last_tx , c 2- > last_tx ) ) ;
}
CHECK ( ( p 1- > last_sig ! = NULL ) = = ( p 2- > last_sig ! = NULL ) ) ;
if ( p 1- > last_sig ) {
CHECK ( memeq ( p 1- > last_sig , sizeof ( * p 1- > last_sig ) ,
p 2- > last_sig , sizeof ( * p 2- > last_sig ) ) ) ;
CHECK ( ( c 1- > last_sig ! = NULL ) = = ( c 2- > last_sig ! = NULL ) ) ;
if ( c 1- > last_sig ) {
CHECK ( memeq ( c 1- > last_sig , sizeof ( * c 1- > last_sig ) ,
c 2- > last_sig , sizeof ( * c 2- > last_sig ) ) ) ;
}
if ( p 1- > remote_shutdown_scriptpubkey ) {
CHECK ( p 2- > remote_shutdown_scriptpubkey ) ;
CHECK ( p 1- > local_shutdown_idx = = p 2- > local_shutdown_idx ) ;
if ( c 1- > remote_shutdown_scriptpubkey ) {
CHECK ( c 2- > remote_shutdown_scriptpubkey ) ;
CHECK ( c 1- > local_shutdown_idx = = c 2- > local_shutdown_idx ) ;
}
CHECK ( p 1- > last_was_revoke = = p 2- > last_was_revoke ) ;
CHECK ( c 1- > last_was_revoke = = c 2- > last_was_revoke ) ;
return true ;
}
static struct wallet_ channel * wallet_channel_load ( struct wallet * w , const u64 id )
static struct channel * wallet_channel_load ( struct wallet * w , const u64 db id)
{
struct list_head peers ;
struct peer * peer ;
list_head_init ( & peers ) ;
struct channel * channel ;
/* We expect only one peer, but reuse same code */
if ( ! wallet_channels_load_active ( w , w , & peers ) )
if ( ! wallet_channels_load_active ( w , w ) )
return NULL ;
peer = list_top ( & peers , struct peer , list ) ;
peer = list_top ( & w - > ld - > peers , struct peer , list ) ;
CHECK ( peer ) ;
CHECK ( peer - > channel - > id = = id ) ;
return peer - > channel ;
/* We load lots of identical dbid channels: use last one */
channel = list_tail ( & peer - > channels , struct channel , list ) ;
assert ( channel - > dbid = = dbid ) ;
return channel ;
}
static bool test_channel_crud ( const tal_t * ctx )
static bool test_channel_crud ( struct lightningd * ld , const tal_t * ctx )
{
struct wallet * w = create_test_wallet ( ctx ) ;
struct wallet_ channel c1 , * c2 = tal ( w , struct wallet_ channel) ;
struct peer p ;
struct wallet * w = create_test_wallet ( ld , ctx ) ;
struct channel c1 , * c2 = tal ( w , struct channel ) ;
struct peer * p ;
struct channel_info ci ;
struct bitcoin_txid * hash = tal ( w , struct bitcoin_txid ) ;
struct pubkey pk ;
@ -366,21 +849,19 @@ static bool test_channel_crud(const tal_t *ctx)
memset ( & c1 , 0 , sizeof ( c1 ) ) ;
memset ( c2 , 0 , sizeof ( * c2 ) ) ;
memset ( & p , 0 , sizeof ( p ) ) ;
memset ( & ci , 3 , sizeof ( ci ) ) ;
mempat ( hash , sizeof ( * hash ) ) ;
mempat ( sig , sizeof ( * sig ) ) ;
mempat ( & last_commit , sizeof ( last_commit ) ) ;
pubkey_from_der ( tal_hexdata ( w , " 02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc " , 66 ) , 33 , & pk ) ;
ci . feerate_per_kw [ LOCAL ] = ci . feerate_per_kw [ REMOTE ] = 31337 ;
mempat ( & p . id , sizeof ( p . id ) ) ;
mempat ( scriptpubkey , tal_len ( scriptpubkey ) ) ;
c1 . first_blocknum = 1 ;
c1 . peer = & p ;
p . id = pk ;
p . our_msatoshi = NULL ;
p . last_tx = NULL ;
p . state = CHANNELD_NORMAL ;
p = new_peer ( ld , 0 , & pk , NULL ) ;
c1 . peer = p ;
c1 . our_msatoshi = NULL ;
c1 . last_tx = NULL ;
c1 . state = CHANNELD_NORMAL ;
memset ( & ci . their_config , 0 , sizeof ( struct channel_config ) ) ;
ci . remote_fundingkey = pk ;
ci . theirbase . revocation = pk ;
@ -397,85 +878,85 @@ static bool test_channel_crud(const tal_t *ctx)
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Load from DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v1) " ) ;
/* We just inserted them into an empty DB so this must be 1 */
CHECK ( c1 . id = = 1 ) ;
CHECK ( c1 . db id = = 1 ) ;
CHECK ( c1 . peer - > dbid = = 1 ) ;
CHECK ( c1 . peer - > their_shachain . id = = 1 ) ;
CHECK ( c1 . their_shachain . id = = 1 ) ;
/* Variant 2: update with scid set */
c1 . peer - > scid = talz ( w , struct short_channel_id ) ;
c1 . scid = talz ( w , struct short_channel_id ) ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v2) " ) ;
/* Updates should not result in new ids */
CHECK ( c1 . id = = 1 ) ;
CHECK ( c1 . db id = = 1 ) ;
CHECK ( c1 . peer - > dbid = = 1 ) ;
CHECK ( c1 . peer - > their_shachain . id = = 1 ) ;
CHECK ( c1 . their_shachain . id = = 1 ) ;
/* Variant 3: update with our_satoshi set */
c1 . peer - > our_msatoshi = & msat ;
c1 . peer - > last_was_revoke = ! c1 . peer - > last_was_revoke ;
c1 . our_msatoshi = & msat ;
c1 . last_was_revoke = ! c1 . last_was_revoke ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v3) " ) ;
/* Variant 4: update with funding_tx_id */
c1 . peer - > funding_txid = hash ;
c1 . funding_txid = hash ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v4) " ) ;
/* Variant 5: update with channel_info */
p . channel_info = & ci ;
c1 . channel_info = & ci ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v5) " ) ;
/* Variant 6: update with last_commit_sent */
p . last_sent_commit = & last_commit ;
c1 . last_sent_commit = & last_commit ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v6) " ) ;
/* Variant 7: update with last_tx (taken from BOLT #3) */
p . last_tx = bitcoin_tx_from_hex ( w , " 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220 " , strlen ( " 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220 " ) ) ;
p . last_sig = sig ;
c1 . last_tx = bitcoin_tx_from_hex ( w , " 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220 " , strlen ( " 02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220 " ) ) ;
c1 . last_sig = sig ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v7) " ) ;
/* Variant 8: update and add remote_shutdown_scriptpubkey */
p . remote_shutdown_scriptpubkey = scriptpubkey ;
p . local_shutdown_idx = 1337 ;
c1 . remote_shutdown_scriptpubkey = scriptpubkey ;
c1 . local_shutdown_idx = 1337 ;
wallet_channel_save ( w , & c1 ) ;
CHECK_MSG ( ! wallet_err , tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . id ) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( c2 = wallet_channel_load ( w , c1 . db id) , tal_fmt ( w , " Load from DB " ) ) ;
CHECK_MSG ( ! wallet_err ,
tal_fmt ( w , " Insert into DB: %s " , wallet_err ) ) ;
CHECK_MSG ( channelseq ( & c1 , c2 ) , " Compare loaded with saved (v8) " ) ;
@ -486,11 +967,11 @@ static bool test_channel_crud(const tal_t *ctx)
return true ;
}
static bool test_channel_config_crud ( const tal_t * ctx )
static bool test_channel_config_crud ( struct lightningd * ld , const tal_t * ctx )
{
struct channel_config * cc1 = talz ( ctx , struct channel_config ) ,
* cc2 = talz ( ctx , struct channel_config ) ;
struct wallet * w = create_test_wallet ( ctx ) ;
struct wallet * w = create_test_wallet ( ld , ctx ) ;
CHECK ( w ) ;
cc1 - > dust_limit_satoshis = 1 ;
@ -510,21 +991,21 @@ static bool test_channel_config_crud(const tal_t *ctx)
return true ;
}
static bool test_htlc_crud ( const tal_t * ctx )
static bool test_htlc_crud ( struct lightningd * ld , const tal_t * ctx )
{
struct htlc_in in , * hin ;
struct htlc_out out , * hout ;
struct preimage payment_key ;
struct wallet_ channel * chan = tal ( ctx , struct wallet_ channel) ;
struct channel * chan = tal ( ctx , struct channel ) ;
struct peer * peer = talz ( ctx , struct peer ) ;
struct wallet * w = create_test_wallet ( ctx ) ;
struct wallet * w = create_test_wallet ( ld , ctx ) ;
struct htlc_in_map * htlcs_in = tal ( ctx , struct htlc_in_map ) ;
struct htlc_out_map * htlcs_out = tal ( ctx , struct htlc_out_map ) ;
/* Make sure we have our references correct */
CHECK ( transaction_wrap ( w - > db ,
db_exec ( __func__ , w - > db , " INSERT INTO channels (id) VALUES (1); " ) ) ) ;
chan - > id = 1 ;
chan - > db id = 1 ;
chan - > peer = peer ;
memset ( & in , 0 , sizeof ( in ) ) ;
@ -598,10 +1079,10 @@ static bool test_htlc_crud(const tal_t *ctx)
return true ;
}
static bool test_payment_crud ( const tal_t * ctx )
static bool test_payment_crud ( struct lightningd * ld , const tal_t * ctx )
{
struct wallet_payment * t = tal ( ctx , struct wallet_payment ) , * t2 ;
struct wallet * w = create_test_wallet ( ctx ) ;
struct wallet * w = create_test_wallet ( ld , ctx ) ;
mempat ( t , sizeof ( * t ) ) ;
memset ( & t - > destination , 1 , sizeof ( t - > destination ) ) ;
@ -642,13 +1123,21 @@ int main(void)
{
bool ok = true ;
tal_t * tmpctx = tal_tmpctx ( NULL ) ;
struct lightningd * ld = tal ( tmpctx , struct lightningd ) ;
/* Only elements in ld we should access */
list_head_init ( & ld - > peers ) ;
pubkey_from_der ( tal_hexdata ( tmpctx , " 02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc " , 66 ) , 33 , & ld - > id ) ;
/* Accessed in peer destructor sanity check */
htlc_in_map_init ( & ld - > htlcs_in ) ;
htlc_out_map_init ( & ld - > htlcs_out ) ;
ok & = test_wallet_outputs ( ) ;
ok & = test_shachain_crud ( ) ;
ok & = test_channel_crud ( tmpctx ) ;
ok & = test_channel_config_crud ( tmpctx ) ;
ok & = test_htlc_crud ( tmpctx ) ;
ok & = test_payment_crud ( tmpctx ) ;
ok & = test_channel_crud ( ld , tmpctx ) ;
ok & = test_channel_config_crud ( ld , tmpctx ) ;
ok & = test_htlc_crud ( ld , tmpctx ) ;
ok & = test_payment_crud ( ld , tmpctx ) ;
tal_free ( tmpctx ) ;
return ! ok ;