@@ -70,6 +70,13 @@ const UPGRADE_GUARDIAN_SET_VAA_1 : &str = "010000000001007ac31b282c2aeeeb37f3385
70
70
const UPGRADE_GUARDIAN_SET_VAA_2 : & str = "01000000010d0012e6b39c6da90c5dfd3c228edbb78c7a4c97c488ff8a346d161a91db067e51d638c17216f368aa9bdf4836b8645a98018ca67d2fec87d769cabfdf2406bf790a0002ef42b288091a670ef3556596f4f47323717882881eaf38e03345078d07a156f312b785b64dae6e9a87e3d32872f59cb1931f728cecf511762981baf48303668f0103cef2616b84c4e511ff03329e0853f1bd7ee9ac5ba71d70a4d76108bddf94f69c2a8a84e4ee94065e8003c334e899184943634e12043d0dda78d93996da073d190104e76d166b9dac98f602107cc4b44ac82868faf00b63df7d24f177aa391e050902413b71046434e67c770b19aecdf7fce1d1435ea0be7262e3e4c18f50ddc8175c0105d9450e8216d741e0206a50f93b750a47e0a258b80eb8fed1314cc300b3d905092de25cd36d366097b7103ae2d184121329ba3aa2d7c6cc53273f11af14798110010687477c8deec89d36a23e7948feb074df95362fc8dcbd8ae910ac556a1dee1e755c56b9db5d710c940938ed79bc1895a3646523a58bc55f475a23435a373ecfdd0107fb06734864f79def4e192497362513171530daea81f07fbb9f698afe7e66c6d44db21323144f2657d4a5386a954bb94eef9f64148c33aef6e477eafa2c5c984c01088769e82216310d1827d9bd48645ec23e90de4ef8a8de99e2d351d1df318608566248d80cdc83bdcac382b3c30c670352be87f9069aab5037d0b747208eae9c650109e9796497ff9106d0d1c62e184d83716282870cef61a1ee13d6fc485b521adcce255c96f7d1bca8d8e7e7d454b65783a830bddc9d94092091a268d311ecd84c26010c468c9fb6d41026841ff9f8d7368fa309d4dbea3ea4bbd2feccf94a92cc8a20a226338a8e2126cd16f70eaf15b4fc9be2c3fa19def14e071956a605e9d1ac4162010e23fcb6bd445b7c25afb722250c1acbc061ed964ba9de1326609ae012acdfb96942b2a102a2de99ab96327859a34a2b49a767dbdb62e0a1fb26af60fe44fd496a00106bb0bac77ac68b347645f2fb1ad789ea9bd76fb9b2324f25ae06f97e65246f142df717f662e73948317182c62ce87d79c73def0dba12e5242dfc038382812cfe00126da03c5e56cb15aeeceadc1e17a45753ab4dc0ec7bf6a75ca03143ed4a294f6f61bc3f478a457833e43084ecd7c985bf2f55a55f168aac0e030fc49e845e497101626e9d9a5d9e343f00010000000000000000000000000000000000000000000000000000000000000004c1759167c43f501c2000000000000000000000000000000000000000000000000000000000436f7265020000000000021358cc3ae5c097b213ce3c81979e1b9f9570746aa5ff6cb952589bde862c25ef4392132fb9d4a42157114de8460193bdf3a2fcf81f86a09765f4762fd1107a0086b32d7a0977926a205131d8731d39cbeb8c82b2fd82faed2711d59af0f2499d16e726f6b211b39756c042441be6d8650b69b54ebe715e234354ce5b4d348fb74b958e8966e2ec3dbd4958a7cd66b9590e1c41e0b226937bf9217d1d67fd4e91f574a3bf913953d695260d88bc1aa25a4eee363ef0000ac0076727b35fbea2dac28fee5ccb0fea768eaf45ced136b9d9e24903464ae889f5c8a723fc14f93124b7c738843cbb89e864c862c38cddcccf95d2cc37a4dc036a8d232b48f62cdd4731412f4890da798f6896a3331f64b48c12d1d57fd9cbe7081171aa1be1d36cafe3867910f99c09e347899c19c38192b6e7387ccd768277c17dab1b7a5027c0b3cf178e21ad2e77ae06711549cfbb1f9c7a9d8096e85e1487f35515d02a92753504a8d75471b9f49edb6fbebc898f403e4773e95feb15e80c9a99c8348d" ;
71
71
const UPGRADE_GUARDIAN_SET_VAA_3 : & str = "01000000020d00ce45474d9e1b1e7790a2d210871e195db53a70ffd6f237cfe70e2686a32859ac43c84a332267a8ef66f59719cf91cc8df0101fd7c36aa1878d5139241660edc0010375cc906156ae530786661c0cd9aef444747bc3d8d5aa84cac6a6d2933d4e1a031cffa30383d4af8131e929d9f203f460b07309a647d6cd32ab1cc7724089392c000452305156cfc90343128f97e499311b5cae174f488ff22fbc09591991a0a73d8e6af3afb8a5968441d3ab8437836407481739e9850ad5c95e6acfcc871e951bc30105a7956eefc23e7c945a1966d5ddbe9e4be376c2f54e45e3d5da88c2f8692510c7429b1ea860ae94d929bd97e84923a18187e777aa3db419813a80deb84cc8d22b00061b2a4f3d2666608e0aa96737689e3ba5793810ff3a52ff28ad57d8efb20967735dc5537a2e43ef10f583d144c12a1606542c207f5b79af08c38656d3ac40713301086b62c8e130af3411b3c0d91b5b50dcb01ed5f293963f901fc36e7b0e50114dce203373b32eb45971cef8288e5d928d0ed51cd86e2a3006b0af6a65c396c009080009e93ab4d2c8228901a5f4525934000b2c26d1dc679a05e47fdf0ff3231d98fbc207103159ff4116df2832eea69b38275283434e6cd4a4af04d25fa7a82990b707010aa643f4cf615dfff06ffd65830f7f6cf6512dabc3690d5d9e210fdc712842dc2708b8b2c22e224c99280cd25e5e8bfb40e3d1c55b8c41774e287c1e2c352aecfc010b89c1e85faa20a30601964ccc6a79c0ae53cfd26fb10863db37783428cd91390a163346558239db3cd9d420cfe423a0df84c84399790e2e308011b4b63e6b8015010ca31dcb564ac81a053a268d8090e72097f94f366711d0c5d13815af1ec7d47e662e2d1bde22678113d15963da100b668ba26c0c325970d07114b83c5698f46097010dc9fda39c0d592d9ed92cd22b5425cc6b37430e236f02d0d1f8a2ef45a00bde26223c0a6eb363c8b25fd3bf57234a1d9364976cefb8360e755a267cbbb674b39501108db01e444ab1003dd8b6c96f8eb77958b40ba7a85fefecf32ad00b7a47c0ae7524216262495977e09c0989dd50f280c21453d3756843608eacd17f4fdfe47600001261025228ef5af837cb060bcd986fcfa84ccef75b3fa100468cfd24e7fadf99163938f3b841a33496c2706d0208faab088bd155b2e20fd74c625bb1cc8c43677a0163c53c409e0c5dfa000100000000000000000000000000000000000000000000000000000000000000046c5a054d7833d1e42000000000000000000000000000000000000000000000000000000000436f7265020000000000031358cc3ae5c097b213ce3c81979e1b9f9570746aa5ff6cb952589bde862c25ef4392132fb9d4a42157114de8460193bdf3a2fcf81f86a09765f4762fd1107a0086b32d7a0977926a205131d8731d39cbeb8c82b2fd82faed2711d59af0f2499d16e726f6b211b39756c042441be6d8650b69b54ebe715e234354ce5b4d348fb74b958e8966e2ec3dbd4958a7cd15e7caf07c4e3dc8e7c469f92c8cd88fb8005a2074a3bf913953d695260d88bc1aa25a4eee363ef0000ac0076727b35fbea2dac28fee5ccb0fea768eaf45ced136b9d9e24903464ae889f5c8a723fc14f93124b7c738843cbb89e864c862c38cddcccf95d2cc37a4dc036a8d232b48f62cdd4731412f4890da798f6896a3331f64b48c12d1d57fd9cbe7081171aa1be1d36cafe3867910f99c09e347899c19c38192b6e7387ccd768277c17dab1b7a5027c0b3cf178e21ad2e77ae06711549cfbb1f9c7a9d8096e85e1487f35515d02a92753504a8d75471b9f49edb6fbebc898f403e4773e95feb15e80c9a99c8348d" ;
72
72
73
+ /**
74
+ * The VAA is split at this index when writing the encoded VAA, this allow us to
75
+ * optimize the number of transactions by putting the maximum possible amount of data in the first transaction.
76
+ * This constant is chosen to pack the first transaction maximally.
77
+ */
78
+ const VAA_SPLIT_INDEX : usize = 846 ;
79
+
73
80
fn main ( ) -> Result < ( ) > {
74
81
let cli = Cli :: parse ( ) ;
75
82
let Cli {
@@ -87,8 +94,13 @@ fn main() -> Result<()> {
87
94
88
95
let ( vaa, merkle_price_updates) = deserialize_accumulator_update_data ( & payload) ?;
89
96
90
- let encoded_vaa = process_write_encoded_vaa ( & rpc_client, & vaa, wormhole, & payer) ?;
91
- process_post_price_update ( & rpc_client, encoded_vaa, & payer, & merkle_price_updates[ 0 ] ) ?;
97
+ process_write_encoded_vaa_and_post_price_update (
98
+ & rpc_client,
99
+ & vaa,
100
+ wormhole,
101
+ & payer,
102
+ & merkle_price_updates[ 0 ] ,
103
+ ) ?;
92
104
}
93
105
94
106
Action :: InitializeWormholeReceiver { } => {
@@ -209,37 +221,6 @@ pub fn process_upgrade_guardian_set(
209
221
Ok ( ( ) )
210
222
}
211
223
212
- pub fn process_post_price_update (
213
- rpc_client : & RpcClient ,
214
- encoded_vaa : Pubkey ,
215
- payer : & Keypair ,
216
- merkle_price_update : & MerklePriceUpdate ,
217
- ) -> Result < Pubkey > {
218
- let price_update_keypair = Keypair :: new ( ) ;
219
-
220
- let post_update_accounts = pyth_solana_receiver:: accounts:: PostUpdates :: populate (
221
- payer. pubkey ( ) ,
222
- encoded_vaa,
223
- price_update_keypair. pubkey ( ) ,
224
- )
225
- . to_account_metas ( None ) ;
226
- let post_update_instructions = Instruction {
227
- program_id : pyth_solana_receiver:: id ( ) ,
228
- accounts : post_update_accounts,
229
- data : pyth_solana_receiver:: instruction:: PostUpdates {
230
- price_update : merkle_price_update. clone ( ) ,
231
- }
232
- . data ( ) ,
233
- } ;
234
-
235
- process_transaction (
236
- rpc_client,
237
- vec ! [ post_update_instructions] ,
238
- & vec ! [ payer, & price_update_keypair] ,
239
- ) ?;
240
- Ok ( price_update_keypair. pubkey ( ) )
241
- }
242
-
243
224
fn deserialize_guardian_set ( buf : & mut & [ u8 ] , legacy_guardian_set : bool ) -> Result < GuardianSet > {
244
225
if !legacy_guardian_set {
245
226
// Skip anchor discriminator
@@ -320,13 +301,14 @@ pub fn process_legacy_post_vaa(
320
301
}
321
302
322
303
/**
323
- * This function posts a VAA using the new way of interacting with wormhole, we will use it for price updates
304
+ * This function posts a VAA using the new way of interacting with wormhole and then posts a price update using the VAA
324
305
*/
325
- pub fn process_write_encoded_vaa (
306
+ pub fn process_write_encoded_vaa_and_post_price_update (
326
307
rpc_client : & RpcClient ,
327
308
vaa : & [ u8 ] ,
328
309
wormhole : Pubkey ,
329
310
payer : & Keypair ,
311
+ merkle_price_update : & MerklePriceUpdate ,
330
312
) -> Result < Pubkey > {
331
313
let encoded_vaa_keypair = Keypair :: new ( ) ;
332
314
let encoded_vaa_size: usize = vaa. len ( ) + EncodedVaa :: VAA_START ;
@@ -350,12 +332,6 @@ pub fn process_write_encoded_vaa(
350
332
data : wormhole_core_bridge_solana:: instruction:: InitEncodedVaa . data ( ) ,
351
333
} ;
352
334
353
- process_transaction (
354
- rpc_client,
355
- vec ! [ create_encoded_vaa, init_encoded_vaa_instruction] ,
356
- & vec ! [ payer, & encoded_vaa_keypair] ,
357
- ) ?;
358
-
359
335
let write_encoded_vaa_accounts = wormhole_core_bridge_solana:: accounts:: WriteEncodedVaa {
360
336
write_authority : payer. pubkey ( ) ,
361
337
draft_vaa : encoded_vaa_keypair. pubkey ( ) ,
@@ -364,27 +340,45 @@ pub fn process_write_encoded_vaa(
364
340
365
341
let write_encoded_vaa_accounts_instruction = Instruction {
366
342
program_id : wormhole,
367
- accounts : write_encoded_vaa_accounts,
343
+ accounts : write_encoded_vaa_accounts. clone ( ) ,
368
344
data : wormhole_core_bridge_solana:: instruction:: WriteEncodedVaa {
369
345
args : WriteEncodedVaaArgs {
370
346
index : 0 ,
371
- data : vaa. to_vec ( ) ,
347
+ data : vaa[ .. VAA_SPLIT_INDEX ] . to_vec ( ) ,
372
348
} ,
373
349
}
374
350
. data ( ) ,
375
351
} ;
376
352
353
+
354
+ // 1st transaction
377
355
process_transaction (
378
356
rpc_client,
379
- vec ! [ write_encoded_vaa_accounts_instruction] ,
380
- & vec ! [ payer] ,
357
+ vec ! [
358
+ create_encoded_vaa,
359
+ init_encoded_vaa_instruction,
360
+ write_encoded_vaa_accounts_instruction,
361
+ ] ,
362
+ & vec ! [ payer, & encoded_vaa_keypair] ,
381
363
) ?;
382
364
365
+ let write_encoded_vaa_accounts_instruction_2 = Instruction {
366
+ program_id : wormhole,
367
+ accounts : write_encoded_vaa_accounts,
368
+ data : wormhole_core_bridge_solana:: instruction:: WriteEncodedVaa {
369
+ args : WriteEncodedVaaArgs {
370
+ index : VAA_SPLIT_INDEX . try_into ( ) . unwrap ( ) ,
371
+ data : vaa[ VAA_SPLIT_INDEX ..] . to_vec ( ) ,
372
+ } ,
373
+ }
374
+ . data ( ) ,
375
+ } ;
376
+
383
377
let ( header, _) : ( Header , Body < & RawMessage > ) = serde_wormhole:: from_slice ( vaa) . unwrap ( ) ;
384
378
let guardian_set = GuardianSet :: key ( & wormhole, header. guardian_set_index ) ;
385
379
386
380
let request_compute_units_instruction: Instruction =
387
- ComputeBudgetInstruction :: set_compute_unit_limit ( 400_000 ) ;
381
+ ComputeBudgetInstruction :: set_compute_unit_limit ( 600_000 ) ;
388
382
389
383
let verify_encoded_vaa_accounts = wormhole_core_bridge_solana:: accounts:: VerifyEncodedVaaV1 {
390
384
guardian_set,
@@ -398,15 +392,38 @@ pub fn process_write_encoded_vaa(
398
392
accounts : verify_encoded_vaa_accounts,
399
393
data : wormhole_core_bridge_solana:: instruction:: VerifyEncodedVaaV1 { } . data ( ) ,
400
394
} ;
395
+
396
+ let price_update_keypair = Keypair :: new ( ) ;
397
+
398
+ let post_update_accounts = pyth_solana_receiver:: accounts:: PostUpdates :: populate (
399
+ payer. pubkey ( ) ,
400
+ encoded_vaa_keypair. pubkey ( ) ,
401
+ price_update_keypair. pubkey ( ) ,
402
+ )
403
+ . to_account_metas ( None ) ;
404
+ let post_update_instructions = Instruction {
405
+ program_id : pyth_solana_receiver:: id ( ) ,
406
+ accounts : post_update_accounts,
407
+ data : pyth_solana_receiver:: instruction:: PostUpdates {
408
+ price_update : merkle_price_update. clone ( ) ,
409
+ }
410
+ . data ( ) ,
411
+ } ;
412
+
413
+ // 2nd transaction
401
414
process_transaction (
402
415
rpc_client,
403
416
vec ! [
404
417
request_compute_units_instruction,
418
+ write_encoded_vaa_accounts_instruction_2,
405
419
verify_encoded_vaa_instruction,
420
+ post_update_instructions,
406
421
] ,
407
- & vec ! [ payer] ,
422
+ & vec ! [ payer, & price_update_keypair ] ,
408
423
) ?;
409
- Ok ( encoded_vaa_keypair. pubkey ( ) )
424
+
425
+
426
+ Ok ( price_update_keypair. pubkey ( ) )
410
427
}
411
428
412
429
pub fn process_transaction (
0 commit comments