Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(staker): add eligibility check #239

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

FranklinWaller
Copy link
Member

Motivation

Add eligibility check to the query.
NOTICE: This function is more of a suggestion than an actual check, it helps the round-robin version of the overlay network coordinate with each other. This does not need to be checked at commit level.

Explanation of Changes

  • Add extra check for IsEligible query

Testing

Added a couple extra tests to make sure the round robin mechanism works as expected

Related PRs and Issues

closes #236

@FranklinWaller FranklinWaller linked an issue Dec 9, 2024 that may be closed by this pull request
@FranklinWaller FranklinWaller requested a review from a team December 9, 2024 12:28
Comment on lines +6 to +7
pub fn is_eligible_for_dr(deps: Deps, dr_id: [u8; 32], public_key: PublicKey) -> Result<bool, ContractError> {
let data_request = may_load_request(deps.storage, &dr_id)?.unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should clean up these unwraps, we can do load_request here instead.

But for the other expects/unwraps we should also clean them up. Otherwise this function returns a Result for no reason since we don't bubble up errors anywhere and instead panic.

Comment on lines +8 to +16
let stakers = STAKERS.stakers.keys_raw(deps.storage, None, None, Order::Ascending);
let all_stakers = stakers.collect::<Vec<Vec<u8>>>();

let stakers_length: u64 = all_stakers.len().try_into().expect("cannot convert to u64");
let (staker_index, _) = all_stakers
.iter()
.enumerate()
.find(|(_, pk)| public_key.as_ref() == pk.as_slice())
.expect("Could not find staker");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have to iterate the entire staker pool to find one or ask for the length? Ideally, if we need length of Staker pool we should start storing it on the type. We could also, then return a Staker's index when asking for one.

This staker index would also be non-deterministic since its from the cw-storage-plus not our EnumerableSet type which has swap remove. Every time we run raw_keys the order would be different.

@FranklinWaller FranklinWaller merged commit e251394 into main Dec 9, 2024
2 checks passed
@FranklinWaller FranklinWaller deleted the feat/dr-is-eligible-check branch December 9, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🔧 Implement round robin mechanism
3 participants