Full lesson
DeCFD
What it does
From the project README:
A genetic algorithm designs wing profiles. A network of miners runs the wind-tunnel simulations. A Solana program holds the money: miners who fake results get caught and lose their stake.
- Original
- chuikomykhail-droid/DeCFD
- SuperStack fork
- Blockchains/DeCFD @
b0698f7 - Stars
- 0
- Last push (original)
- 2026-10-07
- Languages
- Python, JavaScript, C++, Rust, CSS, HTML
- Detected stack
- Anchor
- Categories
- Other
- Licence
- MIT
Architecture
29 source files. By extension: .py ×25, .js ×2, .cpp ×1, .rs ×1.
| Top-level directory | Source files |
|---|---|
orchestrator_py | 19 |
tests | 4 |
worker_cpp | 2 |
dashboard | 1 |
solana | 1 |
docs | 1 |
validation | 1 |
On-chain programs: solana/programs/decfd
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/decfd/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
solana/programs/decfd/src/lib.rs L193–216 @ b0698f7 · MIT · original if m.stake < c.min_stake { m.status = MINER_BANNED; } c.treasury += to_treasury; let j = &mut ctx.accounts.job; j.reserved = j.reserved.checked_sub(t.reward).ok_or(DecfdError::Overflow)?; t.status = TASK_REJECTED; msg!("slashed {} lamports ({} to the verifier), banned: {}", penalty, to_verifier, m.status == MINER_BANNED); Ok(()) } /// Pay a task: anyone may call it once the task is verified or its challenge window passed. pub fn settle_task(ctx: Context<SettleTask>) -> Result<()> { let t = &mut ctx.accounts.task; let now = Clock::get()?.unix_timestamp; let window_over = t.status == TASK_SUBMITTED && now >= t.submitted_at + ctx.accounts.config.challenge_window; require!(t.status == TASK_VERIFIED || window_over, DecfdError::NotSettleable); let j = &mut ctx.accounts.job; move_lamports(&j.to_account_info(), &ctx.accounts.miner_wallet.to_account_info(), t.reward)?; j.escrow = j.escrow.checked_sub(t.reward).ok_or(DecfdError::Overflow)?; j.reserved = j.reserved.checked_sub(t.reward).ok_or(DecfdError::Overflow)?;- Line 193
if m.stake < c.min_stake {: Touches staking state: the amount locked and when it was locked. - Line 198
j.reserved = j.reserved.checked_sub(t.reward).ok_or(DecfdError::Overflow)?;: Uses checked arithmetic so overflow fails instead of wrapping. - Line 200
msg!("slashed {} lamports ({} to the verifier), banned: {}", penalty, to_verifier,: Logs to the program log, which is visible in explorers and the test output. - Line 208
let now = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 211
require!(t.status == TASK_VERIFIED || window_over, DecfdError::NotSettleable);: An explicit validation that aborts the instruction with an error.
orchestrator_py/network/solana_ledger.py L85–108 @ b0698f7 · MIT · originaldef miner_pda(program, config, authority): return Pubkey.find_program_address([b"miner", _pk(config), _pk(authority)], program)[0] def job_pda(program, config, job_id): return Pubkey.find_program_address([b"job", _pk(config), _u64(job_id)], program)[0] def task_pda(program, job, index): return Pubkey.find_program_address([b"task", _pk(job), _u32(index)], program)[0] # ------------------------------------------------------------------------------ decodingdef decode_config(d): return {"admin": str(Pubkey(d[8:40])), "verifier": str(Pubkey(d[40:72])), "network_id": struct.unpack_from("<Q", d, 72)[0], "min_stake": struct.unpack_from("<Q", d, 80)[0], "challenge_window": struct.unpack_from("<q", d, 88)[0], "treasury": struct.unpack_from("<Q", d, 96)[0], "slash_bps": struct.unpack_from("<H", d, 104)[0], "verifier_share_bps": struct.unpack_from("<H", d, 106)[0]} def decode_miner(d): n = struct.unpack_from("<I", d, 106)[0] return {"config": str(Pubkey(d[8:40])), "authority": str(Pubkey(d[40:72])), "stake": struct.unpack_from("<Q", d, 72)[0], "earned": struct.unpack_from("<Q", d, 80)[0],- Line 86
return Pubkey.find_program_address([b"miner", _pk(config), _pk(authority)], program)[0]: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 108
"stake": struct.unpack_from("<Q", d, 72)[0], "earned": struct.unpack_from("<Q", d, 80)[0],: Touches staking state: the amount locked and when it was locked.
orchestrator_py/network/solana_rpc.py L61–84 @ b0698f7 · MIT · original pass time.sleep(wait * random.uniform(0.8, 1.3)) delay = min(delay * 2, 15.0) continue raise RpcError(f"{method}: HTTP {e.code} {e.read()[:200]!r}") from e except (urllib.error.URLError, TimeoutError, ConnectionError) as e: if not last: time.sleep(delay * random.uniform(0.8, 1.3)) delay = min(delay * 2, 15.0) continue raise RpcError(f"{method}: {e}") from e if "error" in reply: raise RpcError(f"{method}: {reply['error']}") return reply["result"] raise RpcError(f"{method}: no reply") # ------------------------------------------------------------------ helpers def latest_blockhash(self): return Hash.from_string(self.call("getLatestBlockhash", [{"commitment": "confirmed"}])["value"]["blockhash"]) def send(self, tx_bytes): """Send a signed transaction; preflight simulation catches program errors early.""" return self.call("sendTransaction", [base64.b64encode(tx_bytes).decode(), {"encoding": "base64", "preflightCommitment": "confirmed"}])- Line 79
return Hash.from_string(self.call("getLatestBlockhash", [{"commitment": "confirmed"}])["va: Fetches a recent blockhash. Transactions expire if it gets too old. - Line 83
return self.call("sendTransaction", [base64.b64encode(tx_bytes).decode(),: Submits the signed transaction to the cluster.
How to run
No package.json, Anchor.toml, Cargo.toml, go.mod or Makefile was found near the root. See the project README.
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)