Skip to content

Commit a9f6e0e

Browse files
jayantkJayant Krishnamurthytompntn
authored
[wip] Request compute units for price update transactions (#301)
* compute budget * hex * Flip endianness Co-authored-by: Jayant Krishnamurthy <[email protected]> Co-authored-by: Tom Pointon <[email protected]>
1 parent c542c5e commit a9f6e0e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

pc/rpc_client.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,19 +910,29 @@ bool rpc::upd_price::build_tx(
910910
auto& first = *upds[ 0 ];
911911

912912
// accounts
913-
tx.add_len( n + 3 ); // n + 3 accounts: publish, symbol{n}, sysvar, program
913+
tx.add_len( n + 4 ); // n + 4 accounts: publish, symbol{n}, sysvar, pyth program, compute budget program
914914
tx.add( *first.pkey_ ); // publish account
915915
for ( unsigned i = 0; i < n; ++i ) {
916916
tx.add( *upds[ i ]->akey_ ); // symbol account
917917
}
918918
tx.add( *(pub_key*)sysvar_clock ); // sysvar account
919919
tx.add( *first.gkey_ ); // programid
920+
tx.add( *(pub_key*)compute_budget_program_id ); // compute budget program id
920921

921922
// recent block hash
922923
tx.add( *first.bhash_ ); // recent block hash
923924

924925
// instructions section
925-
tx.add_len( n ); // n instruction(s)
926+
tx.add_len( n + 1 ); // 1 compute limit instruction, n upd_price instruction(s)
927+
928+
// Set compute limit
929+
tx.add( (uint8_t)( n + 3 ) ); // compute budget program id index in accounts list
930+
tx.add_len<0>(); // no accounts
931+
// compute limit instruction parameters
932+
tx.add_len<sizeof(uint8_t) + sizeof(uint32_t)>(); // uint8_t enum variant + uint32_t requested compute units
933+
tx.add( (uint8_t) 2 ); // SetComputeLimit enum variant
934+
tx.add( (uint32_t) CU_BUDGET_PER_IX * n ); // the budget (scaled for number of instructions)
935+
926936
for ( unsigned i = 0; i < n; ++i ) {
927937
tx.add( (uint8_t)( n + 2 ) ); // program_id index
928938
tx.add_len< 3 >(); // 3 accounts: publish, symbol, sysvar

program/c/src/oracle/oracle.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ const uint64_t EXTRA_PUBLISHER_SPACE = 3072ULL;
5353
#define PC_ACCTYPE_TEST 4
5454
#define PC_ACCTYPE_PERMISSIONS 5
5555

56+
57+
// Compute budget requested per price update instruction
58+
// The biggest instruction appears to be about ~10300 CUs, so overestimate by 100%.
59+
#define CU_BUDGET_PER_IX 20000
60+
5661
// binary version of sysvar_clock account id
5762
const uint64_t sysvar_clock[] = {
5863
0xc974c71817d5a706UL,
@@ -61,6 +66,21 @@ const uint64_t sysvar_clock[] = {
6166
0x215b5573UL
6267
};
6368

69+
// compute budget program id in hex (but wrong endianness)
70+
/*
71+
321721e56f460603
72+
e79bc372baadecff
73+
6b12f7c5bbe58cbc
74+
403a9b432c
75+
*/
76+
77+
const uint64_t compute_budget_program_id[] = {
78+
0x321721e56f460603UL,
79+
0xe79bc372baadecffUL,
80+
0x6b12f7c5bbe58cbcUL,
81+
0x403a9b432cUL
82+
};
83+
6484
// public key of symbol or publisher account
6585
typedef union pc_pub_key
6686
{

0 commit comments

Comments
 (0)