mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
channel_id: save to database, dont derive from funding_txid
v2 channel open uses a different method to derive the channel_id, so now we save it to the database so that we dont have to remember how to derive it for each. includes a migration for existing channels
This commit is contained in:
parent
b2170cf3f4
commit
864f2f3e21
@ -3212,6 +3212,7 @@ static void init_channel(struct peer *peer)
|
||||
if (!fromwire_channeld_init(peer, msg,
|
||||
&chainparams,
|
||||
&peer->our_features,
|
||||
&peer->channel_id,
|
||||
&funding_txid, &funding_txout,
|
||||
&funding,
|
||||
&minimum_depth,
|
||||
@ -3316,10 +3317,7 @@ static void init_channel(struct peer *peer)
|
||||
get_per_commitment_point(peer->next_index[LOCAL],
|
||||
&peer->next_local_per_commit, NULL);
|
||||
|
||||
/* channel_id is set from funding txout */
|
||||
derive_channel_id(&peer->channel_id, &funding_txid, funding_txout);
|
||||
|
||||
peer->channel = new_full_channel(peer,
|
||||
peer->channel = new_full_channel(peer, &peer->channel_id,
|
||||
&funding_txid,
|
||||
funding_txout,
|
||||
minimum_depth,
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <common/cryptomsg.h>
|
||||
#include <common/channel_config.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/features.h>
|
||||
#include <common/fee_states.h>
|
||||
@ -9,6 +10,7 @@
|
||||
msgtype,channeld_init,1000
|
||||
msgdata,channeld_init,chainparams,chainparams,
|
||||
msgdata,channeld_init,our_features,feature_set,
|
||||
msgdata,channeld_init,channel_id,channel_id,
|
||||
msgdata,channeld_init,funding_txid,bitcoin_txid,
|
||||
msgdata,channeld_init,funding_txout,u16,
|
||||
msgdata,channeld_init,funding_satoshi,amount_sat,
|
||||
|
|
8
channeld/channeld_wiregen.c
generated
8
channeld/channeld_wiregen.c
generated
@ -98,7 +98,7 @@ bool channeld_wire_is_defined(u16 type)
|
||||
|
||||
/* WIRE: CHANNELD_INIT */
|
||||
/* Begin! (passes gossipd-client fd) */
|
||||
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases)
|
||||
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases)
|
||||
{
|
||||
u16 num_last_sent_commit = tal_count(last_sent_commit);
|
||||
u16 num_existing_htlcs = tal_count(htlcs);
|
||||
@ -112,6 +112,7 @@ u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams
|
||||
towire_u16(&p, WIRE_CHANNELD_INIT);
|
||||
towire_chainparams(&p, chainparams);
|
||||
towire_feature_set(&p, our_features);
|
||||
towire_channel_id(&p, channel_id);
|
||||
towire_bitcoin_txid(&p, funding_txid);
|
||||
towire_u16(&p, funding_txout);
|
||||
towire_amount_sat(&p, funding_satoshi);
|
||||
@ -188,7 +189,7 @@ u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases)
|
||||
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases)
|
||||
{
|
||||
u16 num_last_sent_commit;
|
||||
u16 num_existing_htlcs;
|
||||
@ -205,6 +206,7 @@ bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainp
|
||||
return false;
|
||||
fromwire_chainparams(&cursor, &plen, chainparams);
|
||||
*our_features = fromwire_feature_set(ctx, &cursor, &plen);
|
||||
fromwire_channel_id(&cursor, &plen, channel_id);
|
||||
fromwire_bitcoin_txid(&cursor, &plen, funding_txid);
|
||||
*funding_txout = fromwire_u16(&cursor, &plen);
|
||||
*funding_satoshi = fromwire_amount_sat(&cursor, &plen);
|
||||
@ -1184,4 +1186,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
|
||||
}
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:b706854b9a5a26d5176006150ca8a0d18def0fe79a255b55383a3b5beb6f86af
|
||||
// SHA256STAMP:b2694c40c2801c4f6d4c49be6f6eee583bac168a96d6bb2bac6a845744d3cbee
|
||||
|
7
channeld/channeld_wiregen.h
generated
7
channeld/channeld_wiregen.h
generated
@ -9,6 +9,7 @@
|
||||
#include <wire/wire.h>
|
||||
#include <common/cryptomsg.h>
|
||||
#include <common/channel_config.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/features.h>
|
||||
#include <common/fee_states.h>
|
||||
@ -88,8 +89,8 @@ bool channeld_wire_is_defined(u16 type);
|
||||
|
||||
/* WIRE: CHANNELD_INIT */
|
||||
/* Begin! (passes gossipd-client fd) */
|
||||
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases);
|
||||
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases);
|
||||
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases);
|
||||
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases);
|
||||
|
||||
/* WIRE: CHANNELD_FUNDING_DEPTH */
|
||||
/* master->channeld funding hit new depth(funding locked if >= lock depth) */
|
||||
@ -229,4 +230,4 @@ bool fromwire_send_onionmsg(const tal_t *ctx, const void *p, u8 onion[1366], str
|
||||
|
||||
|
||||
#endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */
|
||||
// SHA256STAMP:b706854b9a5a26d5176006150ca8a0d18def0fe79a255b55383a3b5beb6f86af
|
||||
// SHA256STAMP:b2694c40c2801c4f6d4c49be6f6eee583bac168a96d6bb2bac6a845744d3cbee
|
||||
|
@ -90,6 +90,7 @@ static bool balance_ok(const struct balance *balance,
|
||||
}
|
||||
|
||||
struct channel *new_full_channel(const tal_t *ctx,
|
||||
const struct channel_id *cid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u32 minimum_depth,
|
||||
@ -107,6 +108,7 @@ struct channel *new_full_channel(const tal_t *ctx,
|
||||
enum side opener)
|
||||
{
|
||||
struct channel *channel = new_initial_channel(ctx,
|
||||
cid,
|
||||
funding_txid,
|
||||
funding_txout,
|
||||
minimum_depth,
|
||||
|
@ -7,11 +7,13 @@
|
||||
#include <common/initial_channel.h>
|
||||
#include <common/sphinx.h>
|
||||
|
||||
struct channel_id;
|
||||
struct existing_htlc;
|
||||
|
||||
/**
|
||||
* new_full_channel: Given initial fees and funding, what is initial state?
|
||||
* @ctx: tal context to allocate return value from.
|
||||
* @cid: The channel id.
|
||||
* @funding_txid: The commitment transaction id.
|
||||
* @funding_txout: The commitment transaction output number.
|
||||
* @minimum_depth: The minimum confirmations needed for funding transaction.
|
||||
@ -31,6 +33,7 @@ struct existing_htlc;
|
||||
* Returns state, or NULL if malformed.
|
||||
*/
|
||||
struct channel *new_full_channel(const tal_t *ctx,
|
||||
const struct channel_id *cid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u32 minimum_depth,
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "../../common/channel_id.c"
|
||||
#include "../../common/fee_states.c"
|
||||
#include "../../common/initial_channel.c"
|
||||
#include "../../common/keyset.c"
|
||||
@ -9,7 +10,6 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/setup.h>
|
||||
#include <common/sphinx.h>
|
||||
#include <common/type_to_string.h>
|
||||
@ -20,10 +20,6 @@
|
||||
/* Generated stub for fromwire_bigsize */
|
||||
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_channel_id */
|
||||
void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||
struct channel_id *channel_id UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_node_id */
|
||||
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
|
||||
@ -40,9 +36,6 @@ void status_failed(enum status_failreason code UNNEEDED,
|
||||
/* Generated stub for towire_bigsize */
|
||||
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
|
||||
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }
|
||||
/* Generated stub for towire_channel_id */
|
||||
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
|
||||
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for towire_node_id */
|
||||
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
|
||||
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
|
||||
@ -359,6 +352,7 @@ int main(int argc, const char *argv[])
|
||||
struct bitcoin_txid funding_txid;
|
||||
/* We test from both sides. */
|
||||
struct channel *lchannel, *rchannel;
|
||||
struct channel_id cid;
|
||||
struct amount_sat funding_amount;
|
||||
u32 *feerate_per_kw;
|
||||
unsigned int funding_output_index;
|
||||
@ -480,7 +474,8 @@ int main(int argc, const char *argv[])
|
||||
to_local = AMOUNT_MSAT(7000000000);
|
||||
to_remote = AMOUNT_MSAT(3000000000);
|
||||
feerate_per_kw[LOCAL] = feerate_per_kw[REMOTE] = 15000;
|
||||
lchannel = new_full_channel(tmpctx,
|
||||
derive_channel_id(&cid, &funding_txid, funding_output_index);
|
||||
lchannel = new_full_channel(tmpctx, &cid,
|
||||
&funding_txid, funding_output_index, 0,
|
||||
funding_amount, to_local,
|
||||
take(new_fee_states(NULL, LOCAL,
|
||||
@ -491,7 +486,7 @@ int main(int argc, const char *argv[])
|
||||
&local_funding_pubkey,
|
||||
&remote_funding_pubkey,
|
||||
false, false, LOCAL);
|
||||
rchannel = new_full_channel(tmpctx,
|
||||
rchannel = new_full_channel(tmpctx, &cid,
|
||||
&funding_txid, funding_output_index, 0,
|
||||
funding_amount, to_remote,
|
||||
take(new_fee_states(NULL, REMOTE,
|
||||
|
@ -628,6 +628,7 @@ int main(int argc, char *argv[])
|
||||
if (!fromwire_closingd_init(ctx, msg,
|
||||
&chainparams,
|
||||
&pps,
|
||||
&channel_id,
|
||||
&funding_txid, &funding_txout,
|
||||
&funding,
|
||||
&funding_pubkey[LOCAL],
|
||||
@ -669,7 +670,6 @@ int main(int argc, char *argv[])
|
||||
status_debug("fee = %s",
|
||||
type_to_string(tmpctx, struct amount_sat, &offer[LOCAL]));
|
||||
status_debug("fee negotiation step = %s", fee_negotiation_step_str);
|
||||
derive_channel_id(&channel_id, &funding_txid, funding_txout);
|
||||
|
||||
funding_wscript = bitcoin_redeem_2of2(ctx,
|
||||
&funding_pubkey[LOCAL],
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <bitcoin/tx.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/cryptomsg.h>
|
||||
#include <common/htlc_wire.h>
|
||||
#include <common/per_peer_state.h>
|
||||
@ -6,6 +7,7 @@
|
||||
msgtype,closingd_init,2001
|
||||
msgdata,closingd_init,chainparams,chainparams,
|
||||
msgdata,closingd_init,pps,per_peer_state,
|
||||
msgdata,closingd_init,channel_id,channel_id,
|
||||
msgdata,closingd_init,funding_txid,bitcoin_txid,
|
||||
msgdata,closingd_init,funding_txout,u16,
|
||||
msgdata,closingd_init,funding_satoshi,amount_sat,
|
||||
|
|
8
closingd/closingd_wiregen.c
generated
8
closingd/closingd_wiregen.c
generated
@ -48,7 +48,7 @@ bool closingd_wire_is_defined(u16 type)
|
||||
|
||||
/* WIRE: CLOSINGD_INIT */
|
||||
/* Begin! (passes peer fd */
|
||||
u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip)
|
||||
u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip)
|
||||
{
|
||||
u16 local_scriptpubkey_len = tal_count(local_scriptpubkey);
|
||||
u16 remote_scriptpubkey_len = tal_count(remote_scriptpubkey);
|
||||
@ -58,6 +58,7 @@ u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams
|
||||
towire_u16(&p, WIRE_CLOSINGD_INIT);
|
||||
towire_chainparams(&p, chainparams);
|
||||
towire_per_peer_state(&p, pps);
|
||||
towire_channel_id(&p, channel_id);
|
||||
towire_bitcoin_txid(&p, funding_txid);
|
||||
towire_u16(&p, funding_txout);
|
||||
towire_amount_sat(&p, funding_satoshi);
|
||||
@ -87,7 +88,7 @@ u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams
|
||||
|
||||
return memcheck(p, tal_count(p));
|
||||
}
|
||||
bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip)
|
||||
bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip)
|
||||
{
|
||||
u16 local_scriptpubkey_len;
|
||||
u16 remote_scriptpubkey_len;
|
||||
@ -100,6 +101,7 @@ bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainp
|
||||
return false;
|
||||
fromwire_chainparams(&cursor, &plen, chainparams);
|
||||
*pps = fromwire_per_peer_state(ctx, &cursor, &plen);
|
||||
fromwire_channel_id(&cursor, &plen, channel_id);
|
||||
fromwire_bitcoin_txid(&cursor, &plen, funding_txid);
|
||||
*funding_txout = fromwire_u16(&cursor, &plen);
|
||||
*funding_satoshi = fromwire_amount_sat(&cursor, &plen);
|
||||
@ -199,4 +201,4 @@ bool fromwire_closingd_complete(const void *p)
|
||||
return false;
|
||||
return cursor != NULL;
|
||||
}
|
||||
// SHA256STAMP:b6e109cf1e06fb2421d1ee78a18015e2f4b8e0697509409357735aaba2a479a5
|
||||
// SHA256STAMP:130dd782a340f537e202f3ce47b003732088f109a5446a17af566b27e0fbed3e
|
||||
|
7
closingd/closingd_wiregen.h
generated
7
closingd/closingd_wiregen.h
generated
@ -8,6 +8,7 @@
|
||||
#include <wire/tlvstream.h>
|
||||
#include <wire/wire.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/cryptomsg.h>
|
||||
#include <common/htlc_wire.h>
|
||||
#include <common/per_peer_state.h>
|
||||
@ -36,8 +37,8 @@ bool closingd_wire_is_defined(u16 type);
|
||||
|
||||
/* WIRE: CLOSINGD_INIT */
|
||||
/* Begin! (passes peer fd */
|
||||
u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip);
|
||||
bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip);
|
||||
u8 *towire_closingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct per_peer_state *pps, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, const struct pubkey *local_fundingkey, const struct pubkey *remote_fundingkey, enum side opener, struct amount_sat local_sat, struct amount_sat remote_sat, struct amount_sat our_dust_limit, struct amount_sat min_fee_satoshi, struct amount_sat fee_limit_satoshi, struct amount_sat initial_fee_satoshi, const u8 *local_scriptpubkey, const u8 *remote_scriptpubkey, u64 fee_negotiation_step, u8 fee_negotiation_step_unit, bool reconnected, u64 next_index_local, u64 next_index_remote, u64 revocations_received, const u8 *channel_reestablish, const struct secret *last_remote_secret, bool dev_fast_gossip);
|
||||
bool fromwire_closingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct per_peer_state **pps, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, struct pubkey *local_fundingkey, struct pubkey *remote_fundingkey, enum side *opener, struct amount_sat *local_sat, struct amount_sat *remote_sat, struct amount_sat *our_dust_limit, struct amount_sat *min_fee_satoshi, struct amount_sat *fee_limit_satoshi, struct amount_sat *initial_fee_satoshi, u8 **local_scriptpubkey, u8 **remote_scriptpubkey, u64 *fee_negotiation_step, u8 *fee_negotiation_step_unit, bool *reconnected, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u8 **channel_reestablish, struct secret *last_remote_secret, bool *dev_fast_gossip);
|
||||
|
||||
/* WIRE: CLOSINGD_RECEIVED_SIGNATURE */
|
||||
/* We received an offer */
|
||||
@ -55,4 +56,4 @@ bool fromwire_closingd_complete(const void *p);
|
||||
|
||||
|
||||
#endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */
|
||||
// SHA256STAMP:b6e109cf1e06fb2421d1ee78a18015e2f4b8e0697509409357735aaba2a479a5
|
||||
// SHA256STAMP:130dd782a340f537e202f3ce47b003732088f109a5446a17af566b27e0fbed3e
|
||||
|
@ -28,8 +28,7 @@ const char *mvt_tag_str(enum mvt_tag tag)
|
||||
}
|
||||
|
||||
struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
|
||||
struct bitcoin_txid *funding_txid,
|
||||
u32 funding_outnum,
|
||||
const struct channel_id *cid,
|
||||
struct sha256 payment_hash,
|
||||
u64 *part_id,
|
||||
struct amount_msat amount,
|
||||
@ -38,7 +37,7 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
|
||||
{
|
||||
struct channel_coin_mvt *mvt = tal(ctx, struct channel_coin_mvt);
|
||||
|
||||
derive_channel_id(&mvt->chan_id, funding_txid, funding_outnum);
|
||||
mvt->chan_id = *cid;
|
||||
mvt->payment_hash = tal_dup(mvt, struct sha256, &payment_hash);
|
||||
mvt->part_id = part_id;
|
||||
mvt->tag = tag;
|
||||
|
@ -117,8 +117,7 @@ struct coin_mvt {
|
||||
};
|
||||
|
||||
struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
|
||||
struct bitcoin_txid *funding_txid,
|
||||
u32 funding_outnum,
|
||||
const struct channel_id *cid,
|
||||
struct sha256 payment_hash,
|
||||
u64 *part_id,
|
||||
struct amount_msat amount,
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
struct channel *new_initial_channel(const tal_t *ctx,
|
||||
const struct channel_id *cid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u32 minimum_depth,
|
||||
@ -32,6 +33,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
||||
struct channel *channel = tal(ctx, struct channel);
|
||||
struct amount_msat remote_msatoshi;
|
||||
|
||||
channel->cid = *cid;
|
||||
channel->funding_txid = *funding_txid;
|
||||
channel->funding_txout = funding_txout;
|
||||
channel->funding = funding;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/channel_config.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/htlc.h>
|
||||
#include <stdbool.h>
|
||||
@ -26,6 +27,10 @@ struct channel_view {
|
||||
};
|
||||
|
||||
struct channel {
|
||||
|
||||
/* The id for this channel */
|
||||
struct channel_id cid;
|
||||
|
||||
/* Funding txid and output. */
|
||||
struct bitcoin_txid funding_txid;
|
||||
unsigned int funding_txout;
|
||||
@ -70,6 +75,7 @@ struct channel {
|
||||
/**
|
||||
* new_initial_channel: Given initial fees and funding, what is initial state?
|
||||
* @ctx: tal context to allocate return value from.
|
||||
* @cid: The channel's id.
|
||||
* @funding_txid: The commitment transaction id.
|
||||
* @funding_txout: The commitment transaction output number.
|
||||
* @minimum_depth: The minimum confirmations needed for funding transaction.
|
||||
@ -89,6 +95,7 @@ struct channel {
|
||||
* Returns channel, or NULL if malformed.
|
||||
*/
|
||||
struct channel *new_initial_channel(const tal_t *ctx,
|
||||
const struct channel_id *cid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u32 minimum_depth,
|
||||
@ -105,7 +112,6 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
||||
bool option_anchor_outputs,
|
||||
enum side opener);
|
||||
|
||||
|
||||
/**
|
||||
* initial_channel_tx: Get the current commitment tx for the *empty* channel.
|
||||
* @ctx: tal context to allocate return value from.
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <channeld/full_channel.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/fee_states.h>
|
||||
#include <common/htlc_wire.h>
|
||||
@ -250,6 +251,7 @@ int main(int argc, char *argv[])
|
||||
struct pubkey funding_localkey, funding_remotekey;
|
||||
u64 commitnum;
|
||||
struct amount_sat funding_amount;
|
||||
struct channel_id cid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
unsigned int funding_outnum;
|
||||
u32 feerate_per_kw;
|
||||
@ -386,7 +388,11 @@ int main(int argc, char *argv[])
|
||||
&remote, &remoteseed,
|
||||
&remotebase, &funding_remotekey, commitnum);
|
||||
|
||||
/* FIXME: option for v2? */
|
||||
derive_channel_id(&cid, &funding_txid, funding_outnum);
|
||||
|
||||
channel = new_full_channel(NULL,
|
||||
&cid,
|
||||
&funding_txid, funding_outnum, 1,
|
||||
funding_amount,
|
||||
local_msat,
|
||||
|
@ -163,6 +163,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
bool remote_funding_locked,
|
||||
/* NULL or stolen */
|
||||
struct short_channel_id *scid,
|
||||
struct channel_id *cid,
|
||||
struct amount_msat our_msat,
|
||||
struct amount_msat msat_to_us_min,
|
||||
struct amount_msat msat_to_us_max,
|
||||
@ -232,6 +233,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
channel->our_funds = our_funds;
|
||||
channel->remote_funding_locked = remote_funding_locked;
|
||||
channel->scid = tal_steal(channel, scid);
|
||||
channel->cid = *cid;
|
||||
channel->our_msat = our_msat;
|
||||
channel->msat_to_us_min = msat_to_us_min;
|
||||
channel->msat_to_us_max = msat_to_us_max;
|
||||
@ -399,7 +401,6 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
va_list ap;
|
||||
char *why;
|
||||
struct channel_id cid;
|
||||
|
||||
va_start(ap, fmt);
|
||||
why = tal_vfmt(tmpctx, fmt, ap);
|
||||
@ -409,12 +410,9 @@ void channel_fail_permanent(struct channel *channel, const char *fmt, ...)
|
||||
channel_state_name(channel), why);
|
||||
|
||||
/* We can have multiple errors, eg. onchaind failures. */
|
||||
if (!channel->error) {
|
||||
derive_channel_id(&cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
channel->error = towire_errorfmt(channel, &cid, "%s", why);
|
||||
}
|
||||
if (!channel->error)
|
||||
channel->error = towire_errorfmt(channel,
|
||||
&channel->cid, "%s", why);
|
||||
|
||||
channel_set_owner(channel, NULL);
|
||||
/* Drop non-cooperatively (unilateral) to chain. */
|
||||
@ -430,7 +428,6 @@ void channel_fail_forget(struct channel *channel, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *why;
|
||||
struct channel_id cid;
|
||||
|
||||
assert(channel->opener == REMOTE &&
|
||||
channel->state == CHANNELD_AWAITING_LOCKIN);
|
||||
@ -442,12 +439,9 @@ void channel_fail_forget(struct channel *channel, const char *fmt, ...)
|
||||
"forget channel",
|
||||
channel_state_name(channel), why);
|
||||
|
||||
if (!channel->error) {
|
||||
derive_channel_id(&cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
channel->error = towire_errorfmt(channel, &cid, "%s", why);
|
||||
}
|
||||
if (!channel->error)
|
||||
channel->error = towire_errorfmt(channel,
|
||||
&channel->cid, "%s", why);
|
||||
|
||||
delete_channel(channel);
|
||||
tal_free(why);
|
||||
|
@ -2,10 +2,12 @@
|
||||
#define LIGHTNING_LIGHTNINGD_CHANNEL_H
|
||||
#include "config.h"
|
||||
#include <ccan/list/list.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <lightningd/channel_state.h>
|
||||
#include <lightningd/peer_htlcs.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
struct channel_id;
|
||||
struct uncommitted_channel;
|
||||
|
||||
struct billboard {
|
||||
@ -69,6 +71,8 @@ struct channel {
|
||||
/* Channel if locked locally. */
|
||||
struct short_channel_id *scid;
|
||||
|
||||
struct channel_id cid;
|
||||
|
||||
/* Amount going to us, not counting unfinished HTLCs; if we have one. */
|
||||
struct amount_msat our_msat;
|
||||
/* Statistics for min and max our_msatoshi. */
|
||||
@ -163,6 +167,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
bool remote_funding_locked,
|
||||
/* NULL or stolen */
|
||||
struct short_channel_id *scid STEALS,
|
||||
struct channel_id *cid,
|
||||
struct amount_msat our_msatoshi,
|
||||
struct amount_msat msatoshi_to_us_min,
|
||||
struct amount_msat msatoshi_to_us_max,
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <bitcoin/script.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <channeld/channeld_wiregen.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/coin_mvt.h>
|
||||
#include <common/features.h>
|
||||
#include <common/gossip_constants.h>
|
||||
@ -77,17 +78,12 @@ void notify_feerate_change(struct lightningd *ld)
|
||||
|
||||
static void record_channel_open(struct channel *channel)
|
||||
{
|
||||
struct channel_id channel_id;
|
||||
struct chain_coin_mvt *mvt;
|
||||
struct amount_msat channel_open_amt;
|
||||
u32 blockheight;
|
||||
|
||||
u8 *ctx = tal(NULL, u8);
|
||||
|
||||
/* figure out the 'account name' */
|
||||
derive_channel_id(&channel_id, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
|
||||
blockheight = short_channel_id_blocknum(channel->scid);
|
||||
|
||||
/* FIXME: logic here will change for dual funded channels */
|
||||
@ -101,7 +97,7 @@ static void record_channel_open(struct channel *channel)
|
||||
if (amount_msat_greater(channel->push, AMOUNT_MSAT(0))) {
|
||||
mvt = new_coin_pushed(ctx, type_to_string(tmpctx,
|
||||
struct channel_id,
|
||||
&channel_id),
|
||||
&channel->cid),
|
||||
&channel->funding_txid,
|
||||
blockheight, channel->push);
|
||||
notify_chain_mvt(channel->peer->ld, mvt);
|
||||
@ -115,7 +111,7 @@ static void record_channel_open(struct channel *channel)
|
||||
|
||||
mvt = new_coin_deposit(ctx,
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel_id),
|
||||
&channel->cid),
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
blockheight, channel_open_amt);
|
||||
@ -321,11 +317,7 @@ static void handle_error_channel(struct channel *channel,
|
||||
|
||||
void forget_channel(struct channel *channel, const char *why)
|
||||
{
|
||||
struct channel_id cid;
|
||||
|
||||
derive_channel_id(&cid, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
channel->error = towire_errorfmt(channel, &cid, "%s", why);
|
||||
channel->error = towire_errorfmt(channel, &channel->cid, "%s", why);
|
||||
|
||||
/* If the peer is connected, we let them know. Otherwise
|
||||
* we just directly remove the channel */
|
||||
@ -522,6 +514,7 @@ void peer_start_channeld(struct channel *channel,
|
||||
initmsg = towire_channeld_init(tmpctx,
|
||||
chainparams,
|
||||
ld->our_features,
|
||||
&channel->cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
channel->funding,
|
||||
@ -713,11 +706,7 @@ static struct channel *find_channel_by_id(const struct peer *peer,
|
||||
struct channel *c;
|
||||
|
||||
list_for_each(&peer->channels, c, list) {
|
||||
struct channel_id this_cid;
|
||||
|
||||
derive_channel_id(&this_cid,
|
||||
&c->funding_txid, c->funding_outnum);
|
||||
if (channel_id_eq(&this_cid, cid))
|
||||
if (channel_id_eq(&c->cid, cid))
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
@ -796,9 +785,7 @@ struct command_result *cancel_channel_before_broadcast(struct command *cmd,
|
||||
"peer_id %s",
|
||||
type_to_string(tmpctx, struct node_id,
|
||||
&peer->id));
|
||||
derive_channel_id(&cc->cid,
|
||||
&cancel_channel->funding_txid,
|
||||
cancel_channel->funding_outnum);
|
||||
cc->cid = cancel_channel->cid;
|
||||
|
||||
if (cancel_channel->opener == REMOTE)
|
||||
return command_fail(cmd, FUNDING_CANCEL_NOT_SAFE,
|
||||
|
@ -281,6 +281,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
initmsg = towire_closingd_init(tmpctx,
|
||||
chainparams,
|
||||
pps,
|
||||
&channel->cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
channel->funding,
|
||||
|
@ -40,8 +40,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
return new_channel_coin_mvt(ctx, &channel->cid,
|
||||
hin->payment_hash, NULL,
|
||||
hin->msat, INVOICE,
|
||||
true);
|
||||
@ -51,8 +50,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
return new_channel_coin_mvt(ctx, &channel->cid,
|
||||
hin->payment_hash, NULL,
|
||||
hin->msat, ROUTED,
|
||||
true);
|
||||
@ -62,8 +60,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
return new_channel_coin_mvt(ctx, &channel->cid,
|
||||
hout->payment_hash, &hout->partid,
|
||||
hout->msat, INVOICE,
|
||||
false);
|
||||
@ -73,8 +70,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
return new_channel_coin_mvt(ctx, &channel->cid,
|
||||
hout->payment_hash, NULL,
|
||||
hout->msat, ROUTED,
|
||||
false);
|
||||
|
@ -197,7 +197,6 @@ static void watch_tx_and_outputs(struct channel *channel,
|
||||
|
||||
static void handle_onchain_log_coin_move(struct channel *channel, const u8 *msg)
|
||||
{
|
||||
struct channel_id channel_id;
|
||||
struct chain_coin_mvt *mvt = tal(NULL, struct chain_coin_mvt);
|
||||
|
||||
if (!fromwire_onchaind_notify_coin_mvt(msg, mvt)) {
|
||||
@ -205,10 +204,8 @@ static void handle_onchain_log_coin_move(struct channel *channel, const u8 *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
derive_channel_id(&channel_id, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
mvt->account_name =
|
||||
type_to_string(mvt, struct channel_id, &channel_id);
|
||||
type_to_string(mvt, struct channel_id, &channel->cid);
|
||||
notify_chain_mvt(channel->peer->ld, mvt);
|
||||
tal_free(mvt);
|
||||
}
|
||||
|
@ -172,6 +172,7 @@ void json_add_uncommitted_channel(struct json_stream *response,
|
||||
static struct channel *
|
||||
wallet_commit_channel(struct lightningd *ld,
|
||||
struct uncommitted_channel *uc,
|
||||
struct channel_id *cid,
|
||||
struct bitcoin_tx *remote_commit,
|
||||
struct bitcoin_signature *remote_commit_sig,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
@ -262,6 +263,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
local_funding,
|
||||
false, /* !remote_funding_locked */
|
||||
NULL, /* no scid yet */
|
||||
cid,
|
||||
/* The three arguments below are msatoshi_to_us,
|
||||
* msatoshi_to_us_min, and msatoshi_to_us_max.
|
||||
* Because, this is a newly-funded channel,
|
||||
@ -339,7 +341,8 @@ static void funding_success(struct channel *channel)
|
||||
|
||||
response = json_stream_success(cmd);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id, &fc->cid));
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
&channel->cid));
|
||||
json_add_bool(response, "commitments_secured", true);
|
||||
was_pending(command_success(cmd, response));
|
||||
}
|
||||
@ -410,6 +413,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
struct funding_channel *fc)
|
||||
{
|
||||
struct channel_info channel_info;
|
||||
struct channel_id cid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_txout;
|
||||
struct bitcoin_signature remote_commit_sig;
|
||||
@ -457,8 +461,12 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
"%s", type_to_string(tmpctx, struct pubkey,
|
||||
&channel_info.remote_per_commit));
|
||||
|
||||
/* Saved with channel to disk */
|
||||
derive_channel_id(&cid, &funding_txid, funding_txout);
|
||||
|
||||
/* Steals fields from uc */
|
||||
channel = wallet_commit_channel(ld, fc->uc,
|
||||
&cid,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
@ -479,9 +487,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
|
||||
/* Watch for funding confirms */
|
||||
channel_watch_funding(ld, channel);
|
||||
|
||||
/* Needed for the success statement */
|
||||
derive_channel_id(&fc->cid, &channel->funding_txid, funding_txout);
|
||||
|
||||
if (pbase)
|
||||
wallet_penalty_base_add(ld->wallet, channel->dbid, pbase);
|
||||
|
||||
@ -504,6 +509,7 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
struct channel_info channel_info;
|
||||
struct bitcoin_signature remote_commit_sig;
|
||||
struct bitcoin_tx *remote_commit;
|
||||
struct channel_id cid;
|
||||
struct lightningd *ld = openingd->ld;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_outnum;
|
||||
@ -561,8 +567,11 @@ static void opening_fundee_finished(struct subd *openingd,
|
||||
goto failed;
|
||||
}
|
||||
|
||||
derive_channel_id(&cid, &funding_txid, funding_outnum);
|
||||
|
||||
/* Consumes uc */
|
||||
channel = wallet_commit_channel(ld, uc,
|
||||
&cid,
|
||||
remote_commit,
|
||||
&remote_commit_sig,
|
||||
&funding_txid,
|
||||
|
@ -696,7 +696,6 @@ static void json_add_channel(struct lightningd *ld,
|
||||
struct json_stream *response, const char *key,
|
||||
const struct channel *channel)
|
||||
{
|
||||
struct channel_id cid;
|
||||
struct channel_stats channel_stats;
|
||||
struct amount_msat funding_msat;
|
||||
struct peer *p = channel->peer;
|
||||
@ -719,10 +718,8 @@ static void json_add_channel(struct lightningd *ld,
|
||||
node_id_idx(&ld->id, &channel->peer->id));
|
||||
}
|
||||
|
||||
derive_channel_id(&cid, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id, &cid));
|
||||
type_to_string(tmpctx, struct channel_id, &channel->cid));
|
||||
json_add_txid(response, "funding_txid", &channel->funding_txid);
|
||||
|
||||
if (channel->shutdown_scriptpubkey[LOCAL]) {
|
||||
@ -970,13 +967,9 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload STEALS,
|
||||
|
||||
/* We consider this "active" but we only send an error */
|
||||
case AWAITING_UNILATERAL: {
|
||||
struct channel_id cid;
|
||||
derive_channel_id(&cid,
|
||||
&channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
/* channel->error is not saved in db, so this can
|
||||
* happen if we restart. */
|
||||
error = towire_errorfmt(tmpctx, &cid,
|
||||
error = towire_errorfmt(tmpctx, &channel->cid,
|
||||
"Awaiting unilateral close");
|
||||
goto send_error;
|
||||
}
|
||||
@ -1279,7 +1272,6 @@ command_find_channel(struct command *cmd,
|
||||
{
|
||||
struct lightningd *ld = cmd->ld;
|
||||
struct channel_id cid;
|
||||
struct channel_id channel_cid;
|
||||
struct short_channel_id scid;
|
||||
struct peer *peer;
|
||||
|
||||
@ -1288,10 +1280,7 @@ command_find_channel(struct command *cmd,
|
||||
*channel = peer_active_channel(peer);
|
||||
if (!*channel)
|
||||
continue;
|
||||
derive_channel_id(&channel_cid,
|
||||
&(*channel)->funding_txid,
|
||||
(*channel)->funding_outnum);
|
||||
if (channel_id_eq(&channel_cid, &cid))
|
||||
if (channel_id_eq(&(*channel)->cid, &cid))
|
||||
return NULL;
|
||||
}
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
@ -1879,8 +1868,6 @@ static struct command_result *param_msat_u32(struct command *cmd,
|
||||
static void set_channel_fees(struct command *cmd, struct channel *channel,
|
||||
u32 base, u32 ppm, struct json_stream *response)
|
||||
{
|
||||
struct channel_id cid;
|
||||
|
||||
/* set new values */
|
||||
channel->feerate_base = base;
|
||||
channel->feerate_ppm = ppm;
|
||||
@ -1894,11 +1881,10 @@ static void set_channel_fees(struct command *cmd, struct channel *channel,
|
||||
wallet_channel_save(cmd->ld->wallet, channel);
|
||||
|
||||
/* write JSON response entry */
|
||||
derive_channel_id(&cid, &channel->funding_txid, channel->funding_outnum);
|
||||
json_object_start(response, NULL);
|
||||
json_add_node_id(response, "peer_id", &channel->peer->id);
|
||||
json_add_string(response, "channel_id",
|
||||
type_to_string(tmpctx, struct channel_id, &cid));
|
||||
type_to_string(tmpctx, struct channel_id, &channel->cid));
|
||||
if (channel->scid)
|
||||
json_add_short_channel_id(response, "short_channel_id", channel->scid);
|
||||
json_object_end(response);
|
||||
@ -2158,7 +2144,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
struct short_channel_id *scid;
|
||||
struct channel_id *find_cid, cid;
|
||||
struct channel_id *find_cid;
|
||||
struct dev_forget_channel_cmd *forget = tal(cmd, struct dev_forget_channel_cmd);
|
||||
forget->cmd = cmd;
|
||||
|
||||
@ -2182,10 +2168,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
list_for_each(&peer->channels, channel, list) {
|
||||
/* Check for channel id first */
|
||||
if (find_cid) {
|
||||
derive_channel_id(&cid, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
|
||||
if (!channel_id_eq(find_cid, &cid))
|
||||
if (!channel_id_eq(find_cid, &channel->cid))
|
||||
continue;
|
||||
}
|
||||
if (scid) {
|
||||
|
@ -696,6 +696,7 @@ static bool funder_finalize_channel_setup(struct state *state,
|
||||
u8 *msg;
|
||||
struct channel_id id_in;
|
||||
const u8 *wscript;
|
||||
struct channel_id cid;
|
||||
char *err_reason;
|
||||
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
||||
|
||||
@ -707,7 +708,11 @@ static bool funder_finalize_channel_setup(struct state *state,
|
||||
* part (common/initial_channel) which doesn't support HTLCs and is
|
||||
* enough for us here, and the complete channel support required by
|
||||
* `channeld` which lives in channeld/full_channel. */
|
||||
derive_channel_id(&cid,
|
||||
&state->funding_txid, state->funding_txout);
|
||||
|
||||
state->channel = new_initial_channel(state,
|
||||
&cid,
|
||||
&state->funding_txid,
|
||||
state->funding_txout,
|
||||
state->minimum_depth,
|
||||
@ -813,7 +818,6 @@ static bool funder_finalize_channel_setup(struct state *state,
|
||||
peer_failed(state->pps,
|
||||
&state->channel_id,
|
||||
"Parsing funding_signed: %s", tal_hex(msg, msg));
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* This message introduces the `channel_id` to identify the channel.
|
||||
@ -837,8 +841,7 @@ static bool funder_finalize_channel_setup(struct state *state,
|
||||
*
|
||||
* Let this be a lesson: beware premature specification, even if you
|
||||
* suspect "we'll need it later!". */
|
||||
derive_channel_id(&state->channel_id,
|
||||
&state->funding_txid, state->funding_txout);
|
||||
state->channel_id = cid;
|
||||
|
||||
if (!channel_id_eq(&id_in, &state->channel_id))
|
||||
peer_failed(state->pps, &id_in,
|
||||
@ -1191,6 +1194,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
||||
|
||||
/* Now we can create the channel structure. */
|
||||
state->channel = new_initial_channel(state,
|
||||
&state->channel_id,
|
||||
&state->funding_txid,
|
||||
state->funding_txout,
|
||||
state->minimum_depth,
|
||||
|
@ -249,6 +249,18 @@ def test_backfill_scriptpubkeys(node_factory, bitcoind):
|
||||
for exp, actual in zip(script_map_2, scripts):
|
||||
assert exp == actual
|
||||
|
||||
# Also check that the full_channel_id has been filled in
|
||||
results = l2.db_query('SELECT hex(full_channel_id) AS cid, hex(funding_tx_id) as txid, funding_tx_outnum FROM channels')
|
||||
|
||||
def _chan_id(txid, outnum):
|
||||
chanid = bytearray.fromhex(txid)
|
||||
chanid[-1] ^= outnum % 256
|
||||
chanid[-2] ^= outnum // 256
|
||||
return chanid.hex()
|
||||
|
||||
for row in results:
|
||||
assert _chan_id(row['txid'], row['funding_tx_outnum']) == row['cid'].lower()
|
||||
|
||||
|
||||
@unittest.skipIf(VALGRIND and not DEVELOPER, "Without developer valgrind will complain about debug symbols missing")
|
||||
def test_optimistic_locking(node_factory, bitcoind):
|
||||
|
59
wallet/db.c
59
wallet/db.c
@ -5,6 +5,7 @@
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/key_derive.h>
|
||||
#include <common/node_id.h>
|
||||
@ -41,6 +42,9 @@ static void migrate_last_tx_to_psbt(struct lightningd *ld, struct db *db,
|
||||
static void fillin_missing_scriptpubkeys(struct lightningd *ld, struct db *db,
|
||||
const struct ext_key *bip32_base);
|
||||
|
||||
static void fillin_missing_channel_id(struct lightningd *ld, struct db *db,
|
||||
const struct ext_key *bip32_base);
|
||||
|
||||
/* Do not reorder or remove elements from this array, it is used to
|
||||
* migrate existing databases from a previous state, based on the
|
||||
* string indices */
|
||||
@ -640,6 +644,7 @@ static struct migration dbmigrations[] = {
|
||||
/* We need to know if it was option_anchor_outputs to spend to_remote */
|
||||
{SQL("ALTER TABLE outputs ADD option_anchor_outputs INTEGER"
|
||||
" DEFAULT 0;"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD full_channel_id BLOB DEFAULT NULL;"), fillin_missing_channel_id},
|
||||
};
|
||||
|
||||
/* Leak tracking. */
|
||||
@ -1223,6 +1228,49 @@ void fillin_missing_scriptpubkeys(struct lightningd *ld, struct db *db,
|
||||
tal_free(stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
* V2 channel open has a different channel_id format than v1. prior to this, we
|
||||
* could simply derive the channel_id whenever it was required, but since there
|
||||
* are now two ways to do it, we save the derived channel id.
|
||||
*/
|
||||
static void fillin_missing_channel_id(struct lightningd *ld, struct db *db,
|
||||
const struct ext_key *bip32_base)
|
||||
{
|
||||
|
||||
struct db_stmt *stmt;
|
||||
|
||||
stmt = db_prepare_v2(db, SQL("SELECT"
|
||||
" id"
|
||||
", funding_tx_id"
|
||||
", funding_tx_outnum"
|
||||
" FROM channels;"));
|
||||
|
||||
db_query_prepared(stmt);
|
||||
while (db_step(stmt)) {
|
||||
struct db_stmt *update_stmt;
|
||||
size_t id;
|
||||
struct bitcoin_txid funding_txid;
|
||||
struct channel_id cid;
|
||||
u32 outnum;
|
||||
|
||||
id = db_column_int(stmt, 0);
|
||||
db_column_txid(stmt, 1, &funding_txid);
|
||||
outnum = db_column_int(stmt, 2);
|
||||
derive_channel_id(&cid, &funding_txid, outnum);
|
||||
|
||||
update_stmt = db_prepare_v2(db, SQL("UPDATE channels"
|
||||
" SET full_channel_id = ?"
|
||||
" WHERE id = ?;"));
|
||||
db_bind_channel_id(update_stmt, 0, &cid);
|
||||
db_bind_int(update_stmt, 1, id);
|
||||
|
||||
db_exec_prepared_v2(update_stmt);
|
||||
tal_free(update_stmt);
|
||||
}
|
||||
|
||||
tal_free(stmt);
|
||||
}
|
||||
|
||||
/* We're moving everything over to PSBTs from tx's, particularly our last_tx's
|
||||
* which are commitment transactions for channels.
|
||||
* This migration loads all of the last_tx's and 're-formats' them into psbts,
|
||||
@ -1386,6 +1434,11 @@ void db_bind_txid(struct db_stmt *stmt, int pos, const struct bitcoin_txid *t)
|
||||
db_bind_sha256d(stmt, pos, &t->shad);
|
||||
}
|
||||
|
||||
void db_bind_channel_id(struct db_stmt *stmt, int pos, const struct channel_id *id)
|
||||
{
|
||||
db_bind_blob(stmt, pos, id->id, sizeof(id->id));
|
||||
}
|
||||
|
||||
void db_bind_node_id(struct db_stmt *stmt, int pos, const struct node_id *id)
|
||||
{
|
||||
db_bind_blob(stmt, pos, id->k, sizeof(id->k));
|
||||
@ -1505,6 +1558,12 @@ void db_column_preimage(struct db_stmt *stmt, int col,
|
||||
memcpy(preimage, raw, size);
|
||||
}
|
||||
|
||||
void db_column_channel_id(struct db_stmt *stmt, int col, struct channel_id *dest)
|
||||
{
|
||||
assert(db_column_bytes(stmt, col) == sizeof(dest->id));
|
||||
memcpy(dest->id, db_column_blob(stmt, col), sizeof(dest->id));
|
||||
}
|
||||
|
||||
void db_column_node_id(struct db_stmt *stmt, int col, struct node_id *dest)
|
||||
{
|
||||
assert(db_column_bytes(stmt, col) == sizeof(dest->k));
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <secp256k1_ecdh.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct channel_id;
|
||||
struct ext_key;
|
||||
struct lightningd;
|
||||
struct log;
|
||||
@ -107,6 +108,7 @@ void db_bind_sha256d(struct db_stmt *stmt, int pos, const struct sha256_double *
|
||||
void db_bind_secret(struct db_stmt *stmt, int pos, const struct secret *s);
|
||||
void db_bind_secret_arr(struct db_stmt *stmt, int col, const struct secret *s);
|
||||
void db_bind_txid(struct db_stmt *stmt, int pos, const struct bitcoin_txid *t);
|
||||
void db_bind_channel_id(struct db_stmt *stmt, int pos, const struct channel_id *id);
|
||||
void db_bind_node_id(struct db_stmt *stmt, int pos, const struct node_id *ni);
|
||||
void db_bind_node_id_arr(struct db_stmt *stmt, int col,
|
||||
const struct node_id *ids);
|
||||
@ -147,6 +149,7 @@ void db_column_secret(struct db_stmt *stmt, int col, struct secret *s);
|
||||
struct secret *db_column_secret_arr(const tal_t *ctx, struct db_stmt *stmt,
|
||||
int col);
|
||||
void db_column_txid(struct db_stmt *stmt, int pos, struct bitcoin_txid *t);
|
||||
void db_column_channel_id(struct db_stmt *stmt, int col, struct channel_id *dest);
|
||||
void db_column_node_id(struct db_stmt *stmt, int pos, struct node_id *ni);
|
||||
struct node_id *db_column_node_id_arr(const tal_t *ctx, struct db_stmt *stmt,
|
||||
int col);
|
||||
|
32
wallet/db_postgres_sqlgen.c
generated
32
wallet/db_postgres_sqlgen.c
generated
@ -818,6 +818,12 @@ struct db_query db_postgres_queries[] = {
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD full_channel_id BLOB DEFAULT NULL;",
|
||||
.query = "ALTER TABLE channels ADD full_channel_id BYTEA DEFAULT NULL;",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
.query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = $1",
|
||||
@ -890,6 +896,18 @@ struct db_query db_postgres_queries[] = {
|
||||
.placeholders = 3,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;",
|
||||
.query = "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;",
|
||||
.placeholders = 0,
|
||||
.readonly = true,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE channels SET full_channel_id = ? WHERE id = ?;",
|
||||
.query = "UPDATE channels SET full_channel_id = $1 WHERE id = $2;",
|
||||
.placeholders = 2,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;",
|
||||
.query = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;",
|
||||
@ -1113,8 +1131,8 @@ struct db_query db_postgres_queries[] = {
|
||||
.readonly = true,
|
||||
},
|
||||
{
|
||||
.name = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.query = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < $1;",
|
||||
.name = "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.query = "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < $1;",
|
||||
.placeholders = 1,
|
||||
.readonly = true,
|
||||
},
|
||||
@ -1179,9 +1197,9 @@ struct db_query db_postgres_queries[] = {
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.query = "UPDATE channels SET shachain_remote_id=$1, short_channel_id=$2, state=$3, funder=$4, channel_flags=$5, minimum_depth=$6, next_index_local=$7, next_index_remote=$8, next_htlc_id=$9, funding_tx_id=$10, funding_tx_outnum=$11, funding_satoshi=$12, our_funding_satoshi=$13, funding_locked_remote=$14, push_msatoshi=$15, msatoshi_local=$16, shutdown_scriptpubkey_remote=$17, shutdown_keyidx_local=$18, channel_config_local=$19, last_tx=$20, last_sig=$21, last_was_revoke=$22, min_possible_feerate=$23, max_possible_feerate=$24, msatoshi_to_us_min=$25, msatoshi_to_us_max=$26, feerate_base=$27, feerate_ppm=$28, remote_upfront_shutdown_script=$29, option_static_remotekey=$30, option_anchor_outputs=$31, shutdown_scriptpubkey_local=$32 WHERE id=$33",
|
||||
.placeholders = 33,
|
||||
.name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.query = "UPDATE channels SET shachain_remote_id=$1, short_channel_id=$2, full_channel_id=$3, state=$4, funder=$5, channel_flags=$6, minimum_depth=$7, next_index_local=$8, next_index_remote=$9, next_htlc_id=$10, funding_tx_id=$11, funding_tx_outnum=$12, funding_satoshi=$13, our_funding_satoshi=$14, funding_locked_remote=$15, push_msatoshi=$16, msatoshi_local=$17, shutdown_scriptpubkey_remote=$18, shutdown_keyidx_local=$19, channel_config_local=$20, last_tx=$21, last_sig=$22, last_was_revoke=$23, min_possible_feerate=$24, max_possible_feerate=$25, msatoshi_to_us_min=$26, msatoshi_to_us_max=$27, feerate_base=$28, feerate_ppm=$29, remote_upfront_shutdown_script=$30, option_static_remotekey=$31, option_anchor_outputs=$32, shutdown_scriptpubkey_local=$33 WHERE id=$34",
|
||||
.placeholders = 34,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
@ -1624,10 +1642,10 @@ struct db_query db_postgres_queries[] = {
|
||||
},
|
||||
};
|
||||
|
||||
#define DB_POSTGRES_QUERY_COUNT 269
|
||||
#define DB_POSTGRES_QUERY_COUNT 272
|
||||
|
||||
#endif /* HAVE_POSTGRES */
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||
|
||||
// SHA256STAMP:933e3d44cffab23c051a63163d4b24bcef044ad617ec3db040e6a92f9c55e0c6
|
||||
// SHA256STAMP:d9e28ea3b9764c7f3d5cc2bba2ac18493fc00bb42d13e94d0589824512aa1e01
|
||||
|
32
wallet/db_sqlite3_sqlgen.c
generated
32
wallet/db_sqlite3_sqlgen.c
generated
@ -818,6 +818,12 @@ struct db_query db_sqlite3_queries[] = {
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "ALTER TABLE channels ADD full_channel_id BLOB DEFAULT NULL;",
|
||||
.query = "ALTER TABLE channels ADD full_channel_id BLOB DEFAULT NULL;",
|
||||
.placeholders = 0,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
.query = "UPDATE vars SET intval = intval + 1 WHERE name = 'data_version' AND intval = ?",
|
||||
@ -890,6 +896,18 @@ struct db_query db_sqlite3_queries[] = {
|
||||
.placeholders = 3,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;",
|
||||
.query = "SELECT id, funding_tx_id, funding_tx_outnum FROM channels;",
|
||||
.placeholders = 0,
|
||||
.readonly = true,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE channels SET full_channel_id = ? WHERE id = ?;",
|
||||
.query = "UPDATE channels SET full_channel_id = ? WHERE id = ?;",
|
||||
.placeholders = 2,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;",
|
||||
.query = "SELECT c.id, p.node_id, c.last_tx, c.funding_satoshi, c.fundingkey_remote, c.last_sig FROM channels c LEFT OUTER JOIN peers p ON p.id = c.peer_id;",
|
||||
@ -1113,8 +1131,8 @@ struct db_query db_sqlite3_queries[] = {
|
||||
.readonly = true,
|
||||
},
|
||||
{
|
||||
.name = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.query = "SELECT id, peer_id, short_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.name = "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.query = "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, option_static_remotekey, option_anchor_outputs, shutdown_scriptpubkey_local FROM channels WHERE state < ?;",
|
||||
.placeholders = 1,
|
||||
.readonly = true,
|
||||
},
|
||||
@ -1179,9 +1197,9 @@ struct db_query db_sqlite3_queries[] = {
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
.name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.query = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.placeholders = 33,
|
||||
.name = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.query = "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, option_static_remotekey=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=? WHERE id=?",
|
||||
.placeholders = 34,
|
||||
.readonly = false,
|
||||
},
|
||||
{
|
||||
@ -1624,10 +1642,10 @@ struct db_query db_sqlite3_queries[] = {
|
||||
},
|
||||
};
|
||||
|
||||
#define DB_SQLITE3_QUERY_COUNT 269
|
||||
#define DB_SQLITE3_QUERY_COUNT 272
|
||||
|
||||
#endif /* HAVE_SQLITE3 */
|
||||
|
||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||
|
||||
// SHA256STAMP:933e3d44cffab23c051a63163d4b24bcef044ad617ec3db040e6a92f9c55e0c6
|
||||
// SHA256STAMP:d9e28ea3b9764c7f3d5cc2bba2ac18493fc00bb42d13e94d0589824512aa1e01
|
||||
|
486
wallet/statements_gettextgen.po
generated
486
wallet/statements_gettextgen.po
generated
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,10 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const s
|
||||
#include <unistd.h>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for derive_channel_id */
|
||||
void derive_channel_id(struct channel_id *channel_id UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, u16 txout UNNEEDED)
|
||||
{ fprintf(stderr, "derive_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for fatal */
|
||||
void fatal(const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
||||
|
159
wallet/wallet.c
159
wallet/wallet.c
@ -937,6 +937,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||
bool ok = true;
|
||||
struct channel_info channel_info;
|
||||
struct short_channel_id *scid;
|
||||
struct channel_id cid;
|
||||
struct channel *chan;
|
||||
u64 peer_dbid;
|
||||
struct peer *peer;
|
||||
@ -971,15 +972,15 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||
scid = NULL;
|
||||
}
|
||||
|
||||
ok &= wallet_shachain_load(w, db_column_u64(stmt, 28), &wshachain);
|
||||
ok &= wallet_shachain_load(w, db_column_u64(stmt, 29), &wshachain);
|
||||
|
||||
remote_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 29, u8);
|
||||
local_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 48, u8);
|
||||
remote_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 30, u8);
|
||||
local_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 49, u8);
|
||||
|
||||
/* Do we have a last_sent_commit, if yes, populate */
|
||||
if (!db_column_is_null(stmt, 42)) {
|
||||
const u8 *cursor = db_column_blob(stmt, 42);
|
||||
size_t len = db_column_bytes(stmt, 42);
|
||||
if (!db_column_is_null(stmt, 43)) {
|
||||
const u8 *cursor = db_column_blob(stmt, 43);
|
||||
size_t len = db_column_bytes(stmt, 43);
|
||||
size_t n = 0;
|
||||
last_sent_commit = tal_arr(tmpctx, struct changed_htlc, n);
|
||||
while (len) {
|
||||
@ -991,41 +992,42 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||
last_sent_commit = NULL;
|
||||
|
||||
#ifdef COMPAT_V060
|
||||
if (!last_sent_commit && !db_column_is_null(stmt, 31)) {
|
||||
if (!last_sent_commit && !db_column_is_null(stmt, 32)) {
|
||||
last_sent_commit = tal(tmpctx, struct changed_htlc);
|
||||
last_sent_commit->newstate = db_column_u64(stmt, 31);
|
||||
last_sent_commit->id = db_column_u64(stmt, 32);
|
||||
last_sent_commit->newstate = db_column_u64(stmt, 32);
|
||||
last_sent_commit->id = db_column_u64(stmt, 33);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!db_column_is_null(stmt, 41)) {
|
||||
if (!db_column_is_null(stmt, 42)) {
|
||||
future_per_commitment_point = tal(tmpctx, struct pubkey);
|
||||
db_column_pubkey(stmt, 41, future_per_commitment_point);
|
||||
db_column_pubkey(stmt, 42, future_per_commitment_point);
|
||||
} else
|
||||
future_per_commitment_point = NULL;
|
||||
|
||||
channel_config_id = db_column_u64(stmt, 3);
|
||||
db_column_channel_id(stmt, 3, &cid);
|
||||
channel_config_id = db_column_u64(stmt, 4);
|
||||
ok &= wallet_channel_config_load(w, channel_config_id, &our_config);
|
||||
db_column_sha256d(stmt, 12, &funding_txid.shad);
|
||||
ok &= db_column_signature(stmt, 34, &last_sig.s);
|
||||
db_column_sha256d(stmt, 13, &funding_txid.shad);
|
||||
ok &= db_column_signature(stmt, 35, &last_sig.s);
|
||||
last_sig.sighash_type = SIGHASH_ALL;
|
||||
|
||||
/* Populate channel_info */
|
||||
db_column_pubkey(stmt, 19, &channel_info.remote_fundingkey);
|
||||
db_column_pubkey(stmt, 20, &channel_info.theirbase.revocation);
|
||||
db_column_pubkey(stmt, 21, &channel_info.theirbase.payment);
|
||||
db_column_pubkey(stmt, 22, &channel_info.theirbase.htlc);
|
||||
db_column_pubkey(stmt, 23, &channel_info.theirbase.delayed_payment);
|
||||
db_column_pubkey(stmt, 24, &channel_info.remote_per_commit);
|
||||
db_column_pubkey(stmt, 25, &channel_info.old_remote_per_commit);
|
||||
db_column_pubkey(stmt, 20, &channel_info.remote_fundingkey);
|
||||
db_column_pubkey(stmt, 21, &channel_info.theirbase.revocation);
|
||||
db_column_pubkey(stmt, 22, &channel_info.theirbase.payment);
|
||||
db_column_pubkey(stmt, 23, &channel_info.theirbase.htlc);
|
||||
db_column_pubkey(stmt, 24, &channel_info.theirbase.delayed_payment);
|
||||
db_column_pubkey(stmt, 25, &channel_info.remote_per_commit);
|
||||
db_column_pubkey(stmt, 26, &channel_info.old_remote_per_commit);
|
||||
|
||||
wallet_channel_config_load(w, db_column_u64(stmt, 4),
|
||||
wallet_channel_config_load(w, db_column_u64(stmt, 5),
|
||||
&channel_info.their_config);
|
||||
|
||||
channel_info.fee_states
|
||||
= wallet_channel_fee_states_load(w,
|
||||
db_column_u64(stmt, 0),
|
||||
db_column_int(stmt, 6));
|
||||
db_column_int(stmt, 7));
|
||||
if (!channel_info.fee_states)
|
||||
ok = false;
|
||||
|
||||
@ -1034,7 +1036,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||
return NULL;
|
||||
}
|
||||
|
||||
final_key_idx = db_column_u64(stmt, 30);
|
||||
final_key_idx = db_column_u64(stmt, 31);
|
||||
if (final_key_idx < 0) {
|
||||
log_broken(w->log, "%s: Final key < 0", __func__);
|
||||
return NULL;
|
||||
@ -1043,60 +1045,61 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||
get_channel_basepoints(w->ld, &peer->id, db_column_u64(stmt, 0),
|
||||
&local_basepoints, &local_funding_pubkey);
|
||||
|
||||
db_column_amount_sat(stmt, 14, &funding_sat);
|
||||
db_column_amount_sat(stmt, 15, &our_funding_sat);
|
||||
db_column_amount_msat(stmt, 17, &push_msat);
|
||||
db_column_amount_msat(stmt, 18, &our_msat);
|
||||
db_column_amount_msat(stmt, 39, &msat_to_us_min);
|
||||
db_column_amount_msat(stmt, 40, &msat_to_us_max);
|
||||
db_column_amount_sat(stmt, 15, &funding_sat);
|
||||
db_column_amount_sat(stmt, 16, &our_funding_sat);
|
||||
db_column_amount_msat(stmt, 18, &push_msat);
|
||||
db_column_amount_msat(stmt, 19, &our_msat);
|
||||
db_column_amount_msat(stmt, 40, &msat_to_us_min);
|
||||
db_column_amount_msat(stmt, 41, &msat_to_us_max);
|
||||
|
||||
/* We want it to take this, rather than copy. */
|
||||
take(channel_info.fee_states);
|
||||
chan = new_channel(peer, db_column_u64(stmt, 0),
|
||||
&wshachain,
|
||||
db_column_int(stmt, 5),
|
||||
db_column_int(stmt, 6),
|
||||
db_column_int(stmt, 7),
|
||||
NULL, /* Set up fresh log */
|
||||
"Loaded from database",
|
||||
db_column_int(stmt, 7),
|
||||
&our_config,
|
||||
db_column_int(stmt, 8),
|
||||
db_column_u64(stmt, 9),
|
||||
&our_config,
|
||||
db_column_int(stmt, 9),
|
||||
db_column_u64(stmt, 10),
|
||||
db_column_u64(stmt, 11),
|
||||
db_column_u64(stmt, 12),
|
||||
&funding_txid,
|
||||
db_column_int(stmt, 13),
|
||||
db_column_int(stmt, 14),
|
||||
funding_sat,
|
||||
push_msat,
|
||||
our_funding_sat,
|
||||
db_column_int(stmt, 16) != 0,
|
||||
db_column_int(stmt, 17) != 0,
|
||||
scid,
|
||||
&cid,
|
||||
our_msat,
|
||||
msat_to_us_min, /* msatoshi_to_us_min */
|
||||
msat_to_us_max, /* msatoshi_to_us_max */
|
||||
db_column_psbt_to_tx(tmpctx, stmt, 33),
|
||||
db_column_psbt_to_tx(tmpctx, stmt, 34),
|
||||
&last_sig,
|
||||
wallet_htlc_sigs_load(tmpctx, w,
|
||||
db_column_u64(stmt, 0),
|
||||
db_column_int(stmt, 47)),
|
||||
db_column_int(stmt, 48)),
|
||||
&channel_info,
|
||||
remote_shutdown_scriptpubkey,
|
||||
local_shutdown_scriptpubkey,
|
||||
final_key_idx,
|
||||
db_column_int(stmt, 35) != 0,
|
||||
db_column_int(stmt, 36) != 0,
|
||||
last_sent_commit,
|
||||
db_column_u64(stmt, 36),
|
||||
db_column_int(stmt, 37),
|
||||
db_column_u64(stmt, 37),
|
||||
db_column_int(stmt, 38),
|
||||
db_column_int(stmt, 39),
|
||||
/* Not connected */
|
||||
false,
|
||||
&local_basepoints, &local_funding_pubkey,
|
||||
future_per_commitment_point,
|
||||
db_column_int(stmt, 43),
|
||||
db_column_int(stmt, 44),
|
||||
db_column_arr(tmpctx, stmt, 45, u8),
|
||||
db_column_int(stmt, 46),
|
||||
db_column_int(stmt, 47));
|
||||
db_column_int(stmt, 45),
|
||||
db_column_arr(tmpctx, stmt, 46, u8),
|
||||
db_column_int(stmt, 47),
|
||||
db_column_int(stmt, 48));
|
||||
|
||||
return chan;
|
||||
}
|
||||
@ -1126,6 +1129,7 @@ static bool wallet_channels_load_active(struct wallet *w)
|
||||
" id"
|
||||
", peer_id"
|
||||
", short_channel_id"
|
||||
", full_channel_id"
|
||||
", channel_config_local"
|
||||
", channel_config_remote"
|
||||
", state"
|
||||
@ -1149,7 +1153,6 @@ static bool wallet_channels_load_active(struct wallet *w)
|
||||
", delayed_payment_basepoint_remote"
|
||||
", per_commit_remote"
|
||||
", old_per_commit_remote"
|
||||
/* FIXME: We don't use these two: */
|
||||
", local_feerate_per_kw"
|
||||
", remote_feerate_per_kw"
|
||||
", shachain_remote_id"
|
||||
@ -1410,6 +1413,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
|
||||
stmt = db_prepare_v2(w->db, SQL("UPDATE channels SET"
|
||||
" shachain_remote_id=?,"
|
||||
" short_channel_id=?,"
|
||||
" full_channel_id=?,"
|
||||
" state=?,"
|
||||
" funder=?,"
|
||||
" channel_flags=?,"
|
||||
@ -1445,42 +1449,43 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
|
||||
db_bind_short_channel_id(stmt, 1, chan->scid);
|
||||
else
|
||||
db_bind_null(stmt, 1);
|
||||
db_bind_int(stmt, 2, chan->state);
|
||||
db_bind_int(stmt, 3, chan->opener);
|
||||
db_bind_int(stmt, 4, chan->channel_flags);
|
||||
db_bind_int(stmt, 5, chan->minimum_depth);
|
||||
|
||||
db_bind_u64(stmt, 6, chan->next_index[LOCAL]);
|
||||
db_bind_u64(stmt, 7, chan->next_index[REMOTE]);
|
||||
db_bind_u64(stmt, 8, chan->next_htlc_id);
|
||||
db_bind_channel_id(stmt, 2, &chan->cid);
|
||||
db_bind_int(stmt, 3, chan->state);
|
||||
db_bind_int(stmt, 4, chan->opener);
|
||||
db_bind_int(stmt, 5, chan->channel_flags);
|
||||
db_bind_int(stmt, 6, chan->minimum_depth);
|
||||
|
||||
db_bind_sha256d(stmt, 9, &chan->funding_txid.shad);
|
||||
db_bind_u64(stmt, 7, chan->next_index[LOCAL]);
|
||||
db_bind_u64(stmt, 8, chan->next_index[REMOTE]);
|
||||
db_bind_u64(stmt, 9, chan->next_htlc_id);
|
||||
|
||||
db_bind_int(stmt, 10, chan->funding_outnum);
|
||||
db_bind_amount_sat(stmt, 11, &chan->funding);
|
||||
db_bind_amount_sat(stmt, 12, &chan->our_funds);
|
||||
db_bind_int(stmt, 13, chan->remote_funding_locked);
|
||||
db_bind_amount_msat(stmt, 14, &chan->push);
|
||||
db_bind_amount_msat(stmt, 15, &chan->our_msat);
|
||||
db_bind_sha256d(stmt, 10, &chan->funding_txid.shad);
|
||||
|
||||
db_bind_talarr(stmt, 16, chan->shutdown_scriptpubkey[REMOTE]);
|
||||
db_bind_int(stmt, 11, chan->funding_outnum);
|
||||
db_bind_amount_sat(stmt, 12, &chan->funding);
|
||||
db_bind_amount_sat(stmt, 13, &chan->our_funds);
|
||||
db_bind_int(stmt, 14, chan->remote_funding_locked);
|
||||
db_bind_amount_msat(stmt, 15, &chan->push);
|
||||
db_bind_amount_msat(stmt, 16, &chan->our_msat);
|
||||
|
||||
db_bind_u64(stmt, 17, chan->final_key_idx);
|
||||
db_bind_u64(stmt, 18, chan->our_config.id);
|
||||
db_bind_psbt(stmt, 19, chan->last_tx->psbt);
|
||||
db_bind_signature(stmt, 20, &chan->last_sig.s);
|
||||
db_bind_int(stmt, 21, chan->last_was_revoke);
|
||||
db_bind_int(stmt, 22, chan->min_possible_feerate);
|
||||
db_bind_int(stmt, 23, chan->max_possible_feerate);
|
||||
db_bind_amount_msat(stmt, 24, &chan->msat_to_us_min);
|
||||
db_bind_amount_msat(stmt, 25, &chan->msat_to_us_max);
|
||||
db_bind_int(stmt, 26, chan->feerate_base);
|
||||
db_bind_int(stmt, 27, chan->feerate_ppm);
|
||||
db_bind_talarr(stmt, 28, chan->remote_upfront_shutdown_script);
|
||||
db_bind_int(stmt, 29, chan->option_static_remotekey);
|
||||
db_bind_int(stmt, 30, chan->option_anchor_outputs);
|
||||
db_bind_talarr(stmt, 31, chan->shutdown_scriptpubkey[LOCAL]);
|
||||
db_bind_u64(stmt, 32, chan->dbid);
|
||||
db_bind_talarr(stmt, 17, chan->shutdown_scriptpubkey[REMOTE]);
|
||||
db_bind_u64(stmt, 18, chan->final_key_idx);
|
||||
db_bind_u64(stmt, 19, chan->our_config.id);
|
||||
db_bind_psbt(stmt, 20, chan->last_tx->psbt);
|
||||
db_bind_signature(stmt, 21, &chan->last_sig.s);
|
||||
db_bind_int(stmt, 22, chan->last_was_revoke);
|
||||
db_bind_int(stmt, 23, chan->min_possible_feerate);
|
||||
db_bind_int(stmt, 24, chan->max_possible_feerate);
|
||||
db_bind_amount_msat(stmt, 25, &chan->msat_to_us_min);
|
||||
db_bind_amount_msat(stmt, 26, &chan->msat_to_us_max);
|
||||
db_bind_int(stmt, 27, chan->feerate_base);
|
||||
db_bind_int(stmt, 28, chan->feerate_ppm);
|
||||
db_bind_talarr(stmt, 29, chan->remote_upfront_shutdown_script);
|
||||
db_bind_int(stmt, 30, chan->option_static_remotekey);
|
||||
db_bind_int(stmt, 31, chan->option_anchor_outputs);
|
||||
db_bind_talarr(stmt, 32, chan->shutdown_scriptpubkey[LOCAL]);
|
||||
db_bind_u64(stmt, 33, chan->dbid);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
|
||||
wallet_channel_config_save(w, &chan->channel_info.their_config);
|
||||
|
Loading…
Reference in New Issue
Block a user