Skip to content

Pass scoring params through the router #2189

Closed

Description

@TheBlueMatt

Currently we require a "stateless" scorer, one which returns an absolute score with no context besides the channel and liquidity. This is somewhat annoying, though, for folks who want to have different scorers at different times - they'll have to create two separate scorers and pass them in. You can see this in the API for ProbabilisticScorer, which requires you pass the params at construction-time. Instead, we should parametrize the scorer with an associated "parameter" type, which is then passed to the router function itself, and allows passing a different, eg, ProbabilisticScorerParams per route-finding call.

Should be pretty straightforward to do - just add a assicated type to the Score trait, then add that as an argument to the score-fetching method and make it an argument to the get_/find_ route function.

Activity

  1. henghonglee commented on Apr 17, 2023

    @henghonglee
    Contributor

    Hi @TheBlueMatt i'd like to give this one a try

  2. henghonglee commented on Apr 17, 2023

    @henghonglee
    Contributor

    Hi @TheBlueMatt, I did some reading of the code and have some questions about this task.

    From how I understand the scorer system, for each time a get_route / find_route is called, you need to use a scorer. a scorer is currently a single-use object that holds a bunch of states.
    The various implementations of Score are these single-use objects that encode the "what" (what the parameters are) and also the "how" (how the scoring is calculated)

    These include:
    FixedPenaltyScorer
    ProbabilisticScorer
    ScorerAccountingForInFlightHtlcs
    BadChannelScorer
    BadNodeScorer

    it seems that find_route requires one of these scorers and is a central public function that does everything to find a single route from a payer to a payee.

    IMHO, I think these scorer constructs do a nice job of abstracting the logic and accompanying state required for that logic. passing in the scorerParams in get_route seem to be very specific for only the ProbabilisticScorer flow and creates a leaky abstraction

    maybe I did not understand "somewhat annoying, though.. different scorers at different times" right in the original text, did you mean to score each channel differently in a single get_route fn call? I can see that it might be very tricky to compose different scorers for a single get_route.
    Maybe the complexity also lies in the multi-path payments and how each found route affects the next and requires a different scorer?

    Could you further elaborate on where the annoyances lie in trying to achieve get_route/find_route with multiple scorers? is it memory related? speed/performance related? or mainly in the ergonomics of the implementations?

  3. henghonglee commented on Apr 19, 2023

    @henghonglee
    Contributor

    image
    image

    @TheBlueMatt
    did you mean something like this? hopefully I'm not missing anything obvious here

  4. TheBlueMatt commented on Apr 19, 2023

    @TheBlueMatt
    CollaboratorAuthor

    IMHO, I think these scorer constructs do a nice job of abstracting the logic and accompanying state required for that logic. passing in the scorerParams in get_route seem to be very specific for only the ProbabilisticScorer flow and creates a leaky abstraction

    The scorers you listed above are largely test-only. In reality, ~everyone uses the ProbabilisticScorer (or the ScorerAccountingForInFlightHtlcs, which actually wraps the probabilistic one, in practice), and if we were to add some completely different scorer it would also likely have some parameters to tune with.

    While you're right that its a lot of extra generics to expose the scoring parameters all the way out through the router, its quite useful in practice - scoring parameters aren't static, some payments may want to prefer to pay less in fees, and others may prefer a higher success probability. Moreso, if we've retried a payment a few times we may even want to prefer a higher success probability for certain retries later on! The current API doesn't allow this, as the parameters are "baked into" the scorer, and you'd have to have a separate scorer for different parameters.

    did you mean something like this? hopefully I'm not missing anything obvious here

    Yep, exactly like that!

  5. henghonglee commented on Apr 26, 2023

    @henghonglee
    Contributor

    Hi, @TheBlueMatt
    I do have an unfinished draft that I would like to have you take a look at. It seems I would be making a large number of changes so I just wanted to make sure (once again) that I'm still on the right track with regard to the task so that i can continue making all the necessary changes

    Created a draft PR here https://github.com/lightningdevkit/rust-lightning/pull/2237/files.

  6. henghonglee commented on May 5, 2023

    @henghonglee
    Contributor

    Ready for review :)

  7. added 13 commits that reference this issue on May 7, 2023
  8. added a commit that references this issue on May 11, 2023
  9. wpaulino commented on Aug 15, 2023

    @wpaulino
    Contributor

    Done in #2237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions