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

build+lncfg: support pruned bitcoind backends #5154

Merged
merged 2 commits into from
Apr 8, 2021

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Mar 30, 2021

To minimally support lnd deployments connected to pruned nodes, we've extended our bitcoind RPC client with the ability to request blocks that the server has already pruned. This is done by connecting to the server's full node peers and querying them directly. The number of peers we connect to can be set through the new pruned-node-max-peers config option; it is configured with a default of 4 at the moment. Ideally, this is a capability supported by the server, though this is not yet possible with bitcoind.

Block caching is not done yet, but will be expected to roll out along with this feature as a separate PR to minimize bandwidth consumption.

Note that a lot of the diff is unrelated due to a name change within the updated btcd dependency that caused changes across several files in the codebase.

Depends on btcsuite/btcwallet#737.
Fixes #2997.

@Roasbeef Roasbeef added this to the 0.13.0 milestone Mar 31, 2021
@Roasbeef Roasbeef added the P1 MUST be fixed or reviewed label Mar 31, 2021
@Roasbeef
Copy link
Member

@wpaulino why do you see this only partially addresses #2997?

@wpaulino
Copy link
Contributor Author

#2997 suggests an alternative path where we control the pruning window instead, and I wasn't sure if we'd still want that. In any case, this branch should fully support pruned nodes by just fetching pruned blocks from peers.

@Roasbeef
Copy link
Member

Roasbeef commented Apr 1, 2021

Ah gotcha, yeah I think this approach is superior as it doesn't require lnd to be in lock-step with the full node. The pruned window route would only work if the node wasn't yet fully synced/pruned when lnd started up. In addition that design wouldn't actually support multiple lnd nodes connecting to a single pruned node, as their prune windows could get out of sync.

@Roasbeef
Copy link
Member

Roasbeef commented Apr 5, 2021

Needs a rebase!

@wpaulino
Copy link
Contributor Author

wpaulino commented Apr 5, 2021

@Roasbeef rebased, the branch now depends on #5047 in order to build.

@wpaulino wpaulino requested a review from Roasbeef April 5, 2021 22:51
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐊

@Roasbeef Roasbeef enabled auto-merge April 6, 2021 03:07
@Roasbeef
Copy link
Member

Roasbeef commented Apr 6, 2021

Weird how it isn't showing conflicts for the commits duplicated here vs the pubkey import stuff just merged in?

This is achieved by some recent work within the BitcoindClient enabling
it to retrieve pruned blocks from its server's peers.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 👑

@Roasbeef Roasbeef disabled auto-merge April 8, 2021 23:34
@Roasbeef Roasbeef merged commit c27e9ab into lightningnetwork:master Apr 8, 2021
@wpaulino wpaulino deleted the pruned-bitcoind-support branch April 8, 2021 23:39
@mandelmonkey
Copy link

Does this mean that LND will be able to validate channels that were created before the pruned data?

@wpaulino
Copy link
Contributor Author

Yes @mandelmonkey, it'll request pruned data from the bitcoind peers.

@vegardengen
Copy link
Contributor

What if the bitcoind peers are also pruned? All of them?

(Maybe I am overly paranoid)

@wpaulino
Copy link
Contributor Author

Good question, lnd will currently block on waiting for a full node connection if that's the case. Glancing at bitcoind's source, I didn't find any requirements for having at least N full node connections, so we wouldn't be able to enforce it at that level. It looks like we could use bitcoind's getnodeaddresses RPC to receive additional addresses the node isn't connected to, but this has yet to be implemented.

@mmilata
Copy link

mmilata commented Jun 17, 2021

Thanks for this useful feature! Is the section https://github.com/lightningnetwork/lnd/blob/master/docs/safety.md#pruned-bitcoind-node still true?

@wpaulino
Copy link
Contributor Author

@mmilata no that needs an update. It's now safe to run a pruned node regardless of how many blocks have been pruned.

Kixunil added a commit to Kixunil/lnd that referenced this pull request Jul 23, 2021
This removes a warning in the documentation saying that pruned nodes are
not supported. This is no longer the case as [pruning is supported since
0.13](lightningnetwork#5154). So instead it
now says pruning is supported and notes the version and implications of
pruning.
@kroese
Copy link

kroese commented Jun 13, 2022

@wpaulino Now that Bitcoin RPC supports getblockfrompeer would it be an option to use that instead of this custom logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 MUST be fixed or reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lnd: first class pruned node support
6 participants