| 227 | } |
| 228 | |
| 229 | struct payment_tree_result payment_collect_result(struct payment *p) |
| 230 | { |
| 231 | struct payment_tree_result res; |
| 232 | size_t numchildren = tal_count(p->children); |
| 233 | res.sent = AMOUNT_MSAT(0); |
| 234 | res.attempts = 1; |
| 235 | res.treestates = p->step; |
| 236 | res.leafstates = 0; |
| 237 | res.preimage = NULL; |
| 238 | res.failure = NULL; |
| 239 | if (p->step == PAYMENT_STEP_FAILED && p->result != NULL) |
| 240 | res.failure = p->result; |
| 241 | |
| 242 | if (numchildren == 0) { |
| 243 | res.leafstates |= p->step; |
| 244 | if (p->result && p->result->state == PAYMENT_COMPLETE) { |
| 245 | res.sent = p->result->amount_sent; |
| 246 | res.preimage = p->result->payment_preimage; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | for (size_t i = 0; i < numchildren; i++) { |
| 251 | struct payment_tree_result cres = |
| 252 | payment_collect_result(p->children[i]); |
| 253 | |
| 254 | /* Some of our subpayments have succeeded, aggregate how much |
| 255 | * we sent in total. */ |
| 256 | if (!amount_msat_accumulate(&res.sent, cres.sent)) |
| 257 | paymod_err( |
| 258 | p, |
| 259 | "Number overflow summing partial payments: %s + %s", |
| 260 | fmt_amount_msat(tmpctx, res.sent), |
| 261 | fmt_amount_msat(tmpctx, cres.sent)); |
| 262 | |
| 263 | /* Bubble up the first preimage we see. */ |
| 264 | if (res.preimage == NULL && cres.preimage != NULL) |
| 265 | res.preimage = cres.preimage; |
| 266 | |
| 267 | res.leafstates |= cres.leafstates; |
| 268 | res.treestates |= cres.treestates; |
| 269 | res.attempts += cres.attempts; |
| 270 | |
| 271 | /* We bubble the failure result with the highest failcode up |
| 272 | * to the root. */ |
| 273 | if (res.failure == NULL || |
| 274 | (cres.failure != NULL && |
| 275 | cres.failure->failcode > res.failure->failcode)) { |
| 276 | res.failure = cres.failure; |
| 277 | } |
| 278 | } |
| 279 | return res; |
| 280 | } |
| 281 | |
| 282 | static struct command_result *payment_waitblockheight_cb(struct command *cmd, |
| 283 | const char *method, |
no test coverage detected