Update the knowledge that this (channel,direction) can send x msat.*/
| 257 | |
| 258 | /* Update the knowledge that this (channel,direction) can send x msat.*/ |
| 259 | static enum renepay_errorcode |
| 260 | chan_extra_can_send_(struct chan_extra *ce, int dir, struct amount_msat x) |
| 261 | { |
| 262 | assert(ce); |
| 263 | assert(dir == 0 || dir == 1); |
| 264 | enum renepay_errorcode err; |
| 265 | |
| 266 | if (amount_msat_greater(x, ce->capacity)) |
| 267 | return RENEPAY_PRECONDITION_ERROR; |
| 268 | |
| 269 | struct amount_msat known_min, known_max; |
| 270 | |
| 271 | // in case we fail, let's remember the original state |
| 272 | known_min = ce->half[dir].known_min; |
| 273 | known_max = ce->half[dir].known_max; |
| 274 | |
| 275 | ce->half[dir].known_min = amount_msat_max(ce->half[dir].known_min, x); |
| 276 | ce->half[dir].known_max = amount_msat_max(ce->half[dir].known_max, x); |
| 277 | |
| 278 | err = chan_extra_adjust_half(ce, !dir); |
| 279 | if (err != RENEPAY_NOERROR) |
| 280 | goto restore_and_fail; |
| 281 | |
| 282 | return RENEPAY_NOERROR; |
| 283 | |
| 284 | restore_and_fail: |
| 285 | // we fail, thus restore the original state |
| 286 | ce->half[dir].known_min = known_min; |
| 287 | ce->half[dir].known_max = known_max; |
| 288 | return err; |
| 289 | } |
| 290 | |
| 291 | enum renepay_errorcode |
| 292 | chan_extra_can_send(struct chan_extra_map *chan_extra_map, |
no test coverage detected