Figure out what we should offer now. */
| 472 | |
| 473 | /* Figure out what we should offer now. */ |
| 474 | static struct amount_sat |
| 475 | adjust_offer(struct per_peer_state *pps, const struct channel_id *channel_id, |
| 476 | const struct feerange *feerange, struct amount_sat remote_offer, |
| 477 | struct amount_sat min_fee_to_accept, u64 fee_negotiation_step, |
| 478 | u8 fee_negotiation_step_unit) |
| 479 | { |
| 480 | struct amount_sat min_plus_one, range_len, step_sat, result; |
| 481 | struct amount_msat step_msat; |
| 482 | |
| 483 | /* Within 1 satoshi? Agree. */ |
| 484 | if (!amount_sat_add(&min_plus_one, feerange->min, AMOUNT_SAT(1))) |
| 485 | peer_failed_warn(pps, channel_id, |
| 486 | "Fee offer %s min too large", |
| 487 | type_to_string(tmpctx, struct amount_sat, |
| 488 | &feerange->min)); |
| 489 | |
| 490 | if (amount_sat_greater_eq(min_plus_one, feerange->max)) |
| 491 | return remote_offer; |
| 492 | |
| 493 | /* feerange has already been adjusted so that our new offer is ok to be |
| 494 | * any number in [feerange->min, feerange->max] and after the following |
| 495 | * min_fee_to_accept is in that range. Thus, pick a fee in |
| 496 | * [min_fee_to_accept, feerange->max]. */ |
| 497 | if (amount_sat_greater(feerange->min, min_fee_to_accept)) |
| 498 | min_fee_to_accept = feerange->min; |
| 499 | |
| 500 | /* Max is below our minimum acceptable? */ |
| 501 | if (!amount_sat_sub(&range_len, feerange->max, min_fee_to_accept)) |
| 502 | peer_failed_warn(pps, channel_id, |
| 503 | "Feerange %s-%s" |
| 504 | " below minimum acceptable %s", |
| 505 | type_to_string(tmpctx, struct amount_sat, |
| 506 | &feerange->min), |
| 507 | type_to_string(tmpctx, struct amount_sat, |
| 508 | &feerange->max), |
| 509 | type_to_string(tmpctx, struct amount_sat, |
| 510 | &min_fee_to_accept)); |
| 511 | |
| 512 | if (fee_negotiation_step_unit == |
| 513 | CLOSING_FEE_NEGOTIATION_STEP_UNIT_SATOSHI) { |
| 514 | /* -1 because the range boundary has already been adjusted with |
| 515 | * one from our previous proposal. So, if the user requested a |
| 516 | * step of 1 satoshi at a time we should just return our end of |
| 517 | * the range from this function. */ |
| 518 | step_msat = amount_msat((fee_negotiation_step - 1) |
| 519 | * MSAT_PER_SAT); |
| 520 | } else { |
| 521 | /* fee_negotiation_step is e.g. 20 to designate 20% from |
| 522 | * range_len (which is in satoshi), so: |
| 523 | * range_len * fee_negotiation_step / 100 [sat] |
| 524 | * is equivalent to: |
| 525 | * range_len * fee_negotiation_step * 10 [msat] */ |
| 526 | step_msat = amount_msat(range_len.satoshis /* Raw: % calc */ * |
| 527 | fee_negotiation_step * 10); |
| 528 | } |
| 529 | |
| 530 | step_sat = amount_msat_to_sat_round_down(step_msat); |
| 531 |
no test coverage detected