Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ec51067
walletrpc: free utx on unsuccessful broadcast
niftynei Oct 8, 2019
4938ac6
amount: helper method for adding sats to an msat amount
niftynei Sep 19, 2019
3023050
df: rename 'funder' to 'opener'
niftynei Sep 9, 2019
1e50e27
df: add wires for dual funding messages
niftynei Sep 10, 2019
64443ac
df: add truncation check for wire messages
niftynei Sep 13, 2019
b8e6154
df: pipe through whether or not we're using v2
niftynei Sep 13, 2019
903ebdb
df: switch from funding -> opener_funding and wire in v2 calls
niftynei Sep 13, 2019
b2970dc
df: stash 'is_v2' into fundchannel object
niftynei Sep 13, 2019
b74767b
df: lookup transaction for the fundchannel_complete
niftynei Sep 13, 2019
c0f2828
hsmd: pull up utxo signing
niftynei Sep 17, 2019
6a8eb06
withdraw: refactor change output handling
niftynei Sep 17, 2019
f2467f1
withdraw: add ability to have additional inputs on a tx
niftynei Sep 17, 2019
eafbeb9
walletrpc: break out output extraction code
niftynei Sep 17, 2019
b3c5438
funding: add method for building a dual-funded tx
niftynei Sep 19, 2019
0755cfa
opening: update wallet_commit_channel for df
niftynei Sep 19, 2019
0b6e099
funding: pass utxos through to openingd
niftynei Sep 19, 2019
b1873a8
dual-funding: wire up opener side of dual funding
niftynei Sep 19, 2019
1c5823f
fundchannel_complete: return 'txid' and 'remote signed' tx
niftynei Sep 19, 2019
974967d
df: wire in feature flag
niftynei Sep 19, 2019
db17094
utxos: pass through the scriptpubkey
niftynei Sep 23, 2019
38ed050
txprepare: zero out change if asked
niftynei Sep 30, 2019
d24a7c7
zero_out_change: add to pylightning
niftynei Oct 8, 2019
9409550
wire: add dual-funding subtypes to list
niftynei Sep 30, 2019
8c0942f
wallet-df: save our_funds amount to channel record
niftynei Sep 30, 2019
6602fa7
utxo: add scriptSig field
niftynei Sep 30, 2019
0ed1635
channeld: add flag for whether channel has our funds
niftynei Sep 30, 2019
e99893d
df: pass opener's change through so we can update utx
niftynei Sep 30, 2019
bd55d30
hsmd: add method for signing dual funded txs
niftynei Sep 30, 2019
b776158
hsmd: allow openingd to call hsm to sign dual-funded tx
niftynei Sep 30, 2019
c6874ab
wallet: method to compute available funds for df
niftynei Sep 30, 2019
83becfc
fundchannel: update to work with dual funding
niftynei Sep 30, 2019
a35d298
listpeers: show funding_allocation for df'd channels
niftynei Sep 30, 2019
cb4f0bc
df-accepter: pass v2 info back to opening_control
niftynei Sep 30, 2019
37b6fe1
df-accepter: if payload is v2, calculate available funds
niftynei Sep 30, 2019
df57686
fundchannel_start: include version of open protocol
niftynei Sep 30, 2019
b5f4c78
df-accepter: accepter logic
niftynei Sep 30, 2019
d6c8317
openchannel: add dual-funding fields to hook
niftynei Sep 30, 2019
c63b5bf
plugins: add documentation for openchannel v2 fields
niftynei Oct 10, 2019
451748d
fixup b5f4c789cb
niftynei Oct 10, 2019
5a66dc4
fixup! f2467f127d
niftynei Oct 10, 2019
0bf122f
fixup! df-accepter: if payload is v2, calculate available funds
niftynei Oct 10, 2019
5f5a3a5
fixup! funding: pass utxos through to openingd
niftynei Oct 10, 2019
9b8d540
fixup! df: lookup transaction for the fundchannel_complete
niftynei Oct 10, 2019
5d72838
fixup! df: pipe through whether or not we're using v2
niftynei Oct 10, 2019
0e88f38
fixup! fundchannel: update to work with dual funding
niftynei Oct 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- JSON API: `fundchannel_start` now includes field `scriptpubkey`
- JSON API: `txprepare` and `withdraw` now accept an optional parameter `utxos`, a list of utxos to include in the prepared transaction
- JSON_API: `close` now accepts an optional parameter `destination`, to which the to-local output will be sent.
- JSON API: `txprepare` includes a parameter `zero_out_change`, which if true leaves the change value as zero. Useful for designating change output for dual-funded transactions. Defaults to false.
- JSON API: `fundchannel_start` now includes `open_channel_version`, a string which indicates
the protocol version used to open the channel.
- Plugin: `openchannel` hook includes fields for v2 channel establishment

- bolt11: support for parsing feature bits (field `9`).

