-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
As per @kianenigma's suggestion, the miner should check if we have enough funds, assuming that it knows how much deposit it typically needs for next round and not use more funds than that + possibly warn if it has too little.
This suggestion came into scope while discussing how to implement the logic to reclaim deposit for discarded solution but seems more generic.
More in details: in process_block
fn, we might want to check if we have sufficient balance for the submission before actually submitting score and solution. Some pseudocode like this
// Check if we have sufficient balance for the submission
let (is_sufficient, available, required) = has_sufficient_balance(
&client,
&signer,
n_pages,
20, // % buffer for transaction fees and other costs. 20 or more ? TBD
).await?;
if !is_sufficient {
log::error!(
target: LOG_TARGET,
"Aborting submission for round {} due to insufficient balance. Available: {}, Required: {}",
round, available, required
);
return Err(Error::InsufficientBalance {
available,
required,
});
}
// (Then continue with the submission)
And also at the beginning of the monitor_cmd
after loading the account info, we should emit a warning if insufficient funds e.g. pseudocode
let initial_pages = static_types::Pages::get(); // Get the expected page count
match has_sufficient_balance(&client, &signer, initial_pages, 20).await {
Ok((true, available, required)) => {
log::info!(
target: LOG_TARGET,
"Initial balance check passed. Available: {}, Required (with buffer): {}",
available, required
);
},
Ok((false, available, required)) => {
log::warn!(
target: LOG_TARGET,
"⚠️ INITIAL BALANCE CHECK FAILED! The account may not have sufficient funds for submissions. Available: {}, Required (with buffer): {}",
available, required
);
// We don't fail here, but provide a warning as the balance might change or requirements might be different
},
Err(e) => {
log::warn!(
target: LOG_TARGET,
"Failed to perform initial balance check: {:?}",
e
);
}
}
Metadata
Metadata
Assignees
Labels
No labels