Skip to content

Commit 405ad48

Browse files
drcpu-githubaesedepece
authored andcommitted
feature(eligibility): validators with 0 power should not be eligibile regardless of the threshold value
1 parent b69661b commit 405ad48

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

validations/src/eligibility/current.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,19 @@ where
154154
Err(e) => {
155155
// Early exit if the stake key does not exist
156156
return match e {
157-
StakesError::ValidatorNotFound { .. } => Ok(IneligibilityReason::NotStaking.into()),
157+
StakesError::ValidatorNotFound { .. } => {
158+
Ok(IneligibilityReason::NotStaking.into())
159+
}
158160
e => Err(e),
159161
};
160162
}
161163
};
162164

165+
// Validators with power 0 should not be eligible to mine a block
166+
if power == Power::from(0) {
167+
return Ok(IneligibilityReason::InsufficientPower.into());
168+
}
169+
163170
// Requirement no. 2 from the WIP:
164171
// "the mining power of the block proposer is in the `rf / stakers`th quantile among the mining powers of all
165172
// the stakers"
@@ -197,6 +204,15 @@ where
197204
}
198205
};
199206

207+
// Validators with power 0 should not be eligible to mine a block
208+
if power == Power::from(0) {
209+
return Ok((
210+
IneligibilityReason::InsufficientPower.into(),
211+
Hash::min(),
212+
0.0,
213+
));
214+
}
215+
200216
let mut rank = self.rank(Capability::Witnessing, epoch);
201217
let (_, max_power) = rank.next().unwrap_or_default();
202218

@@ -353,7 +369,10 @@ mod tests {
353369
match stakes.witnessing_eligibility(isk_1, 100, 2, 0) {
354370
// TODO: verify target hash
355371
Ok((eligible, _target_hash, _)) => {
356-
assert_eq!(eligible, Eligible::No(IneligibilityReason::InsufficientPower));
372+
assert_eq!(
373+
eligible,
374+
Eligible::No(IneligibilityReason::InsufficientPower)
375+
);
357376
}
358377
Err(_) => assert!(false),
359378
}

validations/src/validations.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,7 @@ pub fn validate_commit_transaction(
692692
dr_state.info.current_commit_round,
693693
) {
694694
Ok((eligibility, target_hash, _)) => {
695-
if eligibility == Eligible::No(InsufficientPower)
696-
|| eligibility == Eligible::No(NotStaking)
697-
{
695+
if matches!(eligibility, Eligible::No(_)) {
698696
return Err(TransactionError::ValidatorNotEligible {
699697
validator: proof_pkh,
700698
}
@@ -1876,6 +1874,7 @@ pub fn validate_block_transactions(
18761874
}
18771875
let re_hash_merkle_root = re_mt.root();
18781876

1877+
// Make sure that the block does not try to include data requests asking for too many witnesses
18791878
for transaction in &block.txns.data_request_txns {
18801879
let dr_tx_hash = transaction.hash();
18811880
if !dr_pool.data_request_pool.contains_key(&dr_tx_hash)
@@ -2513,12 +2512,6 @@ pub fn verify_signatures(
25132512
vrf_input,
25142513
target_hash,
25152514
} => {
2516-
log::debug!(
2517-
"[SIGVER-BLOCK-{}] proof: {:?}, input: {:?}",
2518-
i,
2519-
proof,
2520-
vrf_input
2521-
);
25222515
let vrf_hash = proof
25232516
.verify(vrf, vrf_input)
25242517
.map_err(|_| BlockError::NotValidPoe)?;
@@ -2537,12 +2530,6 @@ pub fn verify_signatures(
25372530
dr_hash,
25382531
target_hash,
25392532
} => {
2540-
log::debug!(
2541-
"[SIGVER-DR-{}] proof: {:?}, input: {:?}",
2542-
i,
2543-
proof,
2544-
vrf_input
2545-
);
25462533
let vrf_hash = proof
25472534
.verify(vrf, vrf_input, dr_hash)
25482535
.map_err(|_| TransactionError::InvalidDataRequestPoe)?;

0 commit comments

Comments
 (0)