Skip to content

Commit 541f288

Browse files
committed
peer: add peer_has_error
This handles the case where peer->error is sometimes an empty string Fixes ElementsProject#435
1 parent 600d4d0 commit 541f288

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lightningd/peer_control.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void peer_fail_permanent(struct peer *peer, const u8 *msg TAKES)
189189
(int)tal_len(msg), (char *)msg);
190190

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

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

563563
/* FIXME: We can have errors for multiple channels. */
564-
if (peer->error) {
564+
if (peer_has_error(peer)) {
565565
error = peer->error;
566566
goto send_error;
567567
}

lightningd/peer_control.h

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ static inline bool peer_on_chain(const struct peer *peer)
133133
return peer_state_on_chain(peer->state);
134134
}
135135

136+
static inline bool peer_has_error(const struct peer *peer)
137+
{
138+
return peer->error == NULL || peer->error[0] == '\0';
139+
}
140+
136141
static inline bool peer_wants_reconnect(const struct peer *peer)
137142
{
138143
return peer->state >= CHANNELD_AWAITING_LOCKIN

lightningd/peer_htlcs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ void notify_new_block(struct lightningd *ld, u32 height)
14191419
continue;
14201420

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

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

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

14701470
peer_fail_permanent_str(hin->key.peer,

0 commit comments

Comments
 (0)