From 4d27efc039002771ba5ac71fb0a2faefb945762a Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 16 Apr 2024 11:54:51 +0200 Subject: [PATCH] pay: Add the `chainlag` to the payment The `chainlag` is defined as the positive difference between the height of the last block processed by the node and the best height known by the bitcoin backend. The chainlag is positive when we are still catching up with the blockchain, and `0` otherwise. The `chainlag` is used as an additional offset to the CLTV values when sending payments, allowing payments to be sent even before the chain sync completes. --- plugins/libplugin-pay.c | 2 ++ plugins/libplugin-pay.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 21b4ed565..22adf457d 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -118,6 +118,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd, p->invstring = parent->invstring; p->description = parent->description; p->mods = parent->mods; + p->chainlag = parent->chainlag; } else { assert(cmd != NULL); p->partid = 0; @@ -132,6 +133,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd, p->local_invreq_id = NULL; p->groupid = 0; p->mods = NULL; + p->chainlag = 0; } /* Initialize all modifier data so we can point to the fields when diff --git a/plugins/libplugin-pay.h b/plugins/libplugin-pay.h index 7fdf3d605..7046f9573 100644 --- a/plugins/libplugin-pay.h +++ b/plugins/libplugin-pay.h @@ -326,6 +326,11 @@ struct payment { * explanation if a payment is aborted. */ char *aborterror; + /* How many blocks are we lagging behind the rest of the + network? This needs to be taken into consideration when + sending payments before being fully caught up.*/ + u32 chainlag; + /* Callback to be called when the entire payment process * completes successfully. */ void (*on_payment_success)(struct payment *p);