Skip to content

Commit

Permalink
feature(eligibility): validators with 0 power should not be eligibile…
Browse files Browse the repository at this point in the history
… regardless of the threshold value
  • Loading branch information
drcpu-github authored and aesedepece committed Aug 23, 2024
1 parent b69661b commit 405ad48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
23 changes: 21 additions & 2 deletions validations/src/eligibility/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ where
Err(e) => {
// Early exit if the stake key does not exist
return match e {
StakesError::ValidatorNotFound { .. } => Ok(IneligibilityReason::NotStaking.into()),
StakesError::ValidatorNotFound { .. } => {
Ok(IneligibilityReason::NotStaking.into())
}
e => Err(e),
};
}
};

// Validators with power 0 should not be eligible to mine a block
if power == Power::from(0) {
return Ok(IneligibilityReason::InsufficientPower.into());
}

// Requirement no. 2 from the WIP:
// "the mining power of the block proposer is in the `rf / stakers`th quantile among the mining powers of all
// the stakers"
Expand Down Expand Up @@ -197,6 +204,15 @@ where
}
};

// Validators with power 0 should not be eligible to mine a block
if power == Power::from(0) {
return Ok((
IneligibilityReason::InsufficientPower.into(),
Hash::min(),
0.0,
));
}

let mut rank = self.rank(Capability::Witnessing, epoch);
let (_, max_power) = rank.next().unwrap_or_default();

Expand Down Expand Up @@ -353,7 +369,10 @@ mod tests {
match stakes.witnessing_eligibility(isk_1, 100, 2, 0) {
// TODO: verify target hash
Ok((eligible, _target_hash, _)) => {
assert_eq!(eligible, Eligible::No(IneligibilityReason::InsufficientPower));
assert_eq!(
eligible,
Eligible::No(IneligibilityReason::InsufficientPower)
);
}
Err(_) => assert!(false),
}
Expand Down
17 changes: 2 additions & 15 deletions validations/src/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,7 @@ pub fn validate_commit_transaction(
dr_state.info.current_commit_round,
) {
Ok((eligibility, target_hash, _)) => {
if eligibility == Eligible::No(InsufficientPower)
|| eligibility == Eligible::No(NotStaking)
{
if matches!(eligibility, Eligible::No(_)) {
return Err(TransactionError::ValidatorNotEligible {
validator: proof_pkh,
}
Expand Down Expand Up @@ -1876,6 +1874,7 @@ pub fn validate_block_transactions(
}
let re_hash_merkle_root = re_mt.root();

// Make sure that the block does not try to include data requests asking for too many witnesses
for transaction in &block.txns.data_request_txns {
let dr_tx_hash = transaction.hash();
if !dr_pool.data_request_pool.contains_key(&dr_tx_hash)
Expand Down Expand Up @@ -2513,12 +2512,6 @@ pub fn verify_signatures(
vrf_input,
target_hash,
} => {
log::debug!(
"[SIGVER-BLOCK-{}] proof: {:?}, input: {:?}",
i,
proof,
vrf_input
);
let vrf_hash = proof
.verify(vrf, vrf_input)
.map_err(|_| BlockError::NotValidPoe)?;
Expand All @@ -2537,12 +2530,6 @@ pub fn verify_signatures(
dr_hash,
target_hash,
} => {
log::debug!(
"[SIGVER-DR-{}] proof: {:?}, input: {:?}",
i,
proof,
vrf_input
);
let vrf_hash = proof
.verify(vrf, vrf_input, dr_hash)
.map_err(|_| TransactionError::InvalidDataRequestPoe)?;
Expand Down

0 comments on commit 405ad48

Please sign in to comment.