feat(infra): add P2P handlers, WASM host functions, and distributed storage for decentralized challenges - #46
Conversation
… 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
…tion registrations
…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.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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)
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. Comment |
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/)consensus.rs:platform_consensushost function namespace withConsensusPolicy,ConsensusState, andConsensusHostFunctions— exposesconsensus_get_epoch,consensus_get_validators,consensus_propose_weight,consensus_get_votes,consensus_get_state_hash,consensus_get_submission_count,consensus_get_block_heightterminal.rs:platform_terminalhost function namespace withTerminalPolicy,TerminalState, andTerminalHostFunctions— exposesterminal_exec,terminal_read_file,terminal_write_file,terminal_list_dir,terminal_get_time,terminal_random_seedwith path/command allow-listingsandbox.rs: ImplementHostFunctionRegistrarforSandboxHostFunctionswith real Wasmtime linker registration forsandbox_exec,get_timestamp,log_messageruntime.rs: Register all new host function namespaces (consensus, terminal, sandbox, exec, time) inWasmRuntime::instantiate()alongside existing network and storage host functions; extendRuntimeStateandInstanceConfigwithConsensusState/ConsensusPolicyandTerminalState/TerminalPolicyP2P Consensus (
crates/p2p-consensus/)messages.rs: Add 11 newP2PMessagevariants (appended at end for bincode backward compatibility):JobClaim,JobAssignment,DataRequest,DataResponse,TaskProgress,TaskResult,LeaderboardRequest,LeaderboardResponse,ChallengeUpdate,StorageProposal,StorageVote— with full message structsstate.rs: ExtendChainStatewithleaderboard,active_jobs,task_progress,challenge_storage_rootsfields (all#[serde(default)]); addLeaderboardEntry,JobRecord,JobStatus,TaskProgressRecordtypes; add state methods:assign_job,complete_job,update_leaderboard,get_leaderboard,update_task_progress,update_challenge_storage_root,cleanup_stale_jobsValidator Node (
bins/validator-node/)main.rs: Handle all new P2P message types inhandle_network_event()with proper logging and state updates; handle previously unmatched messages (StateRequest,StateResponse,WeightVote,PeerAnnounce); add stale job cleanup periodic task (120s interval)challenge_storage.rs:ChallengeStorageBackendimplementingStorageBackendtrait backed by realLocalStoragefromdistributed-storage— replacesNoopStorageBackendfor production usewasm_executor.rs: WireConsensusPolicyandTerminalPolicyintoInstanceConfigChallenge SDK WASM (
crates/challenge-sdk-wasm/)host_functions.rs: Addplatform_consensusextern 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
EvaluationInput/EvaluationOutputbincode serializationP2PMessagevariants added at end of enum for backward compatibilityChallengeStorageBackendmoved tovalidator-nodebinary to avoid cyclic dependency betweenwasm-runtime-interfaceanddistributed-storageviaplatform-core