Skip to content

Commit

Permalink
peer: add peer_has_error
Browse files Browse the repository at this point in the history
This handles the case where peer->error is sometimes an empty string

Fixes ElementsProject#435
  • Loading branch information
jb55 committed Dec 13, 2017
1 parent 0610f66 commit 8dc3606
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void peer_fail_permanent(struct peer *peer, const u8 *msg TAKES)
(int)tal_len(msg), (char *)msg);

/* We can have multiple errors, eg. onchaind failures. */
if (!peer->error)
if (peer_has_error(peer))
peer->error = towire_error(peer, &all_channels, msg);

peer_set_owner(peer, NULL);
Expand Down Expand Up @@ -561,7 +561,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
peer_state_name(peer->state));

/* FIXME: We can have errors for multiple channels. */
if (peer->error) {
if (peer_has_error(peer)) {
error = peer->error;
goto send_error;
}
Expand Down
5 changes: 5 additions & 0 deletions lightningd/peer_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ static inline bool peer_on_chain(const struct peer *peer)
return peer_state_on_chain(peer->state);
}

static inline bool peer_has_error(const struct peer *peer)
{
return peer->error == NULL || peer->error[0] == '\0';
}

static inline bool peer_wants_reconnect(const struct peer *peer)
{
return peer->state >= CHANNELD_AWAITING_LOCKIN
Expand Down
4 changes: 2 additions & 2 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ void notify_new_block(struct lightningd *ld, u32 height)
continue;

/* Peer already failed, or we hit it? */
if (hout->key.peer->error)
if (peer_has_error(hout->key.peer))
continue;

peer_fail_permanent_str(hout->key.peer,
Expand Down Expand Up @@ -1464,7 +1464,7 @@ void notify_new_block(struct lightningd *ld, u32 height)
continue;

/* Peer already failed, or we hit it? */
if (hin->key.peer->error)
if (peer_has_error(hin->key.peer))
continue;

peer_fail_permanent_str(hin->key.peer,
Expand Down

0 comments on commit 8dc3606

Please sign in to comment.