mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
mfc: add a 'fail_destination' helper
Caches state at which we failed + sets error
This commit is contained in:
@@ -564,9 +564,7 @@ connect_err(struct command *cmd,
|
|||||||
json_tok_full_len(code_tok),
|
json_tok_full_len(code_tok),
|
||||||
json_tok_full(buf, code_tok));
|
json_tok_full(buf, code_tok));
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_CONNECT_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(mfc, buf, error);
|
|
||||||
|
|
||||||
return connect_done(dest);
|
return connect_done(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1110,9 +1108,7 @@ fundchannel_start_err(struct command *cmd,
|
|||||||
completed, we can then fail.
|
completed, we can then fail.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_START_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(dest->mfc, buf, error);
|
|
||||||
|
|
||||||
return fundchannel_start_done(dest);
|
return fundchannel_start_done(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1408,9 +1404,7 @@ fundchannel_complete_err(struct command *cmd,
|
|||||||
json_tok_full_len(error),
|
json_tok_full_len(error),
|
||||||
json_tok_full(buf, error));
|
json_tok_full(buf, error));
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_COMPLETE_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(mfc, buf, error);
|
|
||||||
|
|
||||||
return fundchannel_complete_done(dest);
|
return fundchannel_complete_done(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1706,6 +1700,17 @@ static bool dest_failed(struct multifundchannel_destination *dest)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fail_destination(struct multifundchannel_destination *dest,
|
||||||
|
char *error TAKES)
|
||||||
|
{
|
||||||
|
dest->fail_state = dest->state;
|
||||||
|
dest->state = MULTIFUNDCHANNEL_FAILED;
|
||||||
|
if (taken(error))
|
||||||
|
dest->error = tal_steal(dest->mfc, error);
|
||||||
|
else
|
||||||
|
dest->error = tal_strdup(dest->mfc, error);
|
||||||
|
}
|
||||||
|
|
||||||
/* Filter the failing destinations. */
|
/* Filter the failing destinations. */
|
||||||
static struct command_result *
|
static struct command_result *
|
||||||
post_cleanup_redo_multifundchannel(struct multifundchannel_redo *redo)
|
post_cleanup_redo_multifundchannel(struct multifundchannel_redo *redo)
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ struct multifundchannel_destination {
|
|||||||
*/
|
*/
|
||||||
enum multifundchannel_state state;
|
enum multifundchannel_state state;
|
||||||
|
|
||||||
|
/* Last known state before failure */
|
||||||
|
enum multifundchannel_state fail_state;
|
||||||
|
|
||||||
/* the actual target script and address. */
|
/* the actual target script and address. */
|
||||||
const u8 *funding_script;
|
const u8 *funding_script;
|
||||||
const char *funding_addr;
|
const char *funding_addr;
|
||||||
@@ -213,6 +216,11 @@ mfc_forward_error(struct command *cmd,
|
|||||||
const char *buf, const jsmntok_t *error,
|
const char *buf, const jsmntok_t *error,
|
||||||
struct multifundchannel_command *);
|
struct multifundchannel_command *);
|
||||||
|
|
||||||
|
/* When a destination fails, we record the furthest state
|
||||||
|
* reached, and the error message for the failure */
|
||||||
|
void fail_destination(struct multifundchannel_destination *dest,
|
||||||
|
char *error TAKES);
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <bitcoin/psbt.h>
|
#include <bitcoin/psbt.h>
|
||||||
#include <ccan/ccan/array_size/array_size.h>
|
#include <ccan/ccan/array_size/array_size.h>
|
||||||
#include <ccan/ccan/cast/cast.h>
|
#include <ccan/ccan/cast/cast.h>
|
||||||
|
#include <ccan/ccan/tal/str/str.h>
|
||||||
#include <common/json_stream.h>
|
#include <common/json_stream.h>
|
||||||
#include <common/psbt_open.h>
|
#include <common/psbt_open.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
@@ -455,8 +456,7 @@ openchannel_signed_err(struct command *cmd,
|
|||||||
json_tok_full_len(code_tok),
|
json_tok_full_len(code_tok),
|
||||||
json_tok_full(buf, code_tok));
|
json_tok_full(buf, code_tok));
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(dest->mfc, buf, error);
|
|
||||||
return after_openchannel_signed(mfc);
|
return after_openchannel_signed(mfc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,9 +808,7 @@ openchannel_update_err(struct command *cmd,
|
|||||||
json_tok_full_len(error),
|
json_tok_full_len(error),
|
||||||
json_tok_full(buf, error));
|
json_tok_full(buf, error));
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(mfc, buf, error);
|
|
||||||
|
|
||||||
return openchannel_update_returned(dest);
|
return openchannel_update_returned(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,8 +1023,9 @@ openchannel_init_ok(struct command *cmd,
|
|||||||
/* Port any updates onto 'parent' PSBT */
|
/* Port any updates onto 'parent' PSBT */
|
||||||
if (!update_parent_psbt(dest->mfc, dest, dest->psbt,
|
if (!update_parent_psbt(dest->mfc, dest, dest->psbt,
|
||||||
dest->updated_psbt, &mfc->psbt)) {
|
dest->updated_psbt, &mfc->psbt)) {
|
||||||
dest->state = MULTIFUNDCHANNEL_FAILED;
|
fail_destination(dest,
|
||||||
dest->error = "Unable to update parent with node's PSBT";
|
take(tal_fmt(NULL, "Unable to update parent"
|
||||||
|
" with node's PSBT")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clone updated-psbt to psbt, so original changeset
|
/* Clone updated-psbt to psbt, so original changeset
|
||||||
@@ -1069,9 +1068,7 @@ openchannel_init_err(struct command *cmd,
|
|||||||
json_tok_full_len(code_tok),
|
json_tok_full_len(code_tok),
|
||||||
json_tok_full(buf, code_tok));
|
json_tok_full(buf, code_tok));
|
||||||
|
|
||||||
dest->state = MULTIFUNDCHANNEL_START_FAILED;
|
fail_destination(dest, take(json_strdup(NULL, buf, error)));
|
||||||
dest->error = json_strdup(dest->mfc, buf, error);
|
|
||||||
|
|
||||||
return openchannel_init_done(dest);
|
return openchannel_init_done(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user