Require a minimum number of nonces.

This commit is contained in:
FiveMovesAhead 2025-03-17 13:10:08 +08:00
parent a1d2134c3d
commit 958ef783a4
2 changed files with 10 additions and 4 deletions

View File

@ -18,10 +18,6 @@ pub async fn submit_precommit<T: Context>(
return Err(anyhow!("Invalid settings.player_id. Must be {}", player_id));
}
if num_nonces == 0 {
return Err(anyhow!("Invalid num_nonces. Must be greater than 0"));
}
let config = ctx.get_config().await;
let latest_block_id = ctx.get_latest_block_id().await;
@ -44,6 +40,15 @@ pub async fn submit_precommit<T: Context>(
return Err(anyhow!("Invalid challenge '{}'", settings.challenge_id));
}
// verify min nonces
let min_nonces = config.benchmarks.min_nonces[&settings.challenge_id];
if num_nonces < min_nonces {
return Err(anyhow!(
"Invalid num_nonces. Must be at least {}",
min_nonces
));
}
// verify algorithm is active
if !ctx
.get_algorithm_state(&settings.algorithm_id)

View File

@ -68,6 +68,7 @@ serializable_struct_with_getters! {
min_per_nonce_fee: PreciseNumber,
min_base_fee: PreciseNumber,
runtime_configs: HashMap<AlgorithmType, RuntimeConfig>,
min_nonces: HashMap<String, u32>,
}
}
serializable_struct_with_getters! {