proposal_should_rbf * * @brief the given output just increased its depth, * so the proposal for it should be RBFed and * rebroadcast. * * @desc precondition: the given output must have an * rbfable proposal as per `proposal_is_rbfable`. */
| 1069 | * rbfable proposal as per `proposal_is_rbfable`. |
| 1070 | */ |
| 1071 | static void proposal_should_rbf(struct tracked_output *out) |
| 1072 | { |
| 1073 | struct bitcoin_tx *tx = NULL; |
| 1074 | u32 depth; |
| 1075 | |
| 1076 | assert(out->proposal); |
| 1077 | assert(proposal_is_rbfable(out->proposal)); |
| 1078 | |
| 1079 | depth = out->depth; |
| 1080 | |
| 1081 | /* Do not RBF at depth 1. |
| 1082 | * |
| 1083 | * Since we react to *onchain* events, whatever proposal we made, |
| 1084 | * the output for that proposal is already at depth 1. |
| 1085 | * |
| 1086 | * Since our initial proposal was broadcasted with the output at |
| 1087 | * depth 1, we should not RBF until a new block arrives, which is |
| 1088 | * at depth 2. |
| 1089 | */ |
| 1090 | if (depth <= 1) |
| 1091 | return; |
| 1092 | |
| 1093 | if (out->proposal->tx_type == OUR_PENALTY_TX) { |
| 1094 | u32 max_depth = to_self_delay[REMOTE]; |
| 1095 | u32 my_depth = depth; |
| 1096 | size_t weight = bitcoin_tx_weight(out->proposal->tx); |
| 1097 | struct amount_sat initial_amount; |
| 1098 | struct amount_sat new_amount; |
| 1099 | |
| 1100 | if (max_depth >= 1) |
| 1101 | max_depth -= 1; |
| 1102 | if (my_depth >= max_depth) |
| 1103 | my_depth = max_depth; |
| 1104 | |
| 1105 | bitcoin_tx_output_get_amount_sat(out->proposal->tx, 0, |
| 1106 | &initial_amount); |
| 1107 | |
| 1108 | /* Compute the new output amount for the RBF. */ |
| 1109 | new_amount = compute_penalty_output_amount(initial_amount, |
| 1110 | my_depth, max_depth, |
| 1111 | weight); |
| 1112 | assert(amount_sat_less_eq(new_amount, initial_amount)); |
| 1113 | /* Recreate the penalty tx. */ |
| 1114 | tx = replace_penalty_tx_to_us(tmpctx, |
| 1115 | &penalty_to_us, |
| 1116 | out->proposal->tx, &new_amount); |
| 1117 | |
| 1118 | /* We also update the output's value, so our accounting |
| 1119 | * is correct. */ |
| 1120 | out->sat = new_amount; |
| 1121 | |
| 1122 | status_debug("Created RBF OUR_PENALTY_TX with output %s " |
| 1123 | "(originally %s) for depth %"PRIu32"/%"PRIu32".", |
| 1124 | type_to_string(tmpctx, struct amount_sat, |
| 1125 | &new_amount), |
| 1126 | type_to_string(tmpctx, struct amount_sat, |
| 1127 | &initial_amount), |
| 1128 | depth, to_self_delay[LOCAL]); |
no test coverage detected