Skip to content

Commit ac30f09

Browse files
committed
fix: WASM sync writes through P2P consensus + local write-through
- Set require_consensus=true, allow_direct_writes=false for sync - Write locally before P2P broadcast (read-your-own-writes for WASM) - Broadcast to P2P so all validators get the same data via consensus - Increase P2P event channel capacity from 256 to 4096
1 parent 5b57840 commit ac30f09

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

bins/validator-node/src/challenge_storage.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,20 @@ impl StorageBackend for ChallengeStorageBackend {
105105
signature,
106106
});
107107

108-
// Fire and forget - don't block WASM execution on P2P
109-
tracing::info!(
108+
// Write locally first so WASM can read-your-own-writes during sync
109+
let storage_key = build_challenge_storage_key(challenge_id, key);
110+
if let Err(e) = tokio::task::block_in_place(|| {
111+
tokio::runtime::Handle::current().block_on(self.storage.put(
112+
storage_key,
113+
value.to_vec(),
114+
DPutOptions::default(),
115+
))
116+
}) {
117+
tracing::warn!(error = %e, "Failed to write locally before P2P broadcast");
118+
}
119+
120+
// Broadcast via P2P so other validators also apply the write
121+
tracing::debug!(
110122
proposal_id = %hex::encode(&proposal_id[..8]),
111123
challenge_id = %challenge_id,
112124
key_len = key.len(),
@@ -115,7 +127,7 @@ impl StorageBackend for ChallengeStorageBackend {
115127
);
116128
let _ = tx.try_send(P2PCommand::Broadcast(msg));
117129

118-
// Also add the proposal to our local state (we don't receive our own broadcasts)
130+
// Also add the proposal to our local state for vote tracking
119131
if let Some(local_tx) = &self.local_proposal_tx {
120132
let local_proposal = StorageProposal {
121133
proposal_id,

bins/validator-node/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ async fn main() -> Result<()> {
465465
));
466466

467467
// Create event channel for network events
468-
let (event_tx, mut event_rx) = tokio::sync::mpsc::channel::<NetworkEvent>(256);
468+
let (event_tx, mut event_rx) = tokio::sync::mpsc::channel::<NetworkEvent>(4096);
469469

470470
// Initialize P2P network
471471
let network = Arc::new(P2PNetwork::new(

bins/validator-node/src/wasm_executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,8 @@ impl WasmChallengeExecutor {
10341034
challenge_id: module_path.to_string(),
10351035
validator_id: "validator".to_string(),
10361036
storage_host_config: StorageHostConfig {
1037-
allow_direct_writes: true,
1038-
require_consensus: false,
1037+
allow_direct_writes: false,
1038+
require_consensus: true,
10391039
..self.config.storage_host_config.clone()
10401040
},
10411041
storage_backend: Arc::clone(&self.config.storage_backend),

0 commit comments

Comments
 (0)