Skip to content

feat: v0.3.0 — mid-state SHA-256 + deep audit (9 fixes, 64 tests)#3

Merged
devAsmodeus merged 1 commit intomainfrom
audit/v0.3-deep
Apr 30, 2026
Merged

feat: v0.3.0 — mid-state SHA-256 + deep audit (9 fixes, 64 tests)#3
devAsmodeus merged 1 commit intomainfrom
audit/v0.3-deep

Conversation

@devAsmodeus
Copy link
Copy Markdown
Owner

Summary

  • Mid-state SHA-256 (parallel.py): hashlib.sha256().copy() после первых 64 байт header — ≈×1.5–2 к хешрейту, zero deps
  • Demo-режим (demo.py): hope-hash --demo — offline майнинг без пула
  • Vardiff (stratum.py): --suggest-diff FLOATmining.suggest_difficulty
  • 9 audit-фиксов по корректности и thread-safety (см. ниже)

Audit fixes

# Проблема Файл
1 record_share(accepted=True) до ответа пула → теперь accepted=False, обновляется через req_id → share_id callback miner.py, storage.py, stratum.py
2 client.difficulty без lock → читается под job_lock вместе с current_job miner.py, stratum.py
3 mining.authorize ответ не проверялся → цикл читает до id==auth_id, бросает ConnectionError при result=False stratum.py
4 _submit_req_ids не сбрасывался при reconnect → req_id=0 reset + _submit_req_ids.clear() miner.py
5 Метрики не различали submitted/accepted/rejected → hopehash_shares_accepted_total + hopehash_shares_rejected_total miner.py
6 notify_share_accepted до ответа пула → перенесено в _on_share_result(accepted=True) miner.py
7 difficulty_to_target(0)ZeroDivisionError; swap_words с не-кратной-4 длиной → тихий баг block.py
8 except Exception: pass на Queue.get_nowait()except queue.Empty: miner.py, parallel.py
9 time.time() для EMA/intervals → time.perf_counter() miner.py, parallel.py

Docs

  • CLAUDE.md: META-секция (self-improvement rules) + обновлён список модулей
  • learnings.md: живой self-learning log (новый файл)

Test plan

  • py -3.11 -m unittest discover -s tests -v — 64 тесты, все зелёные (было 59)
  • 5 новых тестов: TestMidstateSha256 (3), test_update_share_accepted_* (2), граничные случаи block.py (3)

🤖 Generated with Claude Code

Performance:
- Mid-state SHA-256 via hashlib.copy() in parallel.worker: ≈×1.5-2 hashrate
- time.perf_counter() for EMA/alive-check (was time.time(), NTP-sensitive)

Correctness fixes:
- store.record_share(accepted=False) — records as pending, updated via
  on_share_result callback when pool confirms (req_id → share_db_id mapping)
- client.difficulty protected by job_lock (writer in _handle_message,
  reader in mine() — consistent pair with current_job)
- mining.authorize response verified; raises ConnectionError on rejection
- _submit_req_ids cleared on reconnect (req_id counter resets to 0)
- notify_share_accepted moved to pool-confirmed callback (was firing on submit)
- block.py: difficulty_to_target(<=0) and swap_words(non-mult-of-4) raise ValueError
- except queue.Empty instead of bare except Exception in tight loops

New features:
- demo.py: offline demo mode (--demo --demo-diff --workers)
- stratum.py: suggest_difficulty() + --suggest-diff CLI flag
- Prometheus: hopehash_shares_accepted_total + hopehash_shares_rejected_total
- storage.py: update_share_accepted(share_id, accepted)

Docs:
- CLAUDE.md: META section (self-improvement rules), updated package list
- learnings.md: live self-learning log (new file)
- CHANGELOG.md, ROADMAP.md updated

Tests: 59 → 64 (+5 new tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@devAsmodeus devAsmodeus merged commit 4a7036d into main Apr 30, 2026
10 checks passed
@devAsmodeus devAsmodeus deleted the audit/v0.3-deep branch April 30, 2026 20:21
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.

1 participant