@@ -23,7 +23,6 @@ extern "C" {
2323#define PC_MAP_TABLE_SIZE 640
2424
2525 // Total price component slots available
26- #define PC_NUM_COMP_SOLANA 32
2726#define PC_NUM_COMP_PYTHNET 128
2827
2928// PC_NUM_COMP - number of price components in use
@@ -208,13 +207,45 @@ typedef struct pc_price
208207
209208
210209// Replace Solana component size's contribution with Pythnet's
211- #define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (3312 \
212- - PC_NUM_COMP_SOLANA * sizeof(pc_price_comp_t) \
210+ /*
211+ The value 240 is derived from the fixed size of the pc_price_t struct excluding the size of the comp_ array.
212+ Here is the breakdown of the sizes (in bytes) for each field within the pc_price_t struct:
213+
214+ - magic_ (uint32_t): 4 bytes
215+ - ver_ (uint32_t): 4 bytes
216+ - type_ (uint32_t): 4 bytes
217+ - size_ (uint32_t): 4 bytes
218+ - ptype_ (uint32_t): 4 bytes
219+ - expo_ (int32_t): 4 bytes
220+ - num_ (uint32_t): 4 bytes
221+ - num_qt_ (uint32_t): 4 bytes
222+ - last_slot_ (uint64_t): 8 bytes
223+ - valid_slot_ (uint64_t): 8 bytes
224+ - twap_ (pc_ema_t): 24 bytes (3 fields of int64_t each taking 8 bytes)
225+ - twac_ (pc_ema_t): 24 bytes (similar to twap_)
226+ - timestamp_ (int64_t): 8 bytes
227+ - min_pub_ (uint8_t): 1 byte
228+ - message_sent_ (int8_t): 1 byte
229+ - max_latency_ (uint8_t): 1 byte
230+ - drv3_ (int8_t): 1 byte
231+ - drv4_ (int32_t): 4 bytes
232+ - prod_ (pc_pub_key_t): 32 bytes (assuming pc_pub_key_t is a 32-byte array or struct)
233+ - next_ (pc_pub_key_t): 32 bytes (similar to prod_)
234+ - prev_slot_ (uint64_t): 8 bytes
235+ - prev_price_ (int64_t): 8 bytes
236+ - prev_conf_ (uint64_t): 8 bytes
237+ - prev_timestamp_ (int64_t): 8 bytes
238+ - agg_ (pc_price_info_t): 32 bytes
239+
240+ Adding up all these sizes gives us a total of 240 bytes for the fixed part of the pc_price_t struct.
241+ 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.
242+ */
243+ #define PC_EXPECTED_PRICE_T_SIZE_PYTHNET (240 \
213244 + PC_NUM_COMP * sizeof(pc_price_comp_t) \
214245 )
215246
216247static_assert ( sizeof ( pc_price_t ) == PC_EXPECTED_PRICE_T_SIZE_PYTHNET , "" );
217- #undef PC_EXPECTED_PRICE_SIZE_PYTHNET
248+ #undef PC_EXPECTED_PRICE_T_SIZE_PYTHNET
218249
219250
220251// This constant needs to be an upper bound of the price account size, it is used within pythd for ztsd.
0 commit comments