Expand Down
10 changes: 10 additions & 0 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

#define SEGREGATED_WITNESS_FLAG 0x1

struct bitcoin_tx_output *new_tx_output(const tal_t *ctx,
struct amount_sat amount,
const u8 *script)
{
struct bitcoin_tx_output *output = tal(ctx, struct bitcoin_tx_output);
output->amount = amount;
output->script = tal_dup_arr(output, u8, script, tal_count(script), 0);
return output;
}

int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script,
struct amount_sat amount)
{
Expand Down
8 changes: 7 additions & 1 deletion bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ struct bitcoin_tx_input {
u8 *script;
u32 sequence_number;

/* Only if BIP141 used. */
/* If BIP141 used, or is external input */
u8 **witness;

/* Needed for external inputs */
struct amount_sat amount;
};

struct bitcoin_tx_output *new_tx_output(const tal_t *ctx,
struct amount_sat amount,
const u8 *script);

/* SHA256^2 the tx: simpler than sha256_tx */
void bitcoin_txid(const struct bitcoin_tx *tx, struct bitcoin_txid *txid);
Expand Down
3 changes: 2 additions & 1 deletion channeld/channel_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ msgdata,channel_init,remote_fundingkey,pubkey,
msgdata,channel_init,remote_basepoints,basepoints,
msgdata,channel_init,remote_per_commit,pubkey,
msgdata,channel_init,old_remote_per_commit,pubkey,
msgdata,channel_init,funder,enum side,
msgdata,channel_init,opener,enum side,
msgdata,channel_init,local_funded,bool,
msgdata,channel_init,fee_base,u32,
msgdata,channel_init,fee_proportional,u32,
msgdata,channel_init,local_msatoshi,amount_msat,
Expand Down
50 changes: 30 additions & 20 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* - if the sender is not responsible for paying the Bitcoin fee:
* - MUST fail the channel.
*/
if (peer->channel->funder != REMOTE)
if (peer->channel->opener != REMOTE)
peer_failed(peer->pps,
&peer->channel_id,
"update_fee from non-funder?");
"update_fee from non-opener?");

status_debug("update_fee %u, range %u-%u",
feerate, peer->feerate_min, peer->feerate_max);
Expand Down Expand Up @@ -1128,7 +1128,7 @@ static void send_commit(struct peer *peer)
}

