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

Restart tweaks #161

Merged
merged 5 commits into from
Jul 8, 2024
Merged

Restart tweaks #161

merged 5 commits into from
Jul 8, 2024

Conversation

Mantelijo
Copy link
Collaborator

This PR fixes a bug where fundingRate and openInterest values are not set on service start and additionally fixes potential restarts on redis TS.GET calls when key does not exist

@Mantelijo Mantelijo requested a review from a team as a code owner July 3, 2024 10:32
@Mantelijo Mantelijo requested a review from b1674927 July 3, 2024 10:32
if (px != undefined) {
this.idxPrices.set(indices[k], px);
}
updatedIndices.push(indices[k]);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to add indices[k] to updatedIndices if the price px is undefined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

px can only be undefined if ts.get call fails, which would trigger try/catch with ERR TSDB: the key does not exist

Copy link
Contributor

Choose a reason for hiding this comment

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

ok so then the lines 140 to 142 are useless and they should be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

px_ts can actually be null if there are no entries in the timeseries, but the key exists. Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

what is the actual change in this file other than formatting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nothing, this is the default prettier formatting

Copy link
Contributor

Choose a reason for hiding this comment

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

https://stackoverflow.com/questions/2214480/committing-when-changing-source-formatting
"23

Yes. If you need to do whitespace changes, doing them in a separate commit that contains only this kind of cleanup is the best practice. This avoids problems with trying to see what part of a giant diff is actual code changes, and what part is just formatting (cosmetic) changes.

That said, you should try to keep these kind of changes to a minimum, and only do it at all when it is necessary and compatible with whatever coding standards are used in your company / community / project / etc."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved to different PR

Copy link
Contributor

Choose a reason for hiding this comment

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

as discussed we should make this thread safe:

  • this.isInitialized=true only after update
  • change update accordingly for example with an optional argument
  • this.isInitialized should be checked on price updates (and potentially other functions that would send out funding rates)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not needed, since initial update runs before we start http or websockets server

@Mantelijo Mantelijo requested review from b1674927 and removed request for b1674927 July 3, 2024 14:53
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the change in this file other than formatting?

console.log("onUpdateMarkPrice: eventListener not initialized");
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

if this is possible, then it is also possible that we receive the event between assigning this.isInitialized=true and calling this._update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is now changed, we set isInitialized only after first update call

// Do not allow 0 funding rate to be sent out
if (fundingRate === 0) {
console.log(`[onUpdateMarkPrice] funding rate is 0 for ${perpetualId}`);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be an error. Because if the code is correct we never run into this situation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adjusted

console.log(`[updateMarkPrice] funding rate is 0 for ${perpetualId}`);
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, should be an error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adjusted

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@b1674927 are you sure it is not possible to have 0 fundingRate for a perpetual? On arbitrum sepolia perp 30004 currently has 0 funding rate:

{
"id": 300004,
"state": "NORMAL",
"baseCurrency": "WIF",
"quoteCurrency": "USD",
"indexPrice": 1,
"collToQuoteIndexPrice": 1.000005,
"markPrice": 1,
"midPrice": 1,
"currentFundingRateBps": 0,
"openInterestBC": 0,
"isMarketClosed": false
}

This would basically crash the backend

Copy link
Contributor

Choose a reason for hiding this comment

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

Good observation, as soon as the perp is traded for the first time, the funding rate is non-zero.

//
// 2024-07-02: this exchangeInfo call does not actually issue the
// "update" call, since initialization is not yet done in
// EventListener when priceInterfaceInitialize is called.
const info = await this.sdkInterface.exchangeInfo();
Copy link
Contributor

Choose a reason for hiding this comment

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

so should we remove it then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, the info is needed for _initIdxNamesToPerpetualIds

@b1674927 b1674927 merged commit ac3b59f into dev Jul 8, 2024
@b1674927 b1674927 deleted the restart_tweaks branch July 8, 2024 16:48
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