Skip to content

Commit

Permalink
recv_block: ask for block contents on reinject.
Browse files Browse the repository at this point in the history
Now we query blocks out of order, we often will get a block through
reinjection (once we finally get its prev) rather than directly from
the packet path.  Assume that if this happens, we are syncing, and thus
want to ask about contents and children.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Sep 16, 2014
1 parent 727ec75 commit 6851d62
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions recv_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void ask_block_contents(struct state *state, const struct block *b)
/* peer is NULL if from generator, re-trying detached block or jsonrpc. */
static enum protocol_ecode
recv_block(struct state *state, struct log *log, struct peer *peer,
const tal_t *pkt_ctx, const struct block_info *bi,
const tal_t *pkt_ctx, const struct block_info *bi, bool need_contents,
struct block **block)
{
struct block *b, *prev;
Expand Down Expand Up @@ -184,7 +184,7 @@ recv_block(struct state *state, struct log *log, struct peer *peer,
bad_shard);
} else {
/* If we're syncing, ask about children, contents */
if (peer && peer->we_are_syncing) {
if (need_contents) {
/* FIXME: Don't do these if below horizon */
todo_add_get_children(state, &b->sha);
get_block_contents(state, b);
Expand Down Expand Up @@ -229,7 +229,7 @@ recv_block_pkt(struct state *state, struct log *log, struct peer *peer,
return e;
}

return recv_block(state, log, peer, pkt, &bi, block);
return recv_block(state, log, peer, pkt, &bi, peer->we_are_syncing, block);
}

static struct txptr_with_ref
Expand Down Expand Up @@ -525,7 +525,8 @@ void recv_block_reinject(struct state *state,
{
struct block *b;

recv_block(state, state->log, NULL, pkt_ctx, bi, &b);
/* A reinject implies we are catching up: explicitly ask for contents. */
recv_block(state, state->log, NULL, pkt_ctx, bi, true, &b);
}

static char *json_submitblock(struct json_connection *jcon,
Expand Down Expand Up @@ -553,7 +554,7 @@ static char *json_submitblock(struct json_connection *jcon,
if (e != PROTOCOL_ECODE_NONE)
return (char *)ecode_name(e);

e = recv_block(jcon->state, jcon->log, NULL, data, &bi, &block);
e = recv_block(jcon->state, jcon->log, NULL, data, &bi, false, &block);
if (e != PROTOCOL_ECODE_NONE)
return (char *)ecode_name(e);

Expand Down

0 comments on commit 6851d62

Please sign in to comment.