Skip to content

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

Merged
vincenzopalazzo merged 1 commit into
ElementsProject:masterfrom
vincenzopalazzo:macros/bitcoind
Jun 13, 2023
Merged

vincenzopalazzo merged 1 commit into
ElementsProject:masterfrom
vincenzopalazzo:macros/bitcoind

Conversation

@vincenzopalazzo

@vincenzopalazzo vincenzopalazzo commented Apr 15, 2023 •

Copy link
Copy Markdown
Collaborator

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 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 <[email protected]>
@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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
@vincenzopalazzo
vincenzopalazzo marked this pull request as ready for review April 16, 2023 11:55
@vincenzopalazzo

Copy link
Copy Markdown
Collaborator 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
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator 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

@rustyrussell rustyrussell left a comment

Copy link
Copy Markdown
Collaborator

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?

Comment thread lightningd/bitcoind.c Resolved
Comment thread plugins/bcli.c Resolved
@vincenzopalazzo

Copy link
Copy Markdown
Collaborator 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

@rustyrussell rustyrussell left a comment

Copy link
Copy Markdown
Collaborator

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 <[email protected]>
@vincenzopalazzo

Copy link
Copy Markdown
Collaborator 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants