mfc: add convenience method for determining 'parity'
is_v2 instead of protocol == OPEN_CHANNEL
This commit is contained in:
parent
bec96a6c5b
commit
822441558c
|
@ -68,6 +68,11 @@ static bool dest_failed(struct multifundchannel_destination *dest)
|
||||||
return dest->state == MULTIFUNDCHANNEL_FAILED;
|
return dest->state == MULTIFUNDCHANNEL_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_v2(const struct multifundchannel_destination *dest)
|
||||||
|
{
|
||||||
|
return dest->protocol == OPEN_CHANNEL;
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
Command Cleanup
|
Command Cleanup
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
@ -501,7 +506,7 @@ after_signpsbt(struct command *cmd,
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
|
|
||||||
/* Check that every dest is in the right state */
|
/* Check that every dest is in the right state */
|
||||||
expected_state = dest->protocol == OPEN_CHANNEL ?
|
expected_state = is_v2(dest) ?
|
||||||
MULTIFUNDCHANNEL_SIGNED : MULTIFUNDCHANNEL_COMPLETED;
|
MULTIFUNDCHANNEL_SIGNED : MULTIFUNDCHANNEL_COMPLETED;
|
||||||
assert(dest->state == expected_state);
|
assert(dest->state == expected_state);
|
||||||
|
|
||||||
|
@ -571,7 +576,7 @@ after_fundchannel_complete(struct multifundchannel_command *mfc)
|
||||||
struct multifundchannel_destination *dest;
|
struct multifundchannel_destination *dest;
|
||||||
|
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
if (dest->protocol != FUND_CHANNEL)
|
if (is_v2(dest))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED
|
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED
|
||||||
|
@ -703,7 +708,7 @@ perform_fundchannel_complete(struct multifundchannel_command *mfc)
|
||||||
mfc->pending = dest_count(mfc, FUND_CHANNEL);
|
mfc->pending = dest_count(mfc, FUND_CHANNEL);
|
||||||
|
|
||||||
for (i = 0; i < tal_count(mfc->destinations); ++i) {
|
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]);
|
fundchannel_complete_dest(&mfc->destinations[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +746,7 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
|
||||||
|
|
||||||
deck_i = 0;
|
deck_i = 0;
|
||||||
for (i = 0; i < tal_count(mfc->destinations); i++) {
|
for (i = 0; i < tal_count(mfc->destinations); i++) {
|
||||||
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
|
if (is_v2(&mfc->destinations[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
assert(deck_i < tal_count(deck));
|
assert(deck_i < tal_count(deck));
|
||||||
|
@ -878,7 +883,7 @@ after_channel_start(struct multifundchannel_command *mfc)
|
||||||
|
|
||||||
/* One of them failed, oh no. */
|
/* One of them failed, oh no. */
|
||||||
return redo_multifundchannel(mfc,
|
return redo_multifundchannel(mfc,
|
||||||
dest->protocol == OPEN_CHANNEL ?
|
is_v2(dest) ?
|
||||||
"openchannel_init" :
|
"openchannel_init" :
|
||||||
"fundchannel_start");
|
"fundchannel_start");
|
||||||
}
|
}
|
||||||
|
@ -1056,7 +1061,7 @@ perform_channel_start(struct multifundchannel_command *mfc)
|
||||||
/* Since v2 is now available, we branch depending
|
/* Since v2 is now available, we branch depending
|
||||||
* on the capability of the peer and our feaures */
|
* on the capability of the peer and our feaures */
|
||||||
for (i = 0; i < tal_count(mfc->destinations); ++i) {
|
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]);
|
openchannel_init_dest(&mfc->destinations[i]);
|
||||||
else
|
else
|
||||||
fundchannel_start_dest(&mfc->destinations[i]);
|
fundchannel_start_dest(&mfc->destinations[i]);
|
||||||
|
|
|
@ -249,6 +249,9 @@ void fail_destination(struct multifundchannel_destination *dest,
|
||||||
size_t dest_count(const struct multifundchannel_command *mfc,
|
size_t dest_count(const struct multifundchannel_command *mfc,
|
||||||
enum channel_protocol);
|
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. */
|
/* Use this instead of command_finished. */
|
||||||
struct command_result *
|
struct command_result *
|
||||||
mfc_finished(struct multifundchannel_command *, struct json_stream *response);
|
mfc_finished(struct multifundchannel_command *, struct json_stream *response);
|
||||||
|
|
|
@ -470,7 +470,7 @@ perform_openchannel_signed(struct multifundchannel_command *mfc)
|
||||||
|
|
||||||
mfc->pending = dest_count(mfc, OPEN_CHANNEL);
|
mfc->pending = dest_count(mfc, OPEN_CHANNEL);
|
||||||
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
|
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;
|
continue;
|
||||||
/* We need to 'port' all of the sigs down to the
|
/* We need to 'port' all of the sigs down to the
|
||||||
* destination PSBTs */
|
* destination PSBTs */
|
||||||
|
@ -501,7 +501,7 @@ collect_sigs(struct multifundchannel_command *mfc)
|
||||||
struct bitcoin_txid dest_txid;
|
struct bitcoin_txid dest_txid;
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
|
|
||||||
if (dest->protocol == FUND_CHANNEL) {
|
if (!is_v2(dest)) {
|
||||||
/* Since we're here, double check that
|
/* Since we're here, double check that
|
||||||
* every v1 has their commitment txs */
|
* every v1 has their commitment txs */
|
||||||
assert(dest->state == MULTIFUNDCHANNEL_COMPLETED);
|
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++) {
|
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
|
||||||
enum multifundchannel_state state =
|
enum multifundchannel_state state =
|
||||||
mfc->destinations[i].protocol == OPEN_CHANNEL ?
|
is_v2(&mfc->destinations[i]) ?
|
||||||
MULTIFUNDCHANNEL_SIGNED :
|
MULTIFUNDCHANNEL_SIGNED :
|
||||||
MULTIFUNDCHANNEL_COMPLETED;
|
MULTIFUNDCHANNEL_COMPLETED;
|
||||||
|
|
||||||
|
@ -631,7 +631,7 @@ funding_transaction_established(struct multifundchannel_command *mfc)
|
||||||
* funding transaction */
|
* funding transaction */
|
||||||
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
|
for (size_t i = 0; i < tal_count(mfc->destinations); i++) {
|
||||||
struct multifundchannel_destination *dest;
|
struct multifundchannel_destination *dest;
|
||||||
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
|
if (is_v2(&mfc->destinations[i]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
|
@ -839,7 +839,7 @@ perform_openchannel_update(struct multifundchannel_command *mfc)
|
||||||
struct multifundchannel_destination *dest;
|
struct multifundchannel_destination *dest;
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
|
|
||||||
if (dest->protocol == FUND_CHANNEL)
|
if (!is_v2(dest))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!update_parent_psbt(mfc, dest, dest->psbt,
|
if (!update_parent_psbt(mfc, dest, dest->psbt,
|
||||||
|
@ -865,7 +865,7 @@ perform_openchannel_update(struct multifundchannel_command *mfc)
|
||||||
dest = &mfc->destinations[i];
|
dest = &mfc->destinations[i];
|
||||||
|
|
||||||
/* We don't *have* psbts for v1 destinations */
|
/* We don't *have* psbts for v1 destinations */
|
||||||
if (dest->protocol == FUND_CHANNEL)
|
if (!is_v2(dest))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!update_node_psbt(mfc, mfc->psbt, &dest->psbt)) {
|
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);
|
mfc->pending = dest_count(mfc, OPEN_CHANNEL);
|
||||||
for (i = 0; i < tal_count(mfc->destinations); i++) {
|
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]);
|
openchannel_update_dest(&mfc->destinations[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue