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

[Human App] Implemented oracle filter #2697

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

eugenvoronov
Copy link
Contributor

@eugenvoronov eugenvoronov commented Oct 25, 2024

Description

Enhanced the Oracle Discovery Service by improving the filtering mechanism for oracles based on their supported job types. The goal is to ensure that only relevant oracles are returned, optimizing the discovery process.

Summary of changes

  • Improved processOracleDiscovery and findOraclesByChainId methods to OracleDiscoveryService.
  • Added new filterOracles and matchesJobTypes methods to OracleDiscoveryService.
  • Implemented new unit tests.

How test the changes

yarn test

Related issues

[HUMAN App] Filter Exchange Oracles by job types allowed in the reputation network
#2613

Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
human-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 8:05am
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
faucet-frontend ⬜️ Ignored (Inspect) Visit Preview Oct 25, 2024 8:05am
faucet-server ⬜️ Ignored (Inspect) Visit Preview Oct 25, 2024 8:05am
human-dashboard-frontend ⬜️ Skipped (Inspect) Oct 25, 2024 8:05am


private filterOracles(foundOracles: IOperator[], jobTypes: string[]) {
if (foundOracles && foundOracles.length > 0) {
const filteredOracles = foundOracles.filter((oracle) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are you filtering the oracles if they dont have url?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check is here:

const filteredOracles = oracles.filter((oracle) => {
        if (!oracle.url || oracle.url === null) {
          return false;
        }
        return true;
});

If oracle don't have .url we skip it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just dont see a reason to filter out the ones that don't have a url

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 will try to find more efficient way


if (!jobTypes || jobTypes === '') {
throw new HttpException(
`Unable to retrieve job types from address: ${address}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets not throw an exception if the job types are not set, just return an empty array or undefined

) {}

async processOracleDiscovery(
command: OracleDiscoveryCommand,
): Promise<OracleDiscoveryResponse[]> {
const address = this.configService.reputationOracleAddress;
const chainIds = this.configService.chainIdsEnabled;
const jobTypesByChainId = new Map<ChainId, string[]>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this variable is not used

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 used here:
jobTypesByChainId.set(+chainId, jobTypes);

Copy link
Collaborator

@portuu3 portuu3 Oct 25, 2024

Choose a reason for hiding this comment

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

yes, you are setting the values but never using it

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 see what do you mean, I used it before optimised previous solution, thanks

@@ -49,4 +49,42 @@ export class KvStoreGateway {
return fetchedData;
}
}

async getJobTypesByAddress(address: string): Promise<string | void> {
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 use the chainId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chainId used inside getJobTypesByAddress method.

const chainId: ChainId = Number(network?.chainId);

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean pass it as parameter

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 we really need this? Since we have only one chainId assigned to rpcUrl in configs.

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.

2 participants