| 862 | } |
| 863 | |
| 864 | static size_t calc_weight(struct splice_cmd *splice_cmd, |
| 865 | bool simulate_wallet_outputs) |
| 866 | { |
| 867 | struct splice_script_result *action; |
| 868 | struct plugin *plugin = splice_cmd->cmd->plugin; |
| 869 | struct wally_psbt *psbt = splice_cmd->psbt; |
| 870 | size_t lweight = 0, weight = 0; |
| 871 | size_t extra_inputs = 0; |
| 872 | size_t extra_outputs = 0; |
| 873 | bool add_wallet_output = output_wallet(splice_cmd) ? true : false; |
| 874 | |
| 875 | plugin_log(plugin, LOG_DBG, "Counting potenetial tx weight;"); |
| 876 | |
| 877 | /* BOLT #2: |
| 878 | * The rest of the transaction bytes' fees are the responsibility of |
| 879 | * the peer who contributed that input or output via `tx_add_input` or |
| 880 | * `tx_add_output`, at the agreed upon `feerate`. |
| 881 | */ |
| 882 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 883 | weight += psbt_input_get_weight(psbt, i, PSBT_GUESS_2OF2); |
| 884 | plugin_log(plugin, LOG_DBG, " Counting input; weight: %zu", |
| 885 | weight - lweight); |
| 886 | lweight = weight; |
| 887 | } |
| 888 | |
| 889 | if (unresolved_wallet_inputs(splice_cmd)) { |
| 890 | add_wallet_output = true; |
| 891 | weight += bitcoin_tx_input_weight(false, |
| 892 | bitcoin_tx_input_witness_weight(UTXO_P2TR) - 1); |
| 893 | plugin_log(plugin, LOG_DBG, " Simulating input (wallet);" |
| 894 | " weight: %zu", weight - lweight); |
| 895 | lweight = weight; |
| 896 | } |
| 897 | |
| 898 | /* Count the splice input manually */ |
| 899 | for (size_t i = 0; i < tal_count(splice_cmd->actions); i++) { |
| 900 | action = splice_cmd->actions[i]; |
| 901 | if (action->channel_id) { |
| 902 | weight += bitcoin_tx_input_weight(false, |
| 903 | bitcoin_tx_2of2_input_witness_weight() - 1); |
| 904 | plugin_log(plugin, LOG_DBG, " Simulating input" |
| 905 | " (channel); weight:" |
| 906 | " %zu", weight - lweight); |
| 907 | lweight = weight; |
| 908 | extra_inputs++; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /* Count the splice outputs manually */ |
| 913 | for (size_t i = 0; i < tal_count(splice_cmd->actions); i++) { |
| 914 | action = splice_cmd->actions[i]; |
| 915 | if (action->onchain_wallet) { |
| 916 | if (!amount_sat_is_zero(action->in_sat) || action->in_ppm) |
| 917 | add_wallet_output = true; |
| 918 | assert(!splice_cmd->actions[i]->channel_id); |
| 919 | } |
| 920 | if (splice_cmd->actions[i]->channel_id) { |
| 921 | weight += bitcoin_tx_output_weight(BITCOIN_SCRIPTPUBKEY_P2WSH_LEN); |
no test coverage detected