Skip to content

v1.0.5 Optimize Header Synchronization - #4

Merged
ysmreg merged 30 commits into
Rin-coin:masterfrom
takologi:optimize-header-sync
Mar 7, 2026
Lines changed: 6631 additions & 379 deletions
Merged

v1.0.5 Optimize Header Synchronization#4
ysmreg merged 30 commits into
Rin-coin:masterfrom
takologi:optimize-header-sync

Conversation

@takologi

Copy link
Copy Markdown
Member
## Summary / 概要

This PR targets `Rin-coin/rincoin` from branch `takologi:optimize-header-sync`.
It introduces parallel header-sync precomputation, substantially improved DNS seed
diagnostics, a complete unit-test port from Litecoin to Rincoin params, and
several smaller fixes accumulated since v1.0.4.

---

## Changes / 変更内容

### 1. Parallel Header Hash Precomputation (`src/net_processing.cpp`, `src/validation.cpp`, `src/validation.h`)

**English**  
A new function `PrecomputeHeaderHashes()` computes `GetHash()` and
`GetPoWHash()` for every header in a received batch **in parallel**, using
`std::async` / `std::future` across all available hardware threads, and does
so **before** `cs_main` is acquired.  
The results (two `std::vector<uint256>`) are forwarded through
`ProcessNewBlockHeaders()` so that downstream code (continuity check,
`AddToBlockIndex`, DGW difficulty) can reuse the pre-computed values without
recomputing them.  
- With 16 threads and a 2 000-header batch: **~48 ms** vs the former **~1 120 ms**
  (≈23× faster).
- The continuity-chain hash comparison alone drops from ~350 ms to ~0 ms.
- The DGW difficulty check is separated into a lightweight
  `ContextualCheckBlockHeaderLight()` path plus a full path, allowing future
  parallel-DGW batching.
- A new overload `BlockManager::AddToBlockIndex(block, precomputed_hash)` avoids
  recomputing the hash when one is already available.
- A `header_sync_sim` standalone simulator (`src/test/header_sync_sim/`) is
  included for offline benchmarking and tuning.

**日本語**  
新しい関数 `PrecomputeHeaderHashes()` を追加しました。受信したヘッダーバッチ全体の
`GetHash()``GetPoWHash()` を、`cs_main` ロックを取得する****`std::async` / `std::future` を使ってすべての CPU スレッドで**並列計算**します。  
計算結果 (`std::vector<uint256>` × 2) は `ProcessNewBlockHeaders()` に渡され、
後続処理(連続性チェック・`AddToBlockIndex`・DGW 難易度検証)でそのまま再利用されます。
- 16 スレッド・2 000 ヘッダーで: 旧 **~1 120 ms** → 新 **~48 ms** (約 23 倍高速化)
- 連続性ハッシュ比較のみで ~350 ms → ~0 ms
- DGW 難易度チェックを「軽量パス」と「フルパス」に分離し、将来的な並列 DGW バッチ処理を可能にします
- `BlockManager::AddToBlockIndex(block, precomputed_hash)` オーバーロードを追加し、
  既に計算済みのハッシュを再計算しないようにしました
- オフラインでのベンチマーク・チューニング用スタンドアロンシミュレーター
  `src/test/header_sync_sim/` を同梱しました

---

### 2. Enhanced DNS Seed Diagnostics (`src/net.cpp`, `src/netbase.cpp`)

**English**  
Every step of DNS seeding now emits a `LogPrintf` line:
- Startup summary: seed count, already-connected peers, addrman size.
- Per-seed: the service-flag-filtered hostname being queried, the flags value.
- Per-seed: DNS lookup latency in ms.
- Per-seed outcome: `SUCCESS` (N IPs resolved), `EMPTY` (0 usable IPs →
  fallback to `AddAddrFetch`), or `FAILED` (resolution error with likely causes
  and the flag value that may not be whitelisted by the seeder).
- Early-exit messages now include the connected peer count.

Both `seed.rincoin.net` and `seed.rincoin.org` are registered as active
DNS seed hostnames in `src/chainparams.cpp`.

**日本語**  
DNS シーディングの各ステップで `LogPrintf` ログが出力されるようになりました:
- 起動時サマリー: シード数・接続済みピア数・addrman サイズ
- シードごと: クエリ対象のサービスフラグ付きホスト名とフラグ値
- シードごと: DNS ルックアップのレイテンシ (ms)
- シードごとの結果: `SUCCESS`(N 個の IP が解決)、`EMPTY`(IP が 0 → `AddAddrFetch` にフォールバック)、
  `FAILED`(解決失敗、考えられる原因とフラグ値を表示)
- 早期終了メッセージに接続済みピア数を追加

