@@ -923,7 +923,7 @@ bool rpc::upd_price::build_tx(
923
923
tx.add ( *first.bhash_ ); // recent block hash
924
924
925
925
// 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)
927
927
928
928
// Set compute limit
929
929
tx.add ( (uint8_t )( n + 3 ) ); // compute budget program id index in accounts list
@@ -933,6 +933,19 @@ bool rpc::upd_price::build_tx(
933
933
tx.add ( (uint8_t ) 2 ); // SetComputeLimit enum variant
934
934
tx.add ( (uint32_t ) CU_BUDGET_PER_IX * n ); // the budget (scaled for number of instructions)
935
935
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
+
936
949
for ( unsigned i = 0 ; i < n; ++i ) {
937
950
tx.add ( (uint8_t )( n + 2 ) ); // program_id index
938
951
tx.add_len < 3 >(); // 3 accounts: publish, symbol, sysvar
0 commit comments