Skip to content

Commit c7180f6

Browse files
committed
fix: use real block height for startup sync and non-blocking background_tick
- Startup sync was hardcoded to block_height=120, epoch=0. Now reads the actual bittensor_block from state_manager so WASM challenges can correctly detect block_height % N == 0 for periodic GitHub refresh. - background_tick now uses try_lock instead of lock on the persistent WASM instance, skipping gracefully when sync() holds the mutex. This prevents background_tick from delaying higher-priority sync calls.
1 parent 61ee724 commit c7180f6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

bins/validator-node/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,13 +1115,15 @@ async fn main() -> Result<()> {
11151115
}
11161116

11171117
// Run sync() on each challenge at startup
1118+
let startup_block = state_manager.apply(|state| state.bittensor_block);
1119+
let startup_epoch = if startup_block > 0 { startup_block / 360 } else { 0 };
11181120
for (challenge_id, module_path) in &challenges {
11191121
let mp = if module_path.is_empty() {
11201122
challenge_id.to_string()
11211123
} else {
11221124
module_path.clone()
11231125
};
1124-
match executor.execute_sync_with_block(&mp, 120, 0) {
1126+
match executor.execute_sync_with_block(&mp, startup_block, startup_epoch) {
11251127
Ok(result) => {
11261128
info!(
11271129
challenge_id = %challenge_id,

bins/validator-node/src/wasm_executor.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,14 +1507,21 @@ impl WasmChallengeExecutor {
15071507

15081508
/// Execute background_tick() on the persistent WASM instance.
15091509
/// Called every block for lightweight background work.
1510+
/// Uses try_lock to avoid blocking sync() which has higher priority.
15101511
pub fn execute_background_tick(
15111512
&self,
15121513
module_path: &str,
15131514
block_height: u64,
15141515
epoch: u64,
15151516
) -> Result<()> {
15161517
let pi = self.get_or_create_persistent(module_path, block_height, epoch)?;
1517-
let mut guard = pi.lock();
1518+
let mut guard = match pi.try_lock() {
1519+
Some(g) => g,
1520+
None => {
1521+
debug!(module = module_path, "background_tick skipped: instance busy (sync in progress)");
1522+
return Ok(());
1523+
}
1524+
};
15181525

15191526
let real_now_ms = std::time::SystemTime::now()
15201527
.duration_since(std::time::UNIX_EPOCH)

0 commit comments

Comments
 (0)