@@ -58,7 +58,7 @@ impl Miner {
58
58
}
59
59
}
60
60
61
- // Set compute units
61
+ // Set compute budget
62
62
let mut final_ixs = vec ! [ ] ;
63
63
match compute_budget {
64
64
ComputeBudget :: Dynamic => {
@@ -70,15 +70,12 @@ impl Miner {
70
70
}
71
71
}
72
72
73
- let priority_fee = match & self . dynamic_fee_strategy {
74
- Some ( _) => self . dynamic_fee ( ) . await ,
75
- None => self . priority_fee . unwrap_or ( 0 ) ,
76
- } ;
77
- println ! ( " Priority fee: {} microlamports" , priority_fee) ;
78
-
73
+ // Set compute unit price
79
74
final_ixs. push ( ComputeBudgetInstruction :: set_compute_unit_price (
80
- priority_fee,
75
+ self . priority_fee . unwrap_or ( 0 ) ,
81
76
) ) ;
77
+
78
+ // Add in user instructions
82
79
final_ixs. extend_from_slice ( ixs) ;
83
80
84
81
// Build tx
@@ -91,24 +88,35 @@ impl Miner {
91
88
} ;
92
89
let mut tx = Transaction :: new_with_payer ( & final_ixs, Some ( & fee_payer. pubkey ( ) ) ) ;
93
90
94
- // Sign tx
95
- let ( hash, _slot) = client
96
- . get_latest_blockhash_with_commitment ( self . rpc_client . commitment ( ) )
97
- . await
98
- . unwrap ( ) ;
99
-
100
- if signer. pubkey ( ) == fee_payer. pubkey ( ) {
101
- tx. sign ( & [ & signer] , hash) ;
102
- } else {
103
- tx. sign ( & [ & signer, & fee_payer] , hash) ;
104
- }
105
-
106
91
// Submit tx
107
92
let progress_bar = spinner:: new_progress_bar ( ) ;
108
93
let mut attempts = 0 ;
109
94
loop {
110
95
progress_bar. set_message ( format ! ( "Submitting transaction... (attempt {})" , attempts, ) ) ;
111
96
97
+ // Sign tx with a new blockhash
98
+ if attempts % 5 == 0 {
99
+ // Reset the compute unit price
100
+ if self . dynamic_fee_strategy . is_some ( ) {
101
+ let fee = self . dynamic_fee ( ) . await ;
102
+ final_ixs. remove ( 1 ) ;
103
+ final_ixs. insert ( 1 , ComputeBudgetInstruction :: set_compute_unit_price ( fee) ) ;
104
+ progress_bar. println ( format ! ( " Priority fee: {} microlamports" , fee) ) ;
105
+ }
106
+
107
+ // Resign the tx
108
+ let ( hash, _slot) = client
109
+ . get_latest_blockhash_with_commitment ( self . rpc_client . commitment ( ) )
110
+ . await
111
+ . unwrap ( ) ;
112
+ if signer. pubkey ( ) == fee_payer. pubkey ( ) {
113
+ tx. sign ( & [ & signer] , hash) ;
114
+ } else {
115
+ tx. sign ( & [ & signer, & fee_payer] , hash) ;
116
+ }
117
+ }
118
+
119
+ // Send transaction
112
120
match client. send_transaction_with_config ( & tx, send_cfg) . await {
113
121
Ok ( sig) => {
114
122
// Skip confirmation
@@ -117,7 +125,7 @@ impl Miner {
117
125
return Ok ( sig) ;
118
126
}
119
127
120
- // Confirm the tx landed
128
+ // Confirm transaction
121
129
for _ in 0 ..CONFIRM_RETRIES {
122
130
std:: thread:: sleep ( Duration :: from_millis ( CONFIRM_DELAY ) ) ;
123
131
match client. get_signature_statuses ( & [ sig] ) . await {
0 commit comments