Skip to content

Commit 5c41cf1

Browse files
committed
cleanup
1 parent 0ac1be8 commit 5c41cf1

File tree

3 files changed

+32
-50
lines changed

3 files changed

+32
-50
lines changed

src/dynamic_fee.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ use serde_json::{json, Value};
66

77
impl Miner {
88
pub async fn dynamic_fee(&self) -> u64 {
9-
let ore_addresses: Vec<String> =
10-
std::iter::once("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ".to_string())
11-
.chain(BUS_ADDRESSES.iter().map(|pubkey| pubkey.to_string()))
12-
.collect();
9+
let ore_addresses: Vec<String> = std::iter::once(ore_api::ID.to_string())
10+
.chain(BUS_ADDRESSES.iter().map(|pubkey| pubkey.to_string()))
11+
.collect();
1312

1413
match &self.dynamic_fee_strategy {
1514
None => self.priority_fee.unwrap_or(0),
1615
Some(strategy) => {
1716
let client = Client::new();
18-
1917
let body = match strategy.as_str() {
2018
"helius" => {
2119
json!({
@@ -46,8 +44,13 @@ impl Miner {
4644
_ => return self.priority_fee.unwrap_or(0),
4745
};
4846

47+
// Send request
48+
let url = self
49+
.dynamic_fee_url
50+
.clone()
51+
.unwrap_or(self.rpc_client.url());
4952
let response: Value = client
50-
.post(self.dynamic_fee_url.as_ref().unwrap())
53+
.post(url)
5154
.json(&body)
5255
.send()
5356
.await
@@ -56,6 +59,7 @@ impl Miner {
5659
.await
5760
.unwrap();
5861

62+
// Parse fee
5963
let calculated_fee = match strategy.as_str() {
6064
"helius" => response["result"]["priorityFeeEstimate"]
6165
.as_f64()
@@ -75,13 +79,13 @@ impl Miner {
7579
_ => return self.priority_fee.unwrap_or(0),
7680
};
7781

78-
// Check if the calculated fee is higher than self.dynamic_fee_max
79-
if let Some(max_fee) = self.dynamic_fee_max {
82+
// Check if the calculated fee is higher than max
83+
if let Some(max_fee) = self.priority_fee {
8084
calculated_fee.min(max_fee)
8185
} else {
8286
calculated_fee
8387
}
8488
}
8589
}
8690
}
87-
}
91+
}

src/main.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct Miner {
3333
pub priority_fee: Option<u64>,
3434
pub dynamic_fee_url: Option<String>,
3535
pub dynamic_fee_strategy: Option<String>,
36-
pub dynamic_fee_max: Option<u64>,
3736
pub rpc_client: Arc<RpcClient>,
3837
pub fee_payer_filepath: Option<String>,
3938
}
@@ -61,7 +60,7 @@ enum Commands {
6160
#[command(about = "Start mining")]
6261
Mine(MineArgs),
6362

64-
#[command(about = "Proof")]
63+
#[command(about = "Fetch a proof account by address")]
6564
Proof(ProofArgs),
6665

6766
#[command(about = "Fetch the current reward rate for each difficulty level")]
@@ -109,24 +108,24 @@ struct Args {
109108
#[arg(
110109
long,
111110
value_name = "FEE_PAYER_FILEPATH",
112-
help = "Filepath to keypair to use for fee payer",
111+
help = "Filepath to keypair to use as transaction fee payer",
113112
global = true
114113
)]
115-
fee_payer_filepath: Option<String>,
114+
fee_payer: Option<String>,
116115

117116
#[arg(
118117
long,
119118
value_name = "MICROLAMPORTS",
120-
help = "Number of microlamports to pay as priority fee per transaction",
121-
default_value = "0",
119+
help = "Price to pay for compute unit. If dynamic fee url is also set, this value will be the max.",
120+
default_value = "500000",
122121
global = true
123122
)]
124123
priority_fee: Option<u64>,
125124

126125
#[arg(
127126
long,
128127
value_name = "DYNAMIC_FEE_URL",
129-
help = "RPC URL to use for dynamic fee estimation. If set will enable dynamic fee pricing instead of static priority fee pricing.",
128+
help = "RPC URL to use for dynamic fee estimation.",
130129
global = true
131130
)]
132131
dynamic_fee_url: Option<String>,
@@ -139,14 +138,6 @@ struct Args {
139138
global = true
140139
)]
141140
dynamic_fee_strategy: Option<String>,
142-
#[arg(
143-
long,
144-
value_name = "DYNAMIC_FEE_MAX",
145-
help = "Maximum priority fee to use for dynamic fee estimation.",
146-
default_value = "500000",
147-
global = true
148-
)]
149-
dynamic_fee_max: Option<u64>,
150141

