Skip to content

Commit 45a09e1

Browse files
Update send_and_confirm.rs
fix dynamic fee not working
1 parent 3820cb3 commit 45a09e1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/send_and_confirm.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ impl Miner {
6363

6464
// Set compute unit price
6565
final_ixs.push(ComputeBudgetInstruction::set_compute_unit_price(
66-
self.priority_fee.unwrap_or(0),
66+
if self.dynamic_fee {
67+
if let Some(dynamic_fee) = self.dynamic_fee().await {
68+
dynamic_fee
69+
}else{
70+
self.priority_fee.unwrap_or(0)
71+
}
72+
} else {
73+
self.priority_fee.unwrap_or(0)
74+
}
6775
));
6876

6977
// Add in user instructions
@@ -89,17 +97,21 @@ impl Miner {
8997
if attempts % 10 == 0 {
9098
// Reset the compute unit price
9199
if self.dynamic_fee {
92-
let fee = if let Some(fee) = self.dynamic_fee().await {
93-
progress_bar.println(format!(" Priority fee: {} microlamports", fee));
94-
fee
100+
if let Some(dynamic_fee) = self.dynamic_fee().await {
101+
progress_bar.println(format!(" Priority fee: {} microlamports", dynamic_fee));
102+
final_ixs.remove(1);
103+
final_ixs.insert(1, ComputeBudgetInstruction::set_compute_unit_price(dynamic_fee));
95104
} else {
96-
let fee = self.priority_fee.unwrap_or(0);
97-
progress_bar.println(format!(" {} Dynamic fees not supported by this RPC. Falling back to static value: {} microlamports", "WARNING".bold().yellow(), fee));
98-
fee
99-
};
100-
final_ixs.remove(1);
101-
final_ixs.insert(1, ComputeBudgetInstruction::set_compute_unit_price(fee));
102-
}
105+
let fallback_fee = self.priority_fee.unwrap_or(0);
106+
progress_bar.println(format!(
107+
"{} Dynamic fees not supported by this RPC. Falling back to static value: {} microlamports",
108+
"WARNING".bold().yellow(),
109+
fallback_fee
110+
));
111+
final_ixs.remove(1);
112+
final_ixs.insert(1, ComputeBudgetInstruction::set_compute_unit_price(fallback_fee));
113+
}
114+
}
103115

104116
// Resign the tx
105117
let (hash, _slot) = client

0 commit comments

Comments
 (0)