channeld: ensure channel_update timestamps always increment.

Covers a possible source of subtle bugs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-01-04 22:10:21 +10:30 committed by Christian Decker
parent 86e1a61165
commit bc631166f0

View File

@ -158,6 +158,9 @@ struct peer {
/* Where we got up to in gossip broadcasts. */
u64 gossip_index;
/* Make sure timestamps move forward. */
u32 last_update_timestamp;
};
static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer);
@ -371,6 +374,11 @@ static u8 *create_channel_update(const tal_t *ctx,
u16 flags;
u8 *cupdate, *msg;
/* Identical timestamps will be ignored. */
if (timestamp <= peer->last_update_timestamp)
timestamp = peer->last_update_timestamp + 1;
peer->last_update_timestamp = timestamp;
/* Set the signature to empty so that valgrind doesn't complain */
secp256k1_ecdsa_signature *sig =
talz(tmpctx, secp256k1_ecdsa_signature);
@ -2529,6 +2537,7 @@ int main(int argc, char *argv[])
peer->peer_outoff = 0;
peer->next_commit_sigs = NULL;
peer->shutdown_sent[LOCAL] = false;
peer->last_update_timestamp = 0;
/* We send these to HSM to get real signatures; don't have valgrind
* complain. */