Skip to content

Conversation

@cctdaniel
Copy link
Contributor

@cctdaniel cctdaniel commented Mar 21, 2024

this is the first refactor in part of the same slot agg changes, intentionally keeping it small and limited to upd_twap so that it's easier to review

@cctdaniel cctdaniel changed the title move upd_twap from upd_aggregate to rust upd_price refactor: move upd_twap from upd_aggregate to rust upd_price Mar 21, 2024
Comment on lines 182 to 187
let agg_diff = {
(clock.slot as i64)
- load_checked::<PriceAccount>(price_account, cmd_args.header.version)?.last_slot_
as i64
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

taken from upd_aggregate.h


assert_eq!(price_data.agg_.price_, 100);
assert_eq!(price_data.agg_.conf_, 10);
assert_eq!(price_data.twap_.val_, 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to keep the asserts and run c_upd_twap after c_upd_aggregate above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm we already have a test_ema.rs which runs c_upd_twap do we need it here again?

Copy link
Contributor

@guibescos guibescos left a comment

Choose a reason for hiding this comment

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

Would like to see other reviews

let agg_diff = {
(clock.slot as i64)
- load_checked::<PriceAccount>(price_account, cmd_args.header.version)?
.prev_slot_ as i64
Copy link
Collaborator

Choose a reason for hiding this comment

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

so the prev_slot after c_upd_aggregate will remain the same as last_slotbefore calling c_upd_aggregate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup since both prev_slot and last_slot is only updated in c_upd_aggregate if ptr->agg_.status_ == PC_STATUS_TRADING


// get number of slots from last published valid price
int64_t agg_diff = ( int64_t )slot - ( int64_t )( ptr->last_slot_ );

Copy link
Contributor

Choose a reason for hiding this comment

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

something to watch out for going forward is the if statement below this comment which updates the previous price. There's a chance that we introduce a bug that updates this multiple times on a single slot, which would make prev_slot == agg_.pub_slot_

@ali-behjati ali-behjati requested a review from anihamde March 22, 2024 19:01
@cctdaniel cctdaniel merged commit 7c14e9e into main Mar 25, 2024
@cctdaniel cctdaniel deleted the refactor-twap branch March 25, 2024 08:22
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.

5 participants