/* If we wanted to update fees, do it now. */
if (peer->channel->funder == LOCAL) {
if (peer->channel->opener == LOCAL) {
u32 feerate, max = approx_max_feerate(peer->channel);

feerate = peer->desired_feerate;
Expand Down Expand Up @@ -1386,11 +1386,11 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
}

/* We were supposed to check this was affordable as we go. */
if (peer->channel->funder == REMOTE) {
if (peer->channel->opener == REMOTE) {
status_debug("Feerates are %u/%u",
peer->channel->view[LOCAL].feerate_per_kw,
peer->channel->view[REMOTE].feerate_per_kw);
assert(can_funder_afford_feerate(peer->channel,
assert(can_opener_afford_feerate(peer->channel,
peer->channel->view[LOCAL]
.feerate_per_kw));
}
Expand Down Expand Up @@ -1584,7 +1584,7 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
peer->old_remote_per_commit = peer->remote_per_commit;
peer->remote_per_commit = next_per_commit;
status_debug("revoke_and_ack %s: remote_per_commit = %s, old_remote_per_commit = %s",
side_to_str(peer->channel->funder),
side_to_str(peer->channel->opener),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey,
Expand Down Expand Up @@ -1863,6 +1863,14 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_FUNDING_SIGNED:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_CLOSING_SIGNED:
#if EXPERIMENTAL_FEATURES
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_FUNDING_COMPOSE:
case WIRE_ACCEPTER_SIGS:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
#endif /* EXPERIMENTAL_FEATURES */
break;

/* These are all swallowed by handle_peer_gossip_or_error */
Expand Down Expand Up @@ -1992,7 +2000,7 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
}

/* Make sure they have the correct fee. */
if (peer->channel->funder == LOCAL) {
if (peer->channel->opener == LOCAL) {
msg = towire_update_fee(NULL, &peer->channel_id,
channel_feerate(peer->channel, REMOTE));
sync_crypto_write(peer->pps, take(msg));
Expand Down Expand Up @@ -2519,7 +2527,7 @@ static void peer_reconnect(struct peer *peer,
* even tell by seeing if fees are different (short of saving full fee
* state in database) since it could be a tiny feechange, or two
* feechanges which cancelled out. */
if (peer->channel->funder == LOCAL)
if (peer->channel->opener == LOCAL)
peer->channel->changes_pending[LOCAL] = true;

peer_billboard(true, "Reconnected, and reestablished.");
Expand Down Expand Up @@ -2687,7 +2695,7 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
* sufficient (by a significant margin) for timely processing of the
* commitment transaction.
*/
if (peer->channel->funder == LOCAL) {
if (peer->channel->opener == LOCAL) {
peer->desired_feerate = feerate;
start_commit_timer(peer);
} else {
Expand Down Expand Up @@ -2928,22 +2936,22 @@ static void init_channel(struct peer *peer)
struct pubkey funding_pubkey[NUM_SIDES];
struct channel_config conf[NUM_SIDES];
struct bitcoin_txid funding_txid;
enum side funder;
enum side opener;
enum htlc_state *hstates;
struct fulfilled_htlc *fulfilled;
enum side *fulfilled_sides;
struct failed_htlc **failed;
enum side *failed_sides;
struct added_htlc *htlcs;
bool reconnected;
u8 *funding_signed;
u8 *sigs_msg;
const u8 *msg;
u32 feerate_per_kw[NUM_SIDES];
u32 minimum_depth, failheight;
struct secret last_remote_per_commit_secret;
secp256k1_ecdsa_signature *remote_ann_node_sig;
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig;
bool option_static_remotekey;
bool option_static_remotekey, local_funded;

assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK));

Expand All @@ -2964,7 +2972,8 @@ static void init_channel(struct peer *peer)
&points[REMOTE],
&peer->remote_per_commit,
&peer->old_remote_per_commit,
&funder,
&opener,
&local_funded,
&peer->fee_base,
&peer->fee_per_satoshi,
&local_msat,
Expand Down Expand Up @@ -2995,7 +3004,7 @@ static void init_channel(struct peer *peer)
&peer->shutdown_sent[REMOTE],
&peer->final_scriptpubkey,
&peer->channel_flags,
&funding_signed,
&sigs_msg,
&peer->announce_depth_reached,
&last_remote_per_commit_secret,
&peer->localfeatures,
Expand All @@ -3015,7 +3024,7 @@ static void init_channel(struct peer *peer)
" next_idx_remote = %"PRIu64
" revocations_received = %"PRIu64
" feerates %u/%u (range %u-%u)",
side_to_str(funder),
side_to_str(opener),
type_to_string(tmpctx, struct pubkey,
&peer->remote_per_commit),
type_to_string(tmpctx, struct pubkey,
Expand Down Expand Up @@ -3063,7 +3072,8 @@ static void init_channel(struct peer *peer)
&funding_pubkey[LOCAL],
&funding_pubkey[REMOTE],
option_static_remotekey,
funder);
local_funded,
opener);

if (!channel_force_htlcs(peer->channel, htlcs, hstates,
fulfilled, fulfilled_sides,
Expand Down Expand Up @@ -3091,7 +3101,7 @@ static void init_channel(struct peer *peer)
&peer->node_ids[REMOTE]);

/* Default desired feerate is the feerate we set for them last. */
if (peer->channel->funder == LOCAL)
if (peer->channel->opener == LOCAL)
peer->desired_feerate = feerate_per_kw[REMOTE];

/* from now we need keep watch over WIRE_CHANNEL_FUNDING_DEPTH */
Expand All @@ -3101,9 +3111,9 @@ static void init_channel(struct peer *peer)
if (reconnected)
peer_reconnect(peer, &last_remote_per_commit_secret);

/* If we have a funding_signed message, send that immediately */
if (funding_signed)
sync_crypto_write(peer->pps, take(funding_signed));
/* If we have a final sigs message, send that immediately */
if (sigs_msg)
sync_crypto_write(peer->pps, take(sigs_msg));

/* Reenable channel */
channel_announcement_negotiate(peer);
Expand Down
4 changes: 2 additions & 2 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid,
unsigned int funding_txout,
struct amount_sat funding,
enum side funder,
enum side opener,
u16 to_self_delay,
const struct keyset *keyset,
u32 feerate_per_kw,
Expand Down Expand Up @@ -126,7 +126,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
* 3. Subtract this base fee from the funder (either `to_local` or
* `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)).
*/
try_subtract_fee(funder, side, base_fee, &self_pay, &other_pay);
try_subtract_fee(opener, side, base_fee, &self_pay, &other_pay);

#ifdef PRINT_ACTUAL_FEE
{
Expand Down
4 changes: 2 additions & 2 deletions channeld/commit_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
* commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from.
* @funding_txid, @funding_out, @funding: funding outpoint.
* @funder: is the LOCAL or REMOTE paying the fee?
* @opener: is the LOCAL or REMOTE paying the fee?
* @keyset: keys derived for this commit tx.
* @feerate_per_kw: feerate to use
* @dust_limit: dust limit below which to trim outputs.
Expand All @@ -48,7 +48,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
const struct bitcoin_txid *funding_txid,
unsigned int funding_txout,
struct amount_sat funding,
enum side funder,
enum side opener,
u16 to_self_delay,
const struct keyset *keyset,
u32 feerate_per_kw,
Expand Down
Loading