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

Fix: getblockfrompeer was always requesting block from the first peer #8069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NicolasDorier
Copy link
Collaborator

@NicolasDorier NicolasDorier commented Feb 8, 2025

I noticed my core-lightning instance was completely stuck on a block in this issue.

Manually running getblockfrompeer on a peer having the block on which core lightning was stuck allowed it to carry on.

I suspect it is because you were always fetching the block from the first peer rather from the last in the list.
Tested this PR for myself, and it fixed the issue.

Additional notes: You seem to request a block even if the node doesn't have a "servicesnames" set to NETWORK, so it is quite slow... if for example the 10 first peers I am connected to are pruned, for every block, it asks to all of them.

Log before this PR: (note that the log is misleading, when it says from peer 4496, skip is was really just asking to the same peer all the time)

2025-02-08T10:15:03.937Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:04.956Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 4804, skip.
2025-02-08T10:15:04.964Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:05.972Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 4750, skip.
2025-02-08T10:15:05.982Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:06.991Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 4650, skip.
2025-02-08T10:15:06.998Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:08.005Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 4496, skip.
2025-02-08T10:15:08.014Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:09.022Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 3749, skip.
2025-02-08T10:15:09.030Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:10.037Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 2921, skip.
2025-02-08T10:15:10.044Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:11.051Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 1873, skip.
2025-02-08T10:15:11.058Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:12.065Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 1856, skip.
2025-02-08T10:15:12.076Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:13.085Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 649, skip.
2025-02-08T10:15:13.095Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:14.106Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 500, skip.
2025-02-08T10:15:14.115Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:15.124Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from peer 1, skip.
2025-02-08T10:15:15.129Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 from the bitcoin backend (maybe pruned).
2025-02-08T10:15:15.130Z DEBUG   plugin-bcli: asked all known peers about block 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8, retry
2025-02-08T10:15:15.130Z UNUSUAL plugin-bcli: bitcoin-cli -datadir=/etc/bitcoin -rpcclienttimeout=60 -rpcconnect=bitcoind getblock 00000000000000000001951c747fda95183cfb26cddaf50a037aedf6332967f8 0 exited with status 1

Log after this PR:

2025-02-08T14:04:23.443Z DEBUG   lightningd: Adding block 838098: 0000000000000000000352bb34f3af26b50f36d809598a67447ce0f72aa60a34
2025-02-08T14:04:23.494Z DEBUG   plugin-clnrest: Notification: {'block': {'hash': '0000000000000000000352bb34f3af26b50f36d809598a67447ce0f72aa60a34', 'height': 838098}, 'block_added': {'hash': '0000000000000000000352bb34f3af26b50f36d809598a67447ce0f72aa60a34', 'height': 838098}}
2025-02-08T14:04:23.514Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:24.534Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from peer 4878.
2025-02-08T14:04:24.541Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:25.550Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from peer 4804.
2025-02-08T14:04:25.559Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:26.566Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from peer 4650.
2025-02-08T14:04:26.575Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:27.583Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708 from peer 4496.
2025-02-08T14:04:27.778Z DEBUG   plugin-bcli: Log pruned 222 entries (mem 10513635 -> 2308079)
2025-02-08T14:04:27.910Z DEBUG   lightningd: Adding block 838099: 00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708
2025-02-08T14:04:27.994Z DEBUG   plugin-clnrest: Notification: {'block': {'hash': '00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708', 'height': 838099}, 'block_added': {'hash': '00000000000000000000aab360c3a5446cf3dbc8efd437796a91af0bb2aa8708', 'height': 838099}}
2025-02-08T14:04:28.016Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:29.038Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from peer 4878.
2025-02-08T14:04:29.046Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:30.056Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from peer 4804.
2025-02-08T14:04:30.064Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from the bitcoin backend (maybe pruned).
2025-02-08T14:04:31.073Z DEBUG   plugin-bcli: try to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from peer 4650.
2025-02-08T14:04:31.085Z DEBUG   plugin-bcli: failed to fetch block 00000000000000000000d7ee1cbc8f4df2cdd304c6100c250486c3c5f3405c90 from the bitcoin backend (maybe pruned).

@NicolasDorier NicolasDorier changed the title Fix: getblockfrompeer was always requesting block to the first peer Fix: getblockfrompeer was always requesting block from the first peer Feb 9, 2025
@endothermicdev
Copy link
Collaborator

Thanks for testing this out. Could you add a commit message with Changelog-Fixed:<fix description>? Our CI is particular about these things.

Copy link
Collaborator

@nepet nepet left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @NicolasDorier! About the slowness: I left a fixup comment in line 631 but never came back to it. I'll pick it up for the next release #8078!

ACK 0cefea4

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.

3 participants