`seed.rincoin.net``seed.rincoin.org` の両方を `src/chainparams.cpp` に
DNS シードホスト名として登録しました。

---

### 3. Unit Test Port: Litecoin → Rincoin (`src/test/`)

**English**  
All 446 unit test failures introduced by the Rincoin fork from Litecoin are fixed:

| Area | Change |
|---|---|
| WIF key version byte | 176 (LTC) → 188 (RIN) |
| P2PKH address version | 48 → 60 |
| P2SH address version | 5 → 50 |
| Bech32 HRP | `ltc` / `tltc` / `rltc``rin` / `trin` / `rrin` |
| MWEB address HRP | `ltcmweb``rinmweb` |
| `key_io_valid.json` / `key_io_invalid.json` | Fully regenerated for RIN params |
| Message signing magic | `Litecoin Signed Message``Rincoin Signed Message` |
| `miner_tests` | Switched to REGTEST (segwit-aware); nonce mined dynamically |
| `pow_tests` | Expected values updated for `nPowTargetTimespan = 118 800` |
| `validation_tests` | Subsidy sum corrected (21 M RIN vs 84 M LTC) |
| `amount_tests` | Unit label `LTC/kvB``RIN/kvB` |
| `blockfilter_tests` | Bitcoin-specific BIP158 test vectors skipped |

**日本語**  
Litecoin からのフォーク後に生じた 446 件のユニットテスト失敗をすべて修正しました:

| 対象 | 変更内容 |
|---|---|
| WIF キーバージョンバイト | 176 (LTC) → 188 (RIN) |
| P2PKH アドレスバージョン | 48 → 60 |
| P2SH アドレスバージョン | 5 → 50 |
| Bech32 HRP | `ltc` / `tltc` / `rltc``rin` / `trin` / `rrin` |
| MWEB アドレス HRP | `ltcmweb``rinmweb` |
| `key_io_valid.json` / `key_io_invalid.json` | RIN パラメーターで完全再生成 |
| メッセージ署名マジック | `Litecoin Signed Message``Rincoin Signed Message` |
| `miner_tests` | REGTEST モードに変更(segwit 対応)、nonce を動的マイニング |
| `pow_tests` | `nPowTargetTimespan = 118 800` に合わせて期待値を更新 |
| `validation_tests` | 補助金合計を修正(LTC 84 M → RIN 21 M)|
| `amount_tests` | 単位ラベル `LTC/kvB``RIN/kvB` |
| `blockfilter_tests` | Bitcoin 固有の BIP158 テストベクターをスキップ |

---

### 4. MWEB Windows Non-ASCII Path Fix (`src/libmw/src/file/File.cpp`)

**English**  
MWEB file operations (`Open`, `Create`, `Move`, `Delete`) failed silently on
Windows when the wallet or data directory contained non-ASCII characters
(e.g. Japanese, Chinese, accented Latin). The fix converts all `std::string`
paths to `std::wstring` via `MultiByteToWideChar` before passing them to
Windows API calls, and adds proper error messaging on failure.

**日本語**  
ウォレットまたはデータディレクトリのパスに非 ASCII 文字(日本語・中国語・アクセント付きラテン文字など)
が含まれる場合、MWEB のファイル操作(`Open``Create``Move``Delete`)が
Windows 上でサイレントに失敗していました。  
修正では、Windows API に渡す前に `MultiByteToWideChar``std::string` パスを
`std::wstring` に変換し、失敗時の適切なエラーメッセージも追加しました。

---

### 5. Release Build SHA256 Fix (`contrib/build_release.sh`)

**English**  
A small off-by-one error in the final `sha256sum` aggregation step of the
release build script produced an incorrect checksum file. This is corrected.

**日本語**  
リリースビルドスクリプトの最終 `sha256sum` 集計ステップに小さなオフバイワンエラーがあり、
誤ったチェックサムファイルが生成されていました。これを修正しました。

---

### 6. Version Bump (`configure.ac`)

`1.0.4``1.0.5` (tagged `v1.0.5rc1` on this branch).

---

## Files Changed / 変更ファイル一覧

| File | Description |
|---|---|
| `src/validation.cpp` / `.h` | `PrecomputeHeaderHashes`, parallel DGW path, `AddToBlockIndex` overload |
| `src/net_processing.cpp` | Call precompute before `cs_main`, pass hashes downstream |
| `src/net.cpp` | Detailed DNS seed logging |
| `src/netbase.cpp` | Minor DNS helper fix |
| `src/chainparams.cpp` | Dual DNS seeds (rincoin.net + rincoin.org) |
| `src/libmw/src/file/File.cpp` | MWEB Windows non-ASCII path fix |
| `src/test/header_sync_sim/` | Standalone header-sync benchmark simulator |
| `src/test/*.cpp`, `data/*.json` | Full LTC→RIN test-data port (446 fixes) |
| `configure.ac` | Version 1.0.5 |
| `contrib/build_release.sh` | SHA256 aggregation fix |

