| 3 | #include <bitcoin/feerate.h> |
| 4 | |
| 5 | u32 feerate_from_style(u32 feerate, enum feerate_style style) |
| 6 | { |
| 7 | /* Make sure it's called somewhere! */ |
| 8 | assert(feerate_floor_check() == FEERATE_FLOOR); |
| 9 | |
| 10 | switch (style) { |
| 11 | case FEERATE_PER_KSIPA: |
| 12 | return feerate; |
| 13 | case FEERATE_PER_KBYTE: |
| 14 | /* Everyone uses satoshi per kbyte, but we use satoshi per ksipa |
| 15 | * (don't round down to zero though)! |
| 16 | * |
| 17 | * Widen before rounding up: on a u32 the +3 wraps for the top |
| 18 | * three values, turning an absurd feerate into 0 or 1 perkw. |
| 19 | * That is the dangerous direction (it underpays our unilateral |
| 20 | * close), and it slips under every bound we check afterwards, |
| 21 | * since those are applied to the converted value. The result |
| 22 | * always fits a u32: (UINT_MAX + 3) / 4 < UINT_MAX. */ |
| 23 | return ((u64)feerate + 3) / 4; |
| 24 | } |
| 25 | abort(); |
| 26 | } |
| 27 | |
| 28 | u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style) |
| 29 | { |
no test coverage detected