lightning: fix self payments (e.g. rebalance) #10271
                
     Draft
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
On master it's currently not possible to do self payments (e.g. rebalance) as additional checks in
save_payment_infointroduced in a7afd59 preventLNWallet.pay_invoice()to overwrite an existingPaymentInfoas they differ more than in status (e.g. direction).I think
PaymentInfoshould be stored separately by direction instead of storingPaymentInfoof both directions indb['lightning_payments']so it is more explicit what "kind" ofPaymentInfois being handled and allow for a receiving and sendingPaymentInfowith the same rhash. Right now this seems prone to bugs (esp with a self-payment where we use the PaymentInfo to handle incoming htlcs but also change its status on the sending side, so two unrelated functions modify the same value).This conflicts with #10230 so I'll shelf this until #10230 is finished.