mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-20 14:44:20 +01:00
sauron: best effort detection of invalid raw blocks
It happens that Esplora will send us trimmed blocks (both my personal instance and blockstream.info, fwiw). Try to detect it without parsing the entire block on our side. Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
committed by
Christian Decker
parent
dc3f691ea1
commit
c16c564c2c
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
from requests.packages.urllib3.util.retry import Retry
|
from requests.packages.urllib3.util.retry import Retry
|
||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
@@ -109,12 +110,25 @@ def getrawblock(plugin, height, **kwargs):
|
|||||||
}
|
}
|
||||||
|
|
||||||
block_url = "{}/block/{}/raw".format(plugin.api_endpoint, blockhash_req.text)
|
block_url = "{}/block/{}/raw".format(plugin.api_endpoint, blockhash_req.text)
|
||||||
|
while True:
|
||||||
block_req = fetch(block_url)
|
block_req = fetch(block_url)
|
||||||
if block_req.status_code != 200:
|
if block_req.status_code != 200:
|
||||||
return {
|
return {
|
||||||
"blockhash": None,
|
"blockhash": None,
|
||||||
"block": None,
|
"block": None,
|
||||||
}
|
}
|
||||||
|
# We may download partial/incomplete files for Esplora. Best effort to
|
||||||
|
# not crash lightningd by sending an invalid (trimmed) block.
|
||||||
|
# NOTE: this will eventually be fixed upstream, at which point we should
|
||||||
|
# just reuse the retry handler.
|
||||||
|
content_len = block_req.headers.get("Content-length")
|
||||||
|
if content_len is None:
|
||||||
|
break
|
||||||
|
if int(content_len) == len(block_req.content):
|
||||||
|
break
|
||||||
|
plugin.log("Esplora gave us an incomplete block, retrying in 2s",
|
||||||
|
level="error")
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"blockhash": blockhash_req.text,
|
"blockhash": blockhash_req.text,
|
||||||
|
|||||||
Reference in New Issue
Block a user