From 031dbaa03f211daf6ce4b4245c92565860dc5ac5 Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 9 Nov 2022 12:39:23 +0000 Subject: [PATCH 1/3] Set price per compute unit --- pc/rpc_client.cpp | 10 +++++++++- program/c/src/oracle/oracle.h | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pc/rpc_client.cpp b/pc/rpc_client.cpp index 9096b19f9..ef3a7e0b4 100644 --- a/pc/rpc_client.cpp +++ b/pc/rpc_client.cpp @@ -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 @@ -933,6 +933,14 @@ 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) + // Set compute unit price + tx.add( (uint8_t)( n + 3 ) ); + tx.add_len<0>(); // no accounts + // compute unit price instruction parameters + tx.add_len(); // uint8_t enum variant + uint32_t compute price + tx.add( (uint8_t) 3 ); // SetComputePrice enum variant + tx.add( (uint64_t) CU_PRICE ); // 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 diff --git a/program/c/src/oracle/oracle.h b/program/c/src/oracle/oracle.h index 56121f6b0..72dfc4695 100644 --- a/program/c/src/oracle/oracle.h +++ b/program/c/src/oracle/oracle.h @@ -58,6 +58,11 @@ const uint64_t EXTRA_PUBLISHER_SPACE = 3072ULL; // The biggest instruction appears to be about ~10300 CUs, so overestimate by 100%. #define CU_BUDGET_PER_IX 20000 +// 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. +#define CU_PRICE 31250 + // binary version of sysvar_clock account id const uint64_t sysvar_clock[] = { 0xc974c71817d5a706UL, @@ -74,6 +79,7 @@ e79bc372baadecff 403a9b432c */ +// correct const uint64_t compute_budget_program_id[] = { 0x321721e56f460603UL, 0xe79bc372baadecffUL, From c94d20dd7653665a90485f83b617f6781241d769 Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 9 Nov 2022 17:37:24 +0000 Subject: [PATCH 2/3] Fix comment --- pc/rpc_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pc/rpc_client.cpp b/pc/rpc_client.cpp index ef3a7e0b4..d8b2b5db0 100644 --- a/pc/rpc_client.cpp +++ b/pc/rpc_client.cpp @@ -937,7 +937,7 @@ bool rpc::upd_price::build_tx( tx.add( (uint8_t)( n + 3 ) ); tx.add_len<0>(); // no accounts // compute unit price instruction parameters - tx.add_len(); // uint8_t enum variant + uint32_t compute price + tx.add_len(); // uint8_t enum variant + uint62_t compute price tx.add( (uint8_t) 3 ); // SetComputePrice enum variant tx.add( (uint64_t) CU_PRICE ); // price we are willing to pay per compute unit in Micro Lamports From 78a29669e88c0178fd6f371854a00c8c78c7b364 Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 9 Nov 2022 17:38:45 +0000 Subject: [PATCH 3/3] Don't define CU_PRICE in header --- pc/rpc_client.cpp | 7 ++++++- program/c/src/oracle/oracle.h | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pc/rpc_client.cpp b/pc/rpc_client.cpp index d8b2b5db0..d823afdfa 100644 --- a/pc/rpc_client.cpp +++ b/pc/rpc_client.cpp @@ -933,13 +933,18 @@ 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(); // uint8_t enum variant + uint62_t compute price tx.add( (uint8_t) 3 ); // SetComputePrice enum variant - tx.add( (uint64_t) CU_PRICE ); // price we are willing to pay per compute unit in Micro Lamports + 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 diff --git a/program/c/src/oracle/oracle.h b/program/c/src/oracle/oracle.h index 72dfc4695..2e4321df9 100644 --- a/program/c/src/oracle/oracle.h +++ b/program/c/src/oracle/oracle.h @@ -58,11 +58,6 @@ const uint64_t EXTRA_PUBLISHER_SPACE = 3072ULL; // The biggest instruction appears to be about ~10300 CUs, so overestimate by 100%. #define CU_BUDGET_PER_IX 20000 -// 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. -#define CU_PRICE 31250 - // binary version of sysvar_clock account id const uint64_t sysvar_clock[] = { 0xc974c71817d5a706UL,