Commit graph

223 commits

Author SHA1 Message Date
Claude
5df40c1de1
chore: sort.Slice → slices.SortFunc
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 16:17:40 +00:00
Claude
45636455ba
chore: use min()/max() builtins (Go 1.21+)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 16:16:01 +00:00
Claude
33a0b57d72
chore: use range-over-integer (Go 1.22+)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 16:14:08 +00:00
Claude
aefec104d4
chore: fmt.Errorf(static) → errors.New
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 16:11:27 +00:00
Claude
d8eb6c5478
docs: archive completed plans, expand history for TUI and difficulty
Some checks failed
Security Scan / security (push) Successful in 9s
Test / Test (push) Failing after 30s
Move all 21 plan files to docs/plans/completed/ — every phase (0-9) is
implemented. Expand history.md with full writeups for the Difficulty
Computation, V2+ Zarcanum Consensus, and TUI Dashboard sections that
were previously just bullet points.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 13:47:35 +00:00
Claude
1da986a0f4
ci: add Forgejo Actions test and security scan workflows
Some checks failed
Security Scan / security (push) Successful in 9s
Test / Test (push) Failing after 34s
Uses reusable workflows from core/go-devops for Go testing
(with race detector and coverage) and security scanning
(govulncheck, gitleaks, trivy).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 03:28:02 +00:00
Claude
cd8ed3d502
docs: add TUI dashboard to architecture and history
Co-Authored-By: Charon <charon@lethean.io>
2026-02-23 00:06:28 +00:00
Claude
0aba33fa6e
test(tui): add ExplorerModel navigation and view tests
Add 5 tests covering Enter (block detail), Esc (back to list),
PgDown, Home, and coinbase-only block detail rendering.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-23 00:05:10 +00:00
Claude
7e95ced104
feat(tui): add cmd/chain binary wiring Frame + P2P sync
Co-Authored-By: Charon <charon@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 00:03:14 +00:00
Claude
527284327b
feat(tui): add ExplorerModel with block list, detail, and tx views
Co-Authored-By: Charon <charon@lethean.io>
2026-02-23 00:00:05 +00:00
Claude
8978aaf878
feat(tui): add KeyHintsModel for context-sensitive footer
Co-Authored-By: Charon <charon@lethean.io>
2026-02-22 23:57:07 +00:00
Claude
df6d4c82c0
feat(tui): add StatusModel for chain sync header
Implements StatusModel as a cli.FrameModel that renders a single-line
chain status bar showing height, sync percentage, difficulty, peer
count and tip age. Includes formatAge and formatDifficulty helpers
with SI suffixes. Adds core/cli as a direct dependency.

Co-Authored-By: Charon <charon@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 23:55:22 +00:00
Claude
572237696a
feat(tui): add Node wrapper with status polling
Co-Authored-By: Charon <charon@lethean.io>
2026-02-22 23:52:50 +00:00
Claude
04861acf93
feat(tui): add custom bubbletea message types
Co-Authored-By: Charon <charon@lethean.io>
2026-02-22 23:50:15 +00:00
Claude
969e30905f
feat(tui): add core/cli dependency for Frame TUI
Add forge.lthn.ai/core/cli to go.mod with replace directive pointing
to the local workspace path. Also adds transitive replace directives
for core/go and core/go-crypt which are dependencies of core/cli.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-22 23:48:58 +00:00
Claude
1cc956631e
docs: add blockchain TUI dashboard design
Standalone TUI in go-blockchain using core/cli Frame (bubbletea).
Day-one scope: chain sync status header + block explorer content.
Model library pattern (tui/) with thin cmd/chain/ wiring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 23:34:12 +00:00
Claude
fedf337da9
chore: sync workspace dependency versions
Run go work sync to align dependency versions across workspace.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:41:04 +00:00
Claude
a803fd1794
feat(consensus): V2 Zarcanum signature and proof verification
Add full V2 transaction verification pipeline: parse SignaturesRaw variant
vector into structured ZC signature data, verify CLSAG GGX ring signatures
per ZC input, verify BPP range proofs, and verify BGE asset surjection
proofs with correct ring construction (mul8 point arithmetic).