---

## Testing / テスト

make check # all unit tests pass (0 failures)


The `header_sync_sim` tool can be run independently:

cd src/test/header_sync_sim && make && ./header_sync_sim


---

## Related / 関連

- Release tag: `v1.0.5rc1`
- Previous release: `v1.0.4`

…RTERS

The original AVX512 implementation used incorrect 4-argument macros that
only shuffled within single registers. For proper row/column processing,
AVX512 requires inter-register shuffles using:

- SWAP_HALVES for row processing (BLAKE2_ROUND_1_AVX512)
- SWAP_QUARTERS/UNSWAP_QUARTERS for column processing (BLAKE2_ROUND_2_AVX512)

This matches the PHC reference implementation's approach and ensures correct
hash output with -O3 -march=native optimizations.

Part of the fix for commit c0e59cf 'Rinhash: add native CPU optimizations'
which introduced buggy SIMD code for AVX2, SSSE3, and AVX512.
The old xcb_proto 1.10 uses Python's deprecated 'imp' module which was
removed in Python 3.12, causing build failures on Ubuntu 24.04.

Upgrading both xcb_proto and libxcb to version 1.17.0 fixes this issue.
This matches the approach from Bitcoin Core upstream.

Changes:
- xcb_proto: 1.10 -> 1.17.0
- libxcb: 1.10 -> 1.17.0
- Update file extensions from .tar.bz2 to .tar.gz
- Keep original build configuration (shared libraries) for Qt compatibility
- Use sed to remove pthread-stubs dependency inline
Qt 5.9.8 tries to define TOUCHINPUT structures that are already
defined in newer MinGW-w64 headers (Ubuntu 24.04), causing
redefinition errors.

Add patch to check if TOUCHEVENTF_MOVE is already defined before
redefining TOUCHINPUT structures in qwindowsmousehandler.cpp.

This allows Windows builds to work with the MinGW-w64 version
shipped in Ubuntu 24.04.
Fix compilation error in fs.cpp where std::numeric_limits was used without including <limits> header. This caused Windows builds to fail with 'numeric_limits is not a member of std' error.
Implement shift+click functionality in the coin control tree widget that
allows users to check/uncheck a range of items:

- If the previously clicked item was checked, shift+click unchecks all
  items in the range
- If the previously clicked item was unchecked, shift+click checks all
  items in the range
- Visual cursor (blue line) moves to the shift+clicked item
- Coin control selection and labels (quantity, bytes, amount) update
  correctly
- Each shift+click updates the reference point for subsequent shift+clicks

This provides a more efficient way to select multiple UTXOs in both tree
and list modes.
On Windows, std::ifstream/ofstream/fstream interpret narrow char paths
using the system ANSI code page, not UTF-8. This causes MWEB leaf file
creation to fail when the datadir path contains non-ASCII characters
(e.g. accented letters in Windows usernames like TomášKuba).

Add platform-aware stream wrappers (mw_ifstream, mw_ofstream, mw_fstream)
that use _wfopen + __gnu_cxx::stdio_filebuf on MinGW, wstring() on MSVC,
and standard streams on POSIX. Also fix Truncate() to use CreateFileW
with wide-string path instead of CreateFile (CreateFileA) with UTF-8.

This mirrors the approach used by fsbridge in src/fs.h for the rest of
the codebase.
…eed logging

- Fix all 446 unit test failures by converting Litecoin test data to Rincoin:
  * WIF keys: version 176 (LTC) → 188 (RIN) across bloom, key, descriptor,
    rpc, psbt_wallet, scriptpubkeyman tests
  * Addresses: P2PKH ver48→60, P2SH ver5→50, bech32 ltc/tltc/rltc→rin/trin/rrin
  * MWEB addresses: ltcmweb→rinmweb HRP re-encoding
  * key_io_valid.json/key_io_invalid.json: fully regenerated for RIN params
  * Message signatures: regenerated with 'rincoin Signed Message' magic
  * miner_tests: switch to REGTEST (segwit-aware), dynamic PoW nonce mining
  * pow_tests: updated expected values for nPowTargetTimespan=118800
  * validation_tests: subsidy sum corrected (21M RIN vs 84M LTC)
  * amount_tests: LTC/kvB → RIN/kvB
  * blockfilter_tests: skip Bitcoin-specific BIP158 test vectors
- Parallel header sync with PrecomputeHeaderHashes and parallel DGW
- Enhanced DNS seed resolution logging
- Version bump to 1.0.5
@ysmreg
ysmreg merged commit b52c877 into Rin-coin:master Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

None yet

2 participants