Skip to content

Set price per compute unit #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pc/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ bool rpc::upd_price::build_tx(
tx.add( *first.bhash_ ); // recent block hash

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

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

// Requested price per compute unit, in micro lamports
// We want to pay 5000 lamports in total, so ((5000/20000) / 8) * (10^6)
// assuming upper bound of 20000 CUs and 8 instructions.
const uint64_t cu_price_micro_lamports = 31250;

// Set compute unit price
tx.add( (uint8_t)( n + 3 ) );
tx.add_len<0>(); // no accounts
// compute unit price instruction parameters
tx.add_len<sizeof(uint8_t) + sizeof(uint64_t)>(); // uint8_t enum variant + uint62_t compute price
tx.add( (uint8_t) 3 ); // SetComputePrice enum variant
tx.add( (uint64_t) cu_price_micro_lamports ); // price we are willing to pay per compute unit in Micro Lamports

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
Expand Down
1 change: 1 addition & 0 deletions program/c/src/oracle/oracle.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ e79bc372baadecff
403a9b432c
*/

// correct
const uint64_t compute_budget_program_id[] = {
0x321721e56f460603UL,
0xe79bc372baadecffUL,
Expand Down