Skip to content

Implement oracle subscriptions#787

Merged
philippwerner merged 31 commits intodevelopfrom
feature/2026-02-20-oracle-subscriptions
Mar 10, 2026
Merged

Implement oracle subscriptions#787
philippwerner merged 31 commits intodevelopfrom
feature/2026-02-20-oracle-subscriptions

Conversation

@philippwerner
Copy link
Contributor

Implements #673

cyber-pc and others added 23 commits February 25, 2026 13:33
The iterative variant massively reduces risk of stack overflows and is
probably faster as well.
Move redundant code to functions.
This makes sure that fee reserve of the test contracts is only set when
starting from scratch, not after loading a snapshot.
Ensures that notifications are in order of querying
@philippwerner philippwerner self-assigned this Mar 7, 2026
@philippwerner philippwerner linked an issue Mar 7, 2026 that may be closed by this pull request
@philippwerner philippwerner moved this to 👀 In review in qubic Mar 7, 2026
@philippwerner philippwerner requested a review from cyber-pc March 9, 2026 14:43

logToConsole(L"Saving oracle subscriptions ...");
sizeToSave = sizeof(OracleSubscription) * MAX_ORACLE_SUBSCRIPTIONS;
sz = saveLargeFile(ORACLE_SNAPSHOT_SUBSCRIPTIONS_FILENAME, sizeToSave, (unsigned char*)subscriptions, directory);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure, but we have nextSubscriptionIdQueue that built from subscriptions, should we rebuild/reload it or it's already been handled else where.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good point. It had not been handled in the version that you have reviewed. I have cherry-picked the fix for this that I have made yesterday from the testnet branch.

break;
const uint16_t contractIndex = (uint16_t)request->reqTickOrId;
response->resType = RespondOracleData::respondSubscriptionIds;
const int32_t* subscriptionIds = nextSubscriptionIdQueue.data();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This subscriptionIds variable is redundant or you want to use it for the following code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch as well. This is unused, originating from copy & paste. I have removed it.

while (nextSubscriptionIdQueue.peek(subscriptionId))
{
// Check if it is time to generate the next query
ASSERT(subscriptionId >= 0 && subscriptionId < usedSubscriberSlots);
Copy link
Collaborator

Choose a reason for hiding this comment

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

subscriptionId < usedSubscriptionSlots instead of subscriptionId < usedSubscriberSlots ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right.

if (subscription.firstSubscriberIndex >= 0)
{
// there is at least one additional subscriber -> update timestamp to next subscriber
subscription.nextQueryTimestamp = subscribers[subscription.firstSubscriberIndex].nextQueryTimestamp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beside updating the timestamp, do we need to update thing like line 933-935 in oracle_engine ?
I saw we update timestamp and re-add this subscription into nextSubscriptionIdQueue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch again. Thanks, you did an excellent review, @cyber-pc!

@philippwerner philippwerner merged commit 7527603 into develop Mar 10, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in qubic Mar 10, 2026
@philippwerner philippwerner deleted the feature/2026-02-20-oracle-subscriptions branch March 10, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Oracles: subscriptions and its scheduler

3 participants