|
| 1 | +# AI Agent Implementation Plan: BitCell RC1 Readiness |
| 2 | + |
| 3 | +This plan outlines a linear, dependency-aware workflow for an AI agent to bring the BitCell codebase to RC1 readiness. Execute these steps in order. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Phase 1: Core Functionality (Transactions & State) |
| 8 | + |
| 9 | +### 1.1. Implement Transaction Building in Wallet GUI |
| 10 | +**Goal**: Enable users to create real transactions. |
| 11 | +**Files**: `crates/bitcell-wallet-gui/src/main.rs` |
| 12 | +**Action**: |
| 13 | +1. Locate `on_send_transaction` callback. |
| 14 | +2. Replace the `mock_tx` string formatting with actual `Transaction` struct construction. |
| 15 | +3. Use `rpc_client.get_nonce(from_address)` to get the correct nonce. |
| 16 | +4. Sign the transaction using the wallet's private key. |
| 17 | +5. Serialize the transaction (bincode/hex). |
| 18 | +6. Call `rpc_client.send_raw_transaction(hex_tx)`. |
| 19 | + |
| 20 | +### 1.2. Implement Raw Transaction Decoding in RPC |
| 21 | +**Goal**: Process incoming raw transactions. |
| 22 | +**Files**: `crates/bitcell-node/src/rpc.rs` |
| 23 | +**Action**: |
| 24 | +1. In `bitcell_sendRawTransaction`: |
| 25 | +2. Decode the hex string into bytes. |
| 26 | +3. Deserialize bytes into `Transaction` struct. |
| 27 | +4. Validate signature and nonce. |
| 28 | +5. Add to `TxPool` (via `node.tx_pool`). |
| 29 | +6. Return the transaction hash. |
| 30 | + |
| 31 | +### 1.3. Implement Balance Fetching in RPC |
| 32 | +**Goal**: Return real account balances. |
| 33 | +**Files**: `crates/bitcell-node/src/rpc.rs` |
| 34 | +**Action**: |
| 35 | +1. In `eth_getBalance`: |
| 36 | +2. Parse the address (PublicKey). |
| 37 | +3. Access `node.blockchain.state`. |
| 38 | +4. Call `state.get_account(address)`. |
| 39 | +5. Return `account.balance` (or 0 if not found). |
| 40 | + |
| 41 | +### 1.4. Implement State Persistence (RocksDB) |
| 42 | +**Goal**: Persist state across restarts. |
| 43 | +**Files**: `crates/bitcell-state/src/storage.rs`, `crates/bitcell-state/Cargo.toml` |
| 44 | +**Action**: |
| 45 | +1. Add `rocksdb` dependency to `bitcell-state`. |
| 46 | +2. Implement `Storage` trait using RocksDB. |
| 47 | +3. Store `Account` and `BondState` data serialized. |
| 48 | +4. Update `StateManager` to use this persistent storage instead of `HashMap`. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Phase 2: Security & Verification |
| 53 | + |
| 54 | +### 2.1. Implement VRF for Block Proposers |
| 55 | +**Goal**: Randomize block proposer selection. |
| 56 | +**Files**: `crates/bitcell-node/src/blockchain.rs`, `crates/bitcell-crypto/src/vrf.rs` (create if needed) |
| 57 | +**Action**: |
| 58 | +1. Implement ECVRF (Elliptic Curve Verifiable Random Function) using `schnorrkel` or similar. |
| 59 | +2. In `produce_block`: |
| 60 | + - Generate VRF output using previous block's VRF output as input. |
| 61 | + - Store `vrf_output` and `vrf_proof` in `BlockHeader`. |
| 62 | +3. In `validate_block`: |
| 63 | + - Verify the `vrf_proof` against the proposer's public key. |
| 64 | + |
| 65 | +### 2.2. Implement ZKP Circuits (Basic Verification) |
| 66 | +**Goal**: Verify battle outcomes cryptographically. |
| 67 | +**Files**: `crates/bitcell-zkp/src/battle_circuit.rs`, `crates/bitcell-zkp/src/lib.rs` |
| 68 | +**Action**: |
| 69 | +1. Update `Groth16Proof` struct to hold real proof data (Bellman/Arkworks). |
| 70 | +2. In `BattleCircuit`: |
| 71 | + - Define constraints for CA evolution (start state -> end state). |
| 72 | + - Even a simplified version checking hash consistency is better than mock. |
| 73 | +3. Update `generate_proof` to actually run the setup and prove. |
| 74 | +4. Update `verify` to run the verifier. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Phase 3: Networking |
| 79 | + |
| 80 | +### 3.1. Integrate libp2p Gossipsub |
| 81 | +**Goal**: Efficient block/tx propagation. |
| 82 | +**Files**: `crates/bitcell-network/src/transport.rs`, `crates/bitcell-network/Cargo.toml` |
| 83 | +**Action**: |
| 84 | +1. Ensure `libp2p` features `gossipsub` are enabled. |
| 85 | +2. Initialize `Gossipsub` behaviour in the swarm. |
| 86 | +3. Subscribe to topics: `blocks`, `transactions`, `consensus`. |
| 87 | +4. Implement `broadcast_block` and `broadcast_transaction` to publish to these topics. |
| 88 | +5. Handle incoming gossip messages in the event loop. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Phase 4: Observability |
| 93 | + |
| 94 | +### 4.1. Real-Time Metrics Collection |
| 95 | +**Goal**: Populate admin dashboard with real data. |
| 96 | +**Files**: `crates/bitcell-admin/src/api/metrics.rs` |
| 97 | +**Action**: |
| 98 | +1. Inject `Arc<Node>` or `Arc<MetricsRegistry>` into the admin API state. |
| 99 | +2. In `get_metrics`: |
| 100 | + - Read `uptime` from node start time. |
| 101 | + - Read `block_height` from blockchain. |
| 102 | + - Read `peer_count` from network manager. |
| 103 | + - Calculate `average_block_time` from recent blocks. |
| 104 | + |
| 105 | +### 4.2. Connect Block Explorer |
| 106 | +**Goal**: Show real chain data. |
| 107 | +**Files**: `crates/bitcell-admin/src/api/blocks.rs` |
| 108 | +**Action**: |
| 109 | +1. In `get_blocks`: |
| 110 | + - Iterate backwards from current height. |
| 111 | + - Fetch blocks from `blockchain`. |
| 112 | + - Map to API response format. |
| 113 | +2. In `get_block_by_hash`: |
| 114 | + - Lookup block in `blockchain`. |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## Phase 5: Polish & Cleanup |
| 119 | + |
| 120 | +### 5.1. Replace Panic with Result |
| 121 | +**Goal**: Robust error handling. |
| 122 | +**Files**: `crates/bitcell-ca/src/grid.rs`, `crates/bitcell-state/src/bonds.rs` |
| 123 | +**Action**: |
| 124 | +1. Search for `panic!`. |
| 125 | +2. Change function signature to return `Result<T, Error>`. |
| 126 | +3. Propagate errors up the stack. |
| 127 | + |
| 128 | +### 5.2. Expose Node Identity & Reputation |
| 129 | +**Goal**: Complete RPC API. |
| 130 | +**Files**: `crates/bitcell-node/src/rpc.rs` |
| 131 | +**Action**: |
| 132 | +1. In `getNodeInfo`, return actual `local_peer_id`. |
| 133 | +2. Implement `bitcell_getReputation` by querying `TournamentManager`. |
| 134 | + |
| 135 | +### 5.3. Hex Parsing Utils |
| 136 | +**Goal**: Clean code. |
| 137 | +**Files**: `crates/bitcell-node/src/rpc.rs` |
| 138 | +**Action**: |
| 139 | +1. Use `hex::decode` consistently instead of manual string slicing. |
| 140 | +2. Add proper error handling for invalid hex strings. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## Execution Strategy |
| 145 | + |
| 146 | +1. **Sequential Execution**: Follow the phases in order (1 -> 5). |
| 147 | +2. **Verification**: Run `cargo test` after each major component implementation. |
| 148 | +3. **Integration**: Run the full node and wallet to verify end-to-end functionality (e.g., send a tx and see it in the explorer). |
0 commit comments