MCPcopy Create free account
hub / github.com/ElementsProject/lightning / routehint_data_init

Function routehint_data_init

plugins/libplugin-pay.c:3163–3219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3161}
3162
3163static struct routehints_data *routehint_data_init(struct payment *p)
3164{
3165 struct routehints_data *pd, *d = tal(p, struct routehints_data);
3166 /* If for some reason we skipped the getroute call (directpay) we'll
3167 * need this to be initialized. */
3168 d->current_routehint = NULL;
3169 if (p->parent != NULL) {
3170 pd = payment_mod_routehints_get_data(payment_root(p));
3171 d->destination_reachable = pd->destination_reachable;
3172 d->routehints = pd->routehints;
3173 pd = payment_mod_routehints_get_data(p->parent);
3174 if (p->parent->step == PAYMENT_STEP_RETRY) {
3175 d->base = pd->base;
3176 d->offset = pd->offset;
3177 /* If the previous try failed to route, advance
3178 * to the next routehint. */
3179 if (!p->parent->route)
3180 ++d->offset;
3181 } else {
3182 size_t num_routehints = tal_count(d->routehints);
3183 d->offset = 0;
3184 /* This used to be pseudorand.
3185 *
3186 * However, it turns out that using the partid for
3187 * this payment has some nice properties.
3188 * The partid is in general quite random, due to
3189 * getting entropy from the network on the timing
3190 * of when payments complete/fail, and the routehint
3191 * randomization is not a privacy or security feature,
3192 * only a reliability one, thus does not need a lot
3193 * of entropy.
3194 *
3195 * But the most important bit is that *splits
3196 * get contiguous partids*, e.g. an adaptive
3197 * split will get two consecutive partid.
3198 * Because of the contiguity, using the partid
3199 * for the base will cause the split-up
3200 * payments to have fairly diverse initial
3201 * routehints.
3202 */
3203 if (num_routehints == 0)
3204 d->base = 0;
3205 else
3206 d->base = (p->partid - 1) % num_routehints;
3207 }
3208 return d;
3209 } else {
3210 /* We defer the actual initialization of the routehints array to
3211 * the step callback when we have the invoice attached. */
3212 d->routehints = NULL;
3213 d->base = 0;
3214 d->offset = 0;
3215 d->destination_reachable = false;
3216 return d;
3217 }
3218 return d;
3219}
3220

Callers

nothing calls this directly

Calls 1

payment_rootFunction · 0.85

Tested by

no test coverage detected