mfc: add convenience method for determining 'parity'

is_v2 instead of protocol == OPEN_CHANNEL
This commit is contained in:
niftynei 2021-03-10 20:20:21 -06:00 committed by Rusty Russell
parent bec96a6c5b
commit 822441558c
3 changed files with 21 additions and 13 deletions

View File

@ -68,6 +68,11 @@ static bool dest_failed(struct multifundchannel_destination *dest)
return dest->state == MULTIFUNDCHANNEL_FAILED;
}
bool is_v2(const struct multifundchannel_destination *dest)
{
return dest->protocol == OPEN_CHANNEL;
}
/*-----------------------------------------------------------------------------
Command Cleanup
-----------------------------------------------------------------------------*/
@ -501,7 +506,7 @@ after_signpsbt(struct command *cmd,
dest = &mfc->destinations[i];
/* Check that every dest is in the right state */
expected_state = dest->protocol == OPEN_CHANNEL ?
expected_state = is_v2(dest) ?
MULTIFUNDCHANNEL_SIGNED : MULTIFUNDCHANNEL_COMPLETED;
assert(dest->state == expected_state);
@ -571,7 +576,7 @@ after_fundchannel_complete(struct multifundchannel_command *mfc)
struct multifundchannel_destination *dest;
dest = &mfc->destinations[i];
if (dest->protocol != FUND_CHANNEL)
if (is_v2(dest))
continue;
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED
@ -703,7 +708,7 @@ perform_fundchannel_complete(struct multifundchannel_command *mfc)
mfc->pending = dest_count(mfc, FUND_CHANNEL);
for (i = 0; i < tal_count(mfc->destinations); ++i) {
if (mfc->destinations[i].protocol == FUND_CHANNEL)
if (!is_v2(&mfc->destinations[i]))
fundchannel_complete_dest(&mfc->destinations[i]);
}
@ -741,7 +746,7 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
deck_i = 0;
for (i = 0; i < tal_count(mfc->destinations); i++) {
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
if (is_v2(&mfc->destinations[i]))
continue;
assert(deck_i < tal_count(deck));
@ -878,7 +883,7 @@ after_channel_start(struct multifundchannel_command *mfc)
/* One of them failed, oh no. */
return redo_multifundchannel(mfc,
dest->protocol == OPEN_CHANNEL ?
is_v2(dest) ?
"openchannel_init" :
"fundchannel_start");
}
@ -1056,7 +1061,7 @@ perform_channel_start(struct multifundchannel_command *mfc)
/* Since v2 is now available, we branch depending
* on the capability of the peer and our feaures */
for (i = 0; i < tal_count(mfc->destinations); ++i) {
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
if (is_v2(&mfc->destinations[i]))
openchannel_init_dest(&mfc->destinations[i]);
else
fundchannel_start_dest(&mfc->destinations[i]);

View File

@ -249,6 +249,9 @@ void fail_destination(struct multifundchannel_destination *dest,
size_t dest_count(const struct multifundchannel_command *mfc,
enum channel_protocol);
/* Is this destination using the v2/OPEN_CHANNEL protocol? */
bool is_v2(const struct multifundchannel_destination *dest);
/* Use this instead of command_finished. */
struct command_result *
mfc_finished(struct multifundchannel_command *, struct json_stream *response);

View File

@ -470,7 +470,7 @@ perform_openchannel_signed(struct multifundchannel_command *mfc)
mfc->pending = dest_count(mfc, OPEN_CHANNEL);
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
if (mfc->destinations[i].protocol == FUND_CHANNEL)
if (!is_v2(&mfc->destinations[i]))
continue;
/* We need to 'port' all of the sigs down to the
* destination PSBTs */
@ -501,7 +501,7 @@ collect_sigs(struct multifundchannel_command *mfc)
struct bitcoin_txid dest_txid;
dest = &mfc->destinations[i];
if (dest->protocol == FUND_CHANNEL) {
if (!is_v2(dest)) {
/* Since we're here, double check that
* every v1 has their commitment txs */
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED);
@ -525,7 +525,7 @@ check_sigs_ready(struct multifundchannel_command *mfc)
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
enum multifundchannel_state state =
mfc->destinations[i].protocol == OPEN_CHANNEL ?
is_v2(&mfc->destinations[i]) ?
MULTIFUNDCHANNEL_SIGNED :
MULTIFUNDCHANNEL_COMPLETED;
@ -631,7 +631,7 @@ funding_transaction_established(struct multifundchannel_command *mfc)
* funding transaction */
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
struct multifundchannel_destination *dest;
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
if (is_v2(&mfc->destinations[i]))
continue;
dest = &mfc->destinations[i];
@ -839,7 +839,7 @@ perform_openchannel_update(struct multifundchannel_command *mfc)
struct multifundchannel_destination *dest;
dest = &mfc->destinations[i];
if (dest->protocol == FUND_CHANNEL)
if (!is_v2(dest))
continue;
if (!update_parent_psbt(mfc, dest, dest->psbt,
@ -865,7 +865,7 @@ perform_openchannel_update(struct multifundchannel_command *mfc)
dest = &mfc->destinations[i];
/* We don't *have* psbts for v1 destinations */
if (dest->protocol == FUND_CHANNEL)
if (!is_v2(dest))
continue;
if (!update_node_psbt(mfc, mfc->psbt, &dest->psbt)) {
@ -878,7 +878,7 @@ perform_openchannel_update(struct multifundchannel_command *mfc)
mfc->pending = dest_count(mfc, OPEN_CHANNEL);
for (i = 0; i < tal_count(mfc->destinations); i++) {
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
if (is_v2(&mfc->destinations[i]))
openchannel_update_dest(&mfc->destinations[i]);
}