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

refactor: remove pythnet feature flag #399

Merged
merged 13 commits into from
Mar 27, 2024
Prev Previous commit
Next Next commit
address comments
cctdaniel committed Mar 27, 2024
commit e6cc1816f987e1204fa2684929306f2e64e28b02
39 changes: 35 additions & 4 deletions program/c/src/oracle/oracle.h
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ extern "C" {
#define PC_MAP_TABLE_SIZE 640

// Total price component slots available
#define PC_NUM_COMP_SOLANA 32
#define PC_NUM_COMP_PYTHNET 128

// PC_NUM_COMP - number of price components in use
@@ -208,13 +207,45 @@ typedef struct pc_price


// Replace Solana component size's contribution with Pythnet's
#define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (3312 \
- PC_NUM_COMP_SOLANA * sizeof(pc_price_comp_t) \
/*
The value 240 is derived from the fixed size of the pc_price_t struct excluding the size of the comp_ array.
Here is the breakdown of the sizes (in bytes) for each field within the pc_price_t struct:
- magic_ (uint32_t): 4 bytes
- ver_ (uint32_t): 4 bytes
- type_ (uint32_t): 4 bytes
- size_ (uint32_t): 4 bytes
- ptype_ (uint32_t): 4 bytes
- expo_ (int32_t): 4 bytes
- num_ (uint32_t): 4 bytes
- num_qt_ (uint32_t): 4 bytes
- last_slot_ (uint64_t): 8 bytes
- valid_slot_ (uint64_t): 8 bytes
- twap_ (pc_ema_t): 24 bytes (3 fields of int64_t each taking 8 bytes)
- twac_ (pc_ema_t): 24 bytes (similar to twap_)
- timestamp_ (int64_t): 8 bytes
- min_pub_ (uint8_t): 1 byte
- message_sent_ (int8_t): 1 byte
- max_latency_ (uint8_t): 1 byte
- drv3_ (int8_t): 1 byte
- drv4_ (int32_t): 4 bytes
- prod_ (pc_pub_key_t): 32 bytes (assuming pc_pub_key_t is a 32-byte array or struct)
- next_ (pc_pub_key_t): 32 bytes (similar to prod_)
- prev_slot_ (uint64_t): 8 bytes
- prev_price_ (int64_t): 8 bytes
- prev_conf_ (uint64_t): 8 bytes
- prev_timestamp_ (int64_t): 8 bytes
- agg_ (pc_price_info_t): 32 bytes
Adding up all these sizes gives us a total of 240 bytes for the fixed part of the pc_price_t struct.
The size of the comp_ array is variable and depends on PC_NUM_COMP, hence it is calculated separately and added to the base size of 240 bytes.
*/
#define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (240 \
+ PC_NUM_COMP * sizeof(pc_price_comp_t) \
)

static_assert( sizeof( pc_price_t ) == PC_EXPECTED_PRICE_T_SIZE_PYTHNET, "" );
#undef PC_EXPECTED_PRICE_SIZE_PYTHNET
#undef PC_EXPECTED_PRICE_T_SIZE_PYTHNET
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this seems like a typo before



// This constant needs to be an upper bound of the price account size, it is used within pythd for ztsd.