@@ -101,15 +101,26 @@ impl StateManager for RewardsManagerContract {
101
101
let num_subgraphs = ids. len ( ) as u64 ;
102
102
let tx = self . contract . set_denied_many ( ids, statuses) ;
103
103
104
- if let Err ( err) = tx. call ( ) . await {
105
- let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
106
- error ! ( self . logger, "Transaction failed" ;
107
- "message" => message,
108
- ) ;
109
- } else {
110
- tx. send ( ) . await ?. await ?;
111
- METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
112
- }
104
+ // Calculate estimated gas
105
+ let estimated_gas_tx = tx. estimate_gas ( ) . await ;
106
+
107
+ let estimated_gas = match estimated_gas_tx {
108
+ Ok ( estimate) => estimate,
109
+ Err ( err) => {
110
+ let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
111
+ error ! ( self . logger, "Transaction failed" ;
112
+ "message" => message,
113
+ ) ;
114
+ // Return `Ok()` to avoid double error logging
115
+ return Ok ( ( ) ) ;
116
+ }
117
+ } ;
118
+
119
+ // Increase the estimated gas by 20%
120
+ let increased_estimate = estimated_gas * U256 :: from ( 120 ) / U256 :: from ( 100 ) ;
121
+
122
+ tx. gas ( increased_estimate) . send ( ) . await ?. await ?;
123
+ METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
113
124
}
114
125
115
126
Ok ( ( ) )
@@ -127,15 +138,26 @@ impl StateManager for SubgraphAvailabilityManagerContract {
127
138
let oracle_index = U256 :: from ( self . oracle_index ) ;
128
139
let tx = self . contract . vote_many ( ids, statuses, oracle_index) ;
129
140
130
- if let Err ( err) = tx. call ( ) . await {
131
- let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
132
- error ! ( self . logger, "Transaction failed" ;
133
- "message" => message,
134
- ) ;
135
- } else {
136
- tx. send ( ) . await ?. await ?;
137
- METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
138
- }
141
+ // Calculate estimated gas
142
+ let estimated_gas_tx = tx. estimate_gas ( ) . await ;
143
+
144
+ let estimated_gas = match estimated_gas_tx {
145
+ Ok ( estimate) => estimate,
146
+ Err ( err) => {
147
+ let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
148
+ error ! ( self . logger, "Transaction failed" ;
149
+ "message" => message,
150
+ ) ;
151
+ // Return `Ok()` to avoid double error logging
152
+ return Ok ( ( ) ) ;
153
+ }
154
+ } ;
155
+
156
+ // Increase the estimated gas by 20%
157
+ let increased_estimate = estimated_gas * U256 :: from ( 120 ) / U256 :: from ( 100 ) ;
158
+
159
+ tx. gas ( increased_estimate) . send ( ) . await ?. await ?;
160
+ METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
139
161
}
140
162
141
163
Ok ( ( ) )
0 commit comments