Skip to content

Commit b283bbc

Browse files
authored
Set price per compute unit (#304)
* Set price per compute unit * Fix comment * Don't define CU_PRICE in header
1 parent a9f6e0e commit b283bbc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pc/rpc_client.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ bool rpc::upd_price::build_tx(
923923
tx.add( *first.bhash_ ); // recent block hash
924924

925925
// instructions section
926-
tx.add_len( n + 1 ); // 1 compute limit instruction, n upd_price instruction(s)
926+
tx.add_len( n + 1 + 1 ); // 1 compute limit instruction, 1 compute unit price instruction, n upd_price instruction(s)
927927

928928
// Set compute limit
929929
tx.add( (uint8_t)( n + 3 ) ); // compute budget program id index in accounts list
@@ -933,6 +933,19 @@ bool rpc::upd_price::build_tx(
933933
tx.add( (uint8_t) 2 ); // SetComputeLimit enum variant
934934
tx.add( (uint32_t) CU_BUDGET_PER_IX * n ); // the budget (scaled for number of instructions)
935935

936+
// Requested price per compute unit, in micro lamports
937+
// We want to pay 5000 lamports in total, so ((5000/20000) / 8) * (10^6)
938+
// assuming upper bound of 20000 CUs and 8 instructions.
939+
const uint64_t cu_price_micro_lamports = 31250;
940+
941+
// Set compute unit price
942+
tx.add( (uint8_t)( n + 3 ) );
943+
tx.add_len<0>(); // no accounts
944+
// compute unit price instruction parameters
945+
tx.add_len<sizeof(uint8_t) + sizeof(uint64_t)>(); // uint8_t enum variant + uint62_t compute price
946+
tx.add( (uint8_t) 3 ); // SetComputePrice enum variant
947+
tx.add( (uint64_t) cu_price_micro_lamports ); // price we are willing to pay per compute unit in Micro Lamports
948+
936949
for ( unsigned i = 0; i < n; ++i ) {
937950
tx.add( (uint8_t)( n + 2 ) ); // program_id index
938951
tx.add_len< 3 >(); // 3 accounts: publish, symbol, sysvar

program/c/src/oracle/oracle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ e79bc372baadecff
7474
403a9b432c
7575
*/
7676

77+
// correct
7778
const uint64_t compute_budget_program_id[] = {
7879
0x321721e56f460603UL,
7980
0xe79bc372baadecffUL,

0 commit comments

Comments
 (0)