Given the constraints on max fee and min prob., * is the flow A better than B? */
| 1486 | /* Given the constraints on max fee and min prob., |
| 1487 | * is the flow A better than B? */ |
| 1488 | static bool is_better( |
| 1489 | struct amount_msat max_fee, |
| 1490 | double min_probability, |
| 1491 | |
| 1492 | struct amount_msat A_fee, |
| 1493 | double A_prob, |
| 1494 | |
| 1495 | struct amount_msat B_fee, |
| 1496 | double B_prob) |
| 1497 | { |
| 1498 | bool A_fee_pass = amount_msat_less_eq(A_fee,max_fee); |
| 1499 | bool B_fee_pass = amount_msat_less_eq(B_fee,max_fee); |
| 1500 | bool A_prob_pass = A_prob >= min_probability; |
| 1501 | bool B_prob_pass = B_prob >= min_probability; |
| 1502 | |
| 1503 | // all bounds are met |
| 1504 | if(A_fee_pass && B_fee_pass && A_prob_pass && B_prob_pass) |
| 1505 | { |
| 1506 | // prefer lower fees |
| 1507 | goto fees_or_prob; |
| 1508 | } |
| 1509 | |
| 1510 | // prefer the solution that satisfies both bounds |
| 1511 | if(!(A_fee_pass && A_prob_pass) && (B_fee_pass && B_prob_pass)) |
| 1512 | { |
| 1513 | return false; |
| 1514 | } |
| 1515 | // prefer the solution that satisfies both bounds |
| 1516 | if((A_fee_pass && A_prob_pass) && !(B_fee_pass && B_prob_pass)) |
| 1517 | { |
| 1518 | return true; |
| 1519 | } |
| 1520 | |
| 1521 | // no solution satisfies both bounds |
| 1522 | |
| 1523 | // bound on fee is met |
| 1524 | if(A_fee_pass && B_fee_pass) |
| 1525 | { |
| 1526 | // pick the highest prob. |
| 1527 | return A_prob > B_prob; |
| 1528 | } |
| 1529 | |
| 1530 | // bound on prob. is met |
| 1531 | if(A_prob_pass && B_prob_pass) |
| 1532 | { |
| 1533 | goto fees_or_prob; |
| 1534 | } |
| 1535 | |
| 1536 | // prefer the solution that satisfies the bound on fees |
| 1537 | if(A_fee_pass && !B_fee_pass) |
| 1538 | { |
| 1539 | return true; |
| 1540 | } |
| 1541 | if(B_fee_pass && !A_fee_pass) |
| 1542 | { |
| 1543 | return false; |
| 1544 | } |
| 1545 |
no test coverage detected