151142
#[command(subcommand)]
152143
command: Commands,
@@ -171,9 +162,7 @@ async fn main() {
171162
// Initialize miner.
172163
let cluster = args.rpc.unwrap_or(cli_config.json_rpc_url);
173164
let default_keypair = args.keypair.unwrap_or(cli_config.keypair_path.clone());
174-
let fee_payer_filepath = args
175-
.fee_payer_filepath
176-
.unwrap_or(cli_config.keypair_path.clone());
165+
let fee_payer_filepath = args.fee_payer.unwrap_or(cli_config.keypair_path.clone());
177166
let rpc_client = RpcClient::new_with_commitment(cluster, CommitmentConfig::confirmed());
178167

179168
let miner = Arc::new(Miner::new(
@@ -182,7 +171,6 @@ async fn main() {
182171
Some(default_keypair),
183172
args.dynamic_fee_url,
184173
args.dynamic_fee_strategy,
185-
args.dynamic_fee_max,
186174
Some(fee_payer_filepath),
187175
));
188176

@@ -235,7 +223,6 @@ impl Miner {
235223
keypair_filepath: Option<String>,
236224
dynamic_fee_url: Option<String>,
237225
dynamic_fee_strategy: Option<String>,
238-
dynamic_fee_max: Option<u64>,
239226
fee_payer_filepath: Option<String>,
240227
) -> Self {
241228
Self {
@@ -244,7 +231,6 @@ impl Miner {
244231
priority_fee,
245232
dynamic_fee_url,
246233
dynamic_fee_strategy,
247-
dynamic_fee_max,
248234
fee_payer_filepath,
249235
}
250236
}

src/send_and_confirm.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const MIN_SOL_BALANCE: f64 = 0.005;
2525
const RPC_RETRIES: usize = 0;
2626
const _SIMULATION_RETRIES: usize = 4;
2727
const GATEWAY_RETRIES: usize = 150;
28-
const CONFIRM_RETRIES: usize = 1;
28+
const CONFIRM_RETRIES: usize = 8;
2929

30-
const CONFIRM_DELAY: u64 = 0;
31-
const GATEWAY_DELAY: u64 = 300;
30+
const CONFIRM_DELAY: u64 = 500;
31+
const GATEWAY_DELAY: u64 = 0; //300;
3232

3333
pub enum ComputeBudget {
3434
Dynamic,
@@ -42,7 +42,6 @@ impl Miner {
4242
compute_budget: ComputeBudget,
4343
skip_confirm: bool,
4444
) -> ClientResult<Signature> {
45-
let progress_bar = spinner::new_progress_bar();
4645
let signer = self.signer();
4746
let client = self.rpc_client.clone();
4847
let fee_payer = self.fee_payer();
@@ -71,16 +70,15 @@ impl Miner {
7170
}
7271
}
7372

74-
let priority_fee = match &self.dynamic_fee_url {
75-
Some(_) => {
76-
self.dynamic_fee().await
77-
}
78-
None => {
79-
self.priority_fee.unwrap_or(0)
80-
}
73+
let priority_fee = match &self.dynamic_fee_strategy {
74+
Some(_) => self.dynamic_fee().await,
75+
None => self.priority_fee.unwrap_or(0),
8176
};
77+
println!(" Priority fee: {} microlamports", priority_fee);
8278

83-
final_ixs.push(ComputeBudgetInstruction::set_compute_unit_price(priority_fee));
79+
final_ixs.push(ComputeBudgetInstruction::set_compute_unit_price(
80+
priority_fee,
81+
));
8482
final_ixs.extend_from_slice(ixs);
8583

8684
// Build tx
@@ -99,23 +97,17 @@ impl Miner {
9997
.await
10098
.unwrap();
10199

102-
103100
if signer.pubkey() == fee_payer.pubkey() {
104101
tx.sign(&[&signer], hash);
105102
} else {
106103
tx.sign(&[&signer, &fee_payer], hash);
107104
}
108105

109106
// Submit tx
107+
let progress_bar = spinner::new_progress_bar();
110108
let mut attempts = 0;
111109
loop {
112-
113-
let message = match &self.dynamic_fee_url {
114-
Some(_) => format!("Submitting transaction... (attempt {} with dynamic priority fee of {} via {})", attempts, priority_fee, self.dynamic_fee_strategy.as_ref().unwrap()),
115-
None => format!("Submitting transaction... (attempt {} with static priority fee of {})", attempts, priority_fee),
116-
};
117-
118-
progress_bar.set_message(message);
110+
progress_bar.set_message(format!("Submitting transaction... (attempt {})", attempts,));
119111

120112
match client.send_transaction_with_config(&tx, send_cfg).await {
121113
Ok(sig) => {

0 commit comments

Comments
 (0)