Skip to content

Commit 072fa03

Browse files
committed
Make requested CU amount and price in upd_price transactions configurable in pythd
1 parent b283bbc commit 072fa03

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

pc/manager.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ using namespace pc;
1414
#define PC_MAX_BATCH 8
1515
// Flush partial batches if not completed within 400 ms.
1616
#define PC_FLUSH_INTERVAL (400L*PC_NSECS_IN_MSEC)
17+
// Compute units requested per price update instruction
18+
// The biggest instruction appears to be about ~10300 CUs, so we overestimate by 100%.
19+
#define PC_UPD_PRICE_COMPUTE_UNITS 20000
1720

1821
///////////////////////////////////////////////////////////////////////////
1922
// manager_sub
@@ -76,6 +79,8 @@ manager::manager()
7679
is_pub_( false ),
7780
cmt_( commitment::e_confirmed ),
7881
max_batch_( PC_MAX_BATCH ),
82+
requested_upd_price_cu_units_( PC_UPD_PRICE_COMPUTE_UNITS ),
83+
requested_upd_price_cu_price_( 0UL ),
7984
sreq_{ { commitment::e_processed } },
8085
secondary_{ nullptr },
8186
is_secondary_( false )
@@ -189,6 +194,22 @@ int64_t manager::get_publish_interval() const
189194
return pub_int_ / PC_NSECS_IN_MSEC;
190195
}
191196

197+
void manager::set_requested_upd_price_cu_units( unsigned cu_units ) {
198+
requested_upd_price_cu_units_ = cu_units;
199+
}
200+
201+
unsigned manager::get_requested_upd_price_cu_units() const {
202+
return requested_upd_price_cu_units_;
203+
}
204+
205+
void manager::set_requested_upd_price_cu_price( unsigned cu_price ) {
206+
requested_upd_price_cu_price_ = cu_price;
207+
}
208+
209+
unsigned manager::get_requested_upd_price_cu_price() const {
210+
return requested_upd_price_cu_price_;
211+
}
212+
192213
void manager::set_max_batch_size( unsigned batch_size )
193214
{
194215
max_batch_ = batch_size;

pc/manager.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ namespace pc
100100
void set_publish_interval( int64_t mill_secs );
101101
int64_t get_publish_interval() const;
102102

103+
// override the amount of requested CU units per upd_price transaction
104+
void set_requested_upd_price_cu_units( unsigned cu_units );
105+
unsigned get_requested_upd_price_cu_units() const;
106+
107+
// override the price per CU for upd_price transaction
108+
void set_requested_upd_price_cu_price( unsigned cu_price );
109+
unsigned get_requested_upd_price_cu_price() const;
110+
103111
// override the default maximum number of price updates to send in a batch
104112
void set_max_batch_size( unsigned batch_size );
105113
unsigned get_max_batch_size() const;
@@ -275,6 +283,8 @@ namespace pc
275283
tx_parser txp_; // handle unexpected errors
276284
commitment cmt_; // account get/subscribe commitment
277285
unsigned max_batch_;// maximum number of price updates that can be sent in a single batch
286+
unsigned requested_upd_price_cu_units_; // amount of requested CU units per upd_price transaction
287+
unsigned requested_upd_price_cu_price_; // price per CU for upd_price transaction
278288

279289
// requests
280290
rpc::get_slot sreq_[1]; // slot subscription

pcapps/pythd.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ int usage()
7272
std::cerr << " -d" << std::endl;
7373
std::cerr << " Turn on debug logging. Can also toggle this on/off via "
7474
"kill -s SIGUSR1 <pid>\n" << std::endl;
75+
std::cerr << " -u" << std::endl;
76+
std::cerr << " Number of compute units requested by each upd_price transaction (default 20000)" << std::endl;
77+
std::cerr << " -v" << std::endl;
78+
std::cerr << " Price per compute unit for each upd_price transaction, in micro lamports (default 31250)" << std::endl;
7579
return 1;
7680
}
7781

@@ -104,6 +108,8 @@ int main(int argc, char **argv)
104108
int pyth_port = get_port();
105109
int opt = 0;
106110
int pub_int = 1000;
111+
unsigned cu_units = 20000;
112+
unsigned cu_price = 31250;
107113
unsigned max_batch_size = 0;
108114
bool do_wait = true, do_tx = true, do_ws = true, do_debug = false;
109115
while( (opt = ::getopt(argc,argv, "r:s:t:p:i:k:w:c:l:m:b:dnxhz" )) != -1 ) {
@@ -123,6 +129,8 @@ int main(int argc, char **argv)
123129
case 'x': do_tx = false; break;
124130
case 'z': do_ws = false; break;
125131
case 'd': do_debug = true; break;
132+
case 'u': cu_units = strtoul(optarg, NULL, 0); break;
133+
case 'v': cu_price = strtoul(optarg, NULL, 0); break;
126134
default: return usage();
127135
}
128136
}
@@ -153,6 +161,8 @@ int main(int argc, char **argv)
153161
mgr.set_do_capture( !cap_file.empty() );
154162
mgr.set_commitment( cmt );
155163
mgr.set_publish_interval( pub_int );
164+
mgr.set_requested_upd_price_cu_units( cu_units );
165+
mgr.set_requested_upd_price_cu_price( cu_price );
156166

157167
bool do_secondary = !secondary_rpc_host.empty();
158168
if ( do_secondary ) {

0 commit comments

Comments
 (0)