-
Notifications
You must be signed in to change notification settings - Fork 20
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
added queue and worker for deviation #636
added queue and worker for deviation #636
Conversation
core/src/worker/data-feed.ts
Outdated
} from '../settings' | ||
import { buildSubmissionRoundJobId, buildHeartbeatJobId } from '../utils' | ||
import { buildSubmissionRoundJobId, buildHeartbeatJobId, hookConsoleError } from '../utils' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imported hookConsoleError
is not used anywhere in this file. Let's remove it.
connection: { | ||
host: process.env.REDIS_HOST || 'localhost', | ||
port: Number(process.env.REDIS_PORT) || 6379 | ||
BullModule.registerQueue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using constants from settings?
import { FETCHER_QUEUE_NAME, DEVIATION_QUEUE_NAME } from '../settings'
@Module({
imports: [
BullModule.registerQueue(
{
name: FETCHER_QUEUE_NAME,
connection: {
host: process.env.REDIS_HOST || 'localhost',
port: Number(process.env.REDIS_PORT) || 6379
}
},
{
name: DEVIATION_QUEUE_NAME,
connection: {
host: process.env.REDIS_HOST || 'localhost',
port: Number(process.env.REDIS_PORT) || 6379
}
}
)
],
...
core/src/worker/data-feed.ts
Outdated
logger | ||
}) | ||
|
||
const { timestamp, value: submission } = await fetchDataFeed({ aggregatorHash, logger }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about passing the timestamp
and submission
through the job request rather than fetching back something what we already had access to during fetcher loop? We could remove the fetchDataFeed
call and definition inside of Orakl Network Fetcher
.
At line 504, we just just extract everything we need from job payload.
const {timestamp, submission, oracleAddress } = inData
const aggregatorHash = keys[0] | ||
const aggregatorId = inData[aggregatorHash].aggregatorId | ||
const feeds = inData[aggregatorHash].feeds | ||
const adapterHash = keys[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for correcting this variable! 🙌
fetcher/src/job/job.processor.ts
Outdated
this.logger.debug(response) | ||
if (abs(aggregate - Number(lastSubmission)) >= lastSubmission * threshold) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is actually not correct because lastSubmission
and submission
operate with an extra decimals that are part of adapter definition (e.g. https://config.orakl.network/adapter/ada-usdt.adapter.json)
How about using this already implemented function instead?
orakl/fetcher/src/job/job.utils.ts
Lines 119 to 153 in f4d2b8c
/** | |
* Test whether the current submission deviates from the last | |
* submission more than given threshold or absolute threshold. If yes, | |
* return `true`, otherwise `false`. | |
* | |
* @param {number} latest submission value | |
* @param {number} current submission value | |
* @param {number} threshold configuration | |
* @param {number} absolute threshold configuration | |
* @return {boolean} | |
*/ | |
export function shouldReport( | |
latestSubmission: number, | |
submission: number, | |
decimals: number, | |
threshold: number, | |
absoluteThreshold: number | |
): boolean { | |
if (latestSubmission && submission) { | |
const denominator = Math.pow(10, decimals) | |
const latestSubmissionReal = latestSubmission / denominator | |
const submissionReal = submission / denominator | |
const range = latestSubmissionReal * threshold | |
const l = latestSubmissionReal - range | |
const r = latestSubmissionReal + range | |
return submissionReal < l || submissionReal > r | |
} else if (!latestSubmission && submission) { | |
// latestSubmission hit zero | |
return submission > absoluteThreshold | |
} else { | |
// Something strange happened, don't report! | |
return false | |
} | |
} |
…ON_QUEUE_NAME ' from setting, using 'shouldReport' function, added timestamp, submission variable in deviation queue
I fixed all the issues. Do you think we can merge this now @martinkersner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one thing left we should fix before merging. The rest looks great! Approving now, please fix the decimals, and then merge.
fetcher/src/job/job.processor.ts
Outdated
submission: aggregate, | ||
oracleAddress | ||
} | ||
if (shouldReport(Number(lastSubmission), aggregate, 8, threshold, absoluteThreshold)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely the decimal value should be 8, but the actual settings that defines it is inside of adapter file. You should be able to get it the same way as threshold for example.
Description
This PR implements deviation worker and queue.
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Deployment