| 200 | } |
| 201 | |
| 202 | struct payment_tree_result payment_collect_result(struct payment *p) |
| 203 | { |
| 204 | struct payment_tree_result res; |
| 205 | size_t numchildren = tal_count(p->children); |
| 206 | res.sent = AMOUNT_MSAT(0); |
| 207 | res.attempts = 1; |
| 208 | res.treestates = p->step; |
| 209 | res.leafstates = 0; |
| 210 | res.preimage = NULL; |
| 211 | res.failure = NULL; |
| 212 | if (p->step == PAYMENT_STEP_FAILED && p->result != NULL) |
| 213 | res.failure = p->result; |
| 214 | |
| 215 | if (numchildren == 0) { |
| 216 | res.leafstates |= p->step; |
| 217 | if (p->result && p->result->state == PAYMENT_COMPLETE) { |
| 218 | res.sent = p->result->amount_sent; |
| 219 | res.preimage = p->result->payment_preimage; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | for (size_t i = 0; i < numchildren; i++) { |
| 224 | struct payment_tree_result cres = |
| 225 | payment_collect_result(p->children[i]); |
| 226 | |
| 227 | /* Some of our subpayments have succeeded, aggregate how much |
| 228 | * we sent in total. */ |
| 229 | if (!amount_msat_add(&res.sent, res.sent, cres.sent)) |
| 230 | paymod_err( |
| 231 | p, |
| 232 | "Number overflow summing partial payments: %s + %s", |
| 233 | type_to_string(tmpctx, struct amount_msat, |
| 234 | &res.sent), |
| 235 | type_to_string(tmpctx, struct amount_msat, |
| 236 | &cres.sent)); |
| 237 | |
| 238 | /* Bubble up the first preimage we see. */ |
| 239 | if (res.preimage == NULL && cres.preimage != NULL) |
| 240 | res.preimage = cres.preimage; |
| 241 | |
| 242 | res.leafstates |= cres.leafstates; |
| 243 | res.treestates |= cres.treestates; |
| 244 | res.attempts += cres.attempts; |
| 245 | |
| 246 | /* We bubble the failure result with the highest failcode up |
| 247 | * to the root. */ |
| 248 | if (res.failure == NULL || |
| 249 | (cres.failure != NULL && |
| 250 | cres.failure->failcode > res.failure->failcode)) { |
| 251 | res.failure = cres.failure; |
| 252 | } |
| 253 | } |
| 254 | return res; |
| 255 | } |
| 256 | |
| 257 | static struct command_result * |
| 258 | payment_getblockheight_success(struct command *cmd, |
no test coverage detected