forked from polkadot-evm/frontier
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexecute.rs
More file actions
752 lines (706 loc) · 21.8 KB
/
execute.rs
File metadata and controls
752 lines (706 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Frontier.
//
// Copyright (c) 2022 Parity Technologies (UK) Ltd.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::sync::Arc;
use ethereum_types::{H256, U256};
use evm::{ExitError, ExitReason};
use jsonrpsee::core::RpcResult as Result;
use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sc_network::config::ExHashT;
use sc_transaction_pool::ChainApi;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{BlockStatus, HeaderBackend};
use sp_runtime::{
generic::BlockId,
traits::{BlakeTwo256, Block as BlockT},
};
use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;
use crate::{
eth::{pending_runtime_api, Eth},
frontier_backend_client, internal_err,
};
/// Default JSONRPC error code return by geth
pub const JSON_RPC_ERROR_DEFAULT: i32 = -32000;
/// JSONRPC error code for a revertal.
pub const REVERT_CODE: i32 = 3;
impl<B, C, P, CT, BE, H: ExHashT, A: ChainApi> Eth<B, C, P, CT, BE, H, A>
where
B: BlockT<Hash = H256> + Send + Sync + 'static,
C: ProvideRuntimeApi<B> + StorageProvider<B, BE>,
C: HeaderBackend<B> + Send + Sync + 'static,
C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
A: ChainApi<Block = B> + 'static,
{
pub fn call(&self, request: CallRequest, number: Option<BlockNumber>) -> Result<Bytes> {
let CallRequest {
from,
to,
gas_price,
max_fee_per_gas,
max_priority_fee_per_gas,
gas,
value,
data,
nonce,
access_list,
..
} = request;
let (gas_price, max_fee_per_gas, max_priority_fee_per_gas) = {
let details = fee_details(gas_price, max_fee_per_gas, max_priority_fee_per_gas)?;
(
details.gas_price,
details.max_fee_per_gas,
details.max_priority_fee_per_gas,
)
};
let (id, api) = match frontier_backend_client::native_block_id::<B, C>(
self.client.as_ref(),
self.backend.as_ref(),
number,
)? {
Some(id) => (id, self.client.runtime_api()),
None => {
// Not mapped in the db, assume pending.
let id = BlockId::Hash(self.client.info().best_hash);
let api = pending_runtime_api(self.client.as_ref(), self.graph.as_ref())?;
(id, api)
}
};
if let Ok(BlockStatus::Unknown) = self.client.status(id) {
return Err(crate::err(JSON_RPC_ERROR_DEFAULT, "header not found", None));
}
let api_version =
if let Ok(Some(api_version)) = api.api_version::<dyn EthereumRuntimeRPCApi<B>>(&id) {
api_version
} else {
return Err(internal_err("failed to retrieve Runtime Api version"));
};
// use given gas limit or query current block's limit
let gas_limit = match gas {
Some(amount) => amount,
None => {
let block = if api_version > 1 {
api.current_block(&id)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
} else {
#[allow(deprecated)]
let legacy_block = api.current_block_before_version_2(&id)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
legacy_block.map(|block| block.into())
};
if let Some(block) = block {
block.header.gas_limit
} else {
return Err(internal_err("block unavailable, cannot query gas limit"));
}
}
};
let data = data.map(|d| d.0).unwrap_or_default();
match to {
Some(to) => {
if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
let info = api.call_before_version_2(
&id,
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
gas_price,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &info.value)?;
Ok(Bytes(info.value))
} else if api_version >= 2 && api_version < 4 {
// Post-london
#[allow(deprecated)]
let info = api.call_before_version_4(
&id,
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &info.value)?;
Ok(Bytes(info.value))
} else if api_version == 4 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
let info = api
.call(
&id,
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
false,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &info.value)?;
Ok(Bytes(info.value))
} else {
Err(internal_err("failed to retrieve Runtime Api version"))
}
}
None => {
if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
let info = api.create_before_version_2(
&id,
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
gas_price,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &[])?;
let code = api
.account_code_at(&id, info.value)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
Ok(Bytes(code))
} else if api_version >= 2 && api_version < 4 {
// Post-london
#[allow(deprecated)]
let info = api.create_before_version_4(
&id,
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &[])?;
let code = api
.account_code_at(&id, info.value)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
Ok(Bytes(code))
} else if api_version == 4 {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
let info = api
.create(
&id,
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
false,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
error_on_execution_failure(&info.exit_reason, &[])?;
let code = api
.account_code_at(&id, info.value)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
Ok(Bytes(code))
} else {
Err(internal_err("failed to retrieve Runtime Api version"))
}
}
}
}
pub async fn estimate_gas(&self, request: CallRequest, _: Option<BlockNumber>) -> Result<U256> {
let client = Arc::clone(&self.client);
let block_data_cache = Arc::clone(&self.block_data_cache);
// Define the lower bound of estimate
const MIN_GAS_PER_TX: U256 = U256([21_000, 0, 0, 0]);
// Get best hash (TODO missing support for estimating gas historically)
let best_hash = client.info().best_hash;
// For simple transfer to simple account, return MIN_GAS_PER_TX directly
let is_simple_transfer = match &request.data {
None => true,
Some(vec) => vec.0.is_empty(),
};
if is_simple_transfer {
if let Some(to) = request.to {
let to_code = client
.runtime_api()
.account_code_at(&BlockId::Hash(best_hash), to)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?;
if to_code.is_empty() {
return Ok(MIN_GAS_PER_TX);
}
}
}
let (gas_price, max_fee_per_gas, max_priority_fee_per_gas) = {
let details = fee_details(
request.gas_price,
request.max_fee_per_gas,
request.max_priority_fee_per_gas,
)?;
(
details.gas_price,
details.max_fee_per_gas,
details.max_priority_fee_per_gas,
)
};
let get_current_block_gas_limit = || async {
let substrate_hash = client.info().best_hash;
let id = BlockId::Hash(substrate_hash);
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(&client, id);
let block = block_data_cache.current_block(schema, substrate_hash).await;
if let Some(block) = block {
Ok(block.header.gas_limit)
} else {
Err(internal_err("block unavailable, cannot query gas limit"))
}
};
// Determine the highest possible gas limits
let mut highest = match request.gas {
Some(gas) => gas,
None => {
// query current block's gas limit
get_current_block_gas_limit().await?
}
};
let api = client.runtime_api();
// Recap the highest gas allowance with account's balance.
if let Some(from) = request.from {
let gas_price = gas_price.unwrap_or_default();
if gas_price > U256::zero() {
let balance = api
.account_basic(&BlockId::Hash(best_hash), from)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.balance;
let mut available = balance;
if let Some(value) = request.value {
if value > available {
return Err(internal_err("insufficient funds for transfer"));
}
available -= value;
}
let allowance = available / gas_price;
if highest > allowance {
log::warn!(
"Gas estimation capped by limited funds original {} balance {} sent {} feecap {} fundable {}",
highest,
balance,
request.value.unwrap_or_default(),
gas_price,
allowance
);
highest = allowance;
}
}
}
struct ExecutableResult {
data: Vec<u8>,
exit_reason: ExitReason,
used_gas: U256,
}
// Create a helper to check if a gas allowance results in an executable transaction.
//
// A new ApiRef instance needs to be used per execution to avoid the overlayed state to affect
// the estimation result of subsequent calls.
//
// Note that this would have a performance penalty if we introduce gas estimation for past
// blocks - and thus, past runtime versions. Substrate has a default `runtime_cache_size` of
// 2 slots LRU-style, meaning if users were to access multiple runtime versions in a short period
// of time, the RPC response time would degrade a lot, as the VersionedRuntime needs to be compiled.
//
// To solve that, and if we introduce historical gas estimation, we'd need to increase that default.
#[rustfmt::skip]
let executable = move |
request, gas_limit, api_version, api: sp_api::ApiRef<'_, C::Api>, estimate_mode
| -> Result<ExecutableResult> {
let CallRequest {
from,
to,
gas,
value,
data,
nonce,
access_list,
..
} = request;
// Use request gas limit only if it less than gas_limit parameter
let gas_limit = core::cmp::min(gas.unwrap_or(gas_limit), gas_limit);
let data = data.map(|d| d.0).unwrap_or_default();
let (exit_reason, data, used_gas) = match to {
Some(to) => {
let info = if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
api.call_before_version_2(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
gas_price,
nonce,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
} else if api_version < 4 {
// Post-london
#[allow(deprecated)]
api.call_before_version_4(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
} else {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
api.call(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
to,
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
};
(info.exit_reason, info.value, info.used_gas)
}
None => {
let info = if api_version == 1 {
// Legacy pre-london
#[allow(deprecated)]
api.create_before_version_2(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
gas_price,
nonce,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
} else if api_version < 4 {
// Post-london
#[allow(deprecated)]
api.create_before_version_4(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
} else {
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
api.create(
&BlockId::Hash(best_hash),
from.unwrap_or_default(),
data,
value.unwrap_or_default(),
gas_limit,
max_fee_per_gas,
max_priority_fee_per_gas,
nonce,
estimate_mode,
Some(
access_list
.into_iter()
.map(|item| (item.address, item.storage_keys))
.collect(),
),
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?
};
(info.exit_reason, Vec::new(), info.used_gas)
}
};
Ok(ExecutableResult {
exit_reason,
data,
used_gas,
})
};
let api_version = if let Ok(Some(api_version)) =
client
.runtime_api()
.api_version::<dyn EthereumRuntimeRPCApi<B>>(&BlockId::Hash(best_hash))
{
api_version
} else {
return Err(internal_err("failed to retrieve Runtime Api version"));
};
// Verify that the transaction succeed with highest capacity
let cap = highest;
let estimate_mode = !cfg!(feature = "rpc_binary_search_estimate");
let ExecutableResult {
data,
exit_reason,
used_gas,
} = executable(
request.clone(),
highest,
api_version,
client.runtime_api(),
estimate_mode,
)?;
match exit_reason {
ExitReason::Succeed(_) => (),
ExitReason::Error(ExitError::OutOfGas) => {
return Err(internal_err(format!(
"gas required exceeds allowance {}",
cap
)))
}
// If the transaction reverts, there are two possible cases,
// it can revert because the called contract feels that it does not have enough
// gas left to continue, or it can revert for another reason unrelated to gas.
ExitReason::Revert(revert) => {
if request.gas.is_some() || request.gas_price.is_some() {
// If the user has provided a gas limit or a gas price, then we have executed
// with less block gas limit, so we must reexecute with block gas limit to
// know if the revert is due to a lack of gas or not.
let ExecutableResult {
data,
exit_reason,
used_gas: _,
} = executable(
request.clone(),
get_current_block_gas_limit().await?,
api_version,
client.runtime_api(),
estimate_mode,
)?;
match exit_reason {
ExitReason::Succeed(_) => {
return Err(internal_err(format!(
"gas required exceeds allowance {}",
cap
)))
}
// The execution has been done with block gas limit, so it is not a lack of gas from the user.
other => error_on_execution_failure(&other, &data)?,
}
} else {
// The execution has already been done with block gas limit, so it is not a lack of gas from the user.
error_on_execution_failure(&ExitReason::Revert(revert), &data)?
}
}
other => error_on_execution_failure(&other, &data)?,
};
#[cfg(not(feature = "rpc_binary_search_estimate"))]
{
Ok(used_gas)
}
#[cfg(feature = "rpc_binary_search_estimate")]
{
// On binary search, evm estimate mode is disabled
let estimate_mode = false;
// Define the lower bound of the binary search
let mut lowest = MIN_GAS_PER_TX;
// Start close to the used gas for faster binary search
let mut mid = std::cmp::min(used_gas * 3, (highest + lowest) / 2);
// Execute the binary search and hone in on an executable gas limit.
let mut previous_highest = highest;
while (highest - lowest) > U256::one() {
let ExecutableResult {
data,
exit_reason,
used_gas: _,
} = executable(
request.clone(),
mid,
api_version,
client.runtime_api(),
estimate_mode,
)?;
match exit_reason {
ExitReason::Succeed(_) => {
highest = mid;
// If the variation in the estimate is less than 10%,
// then the estimate is considered sufficiently accurate.
if (previous_highest - highest) * 10 / previous_highest < U256::one() {
return Ok(highest);
}
previous_highest = highest;
}
ExitReason::Revert(_) | ExitReason::Error(ExitError::OutOfGas) => {
lowest = mid;
}
other => error_on_execution_failure(&other, &data)?,
}
mid = (highest + lowest) / 2;
}
Ok(highest)
}
}
}
pub fn error_on_execution_failure(reason: &ExitReason, data: &[u8]) -> Result<()> {
match reason {
ExitReason::Succeed(_) => Ok(()),
ExitReason::Error(e) => {
if *e == ExitError::OutOfGas {
// `ServerError(0)` will be useful in estimate gas
return Err(internal_err("out of gas"));
}
Err(crate::internal_err_with_data(
format!("evm error: {:?}", e),
&[],
))
}
ExitReason::Revert(_) => {
const OFFSET_START: usize = 4;
let mut message = "VM Exception while processing transaction: revert".to_string();
// If error has no selector
if data.len() < OFFSET_START {
return Err(crate::err(JSON_RPC_ERROR_DEFAULT, message, Some(data)));
}
// A minimum size of error function selector (4) + offset (32) + string length (32)
// should contain a utf-8 encoded revert reason.
if data.len() > 68 {
let message_len = data[36..68].iter().sum::<u8>();
if data.len() >= 68 + message_len as usize {
let body: &[u8] = &data[68..68 + message_len as usize];
if let Ok(reason) = std::str::from_utf8(body) {
message = format!("{} {}", message, reason);
}
}
}
Err(crate::err(REVERT_CODE, message, Some(data)))
}
ExitReason::Fatal(e) => Err(crate::internal_err_with_data(
format!("evm fatal: {:?}", e),
&[],
)),
}
}
struct FeeDetails {
gas_price: Option<U256>,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
}
fn fee_details(
request_gas_price: Option<U256>,
request_max_fee: Option<U256>,
request_priority: Option<U256>,
) -> Result<FeeDetails> {
match (request_gas_price, request_max_fee, request_priority) {
(gas_price, None, None) => {
// Legacy request, all default to gas price.
// A zero-set gas price is None.
let gas_price = if gas_price.unwrap_or_default().is_zero() {
None
} else {
gas_price
};
Ok(FeeDetails {
gas_price,
max_fee_per_gas: gas_price,
max_priority_fee_per_gas: gas_price,
})
}
(_, max_fee, max_priority) => {
// eip-1559
// A zero-set max fee is None.
let max_fee = if max_fee.unwrap_or_default().is_zero() {
None
} else {
max_fee
};
// Ensure `max_priority_fee_per_gas` is less or equal to `max_fee_per_gas`.
if let Some(max_priority) = max_priority {
let max_fee = max_fee.unwrap_or_default();
if max_priority > max_fee {
return Err(internal_err(
"Invalid input: `max_priority_fee_per_gas` greater than `max_fee_per_gas`",
));
}
}
Ok(FeeDetails {
gas_price: max_fee,
max_fee_per_gas: max_fee,
max_priority_fee_per_gas: max_priority,
})
}
}
}