Fix three wire format bugs that caused V2 parsing failures:
- RefTypeGlobalIndex (tag 0x1A) uses 8-byte LE, not varint
- Raw uint64_t variant (tagUint64) uses 8-byte LE, not varint
- zarcanum_tx_data_v1 fee uses FIELD() → 8-byte LE, not VARINT_FIELD()

Add cn_point_sub to C++ bridge and Go wrapper for BGE ring construction.
Add GetZCRingOutputs to chain for fetching ZC ring member data.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-22 00:06:10 +00:00
Claude
3c76dd7070
fix(difficulty): correct LWMA algorithm and hardfork-aware target
Rewrites the LWMA difficulty algorithm to match the C++ daemon exactly:
- Uses N=60 window with linear weighting (position 1..n)
- Clamps solve times to [-6T, 6T]
- Excludes genesis block from the difficulty window
- Selects target based on hardfork: 120s pre-HF2, 240s post-HF2

On testnet, HF2 activates at height 10 (active from height 11),
doubling the target from 120s to 240s. The previous fixed 120s target
produced exactly half the expected difficulty from height 11 onward.

Integration test verifies all 2576 testnet blocks match the daemon.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 22:32:57 +00:00
Claude
ff8f300601
feat(chain): compute difficulty locally during P2P sync
P2PSync now calls NextDifficulty() for each block instead of
hardcoding difficulty=0.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 22:04:49 +00:00
Claude
d456b8be9b
feat(chain): add NextDifficulty for local LWMA computation
Reads stored block timestamps and cumulative difficulties, calls
difficulty.NextDifficulty() with config.BlockTarget. Returns uint64.

Adds getBlockMeta() for lightweight metadata-only lookups.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 22:03:28 +00:00
Claude
c7c536449b
feat(config): add BlockTarget constant (120s)
Replaces magic number 120 in difficulty tests with config.BlockTarget.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:59:41 +00:00
Claude
5b3e274aaa
docs: add difficulty computation design and plan
Local difficulty computation for P2P sync — replaces hardcoded
difficulty=0 with LWMA-based calculation from stored block history.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:58:04 +00:00
Claude
1cfe74fe9b
docs: update architecture and history for block sync
Document NLSAG verification, P2P sync protocol, and shared block
processing.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:34:55 +00:00
Claude
a74ac2e2c7
feat(chain): add Levin P2P connection adapter and sync integration test
LevinP2PConn wraps a levin.Connection to implement the P2PConnection
interface, handling timed_sync keep-alive responses automatically.
Integration test syncs the full testnet chain (2577 blocks) via P2P
in under 5 seconds.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:32:05 +00:00
Claude
c6504276dc
fix(chain): skip overlap block in P2P sync chain entries
RESPONSE_CHAIN_ENTRY includes the fork-point block as its first
entry. The sync loop now skips blocks already stored to avoid
height validation failures on subsequent chain iterations.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:31:59 +00:00
Claude
8caf157b1c
fix(chain): use genesis hash in sparse history for empty chain
SparseChainHistory returned a zero hash when the chain was empty,
which the daemon could not resolve. Send the genesis hash instead
so the peer can locate the fork point and respond with chain entries.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:31:55 +00:00
Claude
c488ef8816
test(p2p): integration test for chain request and block fetch
Performs handshake, REQUEST_CHAIN with genesis hash, reads
RESPONSE_CHAIN_ENTRY, then REQUEST_GET_OBJECTS with the first block
hash and verifies RESPONSE_GET_OBJECTS returns a non-empty block blob.

