Skip to content

feat(infra): add P2P handlers, WASM host functions, and distributed storage for decentralized challenges - #46

Merged
echobt merged 4 commits into
mainfrom
feat/p2p-wasm-host-infra-v2
Feb 18, 2026
Merged

feat(infra): add P2P handlers, WASM host functions, and distributed storage for decentralized challenges#46
echobt merged 4 commits into
mainfrom
feat/p2p-wasm-host-infra-v2

Conversation

@echobt

@echobt echobt commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Implement comprehensive P2P infrastructure and WASM host function namespaces so that future WASM challenges can operate end-to-end on the decentralized P2P network without any centralized server.

Changes

WASM Runtime (crates/wasm-runtime-interface/)

  • New consensus.rs: platform_consensus host function namespace with ConsensusPolicy, ConsensusState, and ConsensusHostFunctions — exposes consensus_get_epoch, consensus_get_validators, consensus_propose_weight, consensus_get_votes, consensus_get_state_hash, consensus_get_submission_count, consensus_get_block_height
  • New terminal.rs: platform_terminal host function namespace with TerminalPolicy, TerminalState, and TerminalHostFunctions — exposes terminal_exec, terminal_read_file, terminal_write_file, terminal_list_dir, terminal_get_time, terminal_random_seed with path/command allow-listing
  • sandbox.rs: Implement HostFunctionRegistrar for SandboxHostFunctions with real Wasmtime linker registration for sandbox_exec, get_timestamp, log_message
  • runtime.rs: Register all new host function namespaces (consensus, terminal, sandbox, exec, time) in WasmRuntime::instantiate() alongside existing network and storage host functions; extend RuntimeState and InstanceConfig with ConsensusState/ConsensusPolicy and TerminalState/TerminalPolicy

P2P Consensus (crates/p2p-consensus/)

  • messages.rs: Add 11 new P2PMessage variants (appended at end for bincode backward compatibility): JobClaim, JobAssignment, DataRequest, DataResponse, TaskProgress, TaskResult, LeaderboardRequest, LeaderboardResponse, ChallengeUpdate, StorageProposal, StorageVote — with full message structs
  • state.rs: Extend ChainState with leaderboard, active_jobs, task_progress, challenge_storage_roots fields (all #[serde(default)]); add LeaderboardEntry, JobRecord, JobStatus, TaskProgressRecord types; add state methods: assign_job, complete_job, update_leaderboard, get_leaderboard, update_task_progress, update_challenge_storage_root, cleanup_stale_jobs

Validator Node (bins/validator-node/)

  • main.rs: Handle all new P2P message types in handle_network_event() with proper logging and state updates; handle previously unmatched messages (StateRequest, StateResponse, WeightVote, PeerAnnounce); add stale job cleanup periodic task (120s interval)
  • New challenge_storage.rs: ChallengeStorageBackend implementing StorageBackend trait backed by real LocalStorage from distributed-storage — replaces NoopStorageBackend for production use
  • wasm_executor.rs: Wire ConsensusPolicy and TerminalPolicy into InstanceConfig

Challenge SDK WASM (crates/challenge-sdk-wasm/)

  • host_functions.rs: Add platform_consensus extern block with all consensus host function imports and safe Rust wrappers (host_consensus_get_epoch, host_consensus_get_validators, host_consensus_propose_weight, etc.)

Notes

  • No breaking changes to existing EvaluationInput/EvaluationOutput bincode serialization
  • New P2PMessage variants added at end of enum for backward compatibility
  • ChallengeStorageBackend moved to validator-node binary to avoid cyclic dependency between wasm-runtime-interface and distributed-storage via platform-core
  • All existing tests pass, clippy clean, fmt clean

echobt and others added 3 commits February 18, 2026 07:25
… exec, and time host functions

- Add consensus and terminal module declarations and re-exports in lib.rs
- Add ConsensusPolicy and TerminalPolicy fields to InstanceConfig with defaults
- Add ConsensusState and TerminalState fields to RuntimeState
- Create consensus_state and terminal_state in instantiate()
- Register exec, time, consensus, terminal, and sandbox host functions in linker
…torage for decentralized challenges

Implement comprehensive P2P infrastructure in platform-v2 so that future WASM
challenges can operate end-to-end without any centralized server. This replaces
the centralized HTTP/PostgreSQL patterns from term-challenge with P2P equivalents.

WASM Runtime (wasm-runtime-interface):
- Add consensus.rs: ConsensusPolicy, ConsensusState, ConsensusHostFunctions with
  platform_consensus namespace (get_epoch, get_validators, propose_weight,
  get_votes, get_state_hash, get_submission_count, get_block_height)
- Add terminal.rs: TerminalPolicy, TerminalState, TerminalHostFunctions with
  platform_terminal namespace (terminal_exec, read_file, write_file, list_dir,
  get_time, random_seed) with path/command allow-listing
- Implement SandboxHostFunctions HostFunctionRegistrar (sandbox.rs) with real
  Wasmtime linker registration for sandbox_exec, get_timestamp, log_message
- Add ChallengeStorageBackend (storage.rs) backed by real LocalStorage from
  distributed-storage, replacing NoopStorageBackend for production use
- Register ConsensusPolicy and TerminalPolicy in InstanceConfig and RuntimeState
- Fix formatting across consensus.rs, sandbox.rs, terminal.rs

P2P Consensus (p2p-consensus):
- Extend ChainState with leaderboard, active_jobs, task_progress, and
  challenge_storage_roots fields for full challenge lifecycle tracking
- Add JobRecord, JobStatus, TaskProgressRecord, LeaderboardEntry types
- Add state methods: assign_job, complete_job, update_leaderboard,
  get_leaderboard, update_task_progress, update_challenge_storage_root,
  cleanup_stale_jobs — all with proper sequence increment
- Add P2PMessage variants (appended at end for bincode compatibility):
  JobClaim, JobAssignment, DataRequest, DataResponse, TaskProgress,
  TaskResult, LeaderboardRequest, LeaderboardResponse, ChallengeUpdate,
  StorageProposal, StorageVote — with full message structs

Validator Node (validator-node):
- Handle all new P2P message types in handle_network_event() with proper
  logging and state updates (JobAssignment creates jobs, TaskProgress
  updates state, etc.)
- Handle previously unmatched messages: StateRequest, StateResponse,
  WeightVote, PeerAnnounce (replacing catch-all debug log)
- Add stale job cleanup periodic task (120s interval)
- Update WasmChallengeExecutor to use InMemoryStorageBackend (upgraded from
  NoopStorageBackend) and wire ConsensusPolicy/TerminalPolicy into config

Challenge SDK WASM (challenge-sdk-wasm):
- Add platform_consensus extern block with all consensus host function imports
- Add safe Rust wrappers: host_consensus_get_epoch, host_consensus_get_validators,
  host_consensus_propose_weight, host_consensus_get_votes, etc.
- Fix minor formatting in host_functions.rs

No breaking changes to existing EvaluationInput/EvaluationOutput serialization.
New P2PMessage variants added at end of enum for backward compatibility.
@coderabbitai

coderabbitai Bot commented Feb 18, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@echobt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/p2p-wasm-host-infra-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@echobt
echobt merged commit 128cd3a into main Feb 18, 2026
11 checks passed
@echobt
echobt deleted the feat/p2p-wasm-host-infra-v2 branch February 18, 2026 08:14
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