@@ -23,7 +23,6 @@ extern "C" {
23
23
#define PC_MAP_TABLE_SIZE 640
24
24
25
25
// Total price component slots available
26
- #define PC_NUM_COMP_SOLANA 32
27
26
#define PC_NUM_COMP_PYTHNET 128
28
27
29
28
// PC_NUM_COMP - number of price components in use
@@ -208,13 +207,45 @@ typedef struct pc_price
208
207
209
208
210
209
// 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 \
213
244
+ PC_NUM_COMP * sizeof(pc_price_comp_t) \
214
245
)
215
246
216
247
static_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
218
249
219
250
220
251
// This constant needs to be an upper bound of the price account size, it is used within pythd for ztsd.
0 commit comments