Also fixes the existing handshake test return code check — the C++
daemon handler returns 1 (not 0) on success.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:17:54 +00:00
Claude
fcb867d53b
fix(p2p): correct network IDs and serialisation for C++ daemon compat
Three bugs found by integration testing against the C++ testnet daemon:

1. NetworkIDMainnet/Testnet had byte 10 swapped — the C++ #ifndef TESTNET
   branch (mainnet) sets P2P_NETWORK_ID_TESTNET_FLAG=1, and the #else
   (testnet) sets it to 0. Counter-intuitive but matches compiled binaries.

2. ClientVersion format "Lethean/go-blockchain 0.1.0" was rejected by the
   daemon's parse_client_version which expects "major.minor.rev.build[commit]".
   Changed to "6.0.1.2[go-blockchain]".

3. RequestChain, RequestGetObjects, and ResponseGetObjects used StringArrayVal
   for hash fields, but the C++ daemon uses KV_SERIALIZE_CONTAINER_POD_AS_BLOB
   which packs all 32-byte hashes into a single concatenated blob. Also,
   ResponseChainEntry.m_block_ids is an object array of block_context_info
   (hash + cumulative size), not a simple hash list.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:17:48 +00:00
Claude
d588f8f8d0
feat(chain): add P2P sync state machine
P2PSync() runs the REQUEST_CHAIN / REQUEST_GET_OBJECTS loop against
a P2PConnection interface. Reuses processBlockBlobs() for shared
validation logic.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 21:00:57 +00:00
Claude
3fe3b558d7
test(chain): verify ring signatures during full chain sync
All pre-HF4 spending transactions on testnet pass NLSAG ring
signature verification end-to-end.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:58:29 +00:00
Claude
37a70c0ff1
feat(chain): add sparse chain history builder for P2P sync
Implements get_short_chain_history() algorithm: recent 10 block hashes
then exponentially-spaced hashes back to genesis.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:56:41 +00:00
Claude
3fe8dec1a4
feat(p2p): add RequestGetObjects and ResponseGetObjects types
Encode/decode for NOTIFY_REQUEST_GET_OBJECTS (2003) and
NOTIFY_RESPONSE_GET_OBJECTS (2004), including BlockCompleteEntry
for block + transaction blob pairs.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:54:14 +00:00
Claude
0e35c2996d
refactor(chain): extract processBlockBlobs for shared RPC/P2P use
The block processing logic is now in processBlockBlobs() which takes
raw wire bytes. The RPC processBlock() becomes a thin hex-decode
wrapper. The P2P sync path will call processBlockBlobs() directly.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:50:36 +00:00
Claude
c395c2ff18
test(chain): add full sync-to-tip integration test
Syncs the entire testnet chain via RPC and verifies every block
decodes, validates, and stores correctly.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:47:01 +00:00
Claude
53311b14d1
fix(chain): resolve missing block blobs from daemon RPC
The Zano daemon's get_blocks_details RPC does not populate the blob
field. This adds resolveBlockBlobs() which batch-fetches miner tx
blobs via /gettransactions and reconstructs block wire blobs from
the parsed header (object_in_json AGGREGATED section) and raw tx
bytes. Also fixes regular tx processing to skip the miner tx entry
that the daemon includes in transactions_details.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:46:56 +00:00
Claude
ad4139c012
fix(chain): mark ZC input key images as spent during sync
TxInputZC (v2+) inputs have key images that must be tracked for
double-spend detection, same as TxInputToKey.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:36:00 +00:00
Claude
c066f4ac92
feat(chain): add context cancellation and progress logging to Sync
Sync() now accepts context.Context for graceful shutdown. Logs progress
every 100 blocks.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:33:08 +00:00
Claude
4bac1f6c04
feat(chain): add GetRingOutputs callback for signature verification
Implements consensus.RingOutputsFn by looking up output public keys from
the chain's global output index and transaction store. Wired into the
sync loop so VerifySignatures=true uses real crypto verification.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:28:54 +00:00
Claude
2c6211d78e
feat(consensus): wire up NLSAG ring signature verification
Connect crypto.CheckRingSignature() to verifyV1Signatures() so
pre-HF4 transactions have their ring signatures cryptographically
verified when a RingOutputsFn callback is provided.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:26:33 +00:00
Claude
ca3d8e04d1
docs: add block sync design and implementation plan
Three-part design: NLSAG signature verification, full RPC sync to tip,
and P2P block sync via REQUEST_CHAIN / REQUEST_GET_OBJECTS. 13-task
implementation plan with TDD steps.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 20:21:14 +00:00
Claude
8335b11a85
feat(wire): v2+ transaction serialisation with real testnet verification
Fix three bugs in the v2+ wire format and add complete variant tag handlers
for Zarcanum proof and signature structures. Verified byte-identical
round-trip against a real post-HF4 coinbase transaction from testnet block
101 (1323 bytes, tx hash 543bc3c2...3b61e0).

