diff --git a/pc/rpc_client.cpp b/pc/rpc_client.cpp index 843b0e421..9096b19f9 100644 --- a/pc/rpc_client.cpp +++ b/pc/rpc_client.cpp @@ -910,19 +910,29 @@ bool rpc::upd_price::build_tx( auto& first = *upds[ 0 ]; // accounts - tx.add_len( n + 3 ); // n + 3 accounts: publish, symbol{n}, sysvar, program + tx.add_len( n + 4 ); // n + 4 accounts: publish, symbol{n}, sysvar, pyth program, compute budget program tx.add( *first.pkey_ ); // publish account for ( unsigned i = 0; i < n; ++i ) { tx.add( *upds[ i ]->akey_ ); // symbol account } tx.add( *(pub_key*)sysvar_clock ); // sysvar account tx.add( *first.gkey_ ); // programid + tx.add( *(pub_key*)compute_budget_program_id ); // compute budget program id // recent block hash tx.add( *first.bhash_ ); // recent block hash // instructions section - tx.add_len( n ); // n instruction(s) + tx.add_len( n + 1 ); // 1 compute limit instruction, n upd_price instruction(s) + + // Set compute limit + tx.add( (uint8_t)( n + 3 ) ); // compute budget program id index in accounts list + tx.add_len<0>(); // no accounts + // compute limit instruction parameters + tx.add_len(); // uint8_t enum variant + uint32_t requested compute units + tx.add( (uint8_t) 2 ); // SetComputeLimit enum variant + tx.add( (uint32_t) CU_BUDGET_PER_IX * n ); // the budget (scaled for number of instructions) + for ( unsigned i = 0; i < n; ++i ) { tx.add( (uint8_t)( n + 2 ) ); // program_id index tx.add_len< 3 >(); // 3 accounts: publish, symbol, sysvar diff --git a/program/c/src/oracle/oracle.h b/program/c/src/oracle/oracle.h index dc7cfc5ad..56121f6b0 100644 --- a/program/c/src/oracle/oracle.h +++ b/program/c/src/oracle/oracle.h @@ -53,6 +53,11 @@ const uint64_t EXTRA_PUBLISHER_SPACE = 3072ULL; #define PC_ACCTYPE_TEST 4 #define PC_ACCTYPE_PERMISSIONS 5 + +// Compute budget requested per price update instruction +// The biggest instruction appears to be about ~10300 CUs, so overestimate by 100%. +#define CU_BUDGET_PER_IX 20000 + // binary version of sysvar_clock account id const uint64_t sysvar_clock[] = { 0xc974c71817d5a706UL, @@ -61,6 +66,21 @@ const uint64_t sysvar_clock[] = { 0x215b5573UL }; +// compute budget program id in hex (but wrong endianness) +/* +321721e56f460603 +e79bc372baadecff +6b12f7c5bbe58cbc +403a9b432c +*/ + +const uint64_t compute_budget_program_id[] = { + 0x321721e56f460603UL, + 0xe79bc372baadecffUL, + 0x6b12f7c5bbe58cbcUL, + 0x403a9b432cUL +}; + // public key of symbol or publisher account typedef union pc_pub_key {