| 5093 | } |
| 5094 | |
| 5095 | static void peer_in(struct peer *peer, const u8 *msg) |
| 5096 | { |
| 5097 | enum peer_wire type = fromwire_peektype(msg); |
| 5098 | |
| 5099 | if (handle_peer_error_or_warning(peer->pps, msg)) |
| 5100 | return; |
| 5101 | |
| 5102 | check_tx_abort(peer, msg, NULL); |
| 5103 | |
| 5104 | /* If we're in STFU mode and aren't waiting for a STFU mode |
| 5105 | * specific message, the only valid message was tx_abort (or a |
| 5106 | * belated announcement_signatures!) */ |
| 5107 | if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) { |
| 5108 | if (peer->splicing && type == WIRE_TX_SIGNATURES) { |
| 5109 | if (peer->splicing->tx_sig_msg) |
| 5110 | peer_failed_warn(peer->pps, &peer->channel_id, |
| 5111 | "Received TX_SIGNATURES while" |
| 5112 | " we already have one cached"); |
| 5113 | peer->splicing->tx_sig_msg = tal_steal(peer->splicing, |
| 5114 | msg); |
| 5115 | return; |
| 5116 | } else if (type != WIRE_ANNOUNCEMENT_SIGNATURES) { |
| 5117 | peer_failed_warn(peer->pps, &peer->channel_id, |
| 5118 | "Received message %s when only TX_ABORT was" |
| 5119 | " valid", peer_wire_name(type)); |
| 5120 | } |
| 5121 | } |
| 5122 | |
| 5123 | /* Must get channel_ready before almost anything. */ |
| 5124 | if (!peer->channel_ready[REMOTE]) { |
| 5125 | if (type != WIRE_CHANNEL_READY |
| 5126 | && type != WIRE_SHUTDOWN |
| 5127 | /* We expect these for v2 !! */ |
| 5128 | && type != WIRE_TX_SIGNATURES |
| 5129 | /* lnd sends these early; it's harmless. */ |
| 5130 | && type != WIRE_UPDATE_FEE |
| 5131 | && type != WIRE_ANNOUNCEMENT_SIGNATURES) { |
| 5132 | peer_failed_warn(peer->pps, &peer->channel_id, |
| 5133 | "%s (%u) before funding locked", |
| 5134 | peer_wire_name(type), type); |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | /* For cleaner errors, we check message is valid during STFU mode */ |
| 5139 | if (peer->stfu_wait_single_msg) |
| 5140 | if (!VALID_STFU_MESSAGE(type)) |
| 5141 | peer_failed_warn(peer->pps, &peer->channel_id, |
| 5142 | "Got invalid message during STFU " |
| 5143 | "mode: %s", |
| 5144 | peer_wire_name(type)); |
| 5145 | |
| 5146 | peer->stfu_wait_single_msg = false; |
| 5147 | |
| 5148 | switch (type) { |
| 5149 | case WIRE_CHANNEL_READY: |
| 5150 | handle_peer_channel_ready(peer, msg); |
| 5151 | return; |
| 5152 | case WIRE_ANNOUNCEMENT_SIGNATURES: |
no test coverage detected