move spam check up in logic

This commit is contained in:
Hardhat Chad
2024-10-15 21:27:06 +00:00
parent 50ac4060c0
commit 5c27bd3d00

View File

@@ -53,15 +53,6 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
return Err(OreError::NeedsReset.into());
}
// Validate the hash digest.
//
// Here we use drillx to validate the provided solution is a valid hash of the challenge.
// If invalid, we return an error.
let solution = Solution::new(args.digest, args.nonce);
if !solution.is_valid(&proof.challenge) {
return Err(OreError::HashInvalid.into());
}
// Reject spam transactions.
//
// If a miner attempts to submit solutions too frequently, we reject with an error. In general,
@@ -73,6 +64,15 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
return Err(OreError::Spam.into());
}
// Validate the hash digest.
//
// Here we use drillx to validate the provided solution is a valid hash of the challenge.
// If invalid, we return an error.
let solution = Solution::new(args.digest, args.nonce);
if !solution.is_valid(&proof.challenge) {
return Err(OreError::HashInvalid.into());
}
// Validate the hash satisfies the minimum difficulty.
//
// We use drillx to get the difficulty (leading zeros) of the hash. If the hash does not have the