From 16129abd82145b863c47b57f53192d93f6e46ed0 Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 6 Jan 2023 09:28:29 +0800 Subject: [PATCH] simplify eip1559 support --- .../contracts/primitives/rpc-core/Cargo.toml | 1 + .../rpc-core/src/types/call_request.rs | 4 ++ .../rpc-core/src/types/transaction_request.rs | 9 ++- src/components/contracts/rpc/src/eth.rs | 61 +++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/components/contracts/primitives/rpc-core/Cargo.toml b/src/components/contracts/primitives/rpc-core/Cargo.toml index 81617b82fa..fe9bee55a6 100644 --- a/src/components/contracts/primitives/rpc-core/Cargo.toml +++ b/src/components/contracts/primitives/rpc-core/Cargo.toml @@ -9,6 +9,7 @@ description = "RPC traits of Ethereum." license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] +ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] } ethereum-types = "0.13.1" futures = "0.3.16" jsonrpc-core = { git = "https://github.com/FindoraNetwork/jsonrpc.git", package = "jsonrpc-core" } diff --git a/src/components/contracts/primitives/rpc-core/src/types/call_request.rs b/src/components/contracts/primitives/rpc-core/src/types/call_request.rs index 0451dbaf65..2e965b9c99 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/call_request.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/call_request.rs @@ -31,6 +31,10 @@ pub struct CallRequest { pub to: Option, /// Gas Price pub gas_price: Option, + /// EIP-1559 Max base fee the caller is willing to pay + pub max_fee_per_gas: Option, + /// EIP-1559 Priority fee the caller is paying to the block author + pub max_priority_fee_per_gas: Option, /// Gas pub gas: Option, /// Value diff --git a/src/components/contracts/primitives/rpc-core/src/types/transaction_request.rs b/src/components/contracts/primitives/rpc-core/src/types/transaction_request.rs index bbddf8d5f4..804b542f74 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/transaction_request.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/transaction_request.rs @@ -19,11 +19,12 @@ //! `TransactionRequest` type use crate::types::Bytes; +use ethereum::AccessListItem; use ethereum_types::{H160, U256}; use serde::{Deserialize, Serialize}; /// Transaction request coming from RPC -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] pub struct TransactionRequest { @@ -33,6 +34,10 @@ pub struct TransactionRequest { pub to: Option, /// Gas Price pub gas_price: Option, + /// Max BaseFeePerGas the user is willing to pay. + pub max_fee_per_gas: Option, + /// The miner's tip. + pub max_priority_fee_per_gas: Option, /// Gas pub gas: Option, /// Value of transaction in wei @@ -41,4 +46,6 @@ pub struct TransactionRequest { pub data: Option, /// Transaction's nonce pub nonce: Option, + /// Pre-pay to warm storage access. + pub access_list: Option>, } diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 5f572cb1b3..5cc6870ee9 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -228,6 +228,25 @@ impl EthApi for EthApiImpl { fn send_transaction(&self, request: TransactionRequest) -> BoxFuture> { debug!(target: "eth_rpc", "send_transaction, request:{:?}", request); + let mut request = request; + let curr_height = match self.block_number() { + Ok(v) => v, + Err(e) => { + return Box::pin(async move { Err(e) }); + } + } + .as_u64(); + if request.gas_price.is_none() + && request.max_fee_per_gas.is_some() + && request.max_priority_fee_per_gas.is_some() + { + request.gas_price = Some( + ::FeeCalculator::min_gas_price( + curr_height, + ), + ); + } + let from = match request.from { Some(from) => from, None => { @@ -345,6 +364,25 @@ impl EthApi for EthApiImpl { ) -> BoxFuture> { debug!(target: "eth_rpc", "call, request:{:?}", request); + let mut request = request; + let curr_height = match self.block_number() { + Ok(v) => v, + Err(e) => { + return Box::pin(async move { Err(e) }); + } + } + .as_u64(); + if request.gas_price.is_none() + && request.max_fee_per_gas.is_some() + && request.max_priority_fee_per_gas.is_some() + { + request.gas_price = Some( + ::FeeCalculator::min_gas_price( + curr_height, + ), + ); + } + let account_base_app = self.account_base_app.clone(); let task = spawn_blocking(move || -> Result { @@ -352,6 +390,8 @@ impl EthApi for EthApiImpl { from, to, gas_price, + max_fee_per_gas: _max_fee_per_gas, + max_priority_fee_per_gas: _max_priority_fee_per_gas, gas, value, data, @@ -764,6 +804,25 @@ impl EthApi for EthApiImpl { ) -> BoxFuture> { debug!(target: "eth_rpc", "estimate_gas, block number {:?} request:{:?}", number, request); + let mut request = request; + let curr_height = match self.block_number() { + Ok(v) => v, + Err(e) => { + return Box::pin(async move { Err(e) }); + } + } + .as_u64(); + if request.gas_price.is_none() + && request.max_fee_per_gas.is_some() + && request.max_priority_fee_per_gas.is_some() + { + request.gas_price = Some( + ::FeeCalculator::min_gas_price( + curr_height, + ), + ); + } + let account_base_app = self.account_base_app.clone(); let task = spawn_blocking(move || { @@ -861,6 +920,8 @@ impl EthApi for EthApiImpl { from, to, gas_price, + max_fee_per_gas: _max_fee_per_gas, + max_priority_fee_per_gas: _max_priority_fee_per_gas, gas, value, data,