mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
onchaind: queue any unexpected messages while waiting for htlcs.
In particular, we could get depth notifications. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
40dc222d94
commit
3b5c24ada1
@@ -66,6 +66,9 @@ static u32 reasonable_depth;
|
|||||||
/* The messages to send at that depth. */
|
/* The messages to send at that depth. */
|
||||||
static u8 **missing_htlc_msgs;
|
static u8 **missing_htlc_msgs;
|
||||||
|
|
||||||
|
/* The messages which were sent to us before init_reply was processed. */
|
||||||
|
static u8 **queued_msgs;
|
||||||
|
|
||||||
/* Our recorded channel balance at 'chain time' */
|
/* Our recorded channel balance at 'chain time' */
|
||||||
static struct amount_msat our_msat;
|
static struct amount_msat our_msat;
|
||||||
|
|
||||||
@@ -2151,6 +2154,8 @@ static void memleak_remove_globals(struct htable *memtable, const tal_t *topctx)
|
|||||||
memleak_remove_pointer(memtable, topctx);
|
memleak_remove_pointer(memtable, topctx);
|
||||||
memleak_remove_region(memtable,
|
memleak_remove_region(memtable,
|
||||||
missing_htlc_msgs, tal_bytelen(missing_htlc_msgs));
|
missing_htlc_msgs, tal_bytelen(missing_htlc_msgs));
|
||||||
|
memleak_remove_region(memtable,
|
||||||
|
queued_msgs, tal_bytelen(queued_msgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handle_dev_memleak(struct tracked_output **outs, const u8 *msg)
|
static bool handle_dev_memleak(struct tracked_output **outs, const u8 *msg)
|
||||||
@@ -2193,13 +2198,19 @@ static void wait_for_resolved(struct tracked_output **outs)
|
|||||||
billboard_update(outs);
|
billboard_update(outs);
|
||||||
|
|
||||||
while (num_not_irrevocably_resolved(outs) != 0) {
|
while (num_not_irrevocably_resolved(outs) != 0) {
|
||||||
u8 *msg = wire_sync_read(outs, REQ_FD);
|
u8 *msg;
|
||||||
struct bitcoin_txid txid;
|
struct bitcoin_txid txid;
|
||||||
u32 input_num, depth, tx_blockheight;
|
u32 input_num, depth, tx_blockheight;
|
||||||
struct preimage preimage;
|
struct preimage preimage;
|
||||||
bool is_replay;
|
bool is_replay;
|
||||||
struct tx_parts *tx_parts;
|
struct tx_parts *tx_parts;
|
||||||
|
|
||||||
|
if (tal_count(queued_msgs)) {
|
||||||
|
msg = tal_steal(outs, queued_msgs[0]);
|
||||||
|
tal_arr_remove(&queued_msgs, 0);
|
||||||
|
} else
|
||||||
|
msg = wire_sync_read(outs, REQ_FD);
|
||||||
|
|
||||||
status_debug("Got new message %s",
|
status_debug("Got new message %s",
|
||||||
onchaind_wire_name(fromwire_peektype(msg)));
|
onchaind_wire_name(fromwire_peektype(msg)));
|
||||||
|
|
||||||
@@ -2253,13 +2264,19 @@ static struct htlcs_info *init_reply(const tal_t *ctx, const char *what)
|
|||||||
peer_billboard(true, what);
|
peer_billboard(true, what);
|
||||||
|
|
||||||
/* Read in htlcs */
|
/* Read in htlcs */
|
||||||
/* FIXME: queue other messages! */
|
for (;;) {
|
||||||
msg = wire_sync_read(tmpctx, REQ_FD);
|
msg = wire_sync_read(queued_msgs, REQ_FD);
|
||||||
if (!fromwire_onchaind_htlcs(htlcs_info, msg,
|
if (fromwire_onchaind_htlcs(htlcs_info, msg,
|
||||||
&htlcs_info->htlcs,
|
&htlcs_info->htlcs,
|
||||||
&htlcs_info->tell_if_missing,
|
&htlcs_info->tell_if_missing,
|
||||||
&htlcs_info->tell_immediately))
|
&htlcs_info->tell_immediately)) {
|
||||||
master_badmsg(WIRE_ONCHAIND_HTLCS, msg);
|
tal_free(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process later */
|
||||||
|
tal_arr_expand(&queued_msgs, msg);
|
||||||
|
}
|
||||||
|
|
||||||
/* We want htlcs to be a valid tal parent, so make it a zero-length
|
/* We want htlcs to be a valid tal parent, so make it a zero-length
|
||||||
* array if NULL (fromwire makes it NULL if there are no entries) */
|
* array if NULL (fromwire makes it NULL if there are no entries) */
|
||||||
@@ -4057,6 +4074,7 @@ int main(int argc, char *argv[])
|
|||||||
status_setup_sync(REQ_FD);
|
status_setup_sync(REQ_FD);
|
||||||
|
|
||||||
missing_htlc_msgs = tal_arr(ctx, u8 *, 0);
|
missing_htlc_msgs = tal_arr(ctx, u8 *, 0);
|
||||||
|
queued_msgs = tal_arr(ctx, u8 *, 0);
|
||||||
|
|
||||||
msg = wire_sync_read(tmpctx, REQ_FD);
|
msg = wire_sync_read(tmpctx, REQ_FD);
|
||||||
if (!fromwire_onchaind_init(tmpctx, msg,
|
if (!fromwire_onchaind_init(tmpctx, msg,
|
||||||
|
|||||||
Reference in New Issue
Block a user