@@ -101,15 +101,28 @@ 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
106
+ . estimate_gas ( )
107
+ . await ;
108
+
109
+ let estimated_gas = match estimated_gas_tx {
110
+ Ok ( estimate) => estimate,
111
+ Err ( err) => {
112
+ let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
113
+ error ! ( self . logger, "Transaction failed" ;
114
+ "message" => message,
115
+ ) ;
116
+ // Return `Ok()` to avoid double error logging
117
+ return Ok ( ( ) ) ;
118
+ }
119
+ } ;
120
+
121
+ // Increase the estimated gas by 20%
122
+ let increased_estimate = estimated_gas * U256 :: from ( 120 ) / U256 :: from ( 100 ) ;
123
+
124
+ tx. gas ( increased_estimate) . send ( ) . await ?. await ?;
125
+ METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
113
126
}
114
127
115
128
Ok ( ( ) )
@@ -127,15 +140,28 @@ impl StateManager for SubgraphAvailabilityManagerContract {
127
140
let oracle_index = U256 :: from ( self . oracle_index ) ;
128
141
let tx = self . contract . vote_many ( ids, statuses, oracle_index) ;
129
142
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
- }
143
+ // Calculate estimated gas
144
+ let estimated_gas_tx = tx
145
+ . estimate_gas ( )
146
+ . await ;
147
+
148
+ let estimated_gas = match estimated_gas_tx {
149
+ Ok ( estimate) => estimate,
150
+ Err ( err) => {
151
+ let message = err. decode_revert :: < String > ( ) . unwrap_or ( err. to_string ( ) ) ;
152
+ error ! ( self . logger, "Transaction failed" ;
153
+ "message" => message,
154
+ ) ;
155
+ // Return `Ok()` to avoid double error logging
156
+ return Ok ( ( ) ) ;
157
+ }
158
+ } ;
159
+
160
+ // Increase the estimated gas by 20%
161
+ let increased_estimate = estimated_gas * U256 :: from ( 120 ) / U256 :: from ( 100 ) ;
162
+
163
+ tx. gas ( increased_estimate) . send ( ) . await ?. await ?;
164
+ METRICS . denied_subgraphs_total . inc_by ( num_subgraphs) ;
139
165
}
140
166
141
167
Ok ( ( ) )
0 commit comments