Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] lightningd: pass the current known block height down to the getchaininfo call #6181

Merged

Conversation

vincenzopalazzo
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo commented Apr 15, 2023

When core lightning is asking the information about
the blockchain with getchaininfo command lightningd
know already the information about the min and max block height.

the problem is when we have a smarter Bitcoin backend that is able
to switch between different clients in some cases is helpful
give the information about current known height by lightningd and
pass it down to the plugin.

In this way, the plugin knows what is the correct known height from lightnind, and can
try to fix some problems if any exist.

This is particularly useful when you are syncing a new backend from scratch
like https://github.com/cloudhead/nakamoto and we avoid returning the
lower height from the known, and avoid the crash of core lightning.

With this information, the plugin can start to sync the chain and return
the answer back only when the chain is in sync with the current status of
lightning.

Used to fix the switch backend in https://github.com/coffee-tools/folgore

@vincenzopalazzo vincenzopalazzo force-pushed the macros/bitcoind branch 3 times, most recently from d4a05d2 to 1623860 Compare April 15, 2023 17:54
@vincenzopalazzo vincenzopalazzo changed the title WIP pass the current known block height lightningd: pass the current known block height down to the getchaininfo call Apr 15, 2023
@vincenzopalazzo vincenzopalazzo marked this pull request as ready for review April 15, 2023 17:56
@vincenzopalazzo vincenzopalazzo requested review from cdecker and rustyrussell and removed request for cdecker April 15, 2023 17:56
@vincenzopalazzo vincenzopalazzo added the rfc Request for Comments label Apr 15, 2023
@vincenzopalazzo vincenzopalazzo requested a review from cdecker April 15, 2023 17:57
@vincenzopalazzo vincenzopalazzo added this to the v23.08 milestone Apr 15, 2023
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Apr 15, 2023
This is build on top of this RFC from core lightning
ElementsProject/lightning#6181

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@vincenzopalazzo vincenzopalazzo marked this pull request as draft April 15, 2023 18:07
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Apr 15, 2023
This is build on top of this RFC from core lightning
ElementsProject/lightning#6181

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Apr 15, 2023
This is build on top of this RFC from core lightning
ElementsProject/lightning#6181

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Apr 16, 2023
This is build on top of this RFC from core lightning
ElementsProject/lightning#6181

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@vincenzopalazzo vincenzopalazzo marked this pull request as ready for review April 16, 2023 11:55
@vincenzopalazzo
Copy link
Contributor Author

Trivial Rebase

@vincenzopalazzo vincenzopalazzo changed the title lightningd: pass the current known block height down to the getchaininfo call [RFC] lightningd: pass the current known block height down to the getchaininfo call May 24, 2023
@rustyrussell
Copy link
Contributor

I think this is the wrong approach?

We should really handle blockheight below what we expect more gracefully. Possibly by just waiting for bitcoind to catch up?

@vincenzopalazzo
Copy link
Contributor Author

We should really handle blockheight below what we expect more gracefully. Possibly by just waiting for bitcoind to catch up?

Mh, yeah, if we want to fix this in core lightning, we can try waiting for bitcoind to sync up instead of failing. However, there are some corner cases that lead me to propose this change.

Bitcoin Core is extremely slow to sync up, so the question here is, how long should we wait? The time depends on various factors.
With this approach of informing the plugin about the height, in some cases, you can start the syncing but move the execution to another backend until the previous one is ready.

The problem I want to solve is that I don't want to be left in the dark when we run getchaininfo, and I want to have the opportunity to wait for the blockchain sync or decide to dispatch the request elsewhere.

In my specific case, I was integrating a BIP 157 compatible backend, so it was very convenient to use wait_height(..). It takes a maximum of a couple of minutes, in contrast to Bitcoin Core's syncing process.

But again, I am happy to work on a solution inside core lightning if you do not think my is the correct path

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, but also mention the new parameter in docs/PLUGINS.md?

lightningd/bitcoind.c Outdated Show resolved Hide resolved
plugins/bcli.c Outdated Show resolved Hide resolved
@vincenzopalazzo
Copy link
Contributor Author

Thanks @rustyrussell

Review applied and also commit docs updated to clarify why we are not
adding the wait height inside the core lightning itself to keep track of
these kinds of changes.

@vincenzopalazzo vincenzopalazzo force-pushed the macros/bitcoind branch 3 times, most recently from 9de6477 to 3fc8b3e Compare June 7, 2023 10:02
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack 3fc8b3e

When core lightning is asking the information about
the blockchain with `getchaininfo` command lightningd
know already the information about the min and max block height.

the problem is when we have a smarter Bitcoin backend that is able
to switch between different clients in some cases is helpful
give the information about current known height by lightningd and
pass it down to the plugin.

In this way, the plugin knows what is the correct known height from lightnind, and can
try to fix some problems if any exit.

This is particularly useful when you are syncing a new backend from scratch
like https://github.com/cloudhead/nakamoto and we avoid returning the
lower height from the known, and avoid the crash of core lightning.

With this information, the plugin can start to sync the chain and return
the answer back only when the chain is in sync with the current status of
lightningd.

Another reason to add this field and not wait the correct block in core
lightning itself is because Bitcoin Core is extremely slow to sync up,
so the question here is, how long should we wait? The time depends
on various factors.

With this approach of informing the plugin about the height, in some cases,
you can start the syncing but move the execution to another backend until
the previous one is ready.

The problem I want to solve is that I don't want to be left in the dark when
we run `getchaininfo`, and I want to have the opportunity to wait for
the blockchain sync or decide to dispatch the request elsewhere.

Changelog-Added: Pass the current known block height down to the getchaininfo call.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
@vincenzopalazzo
Copy link
Contributor Author

Added the changelog inside the commit (we miss the check in the CI, if the CI fails in some previous steps) and trivial rebase!

Ack f3bfd1d

@vincenzopalazzo vincenzopalazzo merged commit 85992e6 into ElementsProject:master Jun 13, 2023
@vincenzopalazzo vincenzopalazzo deleted the macros/bitcoind branch June 13, 2023 14:27
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Dec 28, 2023
Based on ElementsProject/lightning#6181 feature
to allow sync nakamoto.

Link: #54
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Dec 28, 2023
Based on ElementsProject/lightning#6181 feature
to allow sync nakamoto.

Link: #54
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Dec 28, 2023
Based on ElementsProject/lightning#6181 feature
to allow sync nakamoto.

Link: #54
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Dec 28, 2023
Based on ElementsProject/lightning#6181 feature
to allow sync nakamoto.

Link: #54
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
vincenzopalazzo added a commit to coffee-tools/folgore that referenced this pull request Dec 28, 2023
Based on ElementsProject/lightning#6181 feature
to allow sync nakamoto.

Link: #54
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfc Request for Comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants