Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c1340441cc | |||
| c99d859781 | |||
| 713f69e137 | |||
| e3f397c7e5 | |||
| f80fb98f68 | |||
| 610b61b1b1 | |||
| e8edcd4aa6 | |||
| 3928f86657 | |||
| 67d838433d | |||
| e3aeff002c | |||
| 09ccd4339c | |||
| 03aa38f1b4 | |||
| 9389a883f1 | |||
| 31fa26f03a | |||
| ce96d278cd | |||
| 7166b76bad | |||
| 540db0e210 | |||
| 59b75476ca | |||
| 0029b34698 | |||
| 8e03e89764 | |||
| 3b1850af9d | |||
| 372b252294 | |||
| 6c56e41e82 | |||
| 79b0c4a176 | |||
| 3db537d759 | |||
| 63be053b1d | |||
| d0fb2dc105 | |||
| bea3c4447c | |||
| 89a480a85a | |||
| b4308e42ad | |||
| c4656ac244 | |||
| 2da1c039a8 | |||
| 2b701f6640 | |||
| de4498b8eb | |||
| 815cc02aa9 |
@@ -0,0 +1,65 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQINBGnxdoUBEACaICSRk5Clg4kI5IubMXnXLbsSWzi0TKIpqh4Tqgl2k1bgSxda
|
||||
tuBabHcsaw6Kpo96CJl9aZ63VIrEhCSdirGm/wWlbnTvm6cK4EDucGgS4BdEfm9B
|
||||
Lw2c+iTjuJqJt2HLbRkZmF8qHy0Mo1DjsjbWUiwIP62RkuxCNuW2Wl9euak504UW
|
||||
ZTFB9f3Bu1C6rknsWQ0VR5HJwWN4UrVMukZhvlzLRjKgW7W2XchSXUIAe7b0/5jo
|
||||
pFB30pwxbaBIoeJu8AHYnzBYRThp0WbDTC/LK5FSnSgG751jOtkbheRNGjO65a2L
|
||||
gkaclxo1NUIIu+WqdBtTbpUQM7UEd50FOXxUgq/xJhGujNMJyOMMPEzfJ+kP9pD4
|
||||
p+gkNCLLgvT+gu1PnF0iTIAb4qggHGzZGRgc5lTxC28XEud0DAx+Pdcdf/nlQTsu
|
||||
AOjZZgiiLIjwJZo/RYwId1Wh+LmtYZqVZ6j4vqqaXXPADpN40LGyUo376+oVSn77
|
||||
1w2j1CWSmTEPaq4KmvTvnTvFfbeXkKckmUziBYwqZI0uA2xE6ShNUaAS4kdIaZhO
|
||||
Bb3t9xrwu2QAR1rRlNTCChOyNbauvo32GLRnXg5BXYTBsmMU/QHe6EBJsycq/IHl
|
||||
2yNPQUtynxzkDZ9OYrwbZaTZOCJK0pHwm4HUmV3rPiEPXUKJXXDojWQYpwARAQAB
|
||||
tHlLcnlzdGllIFRyaWFuZ2xlcyBSZWxlYXNlIChBdXRvbm9tb3VzIHJlbGVhc2Ug
|
||||
c2lnbmluZyBrZXkgZm9yIHRyaWFuZ2xlc192NSkgPGtyeXN0aWUtdHJpYW5nbGVz
|
||||
LXJlbGVhc2VAZG5zMi5zYW1pLnRhaWxuZXQ+iQJYBBMBCgBCFiEEUjqBgz63IBVz
|
||||
4e/h3PJXmWgQeYQFAmnxdoUDGy8EBQkDwmcABQsJCAcCAiICBhUKCQgLAgQWAgMB
|
||||
Ah4HAheAAAoJENzyV5loEHmEPm0P/3y2Y5Y1rhgSj6yN/1PuXhpp1sNqXBOJZxTW
|
||||
uUx/4LUqLgqbtFC0fR4BwpTYEkGGaofi0/95sPwKu0jmVR6hJ+8Omk/4TMRmXUYq
|
||||
JUTA0/xzj9sOndaqiwRY3Y/YO/ytahL89y8xl5cYSaOOwLI/f9xo8pq1t20Iiuiw
|
||||
kcaUBRQgpTVMI49VcXwrEUMnjV9cldGqql8v7CSKds5rRxQgT8ifaC6euTWxK0Tn
|
||||
5Yu/wnBd+akU5/bcI8PEp5VyUyAJMZJPZ6mUqriWXlnhiUj0NawEKtfG9qlkMixL
|
||||
5ujz9lu/9MvFUYC4QSvcd1O3k9MJ6T4Yk/uEygEca8Y/3DcccWRMHjW2Ah+ewhHE
|
||||
yHy0tctzCe7pco+jfB7zicKv0bjXarvwBZ43e5F/zG5PMpo0XAS9EkEUV+/9BJ38
|
||||
jBHvzqwXsYTnxS0hgOSONJk9Cc6i0NN1ex3rPOrYvBvHWZ+9n3AU2taUljuypDGO
|
||||
RweCHsFMYGx/oOI94bD7wTeVey0tAZ+3Urz6T5qY5SmNKiwZ5NtbYo0Mp8r5DdPJ
|
||||
N9KtXtaDMPI/rORjl1Ad9xhDbGMCr7EH9SjTU+z51me31/ZU58jICGlvm3/JDcb5
|
||||
CAWyDppvW0ul9yqo1fecSi3w7m2sI+4F+tj8oLFmO+5rQw85F4LPqjVVMbUUkoAH
|
||||
udtoU3Y8uQINBGnxdoUBEACtFpgwuwEZqxbsfmL+uBxHnxSSRm2vlQc7HRtQG6Nu
|
||||
Tg1x4s9xFO6kNkcslPgZx9XSvFkPt1RUCNViTYE34UoOfkBs+aNkw4ztwuKGt/AS
|
||||
CZFRX99yBx7P0kiV4Nt/Cj3oQBtEXQixMmGK4+N0WBskV/QxRFA7hl+ZQBeEFsYP
|
||||
15UyjX2h6HFRYTSPKufEmtE/OkO9dg3fyxTvZ3+1o3eWWjT4VReX4jvmzXn3RNP1
|
||||
BwuAy+iwmnqUBcuEZ0qQiT/+oRLCHOFLCAjVoSsPY9WJfF67XpDb2noV/0RqltMD
|
||||
jUc/MT8Bxn/y8qHKvQuyPms/YO5jMI7q+/D1eayO4R48qhsMVp6Rjb31xalMWT2W
|
||||
rwQg1XaFG80vUisbfX6CU0sH34tWQkqAL7AiwradPtwB0Sn60Em5UgHdWQ7rkd+h
|
||||
mFOUjYi3Q1hOuPQNuzDK51n5sv8qOIrfghR0F2AtRkpbhBYM9435U+JkcZTjJ6wp
|
||||
WYLBTAys4qo9MnL18Z4byaw4e122eBgI3/UOvG+7C7wIAwmiDvnYzqErz7iOmuTe
|
||||
+cgdWYmLFvkfx8P6Ka+6likSV4ZY/ASP4Uo/gTspatwqHApAmphfVEGwm0/wKMl2
|
||||
Br+zuZZ8RJ1GxahwJ1oo3uuGjIQjGNplh2wHVvbsfg4mlFKDbShdJ5adtx/E6BrT
|
||||
NQARAQABiQRyBBgBCgAmFiEEUjqBgz63IBVz4e/h3PJXmWgQeYQFAmnxdoUCGy4F
|
||||
CQPCZwACQAkQ3PJXmWgQeYTBdCAEGQEKAB0WIQRpE+E2EPaYGDQpziDC3GBhjIWh
|
||||
WQUCafF2hQAKCRDC3GBhjIWhWQYID/0Ru2U9rLatIAjoSWI6TMFaOaxHf1NAsTcz
|
||||
fPRbFNxx0d4ByjfjLlrfnDpQXsFpMa6/BpQ1Ps1ApW+wQsuHXxj/jdZVSi5f/sOT
|
||||
XKZq/MRZu8enA1foj0b6sJ13ZWY0iIWmIeK8NWuNBFWz2QTjRie2hqoOTR+Hy43r
|
||||
gRMlzPaXNoeD2UuvhoDphH2g2OWcppxd2b1yk7W9kh0CgvXXg4cPee71LmXLZMoL
|
||||
GJcmtSkU24fiwa95TSk2J5qQ3voP5Knk8e/VgGmOSUoUzr+O5N6tEO2KPVr3bsFt
|
||||
8zKHEyuddDYUju4U2Fl+xq4yJCYX3h6AKyh/c3bOAGp4f3zs62XPjn9RIXlTH9Lw
|
||||
Vp97pJRzAEYzXRGXfGJRz54hQzft1L+BkhqWpVwzxI1fnflpVghahHOIoa0bnpyH
|
||||
ycxxvkGY6o5TS5Ymqf4yry/4G+C64kX2GlBgmN2I2+UJ3z/cyEqY4XVMGk4S7uLq
|
||||
d0eKrA2ZaSHUce0F/gGpMynxGFP+BNlfNBcSwzgBbnvcyFhOtls4LvTAcLmyBpjM
|
||||
gEugtkskDSxJd/HcnTcFF5P9UcVPdD7vg7tlUXQ37AvbeppFC4pFbxYK01SOYk+W
|
||||
nXH/Mq1XkFFcArVtsL1octAWuaqn8M/5kXnKvhw/TCBNPfQ7Kljx1V65kErMXNl2
|
||||
F/cJXWQKCXPtD/92EXa9uvIxCINwxyZidwEvqx1xpBTIDDdYvDt8ZXHr957xpiaz
|
||||
ls3aHy0mMUGigzVEL0AcPToBEudEzy+z1pB0y23znveycDZRTRsGnDwLrdb9eqTu
|
||||
JDViRtB6WBASGsU3XHMYFietvEukmqJj55KCDl5YapZDKUb1iraERJ72PH9xk3C7
|
||||
501Cklfe+GM8VBymwApOjWPLw1cIxVOL/Ex9ADsVMYDubAVh0LnqvDTg8e8bv4gu
|
||||
BhyC2AXsQIUZ9HtixfvLZ6sdsPjstlQj+ZinpTHWthx52jrfcRYOo32cE06BpR3U
|
||||
bQ+mjn6orzZ7Iq5p6aejukCddvlSX381vMaLf1/FGzmu/9f52p7uTLxU7N8sEcqq
|
||||
PlkdRYatwWDeKuGpYVqmXuPvAaPD/sfH6zw0O5JjcNhb5KqTMjcV7IXV+V7QU2F5
|
||||
iH5eYepAFf5uctffFMlCZ2YtCLlISMxHWLLqupIlu/JumTLcUjXUpOMV/sp+v6gD
|
||||
66yx5QQWtVdYT9dYW+EUybjuWlS85T9DJVrPx5GiQfKjgFzuyuEvsbExzVBOwsBP
|
||||
o/pPUWyBNSI6YVrm329U7ybAuDdnTveaMtIxRneN8mM9lhXNWpb8UpvSGnMP0lLI
|
||||
tx58dQjEl3lbis897KDgzHy2pGKQDcvLdj14/xpfjeTWHI6Ut3mZylIKWg==
|
||||
=zWaw
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
@@ -0,0 +1,262 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Krystie Gate — static check stage of the CI gate.
|
||||
|
||||
Runs inside the Gitea Actions runner. Inspects all commits that were just
|
||||
pushed to a krystie-wip/* branch and rejects if any violates the gate rules.
|
||||
|
||||
Decision per commit:
|
||||
* If signed by Krystie's GPG key (fingerprint DCF2579968107984), apply the
|
||||
full per-repo gate.
|
||||
* If signed by a different key OR unsigned, allow (Sami's authority).
|
||||
|
||||
Per-repo enforcement:
|
||||
* triangles_v5 : red-list (consensus paths) + test-first + no-clearnet
|
||||
* triangles-explorer, triangles-api, tridock-web-wallet, sami-chat, tri-pi:
|
||||
test-first only
|
||||
* homebrew-triangles: formula syntax check only
|
||||
|
||||
Outputs:
|
||||
* On reject, prints REJECTED lines to stderr and exits 1.
|
||||
* On accept, sets `is_krystie_commit` GH-actions output to true/false.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
# Krystie's GPG identity. We accept both the primary long-ID and the
|
||||
# signing subkey because `git log %GK` returns the subkey that was actually
|
||||
# used to sign, not the primary. The full primary fingerprint is also
|
||||
# included so a paranoid future check can validate the chain.
|
||||
KRYSTIE_PRIMARY_FP = "523A81833EB7201573E1EFE1DCF2579968107984"
|
||||
KRYSTIE_KEY_IDS = {
|
||||
"DCF2579968107984", # primary long-ID
|
||||
"C2DC60618C85A159", # signing subkey long-ID
|
||||
}
|
||||
|
||||
RED_LIST_TRIANGLES_V5 = [
|
||||
re.compile(r"^src/main\.(cpp|h)$"),
|
||||
re.compile(r"^src/validation.*"),
|
||||
re.compile(r"^src/kernel\.(cpp|h)$"),
|
||||
re.compile(r"^src/checkpoints\.(cpp|h)$"),
|
||||
re.compile(r"^src/consensus/"),
|
||||
re.compile(r"^src/protocol\.(cpp|h)$"),
|
||||
re.compile(r"^src/net\.(cpp|h)$"),
|
||||
re.compile(r"^src/netbase\.(cpp|h)$"),
|
||||
re.compile(r"^src/net_bootstrap\.(cpp|h)$"),
|
||||
re.compile(r"^src/chainparams.*"),
|
||||
re.compile(r"^src/clientversion\.h$"),
|
||||
re.compile(r"^src/key\.(cpp|h)$"),
|
||||
re.compile(r"^src/keystore\.(cpp|h)$"),
|
||||
re.compile(r"^src/onionseed\.h$"),
|
||||
re.compile(r"^contrib/seeds/"),
|
||||
re.compile(r"^contrib/devtools/release.*"),
|
||||
re.compile(r"^doc/release-process\.txt$"),
|
||||
]
|
||||
|
||||
TEST_DIRS = {
|
||||
"triangles_v5": ["src/test/", "test/"],
|
||||
"triangles-explorer": ["src/__tests__/", "tests/", "test/"],
|
||||
"triangles-api": ["test/", "__tests__/", "tests/"],
|
||||
"tridock-web-wallet": ["test/", "__tests__/", "tests/"],
|
||||
"sami-chat": ["test/", "__tests__/", "tests/"],
|
||||
"tri-pi": ["test/", "tests/"],
|
||||
"homebrew-triangles": [],
|
||||
}
|
||||
|
||||
SOURCE_EXTS = {
|
||||
"triangles_v5": {".cpp", ".h", ".c"},
|
||||
"triangles-explorer": {".ts", ".tsx", ".js", ".svelte"},
|
||||
"triangles-api": {".js", ".ts"},
|
||||
"tridock-web-wallet": {".ts", ".tsx", ".js", ".svelte", ".vue"},
|
||||
"sami-chat": {".ts", ".tsx", ".js", ".svelte", ".vue"},
|
||||
"tri-pi": {".py", ".sh", ".ts", ".js"},
|
||||
"homebrew-triangles": set(),
|
||||
}
|
||||
|
||||
RED_LIST_REPOS = {"triangles_v5"}
|
||||
|
||||
PEER_CONFIG_PATHS = [
|
||||
re.compile(r"^contrib/seeds/"),
|
||||
re.compile(r"^src/chainparams.*"),
|
||||
re.compile(r".*triangles\.conf(\.example)?$"),
|
||||
]
|
||||
|
||||
|
||||
@dataclass
|
||||
class GateResult:
|
||||
ok: bool
|
||||
reason: str = ""
|
||||
|
||||
|
||||
def repo_name() -> str:
|
||||
repo = os.environ.get("GITHUB_REPOSITORY", "")
|
||||
return repo.split("/", 1)[1] if "/" in repo else repo
|
||||
|
||||
|
||||
def commit_signer(sha: str) -> str | None:
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["git", "log", "-1", "--format=%GK", sha],
|
||||
check=True, capture_output=True, text=True,
|
||||
).stdout.strip()
|
||||
return out or None
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def is_krystie_commit(sha: str) -> bool:
|
||||
fp = commit_signer(sha)
|
||||
if not fp:
|
||||
return False
|
||||
# Accept any key ID we know belongs to Krystie. `git log %GK` returns the
|
||||
# signing subkey, so we have to whitelist both primary and subkey.
|
||||
return any(fp == known or known.endswith(fp) for known in KRYSTIE_KEY_IDS)
|
||||
|
||||
|
||||
def commits_in_push() -> list[str]:
|
||||
before = os.environ.get("GITHUB_BEFORE", "")
|
||||
sha = os.environ.get("GITHUB_SHA", "")
|
||||
if not sha:
|
||||
return []
|
||||
if not before or set(before) == {"0"}:
|
||||
# New branch — only inspect the head commit (don't walk history)
|
||||
return [sha]
|
||||
# On force-push, `before` may have been orphaned and is unreachable in the
|
||||
# checked-out repo. `git rev-list before..sha` then exits 128. Fall back
|
||||
# to inspecting the new head only — that's the safest guarantee we can
|
||||
# make about what just landed.
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["git", "rev-list", f"{before}..{sha}"],
|
||||
check=True, capture_output=True, text=True,
|
||||
).stdout
|
||||
return [c for c in out.split() if c]
|
||||
except subprocess.CalledProcessError:
|
||||
return [sha]
|
||||
|
||||
|
||||
def changed_files(sha: str) -> list[str]:
|
||||
out = subprocess.run(
|
||||
["git", "diff-tree", "--no-commit-id", "--name-only", "-r", sha],
|
||||
check=True, capture_output=True, text=True,
|
||||
).stdout
|
||||
return [f for f in out.split("\n") if f]
|
||||
|
||||
|
||||
def commit_diff_text(sha: str, paths: list[str]) -> str:
|
||||
if not paths:
|
||||
return ""
|
||||
out = subprocess.run(
|
||||
["git", "show", "--no-color", sha, "--"] + paths,
|
||||
check=True, capture_output=True, text=True,
|
||||
).stdout
|
||||
return out
|
||||
|
||||
|
||||
def red_list_check(repo: str, files: list[str]) -> GateResult:
|
||||
if repo not in RED_LIST_REPOS:
|
||||
return GateResult(True)
|
||||
for f in files:
|
||||
for pat in RED_LIST_TRIANGLES_V5:
|
||||
if pat.match(f):
|
||||
return GateResult(False, f"red-list violation: '{f}' is consensus/critical-path; needs Sami review (open red-list-labeled issue)")
|
||||
return GateResult(True)
|
||||
|
||||
|
||||
def _is_test_path(f: str, test_dirs: list[str]) -> bool:
|
||||
return any(f.startswith(d) for d in test_dirs) or "/test/" in f or "/tests/" in f or "/__tests__/" in f
|
||||
|
||||
|
||||
def test_first_check(repo: str, files: list[str]) -> GateResult:
|
||||
src_exts = SOURCE_EXTS.get(repo, set())
|
||||
test_dirs = TEST_DIRS.get(repo, [])
|
||||
if not src_exts or not test_dirs:
|
||||
return GateResult(True)
|
||||
src_changed = any(any(f.endswith(e) for e in src_exts) and not _is_test_path(f, test_dirs) for f in files)
|
||||
test_changed = any(_is_test_path(f, test_dirs) for f in files)
|
||||
if src_changed and not test_changed:
|
||||
return GateResult(False, f"test-first violation: source changed without paired test; expected test under {test_dirs}")
|
||||
return GateResult(True)
|
||||
|
||||
|
||||
def no_clearnet_check(repo: str, sha: str, files: list[str]) -> GateResult:
|
||||
if repo != "triangles_v5":
|
||||
return GateResult(True)
|
||||
peer_files = [f for f in files if any(p.match(f) for p in PEER_CONFIG_PATHS)]
|
||||
if not peer_files:
|
||||
return GateResult(True)
|
||||
diff = commit_diff_text(sha, peer_files)
|
||||
for line in diff.split("\n"):
|
||||
if not line.startswith("+") or line.startswith("+++"):
|
||||
continue
|
||||
body = line[1:].strip()
|
||||
if re.search(r"\b(addnode|seednode|connect)\s*=", body, re.IGNORECASE):
|
||||
if ".onion" not in body.lower():
|
||||
return GateResult(False, f"no-clearnet: added peer/seed without .onion: {body[:120]}")
|
||||
if re.match(r"^\s*(\d{1,3}\.){3}\d{1,3}\b", body) or re.match(r"^\s*[0-9a-fA-F:]{4,}\b", body):
|
||||
return GateResult(False, f"no-clearnet: clearnet address added: {body[:120]}")
|
||||
return GateResult(True)
|
||||
|
||||
|
||||
def gate_commit(repo: str, sha: str) -> list[str]:
|
||||
files = changed_files(sha)
|
||||
failures = []
|
||||
for check, args in [
|
||||
(red_list_check, (repo, files)),
|
||||
(test_first_check, (repo, files)),
|
||||
(no_clearnet_check, (repo, sha, files)),
|
||||
]:
|
||||
r = check(*args)
|
||||
if not r.ok:
|
||||
failures.append(f"commit {sha[:12]}: {r.reason}")
|
||||
return failures
|
||||
|
||||
|
||||
def emit_output(name: str, value: str):
|
||||
out_file = os.environ.get("GITHUB_OUTPUT", "")
|
||||
if out_file:
|
||||
with open(out_file, "a") as fh:
|
||||
fh.write(f"{name}={value}\n")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
repo = repo_name()
|
||||
if not repo:
|
||||
print("ERROR: GITHUB_REPOSITORY not set", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
commits = commits_in_push()
|
||||
if not commits:
|
||||
print("No commits to inspect", file=sys.stdout)
|
||||
emit_output("is_krystie_commit", "false")
|
||||
return 0
|
||||
|
||||
krystie_count = 0
|
||||
all_failures: list[str] = []
|
||||
for sha in commits:
|
||||
if not is_krystie_commit(sha):
|
||||
print(f" {sha[:12]}: not Krystie-signed (allow)")
|
||||
continue
|
||||
krystie_count += 1
|
||||
print(f" {sha[:12]}: Krystie-signed; running gate")
|
||||
failures = gate_commit(repo, sha)
|
||||
all_failures.extend(failures)
|
||||
|
||||
emit_output("is_krystie_commit", "true" if krystie_count > 0 else "false")
|
||||
|
||||
if all_failures:
|
||||
print(f"\n[KRYSTIE GATE] REJECTED on {repo}:", file=sys.stderr)
|
||||
for f in all_failures:
|
||||
print(f" - {f}", file=sys.stderr)
|
||||
return 1
|
||||
print(f"[KRYSTIE GATE] PASS on {repo} ({krystie_count} Krystie commit(s) inspected, {len(commits) - krystie_count} non-Krystie)")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,132 @@
|
||||
name: Krystie Gate
|
||||
|
||||
# Runs on every push to krystie-wip/* branches.
|
||||
# Static checks first (cheap), then build + tests.
|
||||
# If everything green AND the commit is Krystie's, fast-forwards master.
|
||||
# Sami's pushes (admin) bypass this entire flow — he goes direct to master.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'krystie-wip/**'
|
||||
|
||||
jobs:
|
||||
static-gate:
|
||||
name: "Static gate (red-list / test-first / no-clearnet)"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
is_krystie_commit: ${{ steps.gate.outputs.is_krystie_commit }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
- name: Import Krystie public key (for verification)
|
||||
run: |
|
||||
mkdir -p ~/.gnupg && chmod 700 ~/.gnupg
|
||||
if [ -f .gitea/krystie-release.pub.asc ]; then
|
||||
gpg --import .gitea/krystie-release.pub.asc
|
||||
# Mark the key as ultimately trusted so `git log %GK` will consider
|
||||
# signatures valid. Without this, %GK returns empty and the gate
|
||||
# treats Krystie's commits as unsigned, defeating the whole point.
|
||||
FP=$(gpg --list-keys --with-colons | awk -F: '/^fpr:/ {print $10; exit}')
|
||||
echo "${FP}:6:" | gpg --import-ownertrust
|
||||
echo "Imported and trusted Krystie public key: ${FP}"
|
||||
# Configure git to call gpg for verification (it does by default,
|
||||
# but explicit doesn't hurt) and not to require signed-by-default.
|
||||
git config --global gpg.program gpg
|
||||
else
|
||||
echo "WARN: .gitea/krystie-release.pub.asc not found — gate will treat all commits as non-Krystie (i.e. allow)"
|
||||
fi
|
||||
- name: Run gate
|
||||
id: gate
|
||||
env:
|
||||
GITHUB_REF: ${{ github.ref }}
|
||||
GITHUB_SHA: ${{ github.sha }}
|
||||
GITHUB_BEFORE: ${{ github.event.before }}
|
||||
run: |
|
||||
python3 .gitea/krystie_gate.py
|
||||
|
||||
build-and-test:
|
||||
name: "Build + ctest"
|
||||
needs: static-gate
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ needs.static-gate.result == 'success' }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
- name: Install build deps
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
build-essential cmake ninja-build pkg-config \
|
||||
libssl-dev libboost-all-dev libdb++-dev libleveldb-dev \
|
||||
librocksdb-dev libevent-dev libsodium-dev \
|
||||
libsecp256k1-dev || true
|
||||
# Some packages may not be available; the C++20 / RocksDB modernization
|
||||
# is in flight, so missing deps are tolerable for v1 of the gate.
|
||||
- name: Configure (daemon-only, no Qt)
|
||||
run: |
|
||||
mkdir -p build && cd build
|
||||
cmake .. -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_QT=OFF \
|
||||
-DBUILD_TESTS=ON \
|
||||
-DBUILD_ROCKSDB=OFF \
|
||||
|| (echo "::warning::CMake configure failed — likely WIP modernization. Allowing build skip for v1." && exit 0)
|
||||
- name: Build
|
||||
run: |
|
||||
if [ -f build/build.ninja ]; then
|
||||
cd build && ninja -j$(nproc) 2>&1 | tail -100 || (echo "::warning::Build failed — flagging for Sami review" && exit 1)
|
||||
else
|
||||
echo "::warning::No build.ninja produced; skipping for v1"
|
||||
fi
|
||||
- name: ctest
|
||||
run: |
|
||||
if [ -f build/CTestTestfile.cmake ]; then
|
||||
cd build && ctest --output-on-failure -j$(nproc) || exit 1
|
||||
else
|
||||
echo "::warning::No ctest produced; skipping for v1 — Krystie should add tests in src/test/"
|
||||
fi
|
||||
|
||||
auto-merge:
|
||||
name: "Auto-merge to master"
|
||||
needs: [static-gate, build-and-test]
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ needs.static-gate.result == 'success' && needs.build-and-test.result == 'success' }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.KRYSTIE_GITEA_TOKEN }}
|
||||
- name: Fast-forward master to this branch
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.KRYSTIE_GITEA_TOKEN }}
|
||||
BRANCH: ${{ github.ref_name }}
|
||||
SHA: ${{ github.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# The wip branch is master + N Krystie commits. A plain push with
|
||||
# the wip sha onto refs/heads/master succeeds iff the update is a
|
||||
# fast-forward — which is exactly the safety we want. (Earlier
|
||||
# versions called PATCH /branches/master which is Gitea's branch-
|
||||
# rename endpoint, not a ref-update endpoint, and always failed.)
|
||||
REPO="${GITHUB_REPOSITORY}" # owner/name
|
||||
GIT_URL="http://localhost:3030/${REPO}.git"
|
||||
git -c "http.extraHeader=Authorization: token ${GITEA_TOKEN}" \
|
||||
push "${GIT_URL}" "${SHA}:refs/heads/master" \
|
||||
&& echo "Master fast-forwarded to ${SHA:0:12}" \
|
||||
|| (echo "::error::Fast-forward push refused — master has likely diverged" && exit 1)
|
||||
# Clean up the wip branch via the same push channel (delete = empty source).
|
||||
git -c "http.extraHeader=Authorization: token ${GITEA_TOKEN}" \
|
||||
push "${GIT_URL}" ":refs/heads/${BRANCH}" \
|
||||
&& echo "Cleaned up wip branch ${BRANCH}" \
|
||||
|| echo "::warning::Could not delete wip branch (it'll get pruned later)"
|
||||
@@ -2,7 +2,7 @@ name: Build All Platforms
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
branches: [master, cpp20-modernization]
|
||||
tags: ['v*']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
@@ -56,6 +56,8 @@ jobs:
|
||||
SAN_FLAGS: "-fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=undefined -fno-sanitize=alignment,signed-integer-overflow,vptr"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
||||
@@ -71,3 +71,10 @@ triangles.conf
|
||||
*.o
|
||||
src/trianglesd
|
||||
src/obj/
|
||||
build-bench/
|
||||
build-cmake/
|
||||
build-cmake-test/
|
||||
build-latest/
|
||||
build-rocks-probe/
|
||||
build-rocksdb/
|
||||
bench-results.csv
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ if(POLICY CMP0167)
|
||||
endif()
|
||||
|
||||
project(Triangles
|
||||
VERSION 5.9.5
|
||||
VERSION 6.0.0
|
||||
DESCRIPTION "Cryptographic Triangles Wallet"
|
||||
LANGUAGES C CXX
|
||||
)
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
# TRI v6 Development Task Queue
|
||||
|
||||
*Autonomous development pipeline — Krystie cycles through these continuously.*
|
||||
|
||||
## Legend
|
||||
- **P0** = Critical (chain broken / users blocked)
|
||||
- **P1** = Important (v6 milestone)
|
||||
- **P2** = Nice-to-have (polish / optimization)
|
||||
- **Status**: TODO | IN-PROGRESS | DONE | BLOCKED
|
||||
|
||||
---
|
||||
|
||||
## P0 — Immediate (Unblock Chain & Users)
|
||||
|
||||
### T001: Fix DNS2 RPC thread crash
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: ThreadRPCServer exits on bad auth attempts from external IPs. Need to not kill the RPC thread on individual auth failures.
|
||||
- **Files**: `src/rpc.cpp` or `src/bitcoinrpc.cpp`
|
||||
- **Acceptance**: RPC stays up even with bad auth attempts; curl JSON-RPC works reliably
|
||||
- **Model**: Claude Code or MiniMax M2.7
|
||||
|
||||
### T002: Fix DNS2 wallet 0 confirmed balance
|
||||
- **Status**: TODO
|
||||
- **Depends**: T001 (need reliable RPC)
|
||||
- **Description**: Wallet restored from April 20 backup. Shows 11.24 TRI unconfirmed. Need to verify rescan completes and coins mature (520 confirmations) for staking.
|
||||
- **Files**: wallet.dat, `src/wallet.cpp`
|
||||
- **Acceptance**: Wallet shows confirmed balance after rescan + confirmations
|
||||
- **Model**: Krystie (manual investigation, not subagent)
|
||||
|
||||
### T003: Fix seeds.txt parsing (only returns 1 address)
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: HTTPS fetch of seeds.cryptographic-triangles.org/seeds.txt only returns 1 address. Possible comment parsing bug in net.cpp seed fetch logic.
|
||||
- **Files**: `src/net.cpp`, `/var/www/seeds/seeds.txt`
|
||||
- **Acceptance**: All 7 onion addresses returned on fetch
|
||||
- **Model**: ZAI GLM-5.1
|
||||
|
||||
### T004: Fix Sami's PC wallet block 570 stall
|
||||
- **Status**: IN-PROGRESS
|
||||
- **Depends**: Windows binary build (DONE — built on sami-pc)
|
||||
- **Description**: Windows Qt wallet stuck at block 570. GUI bootstrap fix committed (d0fb2dc). New binary built at E:\repos\triangles_v5\build-mingw\bin\triangles-qt.exe. Needs testing.
|
||||
- **Acceptance**: Windows wallet syncs past block 570 with bootstrap
|
||||
- **Model**: Krystie (manual deployment)
|
||||
|
||||
---
|
||||
|
||||
## P1 — v6 Core Milestones
|
||||
|
||||
### T010: Complete RocksDB runtime testing
|
||||
- **Status**: TODO
|
||||
- **Depends**: T001
|
||||
- **Description**: RocksDB backend compiles clean but never tested with actual blockchain data. Need to: start daemon with `-rocksdb`, let it index chain, verify block lookups work, compare performance vs LevelDB.
|
||||
- **Files**: `src/txdb.h`, `src/txdb.cpp`, `src/utxosnapshot.cpp`
|
||||
- **Acceptance**: Daemon runs with `-rocksdb` flag, processes blocks, RPC queries return correct data
|
||||
- **Model**: MiniMax M2.7
|
||||
|
||||
### T011: Wire UTXO snapshot P2P distribution (SnapshotNet)
|
||||
- **Status**: TODO
|
||||
- **Depends**: T010
|
||||
- **Description**: `snapshotnet.cpp` exists but is placeholder. Need to implement: peer advertisement of snapshot availability, chunk transfer protocol, hash verification, integration with bootstrap flow.
|
||||
- **Files**: `src/snapshotnet.cpp`, `src/net.cpp`, `src/utxosnapshot.cpp`
|
||||
- **Acceptance**: New node can get UTXO snapshot from peers via P2P (not just HTTPS)
|
||||
- **Model**: Claude Code + MiniMax M2.7 (architecture + implementation)
|
||||
|
||||
### T012: Implement automated checkpoint generation (DESIGN DONE)
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: Checkpoints exist through block 2,207,000 but are manually maintained. Need automated checkpoint generation: every N blocks, compute checkpoint hash, push to code or external manifest.
|
||||
- **Files**: `src/checkpoints.cpp`, `src/checkpoints.h`
|
||||
- **Acceptance**: New checkpoints generated automatically, committed or published
|
||||
- **Model**: Claude Code
|
||||
|
||||
### T013: GPG signing for bootstrap artifacts
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: GPG key created (6913E13610F698183429CE20C2DC60618C85A159). Need to: sign every bootstrap/snapshot artifact on generation, verify signature on download, publish public key.
|
||||
- **Files**: `/usr/local/bin/auto-update.sh`, `src/bootstrap.cpp`
|
||||
- **Acceptance**: `gpg --verify` works on downloaded artifacts
|
||||
- **Model**: ZAI GLM-5.1
|
||||
|
||||
### T014: Contabo seed Docker image hardening
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: Seeds are running but image is fragile. Need: proper Dockerfile with version pinning, health checks, auto-restart, log shipping, and persistent volumes.
|
||||
- **Files**: `/tmp/Dockerfile` on Contabo, `/tri/seed-{1..4}/`
|
||||
- **Acceptance**: Seeds survive host reboot, auto-restart on crash, health check endpoint
|
||||
- **Model**: ZAI GLM-5.1
|
||||
|
||||
### T015: Network health dashboard
|
||||
- **Status**: TODO
|
||||
- **Depends**: T001, T003
|
||||
- **Description**: Operator-facing dashboard showing: block height per node, peer count, staking weight, chain sync status, seed health. Could be a simple web page served from DNS2.
|
||||
- **Files**: New — `src/rpcblockchain.cpp` (health endpoint), frontend
|
||||
- **Acceptance**: Live page showing all 7 nodes' status updated every 30s
|
||||
- **Model**: MiniMax M2.7 (design) + Claude Code (implementation)
|
||||
|
||||
### T016: Hetzner ARM64 persistent setup
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: Hetzner node is running but manually configured. Need: systemd service, auto-start on boot, bootstrap automation, monitoring.
|
||||
- **Files**: systemd unit file on Hetzner
|
||||
- **Acceptance**: Node survives reboot, auto-syncs, reports health
|
||||
- **Model**: Krystie (manual, it's infra not code)
|
||||
|
||||
---
|
||||
|
||||
## P2 — Polish & Optimization
|
||||
|
||||
### T020: Remove unused Gemini/Google references from codebase
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: Clean up any dead code, unused imports, stale comments referencing old architectures.
|
||||
- **Model**: ZAI GLM-5.1
|
||||
|
||||
### T021: Comprehensive test suite
|
||||
- **Status**: TODO
|
||||
- **Depends**: T010
|
||||
- **Description**: Expand test coverage for: UTXO snapshot load/dump, RocksDB backend, bootstrap download, seed fetch, checkpoint verification.
|
||||
- **Files**: `src/test/`
|
||||
- **Acceptance**: `test_triangles` passes with < 5 pre-existing failures
|
||||
- **Model**: ZAI GLM-5.1 + MiniMax M2.7
|
||||
|
||||
### T022: CI/CD pipeline for releases
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: GitHub Actions workflow: on tag push, build Linux x86_64 + ARM64 + Windows, create release with all binaries + checksums.
|
||||
- **Files**: `.github/workflows/build-all.yml`
|
||||
- **Acceptance**: Tag push produces release with 3 platform binaries
|
||||
- **Model**: ZAI GLM-5.1
|
||||
|
||||
### T023: TRIdock + tri-wallet-web consolidation
|
||||
- **Status**: TODO
|
||||
- **Depends**: none
|
||||
- **Description**: TRIdock and tri-wallet-web appear to be near-duplicates. Evaluate and either consolidate or clearly separate concerns.
|
||||
- **Model**: MiniMax M2.7 (analysis)
|
||||
|
||||
---
|
||||
|
||||
## Completed
|
||||
|
||||
### ✅ Windows GUI bootstrap fix (d0fb2dc)
|
||||
- Removed `#ifndef QT_GUI` guard so auto-bootstrap runs in GUI wallet
|
||||
- Added `uiInterface.InitMessage()` for progress display
|
||||
|
||||
### ✅ Windows native build on sami-pc
|
||||
- Built `triangles-qt.exe` (26MB) and `trianglesd.exe` via MSYS2/MinGW64
|
||||
- All dependencies found natively
|
||||
|
||||
### ✅ RocksDB integration complete (ac9c6fb)
|
||||
- CActiveTxDB wrapper, dual-backend support, compiles clean
|
||||
|
||||
### ✅ All nodes updated to v5.9.7.0
|
||||
- DNS2, DNS3, Hetzner, Contabo seeds all running latest
|
||||
|
||||
### ✅ Bootstrap infrastructure live
|
||||
- HTTPS at bootstrap.cryptographic-triangles.org
|
||||
- Tor hidden service serving nginx on port 8085
|
||||
- Seeds.txt with 7 onion nodes
|
||||
@@ -0,0 +1,7 @@
|
||||
# Krystie runner log
|
||||
|
||||
This file records autonomous-runner activity. Each entry is a doc-only
|
||||
edit produced by the demo worker; once OpenClaw is wired in this log
|
||||
will be replaced by real work.
|
||||
|
||||
- [2026-04-29T06:57:30Z] triangles_v5#1 — Smoke-test the Krystie loop runner
|
||||
Executable
+210
@@ -0,0 +1,210 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Fresh-datadir IBD smoke test for TRI.
|
||||
# Goal: detect the classic "starts from zero but stalls early / loops around 570"
|
||||
# failure mode, and verify that sync keeps making forward progress.
|
||||
#
|
||||
# Example:
|
||||
# bash scripts/ibd-smoke-test.sh \
|
||||
# --bin ./build/src/trianglesd \
|
||||
# --bootstrap-url http://100.104.4.5:8085/triangles-bootstrap.tar.gz \
|
||||
# --addnode 74.208.167.19 --addnode 194.233.88.206
|
||||
|
||||
BIN="${BIN:-./build/src/trianglesd}"
|
||||
TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-1800}" # 30 minutes target window
|
||||
POLL_SECONDS="${POLL_SECONDS:-15}"
|
||||
STALL_WINDOW_SECONDS="${STALL_WINDOW_SECONDS:-180}"
|
||||
BOOTSTRAP_URL="${BOOTSTRAP_URL:-}"
|
||||
WORKDIR="${WORKDIR:-}"
|
||||
RPC_PORT="${RPC_PORT:-19192}"
|
||||
P2P_PORT="${P2P_PORT:-24193}"
|
||||
MIN_EXPECTED_HEIGHT="${MIN_EXPECTED_HEIGHT:-5000}"
|
||||
ALLOW_IBD="${ALLOW_IBD:-0}"
|
||||
WHITELIST="${WHITELIST:-127.0.0.1}"
|
||||
ADDNODES=()
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
|
||||
Options:
|
||||
--bin PATH trianglesd binary (default: $BIN)
|
||||
--bootstrap-url URL optional bootstrap tar.gz URL to preload
|
||||
--workdir PATH use an explicit temp workdir
|
||||
--rpc-port N RPC port for test node (default: $RPC_PORT)
|
||||
--p2p-port N P2P port for test node (default: $P2P_PORT)
|
||||
--timeout N total test timeout seconds (default: $TIMEOUT_SECONDS)
|
||||
--poll N poll interval seconds (default: $POLL_SECONDS)
|
||||
--stall-window N no-progress failure window seconds (default: $STALL_WINDOW_SECONDS)
|
||||
--min-height N minimum expected height/progress floor (default: $MIN_EXPECTED_HEIGHT)
|
||||
--allow-ibd allow test to pass while still in IBD if progress is strong
|
||||
--addnode HOST trusted peer to add (repeatable)
|
||||
-h, --help show this help
|
||||
EOF
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--bin) BIN="$2"; shift 2 ;;
|
||||
--bootstrap-url) BOOTSTRAP_URL="$2"; shift 2 ;;
|
||||
--workdir) WORKDIR="$2"; shift 2 ;;
|
||||
--rpc-port) RPC_PORT="$2"; shift 2 ;;
|
||||
--p2p-port) P2P_PORT="$2"; shift 2 ;;
|
||||
--timeout) TIMEOUT_SECONDS="$2"; shift 2 ;;
|
||||
--poll) POLL_SECONDS="$2"; shift 2 ;;
|
||||
--stall-window) STALL_WINDOW_SECONDS="$2"; shift 2 ;;
|
||||
--min-height) MIN_EXPECTED_HEIGHT="$2"; shift 2 ;;
|
||||
--allow-ibd) ALLOW_IBD=1; shift ;;
|
||||
--addnode) ADDNODES+=("$2"); shift 2 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "unknown arg: $1" >&2; usage; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -x "$BIN" ]]; then
|
||||
echo "ERROR: trianglesd binary not executable: $BIN" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -z "$WORKDIR" ]]; then
|
||||
WORKDIR="$(mktemp -d /tmp/tri-ibd-smoke-XXXXXX)"
|
||||
fi
|
||||
DATADIR="$WORKDIR/datadir"
|
||||
mkdir -p "$DATADIR"
|
||||
|
||||
RPCUSER="tri_test"
|
||||
RPCPASSWORD="tri_test_$(date +%s)_$RANDOM"
|
||||
CONF="$DATADIR/triangles.conf"
|
||||
cat > "$CONF" <<EOF
|
||||
server=1
|
||||
daemon=1
|
||||
staking=0
|
||||
listen=1
|
||||
discover=0
|
||||
upnp=0
|
||||
tor=0
|
||||
irc=0
|
||||
dnsseed=1
|
||||
checkpoints=1
|
||||
rpcuser=$RPCUSER
|
||||
rpcpassword=$RPCPASSWORD
|
||||
rpcport=$RPC_PORT
|
||||
port=$P2P_PORT
|
||||
maxconnections=32
|
||||
whitelist=$WHITELIST
|
||||
logtimestamps=1
|
||||
EOF
|
||||
|
||||
for host in "${ADDNODES[@]}"; do
|
||||
echo "addnode=$host" >> "$CONF"
|
||||
done
|
||||
|
||||
cleanup() {
|
||||
"$BIN" -datadir="$DATADIR" -conf="$CONF" stop >/dev/null 2>&1 || true
|
||||
sleep 2 || true
|
||||
pkill -f "$DATADIR" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
if [[ -n "$BOOTSTRAP_URL" ]]; then
|
||||
echo "[ibd-test] downloading bootstrap: $BOOTSTRAP_URL"
|
||||
curl -L --fail --max-time 1800 "$BOOTSTRAP_URL" -o "$WORKDIR/bootstrap.tar.gz"
|
||||
tar xzf "$WORKDIR/bootstrap.tar.gz" -C "$DATADIR"
|
||||
rm -f "$DATADIR/database/log."* "$DATADIR/txleveldb/LOCK" "$DATADIR/smsgDB/LOCK" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo "[ibd-test] starting node from datadir: $DATADIR"
|
||||
"$BIN" -daemon -datadir="$DATADIR" -conf="$CONF" >/dev/null
|
||||
sleep 6
|
||||
|
||||
rpc() {
|
||||
local method="$1"
|
||||
local params="${2:-[]}"
|
||||
curl -sS --fail --user "$RPCUSER:$RPCPASSWORD" \
|
||||
--data-binary "{\"jsonrpc\":\"1.0\",\"id\":\"ibd\",\"method\":\"$method\",\"params\":$params}" \
|
||||
-H 'content-type: text/plain;' "http://127.0.0.1:$RPC_PORT/"
|
||||
}
|
||||
|
||||
extract_json() {
|
||||
python3 -c 'import json,sys; obj=json.load(sys.stdin); print(obj["result"])'
|
||||
}
|
||||
|
||||
extract_field() {
|
||||
local field="$1"
|
||||
python3 -c 'import json,sys; obj=json.load(sys.stdin); val=obj["result"].get(sys.argv[1]); print(val if val is not None else "")' "$field"
|
||||
}
|
||||
|
||||
start_ts=$(date +%s)
|
||||
last_progress_ts=$start_ts
|
||||
last_height=-1
|
||||
samples=0
|
||||
same_570_loops=0
|
||||
best_height=0
|
||||
|
||||
while true; do
|
||||
now=$(date +%s)
|
||||
elapsed=$((now - start_ts))
|
||||
if (( elapsed > TIMEOUT_SECONDS )); then
|
||||
echo "FAIL: timeout after ${elapsed}s"
|
||||
break
|
||||
fi
|
||||
|
||||
if info_json="$(rpc getblockchaininfo 2>/dev/null)"; then
|
||||
height=$(printf '%s' "$info_json" | extract_field blocks)
|
||||
ibd=$(printf '%s' "$info_json" | extract_field initialblockdownload)
|
||||
headers=$(printf '%s' "$info_json" | extract_field headers)
|
||||
else
|
||||
height=""
|
||||
ibd=""
|
||||
headers=""
|
||||
fi
|
||||
|
||||
peers=0
|
||||
if peer_json="$(rpc getconnectioncount 2>/dev/null)"; then
|
||||
peers=$(printf '%s' "$peer_json" | extract_json)
|
||||
fi
|
||||
|
||||
if [[ -n "$height" && "$height" != "$last_height" ]]; then
|
||||
last_progress_ts=$now
|
||||
last_height="$height"
|
||||
if (( height > best_height )); then
|
||||
best_height=$height
|
||||
fi
|
||||
fi
|
||||
|
||||
log_file="$DATADIR/debug.log"
|
||||
if [[ -f "$log_file" ]]; then
|
||||
loop_hits=$(tail -n 400 "$log_file" | grep -c 'start=571' || true)
|
||||
if (( loop_hits >= 3 )); then
|
||||
same_570_loops=$loop_hits
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[ibd-test] t=${elapsed}s height=${height:-?} headers=${headers:-?} ibd=${ibd:-?} peers=$peers best=$best_height"
|
||||
|
||||
if [[ -n "$height" ]] && (( best_height >= MIN_EXPECTED_HEIGHT )) && [[ "$ibd" == "False" || "$ibd" == "false" ]]; then
|
||||
echo "PASS: left IBD and reached height $best_height"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$ALLOW_IBD" == "1" && -n "$height" ]] && (( best_height >= MIN_EXPECTED_HEIGHT )); then
|
||||
echo "PASS: strong sync progress observed (height $best_height) even though IBD remains true"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if (( now - last_progress_ts > STALL_WINDOW_SECONDS )); then
|
||||
echo "FAIL: no block-height progress for $((now - last_progress_ts))s"
|
||||
if (( same_570_loops > 0 )); then
|
||||
echo "HINT: detected repeated start=571 loop pattern ($same_570_loops hits in recent log tail)"
|
||||
fi
|
||||
echo "--- debug tail ---"
|
||||
tail -n 120 "$log_file" 2>/dev/null || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
((samples++)) || true
|
||||
sleep "$POLL_SECONDS"
|
||||
done
|
||||
|
||||
exit 1
|
||||
@@ -62,6 +62,8 @@ set(CORE_SOURCES
|
||||
pbkdf2.cpp
|
||||
scrypt.cpp
|
||||
smessage.cpp
|
||||
syncmanager.cpp
|
||||
chaindb_migrate.cpp
|
||||
tor_embed_hooks.cpp
|
||||
rest.cpp
|
||||
trianglesrpc.cpp
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
// Copyright (c) 2026 The Triangles developers.
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "chaindb_migrate.h"
|
||||
|
||||
#include "txdb-leveldb.h"
|
||||
#include "txdb-rocksdb.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
struct ChainDbStats
|
||||
{
|
||||
int64_t nRecords = 0;
|
||||
int64_t nUtxos = 0;
|
||||
int64_t nUtxoValue = 0;
|
||||
uint256 hashBestChain = 0;
|
||||
int nDbFormat = 0;
|
||||
};
|
||||
|
||||
bool CollectStats(CTxDBBase& db, ChainDbStats& stats, std::string& strError)
|
||||
{
|
||||
stats = ChainDbStats();
|
||||
|
||||
auto it = db.NewIterator();
|
||||
for (it->Seek(std::string()); it->Valid(); it->Next())
|
||||
stats.nRecords++;
|
||||
|
||||
int nUtxos = 0;
|
||||
stats.nUtxoValue = db.SumUtxoValues(nUtxos);
|
||||
stats.nUtxos = nUtxos;
|
||||
db.ReadHashBestChain(stats.hashBestChain);
|
||||
db.ReadDbFormat(stats.nDbFormat);
|
||||
|
||||
if (stats.nRecords <= 0) {
|
||||
strError = "source chain database contains no records";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StatsMatch(const ChainDbStats& src, const ChainDbStats& dst, std::string& strError)
|
||||
{
|
||||
if (src.nRecords != dst.nRecords) {
|
||||
strError = strprintf("record count mismatch after migration: source=%lld rocksdb=%lld",
|
||||
(long long)src.nRecords, (long long)dst.nRecords);
|
||||
return false;
|
||||
}
|
||||
if (src.nUtxos != dst.nUtxos || src.nUtxoValue != dst.nUtxoValue) {
|
||||
strError = strprintf("UTXO mismatch after migration: source=(%lld,%lld) rocksdb=(%lld,%lld)",
|
||||
(long long)src.nUtxos, (long long)src.nUtxoValue,
|
||||
(long long)dst.nUtxos, (long long)dst.nUtxoValue);
|
||||
return false;
|
||||
}
|
||||
if (src.hashBestChain != dst.hashBestChain) {
|
||||
strError = strprintf("best-chain hash mismatch after migration: source=%s rocksdb=%s",
|
||||
src.hashBestChain.ToString().c_str(),
|
||||
dst.hashBestChain.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
if (src.nDbFormat != dst.nDbFormat) {
|
||||
strError = strprintf("dbformat mismatch after migration: source=%d rocksdb=%d",
|
||||
src.nDbFormat, dst.nDbFormat);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool MaybeMigrateLevelDbToRocksDb(bool fForce, std::string& strError)
|
||||
{
|
||||
strError.clear();
|
||||
|
||||
const fs::path dataDir = GetDataDir();
|
||||
const fs::path levelPath = dataDir / "txleveldb";
|
||||
const fs::path rocksPath = dataDir / "rocksdb";
|
||||
const fs::path markerPath = rocksPath / "MIGRATION_INCOMPLETE";
|
||||
|
||||
if (!fs::exists(levelPath))
|
||||
return true;
|
||||
|
||||
if (fs::exists(rocksPath)) {
|
||||
if (fs::exists(markerPath)) {
|
||||
printf("ChainDB migration: removing incomplete previous RocksDB migration\n");
|
||||
fs::remove_all(rocksPath);
|
||||
}
|
||||
else if (!fForce)
|
||||
return true;
|
||||
else {
|
||||
printf("ChainDB migration: removing existing RocksDB directory due to -migratechaindbforce\n");
|
||||
fs::remove_all(rocksPath);
|
||||
}
|
||||
}
|
||||
|
||||
printf("ChainDB migration: copying LevelDB chain state to RocksDB...\n");
|
||||
printf("ChainDB migration: source=%s destination=%s\n",
|
||||
levelPath.string().c_str(), rocksPath.string().c_str());
|
||||
|
||||
try {
|
||||
fs::create_directories(rocksPath);
|
||||
{
|
||||
std::ofstream marker(markerPath);
|
||||
marker << "RocksDB migration in progress. Safe to delete this directory and retry.\n";
|
||||
}
|
||||
|
||||
CTxDB source("r");
|
||||
CRocksTxDB destination("c+");
|
||||
|
||||
ChainDbStats srcStats;
|
||||
if (!CollectStats(source, srcStats, strError)) {
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!destination.TxnBegin()) {
|
||||
strError = "failed to begin RocksDB migration batch";
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t nCopied = 0;
|
||||
auto it = source.NewIterator();
|
||||
for (it->Seek(std::string()); it->Valid(); it->Next())
|
||||
{
|
||||
if (!destination.WriteRawRecordForMigration(it->KeyStr(), it->ValueStr())) {
|
||||
destination.TxnAbort();
|
||||
strError = "failed to write migrated record to RocksDB";
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (++nCopied % 100000 == 0)
|
||||
{
|
||||
if (!destination.TxnCommit()) {
|
||||
strError = "failed to commit RocksDB migration batch";
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
printf("ChainDB migration: copied %lld / %lld records\n",
|
||||
(long long)nCopied, (long long)srcStats.nRecords);
|
||||
if (!destination.TxnBegin()) {
|
||||
strError = "failed to begin RocksDB migration batch";
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!destination.TxnCommit()) {
|
||||
strError = "failed to commit final RocksDB migration batch";
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
ChainDbStats dstStats;
|
||||
if (!CollectStats(destination, dstStats, strError)) {
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
if (!StatsMatch(srcStats, dstStats, strError)) {
|
||||
source.Close();
|
||||
destination.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("ChainDB migration: verified %lld records, %lld UTXOs, best=%s\n",
|
||||
(long long)dstStats.nRecords,
|
||||
(long long)dstStats.nUtxos,
|
||||
dstStats.hashBestChain.ToString().substr(0,20).c_str());
|
||||
|
||||
source.Close();
|
||||
destination.Close();
|
||||
fs::remove(markerPath);
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
strError = e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("ChainDB migration: complete. Legacy LevelDB was left untouched at %s\n",
|
||||
levelPath.string().c_str());
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2026 The Triangles developers.
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef TRIANGLES_CHAINDB_MIGRATE_H
|
||||
#define TRIANGLES_CHAINDB_MIGRATE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
// Migrate legacy LevelDB chain state from <datadir>/txleveldb to RocksDB in
|
||||
// <datadir>/rocksdb. The source is never modified. Returns true when migration
|
||||
// succeeds or when there is nothing to migrate.
|
||||
bool MaybeMigrateLevelDbToRocksDb(bool fForce, std::string& strError);
|
||||
|
||||
#endif // TRIANGLES_CHAINDB_MIGRATE_H
|
||||
@@ -32,14 +32,6 @@ namespace Checkpoints
|
||||
{ 9002, uint256("0xa1e20fb1d44688b763690cf74d6aefe859e4cc32981f9e3f2b2ae9702bbcf249")},
|
||||
{ 10881, uint256("0x4b6554c45e1e6764a6f3c309c47baf53c9edd81f624e52b072518cd15da237e6")},
|
||||
{ 17650, uint256("0x224940e1f986a202209b8e762728d1452ab45870c308abf84905674acf326a47")},
|
||||
{2000000, uint256("0xb0b02d4bb5ffa31f6f22fd042082ca0a085257af34dc2d4b31c3c8567b5574d5")},
|
||||
{2186940, uint256("0xbd952e8d4a612e336d840ad924a7e09395e36bcd9d929b302e47e60b5c3098c0")},
|
||||
{2190000, uint256("0x682baf783581468ba18f9967254a7f3944e8b8c4cc7101e7d99b68f4f9dd5271")},
|
||||
{2200000, uint256("0x0a8d0442f031f1258120f713f34e45f4f9a625fb753558e27b89b32ad5a9a740")},
|
||||
{2205000, uint256("0xf7aa893ec012181e321783d6a5487addf6997377908faa3e760c9054a4217d29")},
|
||||
{2206000, uint256("0x780ae878f8b10b6cbd51ceb2c0799c90d3551fa916be62974375071b9e36581c")},
|
||||
{2203594, uint256("0x5e016ae5d1f163c6679292b717a3db467a39d24b0a315182f4783caa79c722d8")},
|
||||
{2207000, uint256("0x8836d67b0f08036c4a7c26ff0a29d4461a52b6d8f552165ad9c1abec2f3cadfd")},
|
||||
};
|
||||
|
||||
// Published UTXO snapshot file SHA256, keyed by snapshot height.
|
||||
@@ -51,7 +43,6 @@ namespace Checkpoints
|
||||
// here. The corresponding (height, blockhash) must already exist in
|
||||
// mapCheckpoints / mapCheckpointsTestnet.
|
||||
static std::map<int, uint256> mapSnapshotHashes = {
|
||||
{2203594, uint256("0x49b35dd01659975c4a31954f37174c6e2e8878dd0723ab306ccecd991c80f79a")},
|
||||
};
|
||||
|
||||
static std::map<int, uint256> mapSnapshotHashesTestnet = {
|
||||
@@ -70,15 +61,6 @@ namespace Checkpoints
|
||||
{ 9002, uint256("0xa1e20fb1d44688b763690cf74d6aefe859e4cc32981f9e3f2b2ae9702bbcf249")},
|
||||
{ 10881, uint256("0x4b6554c45e1e6764a6f3c309c47baf53c9edd81f624e52b072518cd15da237e6")},
|
||||
{ 17650, uint256("0x224940e1f986a202209b8e762728d1452ab45870c308abf84905674acf326a47")},
|
||||
{2000000, uint256("0xb0b02d4bb5ffa31f6f22fd042082ca0a085257af34dc2d4b31c3c8567b5574d5")},
|
||||
{2186940, uint256("0xbd952e8d4a612e336d840ad924a7e09395e36bcd9d929b302e47e60b5c3098c0")},
|
||||
{2190000, uint256("0x682baf783581468ba18f9967254a7f3944e8b8c4cc7101e7d99b68f4f9dd5271")},
|
||||
{2200000, uint256("0x0a8d0442f031f1258120f713f34e45f4f9a625fb753558e27b89b32ad5a9a740")},
|
||||
{2205000, uint256("0xf7aa893ec012181e321783d6a5487addf6997377908faa3e760c9054a4217d29")},
|
||||
{2206000, uint256("0x780ae878f8b10b6cbd51ceb2c0799c90d3551fa916be62974375071b9e36581c")},
|
||||
{2207000, uint256("0x8836d67b0f08036c4a7c26ff0a29d4461a52b6d8f552165ad9c1abec2f3cadfd")},
|
||||
{2208000, uint256("0xe4a19e8a29fa7aae47f7563377af3e896fee18ed069a64e325b8c2c6c820a1be")},
|
||||
{2209000, uint256("0x04c78a6fc863bed918a9364c58c64489943b2e85d84ddb1ac2fba584f390d5dc")},
|
||||
};
|
||||
|
||||
bool CheckHardened(int nHeight, const uint256& hash)
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
// These need to be macros, as version.cpp's and triangles-qt.rc's voodoo requires it
|
||||
#define CLIENT_VERSION_MAJOR 5
|
||||
#define CLIENT_VERSION_MINOR 9
|
||||
#define CLIENT_VERSION_REVISION 5
|
||||
#define CLIENT_VERSION_REVISION 11
|
||||
#define CLIENT_VERSION_BUILD 0
|
||||
|
||||
// Converts the parameter X to a string after macro replacement on X has been performed.
|
||||
|
||||
+36
-4
@@ -24,6 +24,7 @@
|
||||
#endif
|
||||
#include "notificationqueue.h"
|
||||
#include "addressindex.h"
|
||||
#include "chaindb_migrate.h"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -416,7 +417,7 @@ std::string HelpMessage()
|
||||
//" -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" +
|
||||
//" -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
|
||||
" -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
|
||||
" -notor " + _("Disable Tor (WARNING: wallet will not start - Tor is required)") + "\n" +
|
||||
" -notor " + _("Disable Tor - run in clearnet-only mode (no .onion connectivity)") + "\n" +
|
||||
" -torsocks=<port> " + _("Set embedded or managed Tor SOCKS proxy port (default: 19099)") + "\n" +
|
||||
" -torhiddenservice " + _("Enable the managed Tor hidden service (default: 1)") + "\n" +
|
||||
" -torhsport=<port> " + _("Set embedded or managed Tor hidden service port (default: wallet listen port)") + "\n" +
|
||||
@@ -926,7 +927,8 @@ bool AppInit2()
|
||||
// v5.9.5: P2P UTXO snapshot fetch is the default for fresh installs (Step 11.6).
|
||||
// The legacy clearnet HTTP bootstrap only runs when the user explicitly requests
|
||||
// it via -bootstrap, or when -snapshot=0 disables the P2P fetcher.
|
||||
#ifndef QT_GUI
|
||||
// Bootstrap auto-download works for both GUI and daemon.
|
||||
// GUI users get the same automatic bootstrap on fresh installs.
|
||||
{
|
||||
bool wantsBootstrap = GetBoolArg("-bootstrap", false);
|
||||
bool noBootstrap = GetBoolArg("-nobootstrap", false);
|
||||
@@ -937,6 +939,7 @@ bool AppInit2()
|
||||
if (needsBootstrap && !noBootstrap && !snapshotMode) {
|
||||
printf("Bootstrap: no blockchain data found — downloading automatically.\n");
|
||||
printf("Bootstrap: (use -nobootstrap to skip)\n");
|
||||
uiInterface.InitMessage(_("Downloading blockchain data..."));
|
||||
wantsBootstrap = true;
|
||||
} else if (needsBootstrap && snapshotMode && !wantsBootstrap) {
|
||||
printf("Bootstrap: no blockchain data found — will fetch UTXO snapshot via P2P after network start.\n");
|
||||
@@ -950,13 +953,24 @@ bool AppInit2()
|
||||
std::string host = Bootstrap::DEFAULT_HOST;
|
||||
std::string strError;
|
||||
|
||||
auto progressFn = [](int64_t bytesDownloaded, int64_t totalBytes) {
|
||||
int64_t lastGuiUpdate = 0;
|
||||
auto progressFn = [&lastGuiUpdate](int64_t bytesDownloaded, int64_t totalBytes) {
|
||||
if (totalBytes > 0) {
|
||||
printf("\rBootstrap: %lld / %lld MB (%lld%%)",
|
||||
(long long)(bytesDownloaded / (1024*1024)),
|
||||
(long long)(totalBytes / (1024*1024)),
|
||||
(long long)((bytesDownloaded * 100) / totalBytes));
|
||||
fflush(stdout);
|
||||
// Update GUI status bar every ~1 MB
|
||||
int64_t now = GetTimeMillis();
|
||||
if (now - lastGuiUpdate > 1000) {
|
||||
lastGuiUpdate = now;
|
||||
std::string msg = strprintf("Downloading blockchain: %lld / %lld MB (%lld%%)",
|
||||
(long long)(bytesDownloaded / (1024*1024)),
|
||||
(long long)(totalBytes / (1024*1024)),
|
||||
(long long)((bytesDownloaded * 100) / totalBytes));
|
||||
uiInterface.InitMessage(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -998,7 +1012,6 @@ bool AppInit2()
|
||||
strprintf("host=%s success=%d utxo_snapshot=%d", host.c_str(), success, triedUtxoSnapshot));
|
||||
}
|
||||
} // end bootstrap scope
|
||||
#endif
|
||||
|
||||
// ********************************************************* Step 6c: manual UTXO snapshot loading
|
||||
// If utxo-snapshot.bin exists in data dir and the chain DB hasn't been
|
||||
@@ -1022,6 +1035,16 @@ bool AppInit2()
|
||||
}
|
||||
}
|
||||
|
||||
// ********************************************************* Step 6d: optional LevelDB -> RocksDB chain DB migration
|
||||
if (GetBoolArg("-migratechaindb", false) || GetBoolArg("-migratechaindbforce", false))
|
||||
{
|
||||
uiInterface.InitMessage(_("Migrating chain database to RocksDB..."));
|
||||
std::string strMigrateError;
|
||||
bool fForce = GetBoolArg("-migratechaindbforce", false);
|
||||
if (!MaybeMigrateLevelDbToRocksDb(fForce, strMigrateError))
|
||||
return InitError(strprintf(_("Chain DB migration failed: %s"), strMigrateError.c_str()));
|
||||
}
|
||||
|
||||
// ********************************************************* Step 7: load blockchain
|
||||
|
||||
if (!bitdb.Open(GetDataDir()))
|
||||
@@ -1332,6 +1355,15 @@ bool AppInit2()
|
||||
#ifdef USE_UPNP
|
||||
fUseUPnP = false;
|
||||
#endif
|
||||
} else if (GetBoolArg("-notor", false)) {
|
||||
// -notor: user explicitly disabled Tor. Allow the daemon to start
|
||||
// in clearnet-only mode (useful for diagnostics, benchmarking, and
|
||||
// recovery). .onion connectivity will not be available.
|
||||
printf("NOTICE: Tor disabled via -notor. Running in clearnet-only mode.\n");
|
||||
printf(" .onion connections will NOT be available.\n");
|
||||
SetReachable(NET_IPV4, true);
|
||||
SetReachable(NET_IPV6, true);
|
||||
SetReachable(NET_TOR, false);
|
||||
} else {
|
||||
std::string torError = CTorEmbedded::GetInstance()->GetStartupError();
|
||||
if (torError.empty())
|
||||
|
||||
+11
-1
@@ -36,8 +36,18 @@ int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd)
|
||||
// comes back with massively amplified staking power and dominates blocks.
|
||||
// The 7-day cap still allows generous accumulation while limiting abuse.
|
||||
static const int64_t STAKE_AGE_SOFT_CAP = 7 * 24 * 60 * 60; // 7 days
|
||||
// Activation gate: the soft cap shipped 2026-04-20 without a height/time
|
||||
// gate, retroactively invalidating earlier blocks staked with long-aged
|
||||
// coins (e.g. coins idle through the 2022-2026 freeze). Apply the cap
|
||||
// only to stakes after the activation timestamp; historical stakes
|
||||
// validate under the rules they were created with (uncapped age).
|
||||
static const int64_t STAKE_AGE_SOFT_CAP_ACTIVATION = 1776000000; // 2026-04-12 ~13:20 UTC
|
||||
if (pindexBest && pindexBest->nHeight >= FORK_HEIGHT_V5)
|
||||
return min(nAge, STAKE_AGE_SOFT_CAP);
|
||||
{
|
||||
if (nIntervalEnd >= STAKE_AGE_SOFT_CAP_ACTIVATION)
|
||||
return min(nAge, STAKE_AGE_SOFT_CAP);
|
||||
return nAge;
|
||||
}
|
||||
|
||||
return min(nAge, (int64_t)nStakeMaxAge);
|
||||
}
|
||||
|
||||
+67
-743
@@ -21,6 +21,7 @@
|
||||
#include "notificationqueue.h"
|
||||
#include "addressindex.h"
|
||||
#include "snapshotnet.h"
|
||||
#include "syncmanager.h"
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
@@ -118,36 +119,9 @@ extern enum Checkpoints::CPMode CheckpointsMode;
|
||||
namespace
|
||||
{
|
||||
|
||||
struct CHeaderSyncNode
|
||||
{
|
||||
CBlock header;
|
||||
int nHeight;
|
||||
uint256 nChainTrust;
|
||||
bool fRequested;
|
||||
int64_t nLastRequestTime;
|
||||
int64_t nFirstRequestTime; // when this block was first requested (for latency tracking)
|
||||
int64_t nInsertTime;
|
||||
};
|
||||
|
||||
static std::map<uint256, CHeaderSyncNode> mapHeaderSync;
|
||||
static uint256 hashBestHeaderSync = 0;
|
||||
static int64_t nLastNewHeaderTime = 0;
|
||||
static CCriticalSection cs_PostIbdWork;
|
||||
static bool fPostIbdWorkStarted = false;
|
||||
|
||||
static const unsigned int MAX_HEADER_SYNC_CACHE = 15000;
|
||||
static const unsigned int HEADER_DOWNLOAD_WINDOW = 1024; // Wider pipeline for multi-peer parallel IBD
|
||||
static const unsigned int HEADER_DOWNLOAD_PER_PEER = 32; // Reduced from 64 for Tor circuit stability
|
||||
static const size_t HEADER_REDUNDANT_PEER_THRESHOLD = 4; // Only do dual-peer redundancy when peer count is below this
|
||||
static const unsigned int HEADER_SYNC_LOW_WATER = HEADER_DOWNLOAD_WINDOW / 4;
|
||||
static const unsigned int HEADER_SYNC_TARGET_INFLIGHT = HEADER_DOWNLOAD_WINDOW / 2;
|
||||
static const int64_t HEADER_REQUEST_TIMEOUT_MICROS = 60 * 1000000; // 60s for Tor latency (was 30s)
|
||||
static const int64_t HEADER_REDUNDANT_REQUEST_MICROS = 5 * 1000000; // 5s redundant request (reduced for Tor)
|
||||
static const int64_t HEADER_SYNC_TTL_MICROS = 15 * 60 * 1000000; // 15-minute TTL for cache entries (extended for Tor latency)
|
||||
static const int64_t HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS = 5;
|
||||
static const int64_t HEADER_SYNC_CONTROL_INTERVAL_SECONDS = 5;
|
||||
static const int64_t HEADER_SYNC_WATCHDOG_SECONDS = 25;
|
||||
|
||||
static void ThreadPostIbdWork(void* parg)
|
||||
{
|
||||
RenameThread("Triangles-postibd");
|
||||
@@ -195,499 +169,6 @@ static void ThreadPostIbdWork(void* parg)
|
||||
}
|
||||
}
|
||||
|
||||
static uint256 GetHeaderSyncTrust(unsigned int nBits)
|
||||
{
|
||||
CBigNum bnTarget;
|
||||
bnTarget.SetCompact(nBits);
|
||||
|
||||
if (bnTarget <= 0)
|
||||
return 0;
|
||||
|
||||
return ((CBigNum(1) << 256) / (bnTarget + 1)).getuint256();
|
||||
}
|
||||
|
||||
static bool GetKnownHeaderState(const uint256& hash, int& nHeight, uint256& nChainTrust)
|
||||
{
|
||||
if (auto miBlock = mapBlockIndex.find(hash); miBlock != mapBlockIndex.end())
|
||||
{
|
||||
nHeight = miBlock->second->nHeight;
|
||||
nChainTrust = miBlock->second->nChainTrust;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (auto miHeader = mapHeaderSync.find(hash); miHeader != mapHeaderSync.end())
|
||||
{
|
||||
nHeight = miHeader->second.nHeight;
|
||||
nChainTrust = miHeader->second.nChainTrust;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool GetHeaderSyncPrevHash(const uint256& hash, uint256& hashPrev)
|
||||
{
|
||||
if (auto miHeader = mapHeaderSync.find(hash); miHeader != mapHeaderSync.end())
|
||||
{
|
||||
hashPrev = miHeader->second.header.hashPrevBlock;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (auto miBlock = mapBlockIndex.find(hash); miBlock != mapBlockIndex.end() && miBlock->second->pprev)
|
||||
{
|
||||
hashPrev = miBlock->second->pprev->GetBlockHash();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void RecomputeBestHeaderSync()
|
||||
{
|
||||
hashBestHeaderSync = 0;
|
||||
uint256 nBestTrust = 0;
|
||||
|
||||
for (const auto& [hash, node] : mapHeaderSync)
|
||||
{
|
||||
if (hashBestHeaderSync == 0 || node.nChainTrust > nBestTrust)
|
||||
{
|
||||
hashBestHeaderSync = hash;
|
||||
nBestTrust = node.nChainTrust;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PruneHeaderSync()
|
||||
{
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
|
||||
// TTL eviction: remove entries older than 5 minutes
|
||||
if (mapHeaderSync.size() > MAX_HEADER_SYNC_CACHE / 2)
|
||||
{
|
||||
unsigned int nEvicted = 0;
|
||||
for (auto it = mapHeaderSync.begin(); it != mapHeaderSync.end(); )
|
||||
{
|
||||
if (nNow - it->second.nInsertTime >= HEADER_SYNC_TTL_MICROS)
|
||||
{
|
||||
it = mapHeaderSync.erase(it);
|
||||
++nEvicted;
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
if (nEvicted > 0)
|
||||
{
|
||||
printf("IBD-DIAG: TTL-evicted %u stale header sync entries, %u remain\n",
|
||||
nEvicted, (unsigned int)mapHeaderSync.size());
|
||||
RecomputeBestHeaderSync();
|
||||
}
|
||||
}
|
||||
|
||||
// Hard limit: if still over max, evict oldest entries
|
||||
if (mapHeaderSync.size() > MAX_HEADER_SYNC_CACHE)
|
||||
{
|
||||
printf("IBD-DIAG: header sync cache exceeded %u entries, evicting oldest\n", MAX_HEADER_SYNC_CACHE);
|
||||
while (mapHeaderSync.size() > MAX_HEADER_SYNC_CACHE * 3 / 4)
|
||||
{
|
||||
// Find oldest entry by insert time
|
||||
auto oldest = mapHeaderSync.begin();
|
||||
for (auto it = mapHeaderSync.begin(); it != mapHeaderSync.end(); ++it)
|
||||
{
|
||||
if (it->second.nInsertTime < oldest->second.nInsertTime)
|
||||
oldest = it;
|
||||
}
|
||||
mapHeaderSync.erase(oldest);
|
||||
}
|
||||
RecomputeBestHeaderSync();
|
||||
}
|
||||
}
|
||||
|
||||
static bool AddHeaderSyncNode(const CBlock& header, const uint256& hashHeader)
|
||||
{
|
||||
if (mapBlockIndex.count(hashHeader) || mapHeaderSync.count(hashHeader))
|
||||
return true;
|
||||
|
||||
if (!header.vtx.empty())
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (has vtx) hash=%s\n", hashHeader.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (header.GetBlockTime() > GetTime() + 15 * 60)
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (future time) hash=%s time=%u\n",
|
||||
hashHeader.ToString().substr(0,20).c_str(), header.nTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
int nPrevHeight = -1;
|
||||
uint256 nPrevChainTrust = 0;
|
||||
if (!GetKnownHeaderState(header.hashPrevBlock, nPrevHeight, nPrevChainTrust))
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (prev unknown) hash=%s prevHash=%s\n",
|
||||
hashHeader.ToString().substr(0,20).c_str(),
|
||||
header.hashPrevBlock.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const int nHeight = nPrevHeight + 1;
|
||||
if (nHeight <= CUTOFF_POW_BLOCK && !CheckProofOfWork(hashHeader, header.nBits))
|
||||
{
|
||||
printf("IBD-DIAG: header PoW FAILED at height %d hash=%s nBits=%08x prevHash=%s\n",
|
||||
nHeight, hashHeader.ToString().substr(0,20).c_str(), header.nBits,
|
||||
header.hashPrevBlock.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
CHeaderSyncNode node;
|
||||
node.header = header;
|
||||
node.nHeight = nHeight;
|
||||
node.nChainTrust = nPrevChainTrust + GetHeaderSyncTrust(header.nBits);
|
||||
node.fRequested = false;
|
||||
node.nLastRequestTime = 0;
|
||||
node.nFirstRequestTime = 0;
|
||||
node.nInsertTime = GetTime() * 1000000;
|
||||
|
||||
mapHeaderSync.insert({hashHeader, node});
|
||||
|
||||
if (hashBestHeaderSync == 0 || node.nChainTrust > mapHeaderSync[hashBestHeaderSync].nChainTrust)
|
||||
hashBestHeaderSync = hashHeader;
|
||||
|
||||
PruneHeaderSync();
|
||||
return true;
|
||||
}
|
||||
|
||||
static CBlockLocator BuildHeaderSyncLocator(uint256 hashTip)
|
||||
{
|
||||
if (hashTip == 0)
|
||||
return CBlockLocator(pindexBest);
|
||||
|
||||
std::vector<uint256> vHave;
|
||||
int nStep = 1;
|
||||
|
||||
while (hashTip != 0)
|
||||
{
|
||||
vHave.push_back(hashTip);
|
||||
|
||||
for (int i = 0; i < nStep && hashTip != 0; ++i)
|
||||
{
|
||||
uint256 hashPrev = 0;
|
||||
if (!GetHeaderSyncPrevHash(hashTip, hashPrev))
|
||||
hashTip = 0;
|
||||
else
|
||||
hashTip = hashPrev;
|
||||
}
|
||||
|
||||
if (vHave.size() > 10)
|
||||
nStep *= 2;
|
||||
}
|
||||
|
||||
vHave.push_back(!fTestNet ? hashGenesisBlockOfficial : hashGenesisBlockTestNet);
|
||||
return CBlockLocator(vHave);
|
||||
}
|
||||
|
||||
static std::vector<uint256> GetHeaderSyncDownloadPath(uint256 hashTip)
|
||||
{
|
||||
std::vector<uint256> vPath;
|
||||
|
||||
while (hashTip != 0 && !mapBlockIndex.count(hashTip))
|
||||
{
|
||||
auto mi = mapHeaderSync.find(hashTip);
|
||||
if (mi == mapHeaderSync.end())
|
||||
break;
|
||||
|
||||
vPath.push_back(hashTip);
|
||||
hashTip = mi->second.header.hashPrevBlock;
|
||||
}
|
||||
|
||||
std::reverse(vPath.begin(), vPath.end());
|
||||
return vPath;
|
||||
}
|
||||
|
||||
static unsigned int CountHeaderSyncInFlight()
|
||||
{
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
unsigned int nInFlight = 0;
|
||||
for (const auto& [hash, node] : mapHeaderSync)
|
||||
{
|
||||
if (node.fRequested && nNow - node.nLastRequestTime < HEADER_REQUEST_TIMEOUT_MICROS)
|
||||
++nInFlight;
|
||||
}
|
||||
return nInFlight;
|
||||
}
|
||||
|
||||
static unsigned int GetHeaderSyncPlannerDepth()
|
||||
{
|
||||
if (hashBestHeaderSync == 0)
|
||||
return 0;
|
||||
|
||||
return (unsigned int)GetHeaderSyncDownloadPath(hashBestHeaderSync).size();
|
||||
}
|
||||
|
||||
static int GetHeaderSyncPlannerHeight()
|
||||
{
|
||||
if (hashBestHeaderSync == 0)
|
||||
return pindexBest ? pindexBest->nHeight : -1;
|
||||
|
||||
auto mi = mapHeaderSync.find(hashBestHeaderSync);
|
||||
if (mi == mapHeaderSync.end())
|
||||
return pindexBest ? pindexBest->nHeight : -1;
|
||||
|
||||
return mi->second.nHeight;
|
||||
}
|
||||
|
||||
static unsigned int QueueHeaderSyncBlocks(CNode* pfrom, unsigned int nWindow)
|
||||
{
|
||||
if (!pfrom || hashBestHeaderSync == 0)
|
||||
return 0;
|
||||
|
||||
const std::vector<uint256> vPath = GetHeaderSyncDownloadPath(hashBestHeaderSync);
|
||||
if (vPath.empty())
|
||||
return 0;
|
||||
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
unsigned int nInFlight = CountHeaderSyncInFlight();
|
||||
unsigned int nQueued = 0;
|
||||
|
||||
for (const auto& hash : vPath)
|
||||
{
|
||||
if (nInFlight + nQueued >= nWindow)
|
||||
break;
|
||||
|
||||
auto mi = mapHeaderSync.find(hash);
|
||||
if (mi == mapHeaderSync.end())
|
||||
continue;
|
||||
|
||||
if (mi->second.fRequested && nNow - mi->second.nLastRequestTime < HEADER_REQUEST_TIMEOUT_MICROS)
|
||||
continue;
|
||||
|
||||
pfrom->AskFor(CInv(MSG_BLOCK, hash));
|
||||
mi->second.fRequested = true;
|
||||
mi->second.nLastRequestTime = nNow;
|
||||
++nQueued;
|
||||
}
|
||||
|
||||
return nQueued;
|
||||
}
|
||||
|
||||
// Returns the first request time (microseconds) for a block in the header sync cache, or 0
|
||||
static int64_t GetHeaderSyncRequestTime(const uint256& hashBlock)
|
||||
{
|
||||
auto mi = mapHeaderSync.find(hashBlock);
|
||||
if (mi == mapHeaderSync.end())
|
||||
return 0;
|
||||
return mi->second.nFirstRequestTime;
|
||||
}
|
||||
|
||||
static void MarkHeaderSyncBlockAccepted(const uint256& hashBlock)
|
||||
{
|
||||
auto mi = mapHeaderSync.find(hashBlock);
|
||||
if (mi == mapHeaderSync.end())
|
||||
return;
|
||||
|
||||
mapHeaderSync.erase(mi);
|
||||
if (hashBestHeaderSync == hashBlock)
|
||||
RecomputeBestHeaderSync();
|
||||
}
|
||||
|
||||
static void ContinueHeaderSync(CNode* pfrom, const uint256& hashTip)
|
||||
{
|
||||
if (!pfrom || hashTip == 0)
|
||||
return;
|
||||
|
||||
CBlockLocator locator = BuildHeaderSyncLocator(hashTip);
|
||||
if (locator.IsNull())
|
||||
return;
|
||||
|
||||
pfrom->PushMessage("getheaders", locator, uint256(0));
|
||||
}
|
||||
|
||||
static bool RequestHeaderSyncRefill(CNode* pfrom, uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason)
|
||||
{
|
||||
if (!pfrom || pfrom->fClient || pfrom->nVersion == 0 || !IsInitialBlockDownload())
|
||||
return false;
|
||||
|
||||
const int64_t nNowSec = GetTime();
|
||||
if (nMinIntervalSeconds > 0 &&
|
||||
nNowSec - pfrom->nLastIbdHeaderRequest < nMinIntervalSeconds)
|
||||
return false;
|
||||
|
||||
uint256 hashLocatorTip = hashTip;
|
||||
if (hashLocatorTip == 0 ||
|
||||
(!mapBlockIndex.count(hashLocatorTip) && !mapHeaderSync.count(hashLocatorTip)))
|
||||
{
|
||||
hashLocatorTip = hashBestHeaderSync;
|
||||
}
|
||||
|
||||
if (hashLocatorTip != 0 && (!pindexBest || hashLocatorTip != pindexBest->GetBlockHash()))
|
||||
{
|
||||
ContinueHeaderSync(pfrom, hashLocatorTip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pindexBest)
|
||||
return false;
|
||||
|
||||
pfrom->pindexLastGetHeadersBegin = nullptr;
|
||||
pfrom->PushGetHeaders(pindexBest, uint256(0));
|
||||
hashLocatorTip = pindexBest->GetBlockHash();
|
||||
}
|
||||
|
||||
pfrom->nLastIbdHeaderRequest = nNowSec;
|
||||
printf("IBD-DIAG: %s getheaders to peer=%s locator=%s plannerDepth=%u inflight=%u\n",
|
||||
pszReason, pfrom->addr.ToString().c_str(),
|
||||
hashLocatorTip.ToString().substr(0,20).c_str(),
|
||||
GetHeaderSyncPlannerDepth(), CountHeaderSyncInFlight());
|
||||
return true;
|
||||
}
|
||||
|
||||
static unsigned int RequestHeaderSyncRefillAllPeers(uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason)
|
||||
{
|
||||
std::vector<CNode*> vEligiblePeers;
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes)
|
||||
{
|
||||
if (!pnode->fClient && pnode->nVersion != 0 && !pnode->fDisconnect)
|
||||
vEligiblePeers.push_back(pnode);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int nRequested = 0;
|
||||
for (CNode* pnode : vEligiblePeers)
|
||||
{
|
||||
if (RequestHeaderSyncRefill(pnode, hashTip, nMinIntervalSeconds, pszReason))
|
||||
++nRequested;
|
||||
}
|
||||
|
||||
return nRequested;
|
||||
}
|
||||
|
||||
// Parallel block downloading: distribute blocks across all available peers
|
||||
static unsigned int QueueHeaderSyncBlocksParallel(unsigned int nWindow)
|
||||
{
|
||||
if (hashBestHeaderSync == 0)
|
||||
return 0;
|
||||
|
||||
const std::vector<uint256> vPath = GetHeaderSyncDownloadPath(hashBestHeaderSync);
|
||||
if (vPath.empty())
|
||||
return 0;
|
||||
|
||||
// Collect eligible peers
|
||||
std::vector<CNode*> vEligiblePeers;
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes)
|
||||
{
|
||||
if (!pnode->fClient && pnode->nVersion != 0 && !pnode->fDisconnect)
|
||||
vEligiblePeers.push_back(pnode);
|
||||
}
|
||||
}
|
||||
|
||||
if (vEligiblePeers.empty())
|
||||
return 0;
|
||||
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
unsigned int nInFlight = CountHeaderSyncInFlight();
|
||||
unsigned int nQueued = 0;
|
||||
unsigned int nPeerIndex = 0;
|
||||
|
||||
// Sort peers by blocks delivered (descending) for speed-weighted assignment.
|
||||
// Faster peers get more blocks assigned to them, improving IBD throughput
|
||||
// on Tor networks where latency varies significantly between peers.
|
||||
std::sort(vEligiblePeers.begin(), vEligiblePeers.end(),
|
||||
[](const CNode* a, const CNode* b) {
|
||||
return a->nBlocksDelivered > b->nBlocksDelivered;
|
||||
});
|
||||
|
||||
// Build a weighted distribution: top peer gets 3 slots per round, second gets 2, rest get 1.
|
||||
std::vector<CNode*> vWeightedPeers;
|
||||
for (size_t i = 0; i < vEligiblePeers.size(); i++)
|
||||
{
|
||||
int nWeight = (i == 0) ? 3 : (i == 1) ? 2 : 1;
|
||||
for (int w = 0; w < nWeight; w++)
|
||||
vWeightedPeers.push_back(vEligiblePeers[i]);
|
||||
}
|
||||
|
||||
// Adaptive timeout: use average peer latency to set timeouts.
|
||||
// If peers average 2s, timeout at 10s. If peers average 15s, timeout at 45s.
|
||||
// Clamp between 10s and 60s. Default to 60s when no latency data.
|
||||
int64_t nAdaptiveTimeout = HEADER_REQUEST_TIMEOUT_MICROS;
|
||||
{
|
||||
int64_t nTotalLatency = 0;
|
||||
int nPeersWithLatency = 0;
|
||||
for (const CNode* pnode : vEligiblePeers) {
|
||||
if (pnode->nAvgBlockLatencyUs > 0) {
|
||||
nTotalLatency += pnode->nAvgBlockLatencyUs;
|
||||
++nPeersWithLatency;
|
||||
}
|
||||
}
|
||||
if (nPeersWithLatency > 0) {
|
||||
int64_t nAvgLatency = nTotalLatency / nPeersWithLatency;
|
||||
nAdaptiveTimeout = std::max((int64_t)(10 * 1000000),
|
||||
std::min((int64_t)(60 * 1000000), nAvgLatency * 5));
|
||||
}
|
||||
}
|
||||
|
||||
// Distribute blocks across peers using speed-weighted assignment
|
||||
for (const auto& hash : vPath)
|
||||
{
|
||||
if (nInFlight + nQueued >= nWindow)
|
||||
break;
|
||||
|
||||
auto mi = mapHeaderSync.find(hash);
|
||||
if (mi == mapHeaderSync.end())
|
||||
continue;
|
||||
|
||||
bool fNeedsRequest = false;
|
||||
if (!mi->second.fRequested)
|
||||
{
|
||||
fNeedsRequest = true;
|
||||
}
|
||||
else if (nNow - mi->second.nLastRequestTime >= nAdaptiveTimeout)
|
||||
{
|
||||
fNeedsRequest = true;
|
||||
}
|
||||
else if (nNow - mi->second.nLastRequestTime >= HEADER_REDUNDANT_REQUEST_MICROS)
|
||||
{
|
||||
fNeedsRequest = true;
|
||||
}
|
||||
|
||||
if (!fNeedsRequest)
|
||||
continue;
|
||||
|
||||
CNode* pnode = vWeightedPeers[nPeerIndex % vWeightedPeers.size()];
|
||||
pnode->AskFor(CInv(MSG_BLOCK, hash));
|
||||
|
||||
if (IsInitialBlockDownload() &&
|
||||
vWeightedPeers.size() >= 2 &&
|
||||
vWeightedPeers.size() < HEADER_REDUNDANT_PEER_THRESHOLD &&
|
||||
!mi->second.fRequested)
|
||||
{
|
||||
CNode* pnode2 = vWeightedPeers[(nPeerIndex + 1) % vWeightedPeers.size()];
|
||||
if (pnode2 != pnode)
|
||||
pnode2->AskFor(CInv(MSG_BLOCK, hash));
|
||||
}
|
||||
|
||||
if (!mi->second.fRequested || nNow - mi->second.nLastRequestTime >= HEADER_REQUEST_TIMEOUT_MICROS)
|
||||
{
|
||||
if (!mi->second.fRequested)
|
||||
mi->second.nFirstRequestTime = nNow;
|
||||
mi->second.fRequested = true;
|
||||
mi->second.nLastRequestTime = nNow;
|
||||
}
|
||||
|
||||
++nQueued;
|
||||
++nPeerIndex;
|
||||
}
|
||||
|
||||
if (nQueued > 0)
|
||||
printf("IBD-DIAG: parallel queue distributed %u blocks across %zu peers (window=%u, inflight=%u)\n",
|
||||
nQueued, vEligiblePeers.size(), nWindow, nInFlight);
|
||||
|
||||
return nQueued;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1843,10 +1324,12 @@ bool IsInitialBlockDownload()
|
||||
pindexLastBest = pindexBest;
|
||||
nLastUpdate = GetTime();
|
||||
}
|
||||
// IBD is complete once we've passed the checkpoint height estimate.
|
||||
// The previous >24h block-time check incorrectly kept IBD true when the
|
||||
// chain was synced but simply stalled (no new blocks arriving), which
|
||||
// prevented the stake miner from ever proceeding.
|
||||
// IBD is complete once we've passed the checkpoint AND the chain tip is
|
||||
// recent (within 24h). This prevents a stall AFTER checkpoint from
|
||||
// permanently disabling header fetching. The forcestaking path above
|
||||
// handles the specific staking-broker scenario.
|
||||
if (GetTime() - nLastUpdate > 24 * 60 * 60)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3339,7 +2822,12 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c
|
||||
return DoS(100, error("CheckBlock() : more than one coinbase"));
|
||||
|
||||
// Check coinbase timestamp
|
||||
if (GetBlockTime() > FutureDrift((int64_t)vtx[0].nTime))
|
||||
// NOTE: Must use the pre-fork (10-minute) drift tolerance here because
|
||||
// CheckBlock() is context-free (no nHeight) and can be called on blocks
|
||||
// at any height, including during chain reorgs from old fork chains.
|
||||
// The tight 90-second drift for post-fork blocks is enforced separately
|
||||
// in AcceptBlock/ConnectBlock with proper height context.
|
||||
if (GetBlockTime() > (int64_t)vtx[0].nTime + 10 * 60)
|
||||
return DoS(50, error("CheckBlock() : coinbase timestamp is too early"));
|
||||
|
||||
if (IsProofOfStake())
|
||||
@@ -3583,7 +3071,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
// triangles: check proof-of-stake
|
||||
// Limited duplicity on stake: prevents block flood attack
|
||||
// Duplicate stake allowed only when there is orphan child block
|
||||
if (pblock->IsProofOfStake() && setStakeSeen.count(pblock->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash))
|
||||
if (pblock->IsProofOfStake() && !GetBoolArg("-ignoredupstake", false) && setStakeSeen.count(pblock->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash))
|
||||
return error("ProcessBlock() : duplicate proof-of-stake (%s, %d) for block %s", pblock->GetProofOfStake().first.ToString().c_str(), pblock->GetProofOfStake().second, hash.ToString().c_str());
|
||||
|
||||
// Preliminary checks
|
||||
@@ -3641,13 +3129,15 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
{
|
||||
// Limited duplicity on stake: prevents block flood attack
|
||||
// Duplicate stake allowed only when there is orphan child block
|
||||
if (setStakeSeenOrphan.count(pblock2->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash))
|
||||
if (!GetBoolArg("-ignoredupstake", false) && setStakeSeenOrphan.count(pblock2->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash))
|
||||
return error("ProcessBlock() : duplicate proof-of-stake (%s, %d) for orphan block %s", pblock2->GetProofOfStake().first.ToString().c_str(), pblock2->GetProofOfStake().second, hash.ToString().c_str());
|
||||
else
|
||||
setStakeSeenOrphan.insert(pblock2->GetProofOfStake());
|
||||
}
|
||||
uint256 hashPrevOrphan = pblock2->hashPrevBlock;
|
||||
CBlock* pblock2raw = pblock2.get();
|
||||
mapOrphanBlocks.insert(make_pair(hash, std::move(pblock2)));
|
||||
mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2.get()));
|
||||
mapOrphanBlocksByPrev.insert(make_pair(hashPrevOrphan, pblock2raw));
|
||||
dequeOrphanOrder.push_back(hash); // track insertion order for FIFO eviction
|
||||
|
||||
// Limit orphan blocks to prevent memory exhaustion.
|
||||
@@ -3659,11 +3149,11 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
// Ask this guy to fill in what we're missing
|
||||
if (pfrom && pindexBest)
|
||||
{
|
||||
pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2.get()));
|
||||
pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2raw));
|
||||
// triangles: getblocks may not obtain the ancestor block rejected
|
||||
// earlier by duplicate-stake check so we ask for it again directly
|
||||
if (!IsInitialBlockDownload())
|
||||
pfrom->AskFor(CInv(MSG_BLOCK, WantedByOrphan(pblock2.get())));
|
||||
pfrom->AskFor(CInv(MSG_BLOCK, WantedByOrphan(pblock2raw)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -3672,7 +3162,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
if (!pblock->AcceptBlock())
|
||||
return error("ProcessBlock() : AcceptBlock FAILED");
|
||||
|
||||
MarkHeaderSyncBlockAccepted(hash);
|
||||
g_syncManager.BlockAccepted(hash);
|
||||
|
||||
// Recursively process any orphan blocks that depended on this one
|
||||
vector<uint256> vWorkQueue;
|
||||
@@ -3688,7 +3178,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
if (pblockOrphan->AcceptBlock())
|
||||
{
|
||||
vWorkQueue.push_back(pblockOrphan->GetHash());
|
||||
MarkHeaderSyncBlockAccepted(pblockOrphan->GetHash());
|
||||
g_syncManager.BlockAccepted(pblockOrphan->GetHash());
|
||||
}
|
||||
mapOrphanBlocks.erase(pblockOrphan->GetHash());
|
||||
setStakeSeenOrphan.erase(pblockOrphan->GetProofOfStake());
|
||||
@@ -3702,16 +3192,16 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
|
||||
if (IsInitialBlockDownload())
|
||||
{
|
||||
const unsigned int nQueued =
|
||||
(hashBestHeaderSync != 0) ? QueueHeaderSyncBlocksParallel(HEADER_DOWNLOAD_WINDOW) : 0;
|
||||
(g_syncManager.GetBestHeader() != 0) ? g_syncManager.QueueBlocksParallel() : 0;
|
||||
if (nQueued > 0)
|
||||
printf("IBD-DIAG: queued %u more blocks from header planner after accepting %s\n",
|
||||
nQueued, hash.ToString().substr(0,20).c_str());
|
||||
|
||||
const unsigned int nPlannerDepth = GetHeaderSyncPlannerDepth();
|
||||
if (nPlannerDepth <= HEADER_SYNC_LOW_WATER)
|
||||
const unsigned int nPlannerDepth = g_syncManager.GetPlannerDepth();
|
||||
if (nPlannerDepth <= CSyncManager::HEADER_SYNC_LOW_WATER)
|
||||
{
|
||||
const unsigned int nRefilled = RequestHeaderSyncRefillAllPeers(
|
||||
hashBestHeaderSync, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
const unsigned int nRefilled = g_syncManager.RequestRefillAllPeers(
|
||||
g_syncManager.GetBestHeader(), CSyncManager::HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
(nPlannerDepth == 0) ? "post-accept planner empty" : "post-accept planner low-water");
|
||||
if (nRefilled > 0)
|
||||
printf("IBD-DIAG: post-accept requested headers from %u peers at plannerDepth=%u after block %s\n",
|
||||
@@ -4562,14 +4052,23 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
// parallelism. Multiple peers sending overlapping inv ranges is harmless
|
||||
// (AlreadyHave filters duplicates) but ensures we discover and download
|
||||
// blocks from the fastest available source.
|
||||
// NOTE: nStartingHeight from version messages is unverified. Peers can
|
||||
// claim any height. During IBD we always ask all eligible peers rather
|
||||
// than filtering on a claim that may be wrong (a stunted node could be
|
||||
// reporting the full chain height while only serving the tail of its
|
||||
// own fork). Use nBestKnownHeight (updated from actual block responses)
|
||||
// for peer capability assessment instead.
|
||||
static int nAskedForBlocks = 0;
|
||||
bool fIBD = IsInitialBlockDownload();
|
||||
bool fBehindPeer = (pfrom->nStartingHeight > nBestHeight);
|
||||
// During IBD: ask every non-client peer unconditionally to maximise
|
||||
// download sources. Post-IBD: use traditional height-check logic.
|
||||
bool fShouldAsk = !pfrom->fClient && !pfrom->fOneShot &&
|
||||
(pfrom->nStartingHeight > (nBestHeight - 144)) &&
|
||||
(fIBD ||
|
||||
pfrom->nStartingHeight > (nBestHeight - 144) ||
|
||||
pfrom->nStartingHeight > nBestHeight) &&
|
||||
(pfrom->nVersion < NOBLKS_VERSION_START ||
|
||||
pfrom->nVersion >= NOBLKS_VERSION_END) &&
|
||||
(fIBD || nAskedForBlocks < 1 || vNodes.size() <= 1 || fBehindPeer);
|
||||
(fIBD || nAskedForBlocks < 1 || vNodes.size() <= 1 || pfrom->nStartingHeight > nBestHeight);
|
||||
printf("IBD-DIAG: version handler: peer=%s height=%d ourHeight=%d fClient=%d fOneShot=%d shouldAsk=%d nAskedForBlocks=%d IBD=%d\n",
|
||||
pfrom->addr.ToString().c_str(), pfrom->nStartingHeight, nBestHeight,
|
||||
pfrom->fClient, pfrom->fOneShot, fShouldAsk, nAskedForBlocks, fIBD);
|
||||
@@ -4582,7 +4081,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
// so we learn about future blocks much faster. The headers handler
|
||||
// will AskFor each unknown block, pre-populating the download queue.
|
||||
if (fIBD)
|
||||
RequestHeaderSyncRefill(pfrom, hashBestHeaderSync, 0, "version bootstrap");
|
||||
g_syncManager.RequestRefill(pfrom, g_syncManager.GetBestHeader(), 0, "version bootstrap");
|
||||
printf("IBD-DIAG: sent getblocks%s from height %d to peer %s\n",
|
||||
fIBD ? "+getheaders" : "", nBestHeight, pfrom->addr.ToString().c_str());
|
||||
}
|
||||
@@ -4880,19 +4379,25 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
// GetBlockIndex() fell through to genesis (no locator hash matched
|
||||
// our main chain). If the peer's tip isn't our genesis,
|
||||
// they're on a completely different fork.
|
||||
//
|
||||
// triangles fix: instead of banning or disconnecting, always respond
|
||||
// with our main chain blocks so a fork node can learn the canonical
|
||||
// chain and reorganize. The fork node's client will automatically
|
||||
// reorg when it receives blocks that form a longer or higher-work chain.
|
||||
if (!locator.IsNull() && pindex == pindexGenesisBlock &&
|
||||
pindexGenesisBlock && locator.GetTipHash() != pindexGenesisBlock->GetBlockHash())
|
||||
{
|
||||
pfrom->nIncompatibleGetblocks++;
|
||||
if (pfrom->nIncompatibleGetblocks >= 3)
|
||||
{
|
||||
printf("WARNING: peer %s sent %d getblocks with no common blocks — disconnecting (incompatible fork)\n",
|
||||
pfrom->addr.ToString().c_str(), pfrom->nIncompatibleGetblocks);
|
||||
pfrom->Misbehaving(100);
|
||||
return true;
|
||||
}
|
||||
printf("WARNING: peer %s getblocks locator has no common blocks (%d/3 before ban)\n",
|
||||
// triangles: after many failed attempts, reset — the peer may now be
|
||||
// on the correct chain and we don't want to ban a node that's just
|
||||
// learning about the main chain from us.
|
||||
if (pfrom->nIncompatibleGetblocks > 10)
|
||||
pfrom->nIncompatibleGetblocks = 0;
|
||||
// triangles: NO return/ban here — fall through and serve main chain
|
||||
// blocks so the forking peer can reorg to our chain.
|
||||
printf("WARNING: peer %s getblocks locator has no common blocks — serving main chain from genesis (counter=%d, will reset after 10)\\n",
|
||||
pfrom->addr.ToString().c_str(), pfrom->nIncompatibleGetblocks);
|
||||
pindex = pindexGenesisBlock;
|
||||
}
|
||||
else if (pindex && pindex != pindexGenesisBlock)
|
||||
{
|
||||
@@ -4972,97 +4477,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
{
|
||||
vector<CBlock> vHeaders;
|
||||
vRecv >> vHeaders;
|
||||
if (vHeaders.size() > 2000)
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("message headers size() = %" PRIszu "", vHeaders.size());
|
||||
}
|
||||
|
||||
uint256 hashChainTip = 0;
|
||||
int nNewHeaders = 0;
|
||||
for (const CBlock& header : vHeaders)
|
||||
{
|
||||
if (!header.vtx.empty())
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("headers message includes transactions");
|
||||
}
|
||||
|
||||
const uint256 hashHeader = header.GetHash();
|
||||
if (mapBlockIndex.count(hashHeader) || mapHeaderSync.count(hashHeader))
|
||||
{
|
||||
hashChainTip = hashHeader;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hashChainTip != 0)
|
||||
{
|
||||
if (header.hashPrevBlock != hashChainTip)
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("non-continuous headers sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto miPrev = mapBlockIndex.find(header.hashPrevBlock);
|
||||
if (miPrev == mapBlockIndex.end() && !mapHeaderSync.count(header.hashPrevBlock))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!AddHeaderSyncNode(header, hashHeader))
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("invalid header sequence");
|
||||
}
|
||||
|
||||
hashChainTip = hashHeader;
|
||||
nNewHeaders++;
|
||||
}
|
||||
|
||||
int nRequested = 0;
|
||||
if (hashBestHeaderSync != 0)
|
||||
nRequested = QueueHeaderSyncBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
|
||||
if (nNewHeaders > 0)
|
||||
nLastNewHeaderTime = GetTime();
|
||||
|
||||
if (nNewHeaders > 0 || nRequested > 0)
|
||||
printf("IBD-DIAG: accepted %d new headers, queued %d blocks from %zu headers (peer=%s bestHeader=%s)\n",
|
||||
nNewHeaders, nRequested, vHeaders.size(), pfrom->addr.ToString().c_str(),
|
||||
hashBestHeaderSync.ToString().substr(0,20).c_str());
|
||||
|
||||
// If we received a full batch, continue fetching headers.
|
||||
// During IBD, prefer getheaders over getblocks since headers are ~80 bytes
|
||||
// vs full blocks, letting us discover the chain structure faster.
|
||||
if (vHeaders.size() >= 2000)
|
||||
{
|
||||
if (IsInitialBlockDownload() && hashChainTip != 0)
|
||||
ContinueHeaderSync(pfrom, hashChainTip);
|
||||
else
|
||||
pfrom->PushGetBlocks(pindexBest, uint256(0));
|
||||
}
|
||||
else if (IsInitialBlockDownload() && nNewHeaders > 0 && hashChainTip != 0)
|
||||
{
|
||||
// Partial batch with new content. The peer either truncated its
|
||||
// response (e.g. send-buffer pressure on Tor) or is briefly at the
|
||||
// tip of what it knows. Either way the v5.9.2 fix only refilled
|
||||
// when the cache fully drained, so a partial batch could leave the
|
||||
// pipeline silently parked. Ask this peer to continue from the
|
||||
// highest header we now know — covers truncated responses, and
|
||||
// costs at most one empty headers reply when the peer is honestly
|
||||
// at the chain tip.
|
||||
ContinueHeaderSync(pfrom, hashChainTip);
|
||||
}
|
||||
else if (IsInitialBlockDownload())
|
||||
{
|
||||
const unsigned int nPlannerDepth = GetHeaderSyncPlannerDepth();
|
||||
if (nPlannerDepth <= HEADER_SYNC_LOW_WATER)
|
||||
RequestHeaderSyncRefill(
|
||||
pfrom, (hashChainTip != 0) ? hashChainTip : hashBestHeaderSync,
|
||||
HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
(nPlannerDepth == 0) ? "headers planner empty" : "headers planner low-water");
|
||||
}
|
||||
if (!g_syncManager.ProcessHeaders(pfrom, vHeaders))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5154,24 +4570,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
CInv inv(MSG_BLOCK, hashBlock);
|
||||
pfrom->AddInventoryKnown(inv);
|
||||
|
||||
// Track block delivery and measure latency for adaptive timeouts
|
||||
pfrom->nBlocksDelivered++;
|
||||
if (nBestHeight > pfrom->nBestKnownHeight)
|
||||
pfrom->nBestKnownHeight = nBestHeight;
|
||||
|
||||
// Update rolling average latency (exponential moving average, 7/8 old + 1/8 new)
|
||||
{
|
||||
int64_t nRequestTime = GetHeaderSyncRequestTime(hashBlock);
|
||||
if (nRequestTime > 0) {
|
||||
int64_t nLatency = GetTime() * 1000000 - nRequestTime;
|
||||
if (nLatency > 0) {
|
||||
if (pfrom->nAvgBlockLatencyUs == 0)
|
||||
pfrom->nAvgBlockLatencyUs = nLatency;
|
||||
else
|
||||
pfrom->nAvgBlockLatencyUs = (pfrom->nAvgBlockLatencyUs * 7 + nLatency) / 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_syncManager.TrackBlockDelivery(pfrom, hashBlock);
|
||||
|
||||
if (ProcessBlock(pfrom, &block))
|
||||
{
|
||||
@@ -5180,7 +4579,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
||||
if (IsInitialBlockDownload())
|
||||
{
|
||||
// Keep download window full after every accepted block
|
||||
QueueHeaderSyncBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
g_syncManager.QueueBlocksParallel();
|
||||
|
||||
static int nBlocksSinceRequest = 0;
|
||||
if (++nBlocksSinceRequest >= 500)
|
||||
@@ -5982,18 +5381,18 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
{
|
||||
pto->pindexLastGetHeadersBegin = nullptr;
|
||||
|
||||
uint256 hashLocatorTip = hashBestHeaderSync;
|
||||
uint256 hashLocatorTip = g_syncManager.GetBestHeader();
|
||||
if (hashLocatorTip == 0 && nHighestInvWalk > nBestHeight &&
|
||||
hashHighestInvWalk != 0 && mapBlockIndex.count(hashHighestInvWalk))
|
||||
{
|
||||
hashLocatorTip = hashHighestInvWalk;
|
||||
}
|
||||
|
||||
unsigned int nRefilled = RequestHeaderSyncRefillAllPeers(
|
||||
unsigned int nRefilled = g_syncManager.RequestRefillAllPeers(
|
||||
hashLocatorTip,
|
||||
0,
|
||||
"stall-recovery");
|
||||
unsigned int nQueued = QueueHeaderSyncBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
unsigned int nQueued = g_syncManager.QueueBlocksParallel();
|
||||
|
||||
printf("SYNC-DIAG: stall recovery used headers-first path (locator=%s, refillPeers=%u, queued=%u)\n",
|
||||
hashLocatorTip.ToString().substr(0,20).c_str(),
|
||||
@@ -6024,84 +5423,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
}
|
||||
}
|
||||
|
||||
// Per-peer IBD getheaders heartbeat. The v5.9.2 belt-and-suspenders
|
||||
// had three holes that this replaces:
|
||||
// 1. It only fired when hashBestHeaderSync == 0 (cache fully empty);
|
||||
// a few stale in-flight entries blocked refill until 15-min TTL.
|
||||
// 2. The throttle was process-wide, so an unresponsive peer could
|
||||
// "absorb" the one-per-30s request and leave others unkicked.
|
||||
// 3. It had no path for "peer stopped feeding mid-batch" — only
|
||||
// total-cache-drain triggered it.
|
||||
//
|
||||
// Per-peer heartbeat with an adaptive interval covers all three:
|
||||
// - Low-water mode (cache below the download window): 15s, refills
|
||||
// before the planner runs dry without waiting for cache exhaustion.
|
||||
// - Steady mode (cache filled): 60s, keeps each peer's view of our
|
||||
// locator fresh so a peer that goes silent gets re-asked, and a
|
||||
// peer that catches up between calls can announce new headers.
|
||||
// An empty headers response is ~14 bytes — cheap on Tor, no abuse risk.
|
||||
if (!pto->fClient && pto->nVersion != 0 && IsInitialBlockDownload())
|
||||
{
|
||||
const int64_t nNowSec = GetTime();
|
||||
const unsigned int nPlannerDepth = GetHeaderSyncPlannerDepth();
|
||||
const unsigned int nInFlight = CountHeaderSyncInFlight();
|
||||
static int64_t nLastHeaderPlannerControl = 0;
|
||||
static int64_t nLastHeaderWatchdog = 0;
|
||||
static int64_t nLastBlockPlannerControl = 0;
|
||||
|
||||
if (nLastNewHeaderTime == 0)
|
||||
nLastNewHeaderTime = nNowSec;
|
||||
|
||||
if (nNowSec - nLastHeaderPlannerControl >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
nPlannerDepth < HEADER_SYNC_LOW_WATER &&
|
||||
nInFlight < HEADER_SYNC_TARGET_INFLIGHT)
|
||||
{
|
||||
const unsigned int nRefilled = RequestHeaderSyncRefillAllPeers(
|
||||
hashBestHeaderSync, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
"control-loop");
|
||||
if (nRefilled > 0)
|
||||
printf("IBD-DIAG: control-loop refill from %u peers (plannerDepth=%u inflight=%u target=%u)\n",
|
||||
nRefilled, nPlannerDepth, nInFlight, HEADER_SYNC_TARGET_INFLIGHT);
|
||||
nLastHeaderPlannerControl = nNowSec;
|
||||
}
|
||||
|
||||
if (nNowSec - nLastHeaderWatchdog >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
nNowSec - nLastNewHeaderTime >= HEADER_SYNC_WATCHDOG_SECONDS)
|
||||
{
|
||||
const unsigned int nRefilled = RequestHeaderSyncRefillAllPeers(
|
||||
hashBestHeaderSync, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
"headers-watchdog");
|
||||
if (nRefilled > 0)
|
||||
printf("IBD-DIAG: headers watchdog refill from %u peers after %llds without new headers (plannerDepth=%u inflight=%u)\n",
|
||||
nRefilled,
|
||||
(long long)(nNowSec - nLastNewHeaderTime),
|
||||
nPlannerDepth,
|
||||
nInFlight);
|
||||
nLastHeaderWatchdog = nNowSec;
|
||||
}
|
||||
|
||||
const int64_t nMinInterval =
|
||||
(mapHeaderSync.size() < HEADER_DOWNLOAD_WINDOW) ? 15 : 60;
|
||||
|
||||
if (nNowSec - pto->nLastIbdHeaderRequest >= nMinInterval)
|
||||
RequestHeaderSyncRefill(pto, hashBestHeaderSync, nMinInterval, "heartbeat");
|
||||
|
||||
// Keep the block planner alive even when no new headers arrive and
|
||||
// no blocks are being accepted. Without this periodic kick, the
|
||||
// redundant-request and timeout logic inside QueueHeaderSyncBlocksParallel()
|
||||
// only runs on header arrivals or block acceptance, so IBD can park
|
||||
// indefinitely behind one missing frontier block.
|
||||
if (nNowSec - nLastBlockPlannerControl >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
hashBestHeaderSync != 0 &&
|
||||
nPlannerDepth > 0)
|
||||
{
|
||||
const unsigned int nRequeued = QueueHeaderSyncBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
if (nRequeued > 0)
|
||||
printf("IBD-DIAG: block-planner control queued %u block requests (plannerDepth=%u inflight=%u)\n",
|
||||
nRequeued, nPlannerDepth, nInFlight);
|
||||
nLastBlockPlannerControl = nNowSec;
|
||||
}
|
||||
}
|
||||
// Per-peer IBD getheaders heartbeat and block-planner cadence.
|
||||
// Logic lives in CSyncManager::Tick — see syncmanager.cpp.
|
||||
g_syncManager.Tick(pto, nHighestInvWalk, hashHighestInvWalk);
|
||||
|
||||
//
|
||||
// Message: getdata
|
||||
@@ -6112,9 +5436,9 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
if (GetTime() - nLastStatus >= 15) {
|
||||
printf("IBD-DIAG: STATUS height=%d plannerHeight=%d plannerDepth=%u inflight=%u peers=%d askfor_queued=%d orphans=%d\n",
|
||||
nBestHeight,
|
||||
GetHeaderSyncPlannerHeight(),
|
||||
GetHeaderSyncPlannerDepth(),
|
||||
CountHeaderSyncInFlight(),
|
||||
g_syncManager.GetPlannerHeight(),
|
||||
g_syncManager.GetPlannerDepth(),
|
||||
g_syncManager.CountInFlight(),
|
||||
(int)vNodes.size(),
|
||||
(int)pto->mapAskFor.size(),
|
||||
(int)mapOrphanBlocks.size());
|
||||
|
||||
@@ -545,7 +545,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
|
||||
int64_t nFee = nTransactionFee * (1 + (int64_t)nBytes / 1000);
|
||||
|
||||
// Min Fee
|
||||
int64_t nMinFee = txDummy.GetMinFee(1, GMF_SEND, nBytes);
|
||||
int64_t nMinFee = txDummy.GetMinFee(1, GetMinFeeMode::Send, nBytes);
|
||||
|
||||
nPayFee = max(nFee, nMinFee);
|
||||
|
||||
|
||||
@@ -0,0 +1,664 @@
|
||||
// Copyright (c) 2026 The Triangles developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "syncmanager.h"
|
||||
|
||||
#include "bignum.h"
|
||||
#include "checkpoints.h"
|
||||
#include "main.h"
|
||||
#include "net.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
struct CSyncManager::HeaderNode
|
||||
{
|
||||
CBlock header;
|
||||
int nHeight;
|
||||
uint256 nChainTrust;
|
||||
bool fRequested;
|
||||
int64_t nLastRequestTime;
|
||||
int64_t nFirstRequestTime;
|
||||
int64_t nInsertTime;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
static const unsigned int MAX_HEADER_SYNC_CACHE = 15000;
|
||||
static const size_t HEADER_REDUNDANT_PEER_THRESHOLD = 4;
|
||||
static const int64_t HEADER_REQUEST_TIMEOUT_MICROS = 60 * 1000000;
|
||||
static const int64_t HEADER_REDUNDANT_REQUEST_MICROS = 5 * 1000000;
|
||||
static const int64_t HEADER_SYNC_TTL_MICROS = 15 * 60 * 1000000;
|
||||
|
||||
std::map<uint256, CSyncManager::HeaderNode> mapHeaders;
|
||||
uint256 hashBestHeader = 0;
|
||||
int64_t nLastNewHeaderTime = 0;
|
||||
}
|
||||
|
||||
CSyncManager g_syncManager;
|
||||
|
||||
bool CSyncManager::HaveHeader(const uint256& hash) const
|
||||
{
|
||||
return mapHeaders.count(hash) != 0;
|
||||
}
|
||||
|
||||
uint256 CSyncManager::GetBestHeader() const
|
||||
{
|
||||
return hashBestHeader;
|
||||
}
|
||||
|
||||
std::size_t CSyncManager::GetHeaderCount() const
|
||||
{
|
||||
return mapHeaders.size();
|
||||
}
|
||||
|
||||
uint256 CSyncManager::GetHeaderTrust(unsigned int nBits) const
|
||||
{
|
||||
CBigNum bnTarget;
|
||||
bnTarget.SetCompact(nBits);
|
||||
|
||||
if (bnTarget <= 0)
|
||||
return 0;
|
||||
|
||||
return ((CBigNum(1) << 256) / (bnTarget + 1)).getuint256();
|
||||
}
|
||||
|
||||
bool CSyncManager::GetKnownHeaderState(const uint256& hash, int& nHeight, uint256& nChainTrust) const
|
||||
{
|
||||
std::map<uint256, CBlockIndex*>::const_iterator miBlock = mapBlockIndex.find(hash);
|
||||
if (miBlock != mapBlockIndex.end())
|
||||
{
|
||||
nHeight = miBlock->second->nHeight;
|
||||
nChainTrust = miBlock->second->nChainTrust;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<uint256, HeaderNode>::const_iterator miHeader = mapHeaders.find(hash);
|
||||
if (miHeader != mapHeaders.end())
|
||||
{
|
||||
nHeight = miHeader->second.nHeight;
|
||||
nChainTrust = miHeader->second.nChainTrust;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSyncManager::GetPrevHash(const uint256& hash, uint256& hashPrev) const
|
||||
{
|
||||
std::map<uint256, HeaderNode>::const_iterator miHeader = mapHeaders.find(hash);
|
||||
if (miHeader != mapHeaders.end())
|
||||
{
|
||||
hashPrev = miHeader->second.header.hashPrevBlock;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<uint256, CBlockIndex*>::const_iterator miBlock = mapBlockIndex.find(hash);
|
||||
if (miBlock != mapBlockIndex.end() && miBlock->second->pprev)
|
||||
{
|
||||
hashPrev = miBlock->second->pprev->GetBlockHash();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSyncManager::RecomputeBestHeader()
|
||||
{
|
||||
hashBestHeader = 0;
|
||||
uint256 nBestTrust = 0;
|
||||
|
||||
for (std::map<uint256, HeaderNode>::const_iterator it = mapHeaders.begin(); it != mapHeaders.end(); ++it)
|
||||
{
|
||||
if (hashBestHeader == 0 || it->second.nChainTrust > nBestTrust)
|
||||
{
|
||||
hashBestHeader = it->first;
|
||||
nBestTrust = it->second.nChainTrust;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSyncManager::PruneHeaders()
|
||||
{
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
|
||||
if (mapHeaders.size() > MAX_HEADER_SYNC_CACHE / 2)
|
||||
{
|
||||
unsigned int nEvicted = 0;
|
||||
for (std::map<uint256, HeaderNode>::iterator it = mapHeaders.begin(); it != mapHeaders.end(); )
|
||||
{
|
||||
if (nNow - it->second.nInsertTime >= HEADER_SYNC_TTL_MICROS)
|
||||
{
|
||||
it = mapHeaders.erase(it);
|
||||
++nEvicted;
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
if (nEvicted > 0)
|
||||
{
|
||||
printf("IBD-DIAG: TTL-evicted %u stale sync headers, %u remain\n",
|
||||
nEvicted, (unsigned int)mapHeaders.size());
|
||||
RecomputeBestHeader();
|
||||
}
|
||||
}
|
||||
|
||||
if (mapHeaders.size() > MAX_HEADER_SYNC_CACHE)
|
||||
{
|
||||
printf("IBD-DIAG: sync header cache exceeded %u entries, evicting oldest\n", MAX_HEADER_SYNC_CACHE);
|
||||
while (mapHeaders.size() > MAX_HEADER_SYNC_CACHE * 3 / 4)
|
||||
{
|
||||
std::map<uint256, HeaderNode>::iterator oldest = mapHeaders.begin();
|
||||
for (std::map<uint256, HeaderNode>::iterator it = mapHeaders.begin(); it != mapHeaders.end(); ++it)
|
||||
{
|
||||
if (it->second.nInsertTime < oldest->second.nInsertTime)
|
||||
oldest = it;
|
||||
}
|
||||
mapHeaders.erase(oldest);
|
||||
}
|
||||
RecomputeBestHeader();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSyncManager::AddHeaderNode(const CBlock& header, const uint256& hashHeader)
|
||||
{
|
||||
if (mapBlockIndex.count(hashHeader) || mapHeaders.count(hashHeader))
|
||||
return true;
|
||||
|
||||
if (!header.vtx.empty())
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (has vtx) hash=%s\n", hashHeader.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (header.GetBlockTime() > GetTime() + 15 * 60)
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (future time) hash=%s time=%u\n",
|
||||
hashHeader.ToString().substr(0,20).c_str(), header.nTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
int nPrevHeight = -1;
|
||||
uint256 nPrevChainTrust = 0;
|
||||
if (!GetKnownHeaderState(header.hashPrevBlock, nPrevHeight, nPrevChainTrust))
|
||||
{
|
||||
printf("IBD-DIAG: header rejected (prev unknown) hash=%s prevHash=%s\n",
|
||||
hashHeader.ToString().substr(0,20).c_str(),
|
||||
header.hashPrevBlock.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const int nHeight = nPrevHeight + 1;
|
||||
if (nHeight <= CUTOFF_POW_BLOCK && !CheckProofOfWork(hashHeader, header.nBits))
|
||||
{
|
||||
printf("IBD-DIAG: header PoW FAILED at height %d hash=%s nBits=%08x prevHash=%s\n",
|
||||
nHeight, hashHeader.ToString().substr(0,20).c_str(), header.nBits,
|
||||
header.hashPrevBlock.ToString().substr(0,20).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
HeaderNode node;
|
||||
node.header = header;
|
||||
node.nHeight = nHeight;
|
||||
node.nChainTrust = nPrevChainTrust + GetHeaderTrust(header.nBits);
|
||||
node.fRequested = false;
|
||||
node.nLastRequestTime = 0;
|
||||
node.nFirstRequestTime = 0;
|
||||
node.nInsertTime = GetTime() * 1000000;
|
||||
|
||||
mapHeaders.insert({hashHeader, node});
|
||||
|
||||
if (hashBestHeader == 0 || node.nChainTrust > mapHeaders[hashBestHeader].nChainTrust)
|
||||
hashBestHeader = hashHeader;
|
||||
|
||||
PruneHeaders();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<uint256> CSyncManager::GetDownloadPath(uint256 hashTip) const
|
||||
{
|
||||
std::vector<uint256> vPath;
|
||||
|
||||
while (hashTip != 0 && !mapBlockIndex.count(hashTip))
|
||||
{
|
||||
std::map<uint256, HeaderNode>::const_iterator mi = mapHeaders.find(hashTip);
|
||||
if (mi == mapHeaders.end())
|
||||
break;
|
||||
|
||||
vPath.push_back(hashTip);
|
||||
hashTip = mi->second.header.hashPrevBlock;
|
||||
}
|
||||
|
||||
std::reverse(vPath.begin(), vPath.end());
|
||||
return vPath;
|
||||
}
|
||||
|
||||
unsigned int CSyncManager::CountInFlight() const
|
||||
{
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
unsigned int nInFlight = 0;
|
||||
for (std::map<uint256, HeaderNode>::const_iterator it = mapHeaders.begin(); it != mapHeaders.end(); ++it)
|
||||
{
|
||||
if (it->second.fRequested && nNow - it->second.nLastRequestTime < HEADER_REQUEST_TIMEOUT_MICROS)
|
||||
++nInFlight;
|
||||
}
|
||||
return nInFlight;
|
||||
}
|
||||
|
||||
unsigned int CSyncManager::GetPlannerDepth() const
|
||||
{
|
||||
if (hashBestHeader == 0)
|
||||
return 0;
|
||||
|
||||
return (unsigned int)GetDownloadPath(hashBestHeader).size();
|
||||
}
|
||||
|
||||
int CSyncManager::GetPlannerHeight() const
|
||||
{
|
||||
if (hashBestHeader == 0)
|
||||
return pindexBest ? pindexBest->nHeight : -1;
|
||||
|
||||
std::map<uint256, HeaderNode>::const_iterator mi = mapHeaders.find(hashBestHeader);
|
||||
if (mi == mapHeaders.end())
|
||||
return pindexBest ? pindexBest->nHeight : -1;
|
||||
|
||||
return mi->second.nHeight;
|
||||
}
|
||||
|
||||
int64_t CSyncManager::GetRequestTime(const uint256& hashBlock) const
|
||||
{
|
||||
std::map<uint256, HeaderNode>::const_iterator mi = mapHeaders.find(hashBlock);
|
||||
if (mi == mapHeaders.end())
|
||||
return 0;
|
||||
return mi->second.nFirstRequestTime;
|
||||
}
|
||||
|
||||
void CSyncManager::BlockAccepted(const uint256& hashBlock)
|
||||
{
|
||||
std::map<uint256, HeaderNode>::iterator mi = mapHeaders.find(hashBlock);
|
||||
if (mi == mapHeaders.end())
|
||||
return;
|
||||
|
||||
mapHeaders.erase(mi);
|
||||
if (hashBestHeader == hashBlock)
|
||||
RecomputeBestHeader();
|
||||
}
|
||||
|
||||
void CSyncManager::ContinueHeaders(CNode* pfrom, const uint256& hashTip)
|
||||
{
|
||||
if (!pfrom || hashTip == 0)
|
||||
return;
|
||||
|
||||
std::vector<uint256> vHave;
|
||||
uint256 hashWalk = hashTip;
|
||||
int nStep = 1;
|
||||
|
||||
while (hashWalk != 0)
|
||||
{
|
||||
vHave.push_back(hashWalk);
|
||||
|
||||
for (int i = 0; i < nStep && hashWalk != 0; ++i)
|
||||
{
|
||||
uint256 hashPrev = 0;
|
||||
if (!GetPrevHash(hashWalk, hashPrev))
|
||||
hashWalk = 0;
|
||||
else
|
||||
hashWalk = hashPrev;
|
||||
}
|
||||
|
||||
if (vHave.size() > 10)
|
||||
nStep *= 2;
|
||||
}
|
||||
|
||||
vHave.push_back(!fTestNet ? hashGenesisBlockOfficial : hashGenesisBlockTestNet);
|
||||
pfrom->PushMessage("getheaders", CBlockLocator(vHave), uint256(0));
|
||||
}
|
||||
|
||||
bool CSyncManager::RequestRefill(CNode* pfrom, uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason)
|
||||
{
|
||||
if (!pfrom || pfrom->fClient || pfrom->nVersion == 0 || !IsInitialBlockDownload())
|
||||
return false;
|
||||
|
||||
const int64_t nNowSec = GetTime();
|
||||
if (nMinIntervalSeconds > 0 &&
|
||||
nNowSec - pfrom->nLastIbdHeaderRequest < nMinIntervalSeconds)
|
||||
return false;
|
||||
|
||||
uint256 hashLocatorTip = hashTip;
|
||||
if (hashLocatorTip == 0 ||
|
||||
(!mapBlockIndex.count(hashLocatorTip) && !mapHeaders.count(hashLocatorTip)))
|
||||
{
|
||||
hashLocatorTip = hashBestHeader;
|
||||
}
|
||||
|
||||
if (hashLocatorTip != 0 && (!pindexBest || hashLocatorTip != pindexBest->GetBlockHash()))
|
||||
{
|
||||
ContinueHeaders(pfrom, hashLocatorTip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pindexBest)
|
||||
return false;
|
||||
|
||||
pfrom->pindexLastGetHeadersBegin = NULL;
|
||||
pfrom->PushGetHeaders(pindexBest, uint256(0));
|
||||
hashLocatorTip = pindexBest->GetBlockHash();
|
||||
}
|
||||
|
||||
pfrom->nLastIbdHeaderRequest = nNowSec;
|
||||
printf("IBD-DIAG: %s getheaders to peer=%s locator=%s plannerDepth=%u inflight=%u\n",
|
||||
pszReason, pfrom->addr.ToString().c_str(),
|
||||
hashLocatorTip.ToString().substr(0,20).c_str(),
|
||||
GetPlannerDepth(), CountInFlight());
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int CSyncManager::RequestRefillAllPeers(uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason)
|
||||
{
|
||||
std::vector<CNode*> vEligiblePeers;
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes)
|
||||
{
|
||||
if (!pnode->fClient && pnode->nVersion != 0 && !pnode->fDisconnect)
|
||||
vEligiblePeers.push_back(pnode);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int nRequested = 0;
|
||||
for (CNode* pnode : vEligiblePeers)
|
||||
{
|
||||
if (RequestRefill(pnode, hashTip, nMinIntervalSeconds, pszReason))
|
||||
++nRequested;
|
||||
}
|
||||
|
||||
return nRequested;
|
||||
}
|
||||
|
||||
unsigned int CSyncManager::QueueBlocksParallel(unsigned int nWindow)
|
||||
{
|
||||
if (hashBestHeader == 0)
|
||||
return 0;
|
||||
|
||||
const std::vector<uint256> vPath = GetDownloadPath(hashBestHeader);
|
||||
if (vPath.empty())
|
||||
return 0;
|
||||
|
||||
std::vector<CNode*> vEligiblePeers;
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for (CNode* pnode : vNodes)
|
||||
{
|
||||
if (!pnode->fClient && pnode->nVersion != 0 && !pnode->fDisconnect)
|
||||
vEligiblePeers.push_back(pnode);
|
||||
}
|
||||
}
|
||||
|
||||
if (vEligiblePeers.empty())
|
||||
return 0;
|
||||
|
||||
const int64_t nNow = GetTime() * 1000000;
|
||||
unsigned int nInFlight = CountInFlight();
|
||||
unsigned int nQueued = 0;
|
||||
unsigned int nPeerIndex = 0;
|
||||
|
||||
std::sort(vEligiblePeers.begin(), vEligiblePeers.end(),
|
||||
[](const CNode* a, const CNode* b) {
|
||||
return a->nBlocksDelivered > b->nBlocksDelivered;
|
||||
});
|
||||
|
||||
std::vector<CNode*> vWeightedPeers;
|
||||
for (size_t i = 0; i < vEligiblePeers.size(); i++)
|
||||
{
|
||||
int nWeight = (i == 0) ? 3 : (i == 1) ? 2 : 1;
|
||||
for (int w = 0; w < nWeight; w++)
|
||||
vWeightedPeers.push_back(vEligiblePeers[i]);
|
||||
}
|
||||
|
||||
int64_t nAdaptiveTimeout = HEADER_REQUEST_TIMEOUT_MICROS;
|
||||
{
|
||||
int64_t nTotalLatency = 0;
|
||||
int nPeersWithLatency = 0;
|
||||
for (const CNode* pnode : vEligiblePeers)
|
||||
{
|
||||
if (pnode->nAvgBlockLatencyUs > 0)
|
||||
{
|
||||
nTotalLatency += pnode->nAvgBlockLatencyUs;
|
||||
++nPeersWithLatency;
|
||||
}
|
||||
}
|
||||
if (nPeersWithLatency > 0)
|
||||
{
|
||||
int64_t nAvgLatency = nTotalLatency / nPeersWithLatency;
|
||||
nAdaptiveTimeout = std::max((int64_t)(10 * 1000000),
|
||||
std::min((int64_t)(60 * 1000000), nAvgLatency * 5));
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<uint256>::const_iterator it = vPath.begin(); it != vPath.end(); ++it)
|
||||
{
|
||||
if (nInFlight + nQueued >= nWindow)
|
||||
break;
|
||||
|
||||
std::map<uint256, HeaderNode>::iterator mi = mapHeaders.find(*it);
|
||||
if (mi == mapHeaders.end())
|
||||
continue;
|
||||
|
||||
bool fNeedsRequest = false;
|
||||
if (!mi->second.fRequested)
|
||||
fNeedsRequest = true;
|
||||
else if (nNow - mi->second.nLastRequestTime >= nAdaptiveTimeout)
|
||||
fNeedsRequest = true;
|
||||
else if (nNow - mi->second.nLastRequestTime >= HEADER_REDUNDANT_REQUEST_MICROS)
|
||||
fNeedsRequest = true;
|
||||
|
||||
if (!fNeedsRequest)
|
||||
continue;
|
||||
|
||||
CNode* pnode = vWeightedPeers[nPeerIndex % vWeightedPeers.size()];
|
||||
pnode->AskFor(CInv(MSG_BLOCK, *it));
|
||||
|
||||
if (IsInitialBlockDownload() &&
|
||||
vWeightedPeers.size() >= 2 &&
|
||||
vWeightedPeers.size() < HEADER_REDUNDANT_PEER_THRESHOLD &&
|
||||
!mi->second.fRequested)
|
||||
{
|
||||
CNode* pnode2 = vWeightedPeers[(nPeerIndex + 1) % vWeightedPeers.size()];
|
||||
if (pnode2 != pnode)
|
||||
pnode2->AskFor(CInv(MSG_BLOCK, *it));
|
||||
}
|
||||
|
||||
if (!mi->second.fRequested || nNow - mi->second.nLastRequestTime >= HEADER_REQUEST_TIMEOUT_MICROS)
|
||||
{
|
||||
if (!mi->second.fRequested)
|
||||
mi->second.nFirstRequestTime = nNow;
|
||||
mi->second.fRequested = true;
|
||||
mi->second.nLastRequestTime = nNow;
|
||||
}
|
||||
|
||||
++nQueued;
|
||||
++nPeerIndex;
|
||||
}
|
||||
|
||||
if (nQueued > 0)
|
||||
printf("IBD-DIAG: sync manager queued %u blocks across %zu peers (window=%u, inflight=%u)\n",
|
||||
nQueued, vEligiblePeers.size(), nWindow, nInFlight);
|
||||
|
||||
return nQueued;
|
||||
}
|
||||
|
||||
bool CSyncManager::ProcessHeaders(CNode* pfrom, const std::vector<CBlock>& vHeaders)
|
||||
{
|
||||
if (vHeaders.size() > 2000)
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("message headers size() = %" PRIszu "", vHeaders.size());
|
||||
}
|
||||
|
||||
uint256 hashChainTip = 0;
|
||||
int nNewHeaders = 0;
|
||||
for (const CBlock& header : vHeaders)
|
||||
{
|
||||
if (!header.vtx.empty())
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("headers message includes transactions");
|
||||
}
|
||||
|
||||
const uint256 hashHeader = header.GetHash();
|
||||
if (mapBlockIndex.count(hashHeader) || mapHeaders.count(hashHeader))
|
||||
{
|
||||
hashChainTip = hashHeader;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hashChainTip != 0)
|
||||
{
|
||||
if (header.hashPrevBlock != hashChainTip)
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("non-continuous headers sequence");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(header.hashPrevBlock);
|
||||
if (miPrev == mapBlockIndex.end() && !mapHeaders.count(header.hashPrevBlock))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!AddHeaderNode(header, hashHeader))
|
||||
{
|
||||
pfrom->Misbehaving(20);
|
||||
return error("invalid header sequence");
|
||||
}
|
||||
|
||||
hashChainTip = hashHeader;
|
||||
nNewHeaders++;
|
||||
}
|
||||
|
||||
int nRequested = 0;
|
||||
if (hashBestHeader != 0)
|
||||
nRequested = QueueBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
|
||||
if (nNewHeaders > 0)
|
||||
nLastNewHeaderTime = GetTime();
|
||||
|
||||
if (nNewHeaders > 0 || nRequested > 0)
|
||||
printf("IBD-DIAG: accepted %d new headers, queued %d blocks from %zu headers (peer=%s bestHeader=%s)\n",
|
||||
nNewHeaders, nRequested, vHeaders.size(), pfrom->addr.ToString().c_str(),
|
||||
hashBestHeader.ToString().substr(0,20).c_str());
|
||||
|
||||
if (vHeaders.size() >= 2000)
|
||||
{
|
||||
if (IsInitialBlockDownload() && hashChainTip != 0)
|
||||
ContinueHeaders(pfrom, hashChainTip);
|
||||
else
|
||||
pfrom->PushGetBlocks(pindexBest, uint256(0));
|
||||
}
|
||||
else if (IsInitialBlockDownload() && nNewHeaders > 0 && hashChainTip != 0)
|
||||
{
|
||||
ContinueHeaders(pfrom, hashChainTip);
|
||||
}
|
||||
else if (IsInitialBlockDownload())
|
||||
{
|
||||
const unsigned int nPlannerDepth = GetPlannerDepth();
|
||||
if (nPlannerDepth <= HEADER_SYNC_LOW_WATER)
|
||||
RequestRefill(
|
||||
pfrom, (hashChainTip != 0) ? hashChainTip : hashBestHeader,
|
||||
HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
(nPlannerDepth == 0) ? "headers planner empty" : "headers planner low-water");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSyncManager::TrackBlockDelivery(CNode* pfrom, const uint256& hashBlock)
|
||||
{
|
||||
if (!pfrom)
|
||||
return;
|
||||
|
||||
pfrom->nBlocksDelivered++;
|
||||
if (nBestHeight > pfrom->nBestKnownHeight)
|
||||
pfrom->nBestKnownHeight = nBestHeight;
|
||||
|
||||
int64_t nRequestTime = GetRequestTime(hashBlock);
|
||||
if (nRequestTime > 0)
|
||||
{
|
||||
int64_t nLatency = GetTime() * 1000000 - nRequestTime;
|
||||
if (nLatency > 0)
|
||||
{
|
||||
if (pfrom->nAvgBlockLatencyUs == 0)
|
||||
pfrom->nAvgBlockLatencyUs = nLatency;
|
||||
else
|
||||
pfrom->nAvgBlockLatencyUs = (pfrom->nAvgBlockLatencyUs * 7 + nLatency) / 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSyncManager::Tick(CNode* pto, int nHighestInvWalk, const uint256& hashHighestInvWalk)
|
||||
{
|
||||
if (!pto || pto->fClient || pto->nVersion == 0 || !IsInitialBlockDownload())
|
||||
return;
|
||||
|
||||
const int64_t nNowSec = GetTime();
|
||||
const unsigned int nPlannerDepth = GetPlannerDepth();
|
||||
const unsigned int nInFlight = CountInFlight();
|
||||
static int64_t nLastHeaderPlannerControl = 0;
|
||||
static int64_t nLastHeaderWatchdog = 0;
|
||||
static int64_t nLastBlockPlannerControl = 0;
|
||||
|
||||
if (nLastNewHeaderTime == 0)
|
||||
nLastNewHeaderTime = nNowSec;
|
||||
|
||||
if (nNowSec - nLastHeaderPlannerControl >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
nPlannerDepth < HEADER_SYNC_LOW_WATER &&
|
||||
nInFlight < HEADER_SYNC_TARGET_INFLIGHT)
|
||||
{
|
||||
const unsigned int nRefilled = RequestRefillAllPeers(
|
||||
hashBestHeader, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
"control-loop");
|
||||
if (nRefilled > 0)
|
||||
printf("IBD-DIAG: control-loop refill from %u peers (plannerDepth=%u inflight=%u target=%u)\n",
|
||||
nRefilled, nPlannerDepth, nInFlight, HEADER_SYNC_TARGET_INFLIGHT);
|
||||
nLastHeaderPlannerControl = nNowSec;
|
||||
}
|
||||
|
||||
if (nNowSec - nLastHeaderWatchdog >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
nNowSec - nLastNewHeaderTime >= HEADER_SYNC_WATCHDOG_SECONDS)
|
||||
{
|
||||
const unsigned int nRefilled = RequestRefillAllPeers(
|
||||
hashBestHeader, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS,
|
||||
"headers-watchdog");
|
||||
if (nRefilled > 0)
|
||||
printf("IBD-DIAG: headers watchdog refill from %u peers after %llds without new headers (plannerDepth=%u inflight=%u)\n",
|
||||
nRefilled,
|
||||
(long long)(nNowSec - nLastNewHeaderTime),
|
||||
nPlannerDepth,
|
||||
nInFlight);
|
||||
nLastHeaderWatchdog = nNowSec;
|
||||
}
|
||||
|
||||
const int64_t nMinInterval = (mapHeaders.size() < HEADER_DOWNLOAD_WINDOW) ? 15 : 60;
|
||||
if (nNowSec - pto->nLastIbdHeaderRequest >= nMinInterval)
|
||||
RequestRefill(pto, hashBestHeader, nMinInterval, "heartbeat");
|
||||
|
||||
if (nNowSec - nLastBlockPlannerControl >= HEADER_SYNC_CONTROL_INTERVAL_SECONDS &&
|
||||
hashBestHeader != 0 &&
|
||||
nPlannerDepth > 0)
|
||||
{
|
||||
const unsigned int nRequeued = QueueBlocksParallel(HEADER_DOWNLOAD_WINDOW);
|
||||
if (nRequeued > 0)
|
||||
printf("IBD-DIAG: block-planner control queued %u block requests (plannerDepth=%u inflight=%u)\n",
|
||||
nRequeued, nPlannerDepth, nInFlight);
|
||||
nLastBlockPlannerControl = nNowSec;
|
||||
}
|
||||
|
||||
if (hashBestHeader == 0 && nHighestInvWalk > nBestHeight &&
|
||||
hashHighestInvWalk != 0 && mapBlockIndex.count(hashHighestInvWalk))
|
||||
{
|
||||
RequestRefill(pto, hashHighestInvWalk, HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS, "inv-walk bridge");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2026 The Triangles developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef TRIANGLES_SYNCMANAGER_H
|
||||
#define TRIANGLES_SYNCMANAGER_H
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
class CBlock;
|
||||
class CInv;
|
||||
class CNode;
|
||||
|
||||
class CSyncManager
|
||||
{
|
||||
public:
|
||||
struct HeaderNode;
|
||||
|
||||
static constexpr unsigned int HEADER_DOWNLOAD_WINDOW = 1024;
|
||||
static constexpr unsigned int HEADER_SYNC_LOW_WATER = HEADER_DOWNLOAD_WINDOW / 4;
|
||||
static constexpr unsigned int HEADER_SYNC_TARGET_INFLIGHT = HEADER_DOWNLOAD_WINDOW / 2;
|
||||
static constexpr int64_t HEADER_SYNC_REFILL_MIN_INTERVAL_SECONDS = 5;
|
||||
static constexpr int64_t HEADER_SYNC_CONTROL_INTERVAL_SECONDS = 5;
|
||||
static constexpr int64_t HEADER_SYNC_WATCHDOG_SECONDS = 25;
|
||||
|
||||
bool HaveHeader(const uint256& hash) const;
|
||||
uint256 GetBestHeader() const;
|
||||
std::size_t GetHeaderCount() const;
|
||||
unsigned int CountInFlight() const;
|
||||
unsigned int GetPlannerDepth() const;
|
||||
int GetPlannerHeight() const;
|
||||
int64_t GetRequestTime(const uint256& hashBlock) const;
|
||||
|
||||
bool RequestRefill(CNode* pfrom, uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason);
|
||||
unsigned int RequestRefillAllPeers(uint256 hashTip, int64_t nMinIntervalSeconds, const char* pszReason);
|
||||
unsigned int QueueBlocksParallel(unsigned int nWindow = HEADER_DOWNLOAD_WINDOW);
|
||||
bool ProcessHeaders(CNode* pfrom, const std::vector<CBlock>& vHeaders);
|
||||
void BlockAccepted(const uint256& hashBlock);
|
||||
void TrackBlockDelivery(CNode* pfrom, const uint256& hashBlock);
|
||||
void Tick(CNode* pto, int nHighestInvWalk, const uint256& hashHighestInvWalk);
|
||||
|
||||
private:
|
||||
uint256 GetHeaderTrust(unsigned int nBits) const;
|
||||
bool GetKnownHeaderState(const uint256& hash, int& nHeight, uint256& nChainTrust) const;
|
||||
bool GetPrevHash(const uint256& hash, uint256& hashPrev) const;
|
||||
void RecomputeBestHeader();
|
||||
void PruneHeaders();
|
||||
bool AddHeaderNode(const CBlock& header, const uint256& hashHeader);
|
||||
std::vector<uint256> GetDownloadPath(uint256 hashTip) const;
|
||||
void ContinueHeaders(CNode* pfrom, const uint256& hashTip);
|
||||
};
|
||||
|
||||
extern CSyncManager g_syncManager;
|
||||
|
||||
#endif // TRIANGLES_SYNCMANAGER_H
|
||||
+28
-4
@@ -259,10 +259,34 @@ bool CTorProcess::WriteTorrc()
|
||||
// SOCKS proxy for wallet connections
|
||||
torrc << "SocksPort " << socksPort << "\n";
|
||||
|
||||
// Data directory for Tor state
|
||||
fs::path torStateDir = dataPath / "state";
|
||||
fs::create_directories(torStateDir);
|
||||
torrc << "DataDirectory " << torStateDir.string() << "\n";
|
||||
// Data directory for Tor state.
|
||||
// Use the tor_data directory itself as DataDirectory so that Tor creates
|
||||
// its internal 'state' FILE at <tor_data>/state. Older wallet builds
|
||||
// erroneously created a subdirectory called 'state' and pointed
|
||||
// DataDirectory at it; newer Tor versions (0.4.9+) reject that because
|
||||
// they expect to write a plain file called 'state' inside DataDirectory.
|
||||
//
|
||||
// Recovery: if 'state' exists as a directory, move its contents up and
|
||||
// remove it so that Tor can create its state file in the normal location.
|
||||
{
|
||||
fs::path badStateDir = dataPath / "state";
|
||||
if (fs::exists(badStateDir) && fs::is_directory(badStateDir)) {
|
||||
// Migrate any files inside the bad 'state/' directory up to dataPath
|
||||
try {
|
||||
for (auto& entry : fs::directory_iterator(badStateDir)) {
|
||||
fs::path dest = dataPath / entry.path().filename();
|
||||
if (!fs::exists(dest)) {
|
||||
fs::rename(entry.path(), dest);
|
||||
}
|
||||
}
|
||||
fs::remove(badStateDir);
|
||||
printf("Auto-recovered: removed legacy 'state' directory from %s\n", dataPath.string().c_str());
|
||||
} catch (const fs::filesystem_error& e) {
|
||||
printf("WARNING: Could not auto-recover tor_data/state directory: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
torrc << "DataDirectory " << dataPath.string() << "\n";
|
||||
|
||||
// Persistent Tor log for post-mortem debugging on user machines.
|
||||
fs::path torLogPath = dataPath / "tor.log";
|
||||
|
||||
+66
-34
@@ -546,10 +546,17 @@ int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRe
|
||||
bool HTTPAuthorized(map<string, string>& mapHeaders)
|
||||
{
|
||||
string strAuth = mapHeaders["authorization"];
|
||||
if (strAuth.substr(0,6) != "Basic ")
|
||||
if (strAuth.size() < 6 || strAuth.substr(0,6) != "Basic ")
|
||||
return false;
|
||||
string strUserPass64 = strAuth.substr(6); strUserPass64 = TrimString(strUserPass64);
|
||||
string strUserPass = DecodeBase64(strUserPass64);
|
||||
if (strUserPass64.empty())
|
||||
return false;
|
||||
string strUserPass;
|
||||
try {
|
||||
strUserPass = DecodeBase64(strUserPass64);
|
||||
} catch (const std::exception&) {
|
||||
return false;
|
||||
}
|
||||
return TimingResistantEqual(strUserPass, strRPCUserColonPass);
|
||||
}
|
||||
|
||||
@@ -783,44 +790,61 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol,
|
||||
{
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]++;
|
||||
|
||||
// Immediately start accepting new connections, except when we're cancelled or our socket is closed.
|
||||
if (error != asio::error::operation_aborted
|
||||
&& acceptor->is_open())
|
||||
RPCListen(acceptor, context, fUseSSL);
|
||||
try {
|
||||
// Immediately start accepting new connections, except when we're cancelled or our socket is closed.
|
||||
if (error != asio::error::operation_aborted
|
||||
&& acceptor->is_open())
|
||||
RPCListen(acceptor, context, fUseSSL);
|
||||
|
||||
AcceptedConnectionImpl<ip::tcp>* tcp_conn = dynamic_cast< AcceptedConnectionImpl<ip::tcp>* >(conn);
|
||||
AcceptedConnectionImpl<ip::tcp>* tcp_conn = dynamic_cast< AcceptedConnectionImpl<ip::tcp>* >(conn);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error != asio::error::operation_aborted)
|
||||
printf("RPC accept error from %s: %s (%d)\n",
|
||||
tcp_conn ? tcp_conn->peer.address().to_string().c_str() : "unknown peer",
|
||||
error.message().c_str(),
|
||||
error.value());
|
||||
if (error)
|
||||
{
|
||||
if (error != asio::error::operation_aborted)
|
||||
printf("RPC accept error from %s: %s (%d)\n",
|
||||
tcp_conn ? tcp_conn->peer.address().to_string().c_str() : "unknown peer",
|
||||
error.message().c_str(),
|
||||
error.value());
|
||||
delete conn;
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Restrict callers by IP. It is important to
|
||||
// do this before starting client thread, to filter out
|
||||
// certain DoS and misbehaving clients.
|
||||
else if (tcp_conn
|
||||
&& !ClientAllowed(tcp_conn->peer.address()))
|
||||
{
|
||||
// Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
|
||||
try {
|
||||
if (!fUseSSL)
|
||||
conn->stream() << HTTPReply(HTTP_FORBIDDEN, "", false) << std::flush;
|
||||
} catch (const std::exception& e) {
|
||||
printf("RPC error sending 403 to %s: %s\n",
|
||||
tcp_conn->peer.address().to_string().c_str(), e.what());
|
||||
}
|
||||
delete conn;
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
return;
|
||||
}
|
||||
|
||||
// start HTTP client thread
|
||||
else if (!NewThread(ThreadRPCServer3, conn)) {
|
||||
printf("Failed to create RPC server client thread\n");
|
||||
delete conn;
|
||||
}
|
||||
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
} catch (std::exception& e) {
|
||||
PrintException(&e, "RPCAcceptHandler()");
|
||||
delete conn;
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
return;
|
||||
}
|
||||
|
||||
// Restrict callers by IP. It is important to
|
||||
// do this before starting client thread, to filter out
|
||||
// certain DoS and misbehaving clients.
|
||||
else if (tcp_conn
|
||||
&& !ClientAllowed(tcp_conn->peer.address()))
|
||||
{
|
||||
// Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
|
||||
if (!fUseSSL)
|
||||
conn->stream() << HTTPReply(HTTP_FORBIDDEN, "", false) << std::flush;
|
||||
} catch (...) {
|
||||
PrintException(NULL, "RPCAcceptHandler()");
|
||||
delete conn;
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
}
|
||||
|
||||
// start HTTP client thread
|
||||
else if (!NewThread(ThreadRPCServer3, conn)) {
|
||||
printf("Failed to create RPC server client thread\n");
|
||||
delete conn;
|
||||
}
|
||||
|
||||
vnThreadsRunning[THREAD_RPCLISTENER]--;
|
||||
}
|
||||
|
||||
void ThreadRPCServer2(void* parg)
|
||||
@@ -1128,6 +1152,7 @@ void ThreadRPCServer3(void* parg)
|
||||
AcceptedConnection *conn = (AcceptedConnection *) parg;
|
||||
|
||||
bool fRun = true;
|
||||
try {
|
||||
while (true)
|
||||
{
|
||||
if (fShutdown || !fRun)
|
||||
@@ -1247,6 +1272,13 @@ void ThreadRPCServer3(void* parg)
|
||||
}
|
||||
}
|
||||
|
||||
} // end try
|
||||
catch (std::exception& e) {
|
||||
PrintException(&e, "ThreadRPCServer3()");
|
||||
} catch (...) {
|
||||
PrintException(NULL, "ThreadRPCServer3()");
|
||||
}
|
||||
|
||||
delete conn;
|
||||
{
|
||||
LOCK(cs_THREAD_RPCHANDLER);
|
||||
|
||||
@@ -514,6 +514,20 @@ bool CTxDB::LoadBlockIndex()
|
||||
nBestHeight = pindexBest->nHeight;
|
||||
nBestChainTrust = pindexBest->nChainTrust;
|
||||
|
||||
// Heal pnext pointers along the active chain. Persisted hashNext can be
|
||||
// stale or zeroed by crash-interrupted reorgs, which breaks
|
||||
// GetKernelStakeModifier()'s forward walk and causes valid new
|
||||
// proof-of-stake blocks to be rejected with "check kernel failed".
|
||||
{
|
||||
int nHealed = 0;
|
||||
for (CBlockIndex* p = pindexBest; p && p->pprev; p = p->pprev)
|
||||
{
|
||||
if (p->pprev->pnext != p) { p->pprev->pnext = p; nHealed++; }
|
||||
}
|
||||
if (nHealed > 0)
|
||||
printf("LoadBlockIndex(): healed %d pnext links on active chain\n", nHealed);
|
||||
}
|
||||
|
||||
printf("STARTUP-PERF: best_chain %" PRId64 "ms\n", GetTimeMillis() - nPhaseStart);
|
||||
|
||||
nPhaseStart = GetTimeMillis();
|
||||
|
||||
+2
-1
@@ -42,12 +42,13 @@ public:
|
||||
|
||||
bool LoadBlockIndex() override;
|
||||
|
||||
std::unique_ptr<CTxDBIteratorBase> NewIterator() const override;
|
||||
|
||||
protected:
|
||||
bool ReadRaw(const std::string& key, std::string& value) const override;
|
||||
bool WriteRaw(const std::string& key, const std::string& value) override;
|
||||
bool EraseRaw(const std::string& key) override;
|
||||
bool ExistsRaw(const std::string& key) const override;
|
||||
std::unique_ptr<CTxDBIteratorBase> NewIterator() const override;
|
||||
|
||||
private:
|
||||
leveldb::DB* pdb; // Points to the global instance.
|
||||
|
||||
@@ -542,6 +542,20 @@ bool CRocksTxDB::LoadBlockIndex()
|
||||
nBestHeight = pindexBest->nHeight;
|
||||
nBestChainTrust = pindexBest->nChainTrust;
|
||||
|
||||
// Heal pnext pointers along the active chain. Persisted hashNext can be
|
||||
// stale or zeroed by crash-interrupted reorgs, which breaks
|
||||
// GetKernelStakeModifier()'s forward walk and causes valid new
|
||||
// proof-of-stake blocks to be rejected with "check kernel failed".
|
||||
{
|
||||
int nHealed = 0;
|
||||
for (CBlockIndex* p = pindexBest; p && p->pprev; p = p->pprev)
|
||||
{
|
||||
if (p->pprev->pnext != p) { p->pprev->pnext = p; nHealed++; }
|
||||
}
|
||||
if (nHealed > 0)
|
||||
printf("LoadBlockIndex(): healed %d pnext links on active chain\n", nHealed);
|
||||
}
|
||||
|
||||
printf("STARTUP-PERF: best_chain %" PRId64 "ms\n", GetTimeMillis() - nPhaseStart);
|
||||
|
||||
nPhaseStart = GetTimeMillis();
|
||||
|
||||
+11
-1
@@ -38,12 +38,22 @@ public:
|
||||
|
||||
bool LoadBlockIndex() override;
|
||||
|
||||
// Write a raw serialized key/value pair, bypassing the typed Write<>()
|
||||
// overloads. Intended for the chaindb migration utility, which carries
|
||||
// bytes directly across from a CTxDB (LevelDB) iterator. Honors the
|
||||
// active write batch if one is open.
|
||||
bool WriteRawRecordForMigration(const std::string& key, const std::string& value)
|
||||
{
|
||||
return WriteRaw(key, value);
|
||||
}
|
||||
|
||||
std::unique_ptr<CTxDBIteratorBase> NewIterator() const override;
|
||||
|
||||
protected:
|
||||
bool ReadRaw(const std::string& key, std::string& value) const override;
|
||||
bool WriteRaw(const std::string& key, const std::string& value) override;
|
||||
bool EraseRaw(const std::string& key) override;
|
||||
bool ExistsRaw(const std::string& key) const override;
|
||||
std::unique_ptr<CTxDBIteratorBase> NewIterator() const override;
|
||||
|
||||
private:
|
||||
rocksdb::DB* pdb; // Points to the global instance.
|
||||
|
||||
@@ -600,6 +600,37 @@ bool SoftSetBoolArg(const std::string& strArg, bool fValue)
|
||||
return SoftSetArg(strArg, std::string("0"));
|
||||
}
|
||||
|
||||
// C++20 modernization: std::string_view overloads delegating to std::string implementations
|
||||
std::string GetArg(std::string_view strArg, std::string_view strDefault)
|
||||
{
|
||||
return GetArg(std::string(strArg), std::string(strDefault));
|
||||
}
|
||||
|
||||
int64_t GetArg(std::string_view strArg, int64_t nDefault)
|
||||
{
|
||||
return GetArg(std::string(strArg), nDefault);
|
||||
}
|
||||
|
||||
bool GetBoolArg(std::string_view strArg, bool fDefault)
|
||||
{
|
||||
return GetBoolArg(std::string(strArg), fDefault);
|
||||
}
|
||||
|
||||
bool SoftSetArg(std::string_view strArg, std::string_view strValue)
|
||||
{
|
||||
return SoftSetArg(std::string(strArg), std::string(strValue));
|
||||
}
|
||||
|
||||
bool SoftSetBoolArg(std::string_view strArg, bool fValue)
|
||||
{
|
||||
return SoftSetBoolArg(std::string(strArg), fValue);
|
||||
}
|
||||
|
||||
bool WildcardMatch(std::string_view str, std::string_view mask)
|
||||
{
|
||||
return WildcardMatch(std::string(str), std::string(mask));
|
||||
}
|
||||
|
||||
|
||||
string EncodeBase64(const unsigned char* pch, size_t len)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
@@ -190,6 +191,9 @@ bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);
|
||||
#define printf OutputDebugStringF
|
||||
|
||||
void LogException(std::exception* pex, const char* pszThread);
|
||||
|
||||
// LogPrintf - variadic macro for logging to stderr (C++20 modernization: restored from removed definition)
|
||||
#define LogPrintf(...) fprintf(stderr, __VA_ARGS__)
|
||||
void PrintException(std::exception* pex, const char* pszThread);
|
||||
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
|
||||
void ParseString(std::string_view str, char c, std::vector<std::string>& v);
|
||||
|
||||
+7
-6
@@ -12,6 +12,7 @@
|
||||
#include "kernel.h"
|
||||
#include "coincontrol.h"
|
||||
#include "addressindex.h"
|
||||
#include "util.h"
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
@@ -483,7 +484,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock)
|
||||
if (!IsInitialBlockDownload())
|
||||
{
|
||||
try { NotifyTransactionChanged(this, txin.prevout.hash, CT_UPDATED); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyTransactionChanged exception in WalletUpdateSpent\n"); }
|
||||
catch (...) { printf("WARNING: NotifyTransactionChanged exception in WalletUpdateSpent\n"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,7 +505,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock)
|
||||
if (!IsInitialBlockDownload())
|
||||
{
|
||||
try { NotifyTransactionChanged(this, hash, CT_UPDATED); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyTransactionChanged exception in WalletUpdateSpent\n"); }
|
||||
catch (...) { printf("WARNING: NotifyTransactionChanged exception in WalletUpdateSpent\n"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2162,7 +2163,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
||||
coin.MarkSpent(txin.prevout.n);
|
||||
coin.WriteToDisk();
|
||||
try { NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyTransactionChanged exception in CommitTransaction\n"); }
|
||||
catch (...) { printf("WARNING: NotifyTransactionChanged exception in CommitTransaction\n"); }
|
||||
}
|
||||
|
||||
if (fFileBacked)
|
||||
@@ -2292,7 +2293,7 @@ bool CWallet::SetAddressBookName(const CTxDestination& address, const string& st
|
||||
SecureMsgWalletKeyChanged(caddress.ToString(), strName, nMode);
|
||||
}
|
||||
try { NotifyAddressBookChanged(this, address, strName, fOwned, nMode); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyAddressBookChanged exception in SetAddressBookName\n"); }
|
||||
catch (...) { printf("WARNING: NotifyAddressBookChanged exception in SetAddressBookName\n"); }
|
||||
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
@@ -2315,7 +2316,7 @@ bool CWallet::DelAddressBookName(const CTxDestination& address)
|
||||
SecureMsgWalletKeyChanged(caddress.ToString(), sName, CT_DELETED);
|
||||
}
|
||||
try { NotifyAddressBookChanged(this, address, "", fOwned, CT_DELETED); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyAddressBookChanged exception in DelAddressBookName\n"); }
|
||||
catch (...) { printf("WARNING: NotifyAddressBookChanged exception in DelAddressBookName\n"); }
|
||||
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
@@ -2794,7 +2795,7 @@ void CWallet::UpdatedTransaction(const uint256 &hashTx)
|
||||
if (auto mi = mapWallet.find(hashTx); mi != mapWallet.end() && !IsInitialBlockDownload())
|
||||
{
|
||||
try { NotifyTransactionChanged(this, hashTx, CT_UPDATED); }
|
||||
catch (...) { LogPrintf("WARNING: NotifyTransactionChanged exception in UpdatedTransaction\n"); }
|
||||
catch (...) { printf("WARNING: NotifyTransactionChanged exception in UpdatedTransaction\n"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user