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

Fellow members fetching #79

Merged
merged 18 commits into from
Sep 15, 2023
Merged

Fellow members fetching #79

merged 18 commits into from
Sep 15, 2023

Conversation

Bullrich
Copy link
Contributor

@Bullrich Bullrich commented Sep 13, 2023

Created the method to fetch the fellows from the parachain using Polkadot-JS. This will be updated to the new library once it becomes available.

The system fetches all the available fellows with a GitHub handle and caches them. When requesting a fellow, it automatically filters the one it needs and returns an array of handles.

This resolves #61

Co-authored-by: Yuri Volkov mutantcornholio@users.noreply.github.com
Co-authored-by: Maksym Hlukhovtsov mordamax@users.noreply.github.com

@Bullrich Bullrich marked this pull request as ready for review September 13, 2023 19:18
@Bullrich Bullrich requested a review from a team as a code owner September 13, 2023 19:18
const requiredRank = Number(ranking);
this.logger.info(`Fetching members of rank '${requiredRank}' or higher`);

if (this.fellowsCache.size < 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will use data from cache in case if there are more than 1 rule bucket with rank: x?
i don't see any other use case then... right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a map. The idea for this is to fetch all the available fellows once and then we filter per request, instead of fetching them multiple times per required rank.

So if you request in one rule a rank 4, it will already fetch them all, so, if you request later rank 2, all the ranks will be available already.

README.md Outdated Show resolved Hide resolved
mockClear(logger);
const members2 = await fellows.getTeamMembers("2");
expect(members2.length).toBeGreaterThan(0);
expect(logger.debug).not.toHaveBeenCalledWith("Connecting to collective parachain");
Copy link
Contributor

@mordamax mordamax Sep 13, 2023

Choose a reason for hiding this comment

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

this is nice test. do you plan to add the actual rule with rank:2 where you see it allows / or disallows if approver is rank < 2 ?

UPD: ah I see you keep adding stuff :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I didn't plan on adding it, but maybe it's no trouble at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually runs out of the box, so that's good!

Copy link
Contributor

@mordamax mordamax Sep 15, 2023

Choose a reason for hiding this comment

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

It actually runs out of the box, so that's good!

where? I haven't seen in this diff changes where the rank: 2 approvals are being tested, could you please point my eyes?

FYI: if there's no test, not a blocker for this PR, just needs to be done now or later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test to src/test/runner/runner.test.ts where it verifies that the user is of a given rank and skips the test.

Copy link
Contributor

@mordamax mordamax Sep 15, 2023

Choose a reason for hiding this comment

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

hmm.. so if author is fellow - it means he doesn't need review? or I don't get
I thought they need to check whether someone who has approved - is a fellow with dan >= X, so then it counts. otherwise the review-bot blocks merge. So I was expecting this kind of test

src/polkadot/fellows.ts Outdated Show resolved Hide resolved
src/polkadot/fellows.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rzadp rzadp left a comment

Choose a reason for hiding this comment

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

Looks good, just one thing: do you have plans for invalidating the cache of fellows?

Comment on lines +27 to +28
const [address]: [string] = key.toHuman();
fellows.push({ address, ...(rank.toHuman() as object) } as FellowData);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, is it basically this?

fellows.push({address: key.toHuman()[0], rank: rank.toHuman()[0]});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yes.

I just used destructuring so that I doesn't look like I'm accessing random array elements which makes it a bit harder to read, but yes.

key is a string with the address, and rank is {rank: 1}.

src/polkadot/fellows.ts Outdated Show resolved Hide resolved
await api.disconnect();
return users;
} catch (error) {
console.error(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

But why do we log an error and throw it again? Wouldn't this lead to double logging?

Copy link
Contributor Author

@Bullrich Bullrich Sep 14, 2023

Choose a reason for hiding this comment

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

As you have seen in a previous comment, the idea was to log the error, disconnect the API and then throw the error, and, if for some reason, there was a problem during the disconnection of the api, this new error would not overshadow the other error.

const users: Map<string, number> = new Map<string, number>();
for (const fellow of fellows) {
this.logger.debug(`Fetching identity of '${fellow.address}', rank: ${fellow.rank}`);
const fellowData = (await api.query.identity.identityOf(fellow.address)).toHuman() as
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this deserves a semaphore, so it could be queried in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know if there is a limit to stop abuse? That was my main concern.

The current execution takes about 2s, which given the fact that this is an action, is not really a problem (the whole action is executed in about 5s).

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if there is a limit to stop abuse? That was my main concern.

Could you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same problem that we have with GitHub, which has a rate limit.

I assume that there is some kind of rate limit when using Polkadot-JS (else what stop people from DOSing it?), and, because I'm fetching 60 accounts, I found it better to do it in order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm not understanding you. Could you please elaborate on what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're speaking of the same thing here. I suggest adding a semaphore, so requests would be processed in parallel, but with a limit on how much parallel requests to make.

In gitspiegel, I've used semaphore-promise library for that.
Check out the usage in core.ts

Bullrich and others added 2 commits September 14, 2023 10:11
Co-authored-by: Przemek Rzad <roopert7@gmail.com>
Co-authored-by: Przemek Rzad <roopert7@gmail.com>
@Bullrich
Copy link
Contributor Author

Bullrich commented Sep 14, 2023

Looks good, just one thing: do you have plans for invalidating the cache of fellows?

No, as the cache is only generated during the instance and not stored long term. The same as with the GitHub reviews, the cache is only used if we need to fetch the same information during the same execution (that lasts ~5 seconds).

So if rule 1 request the teams, we fetch them and cache them, and if rule 2 requests it, we already have them. But once the execution is over the cache disappears with it.

README.md Outdated Show resolved Hide resolved
mockClear(logger);
const members2 = await fellows.getTeamMembers("2");
expect(members2.length).toBeGreaterThan(0);
expect(logger.debug).not.toHaveBeenCalledWith("Connecting to collective parachain");
Copy link
Contributor

@mordamax mordamax Sep 15, 2023

Choose a reason for hiding this comment

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

It actually runs out of the box, so that's good!

where? I haven't seen in this diff changes where the rank: 2 approvals are being tested, could you please point my eyes?

FYI: if there's no test, not a blocker for this PR, just needs to be done now or later

@Bullrich Bullrich dismissed mutantcornholio’s stale review September 15, 2023 16:50

Discussed about the Semaphore and decided to not go with it for this particular case

@Bullrich Bullrich merged commit 29b16b5 into main Sep 15, 2023
13 checks passed
@Bullrich Bullrich deleted the fellow-team-fetching branch September 15, 2023 16:51
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.

Obtain handles from the fellows
4 participants