lightningd: index to speed up sendpay / listsendpays

contrib/giantnode.py shows we're spending a lot of time looking up
payments by payment_hash: sendpays does it to see if we've already
paid, and bookkeeper does it in listsendpays:

```
-   94.52%     0.00%  lightningd  lightningd            [.] read_json
   - 94.52% read_json                                                
      - 94.48% parse_request                                         
         - 94.46% plugin_hook_call_rpc_command                       
            - plugin_hook_call_                                      
               - rpc_command_hook_final                              
                  - 94.46% command_exec                              
                     - 49.08% json_sendpay                           
                        - 49.01% send_payment                        
                           - 48.86% send_payment_core                
                              - 48.84% wallet_payment_list           
                                 - 48.80% db_step                    
                                    + db_sqlite3_step                
                     - 45.38% json_listsendpays                      
                        - 45.36% wallet_payment_list                 
                           - 45.30% db_step                          
                              + 45.30% db_sqlite3_step               
```

This doesn't actually make much of a difference, so see next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-09-19 10:19:52 +09:30
committed by Christian Decker
parent 4cab396cc8
commit 2a5660b3bc

View File

@@ -885,7 +885,8 @@ static struct migration dbmigrations[] = {
{SQL("ALTER TABLE channels ADD alias_remote BIGINT DEFAULT NULL"), NULL},
/* Cheeky immediate completion as best effort approximation of real completion time */
{SQL("ALTER TABLE payments ADD completed_at INTEGER DEFAULT NULL;"), NULL},
{SQL("UPDATE payments SET completed_at = timestamp WHERE status != 0;"), NULL}
{SQL("UPDATE payments SET completed_at = timestamp WHERE status != 0;"), NULL},
{SQL("CREATE INDEX payments_idx ON payments (payment_hash)"), NULL},
};
/* Released versions are of form v{num}[.{num}]* */