Bugs fixed:
- V2 suffix order was attachment+proofs, corrected to attachment+signatures+proofs
- TransactionHash was hashing full blob, corrected to prefix-only (matching C++)
- tagSignedParts was reading 4 fixed bytes, corrected to two varints

New: TxInputZC type, SignaturesRaw field, tagZarcanumTxDataV1 handler,
proof tags 46-48, signature tags 42-45, crypto blob readers for BPP/BPPE/
BGE/CLSAG GGX/GGXXG/aggregation proof/double Schnorr structures.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 19:09:34 +00:00
Claude
dd04cc9dee
feat(crypto): wire BPP/BPPE/BGE proof verification with real testnet data
Add cn_bpp_verify for Bulletproofs++ (1 delta, bpp_crypto_trait_ZC_out)
used by zc_outs_range_proof in post-HF4 transactions. Distinguish from
cn_bppe_verify (2 deltas, bpp_crypto_trait_Zarcanum) used for Zarcanum
PoS proofs.

Key changes:
- Add deserialise_bpp() and cn_bpp_verify() to bridge.cpp
- Add VerifyBPP() Go wrapper in proof.go
- Wire BPPE and BGE stubs into real C++ verify functions
- Add try/catch to all proof verifiers (C++ throws on invalid points)
- Add nil/empty input guards to all Go proof functions
- Test with real BPP proof from testnet block 101 coinbase tx

The BPP proof from tx 543bc3c2... (first post-HF4 coinbase) verifies
successfully through the full CGo pipeline, confirming wire format
deserialisation matches the C++ daemon output.

Co-Authored-By: Charon <charon@lethean.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 18:37:08 +00:00
Claude
cef9a34bea
docs: Phase 8 mining complete
Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:21:36 +00:00
Claude
f9ff8ad877
test(mining): integration test against C++ testnet daemon
Build-tagged //go:build integration. Fetches a real template,
decodes it, computes header mining hash.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:20:05 +00:00
Claude
340aa99db6
test(mining): add CheckNonce and OnNewTemplate coverage
Brings mining/ package coverage from 78% to 86.6%.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:19:05 +00:00
Claude
9bc3158384
test(mining): error handling for invalid difficulty, blob, and submit
Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:16:32 +00:00
Claude
ad121a2dd4
test(mining): block submission and stats verification
Tests with difficulty=1 for guaranteed block finding. Verifies
OnBlockFound callback, submit count, hashrate > 0.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:15:05 +00:00
Claude
538b7b2e02
feat(mining): mining loop with template fetch and nonce grinding
Start(ctx) blocks until cancelled. Polls daemon for new blocks,
decodes template, computes header hash once, grinds nonces with
RandomX, submits solutions.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:11:25 +00:00
Claude
a5185cacf4
feat(mining): Config, Stats, and Miner struct
TemplateProvider interface for testability. Atomic stats for
lock-free reads from any goroutine.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 02:07:05 +00:00