| 91 | } |
| 92 | |
| 93 | struct htlc_in *htlc_in_check(const struct htlc_in *hin, const char *abortstr) |
| 94 | { |
| 95 | if (amount_msat_eq(hin->msat, AMOUNT_MSAT(0))) |
| 96 | return corrupt(abortstr, "zero msatoshi"); |
| 97 | else if (htlc_state_owner(hin->hstate) != REMOTE) |
| 98 | return corrupt(abortstr, "invalid state %s", |
| 99 | htlc_state_name(hin->hstate)); |
| 100 | else if (hin->failonion && hin->preimage) |
| 101 | return corrupt(abortstr, "Both failonion and succeeded"); |
| 102 | else if (hin->badonion != 0 && hin->preimage) |
| 103 | return corrupt(abortstr, "Both badonion and succeeded"); |
| 104 | else if (hin->failonion && hin->badonion) |
| 105 | return corrupt(abortstr, "Both failed and malformed"); |
| 106 | |
| 107 | /* Can't have a resolution while still being added. */ |
| 108 | if (hin->hstate >= RCVD_ADD_HTLC |
| 109 | && hin->hstate <= RCVD_ADD_ACK_REVOCATION) { |
| 110 | if (hin->preimage) |
| 111 | return corrupt(abortstr, "Still adding, has preimage"); |
| 112 | if (hin->failonion) |
| 113 | return corrupt(abortstr, "Still adding, has failmsg"); |
| 114 | if (hin->badonion) |
| 115 | return corrupt(abortstr, "Still adding, has badonion"); |
| 116 | } else if (hin->hstate >= SENT_REMOVE_HTLC |
| 117 | && hin->hstate <= SENT_REMOVE_ACK_REVOCATION) { |
| 118 | if (!hin->preimage && !hin->failonion && !hin->badonion) |
| 119 | return corrupt(abortstr, "Removing, no resolution"); |
| 120 | } else |
| 121 | return corrupt(abortstr, "Bad state %s", |
| 122 | htlc_state_name(hin->hstate)); |
| 123 | |
| 124 | return cast_const(struct htlc_in *, hin); |
| 125 | } |
| 126 | |
| 127 | struct htlc_in *new_htlc_in(const tal_t *ctx, |
| 128 | struct channel *channel, u64 id, |
no test coverage detected