File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -43,4 +43,6 @@ pub enum ComputeUnitLimit {
43
43
Static ( u32 ) ,
44
44
/// Simulate the transaction to find out the compute unit usage
45
45
Simulated ,
46
+ /// Simulate the transaction and add a small percentage to account for potential drift
47
+ SimulatedWithExtraPercentage ( u8 ) ,
46
48
}
Original file line number Diff line number Diff line change @@ -98,10 +98,19 @@ pub(crate) fn simulate_and_update_compute_unit_limit(
98
98
} ;
99
99
100
100
match compute_unit_limit {
101
- ComputeUnitLimit :: Simulated => {
102
- let compute_unit_limit =
101
+ ComputeUnitLimit :: Simulated | ComputeUnitLimit :: SimulatedWithExtraPercentage ( _ ) => {
102
+ let base_compute_unit_limit =
103
103
simulate_for_compute_unit_limit_unchecked ( rpc_client, message) ?;
104
104
105
+ let compute_unit_limit =
106
+ if let ComputeUnitLimit :: SimulatedWithExtraPercentage ( n) = compute_unit_limit {
107
+ ( base_compute_unit_limit as u64 )
108
+ . saturating_mul ( 100_u64 . saturating_add ( * n as u64 ) )
109
+ . saturating_div ( 100 ) as u32
110
+ } else {
111
+ base_compute_unit_limit
112
+ } ;
113
+
105
114
// Overwrite the compute unit limit instruction with the actual units consumed
106
115
message. instructions [ compute_unit_limit_ix_index] . data =
107
116
ComputeBudgetInstruction :: set_compute_unit_limit ( compute_unit_limit) . data ;
@@ -138,7 +147,7 @@ impl WithComputeUnitConfig for Vec<Instruction> {
138
147
compute_unit_limit,
139
148
) ) ;
140
149
}
141
- ComputeUnitLimit :: Simulated => {
150
+ ComputeUnitLimit :: Simulated | ComputeUnitLimit :: SimulatedWithExtraPercentage ( _ ) => {
142
151
// Default to the max compute unit limit because later transactions will be
143
152
// simulated to get the exact compute units consumed.
144
153
self . push ( ComputeBudgetInstruction :: set_compute_unit_limit (
Original file line number Diff line number Diff line change @@ -1709,8 +1709,12 @@ pub fn process_deactivate_stake_account(
1709
1709
* stake_account_pubkey
1710
1710
} ;
1711
1711
1712
+ // DeactivateDelinquent parses a VoteState, which may change between simulation and execution
1712
1713
let compute_unit_limit = match blockhash_query {
1713
1714
BlockhashQuery :: None ( _) | BlockhashQuery :: FeeCalculator ( _, _) => ComputeUnitLimit :: Default ,
1715
+ BlockhashQuery :: All ( _) if deactivate_delinquent => {
1716
+ ComputeUnitLimit :: SimulatedWithExtraPercentage ( 5 )
1717
+ }
1714
1718
BlockhashQuery :: All ( _) => ComputeUnitLimit :: Simulated ,
1715
1719
} ;
1716
1720
let ixs = vec ! [ if deactivate_delinquent {
@@ -2805,9 +2809,10 @@ pub fn process_delegate_stake(
2805
2809
2806
2810
let recent_blockhash = blockhash_query. get_blockhash ( rpc_client, config. commitment ) ?;
2807
2811
2812
+ // DelegateStake parses a VoteState, which may change between simulation and execution
2808
2813
let compute_unit_limit = match blockhash_query {
2809
2814
BlockhashQuery :: None ( _) | BlockhashQuery :: FeeCalculator ( _, _) => ComputeUnitLimit :: Default ,
2810
- BlockhashQuery :: All ( _) => ComputeUnitLimit :: Simulated ,
2815
+ BlockhashQuery :: All ( _) => ComputeUnitLimit :: SimulatedWithExtraPercentage ( 5 ) ,
2811
2816
} ;
2812
2817
let ixs = vec ! [ stake_instruction:: delegate_stake(
2813
2818
stake_account_pubkey,
You can’t perform that action at this time.
0 commit comments