Skip to content

Commit

Permalink
Rewrite the total fee per gas part and code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 13, 2023
1 parent 6a84b88 commit 30c684c
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 43 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ where
number_or_hash: Option<BlockNumberOrHash>,
state_overrides: Option<BTreeMap<H160, CallStateOverride>>,
) -> RpcResult<Bytes> {
log::info!(target: "rpc", "bear: --- Call request: {:?}", request);
let CallRequest {
from,
to,
Expand Down Expand Up @@ -176,7 +175,6 @@ where
};

let data = data.map(|d| d.0).unwrap_or_default();
log::debug!(target: "rpc", "bear: --- Call request: to {:?}", to);
match to {
Some(to) => {
if api_version == 1 {
Expand Down Expand Up @@ -272,7 +270,6 @@ where
error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else if api_version == 5 {
log::info!(target: "rpc", "bear: --- Ready for call api 5");
let info = self
.client
.call_api_at(params)
Expand All @@ -288,7 +285,6 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;

log::debug!(target: "rpc", "bear: --- Call request: result {:?}", info);
error_on_execution_failure(&info.exit_reason, &info.value)?;
info.value
} else {
Expand Down Expand Up @@ -377,7 +373,6 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?;
Ok(Bytes(code))
} else if api_version == 5 {
log::info!(target: "rpc", "bear: --- Ready for call api 5");
// Post-london + access list support
let access_list = access_list.unwrap_or_default();
let info = api
Expand All @@ -401,7 +396,6 @@ where
.map_err(|err| internal_err(format!("runtime error: {err}")))?
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;

log::debug!(target: "rpc", "bear: --- Call request: result {:?}", info);
error_on_execution_failure(&info.exit_reason, &[])?;

let code = api
Expand Down
32 changes: 12 additions & 20 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,33 @@ where
});
}

log::info!(target: "rpc", "bear: --- Before withdraw, max_fee_per_gas: {:?}, max_priority_fee_per_gas: {:?}, is_transactional: {:?}", max_fee_per_gas, max_priority_fee_per_gas, is_transactional);
let (total_fee_per_gas, _actual_priority_fee_per_gas) =
match (max_fee_per_gas, max_priority_fee_per_gas, is_transactional) {
let total_fee_per_gas = if is_transactional {
match (max_fee_per_gas, max_priority_fee_per_gas) {
// Zero max_fee_per_gas for validated transactional calls exist in XCM -> EVM
// because fees are already withdrawn in the xcm-executor.
(Some(max_fee), _, true) if max_fee.is_zero() => (U256::zero(), U256::zero()),
(Some(max_fee), _) if max_fee.is_zero() => U256::zero(),
// With no tip, we pay exactly the base_fee
(Some(_), None, _) => (base_fee, U256::zero()),
(Some(_), None) => base_fee,
// With tip, we include as much of the tip on top of base_fee that we can, never
// exceeding max_fee_per_gas
(Some(max_fee_per_gas), Some(max_priority_fee_per_gas), true) => {
(Some(max_fee_per_gas), Some(max_priority_fee_per_gas)) => {
let actual_priority_fee_per_gas = max_fee_per_gas
.saturating_sub(base_fee)
.min(max_priority_fee_per_gas);
(
base_fee.saturating_add(actual_priority_fee_per_gas),
actual_priority_fee_per_gas,
)

base_fee.saturating_add(actual_priority_fee_per_gas)
}
// Gas price check is skipped for non-transactional calls or creates
(_, _, false) => (Default::default(), U256::zero()),
// Unreachable, previously validated. Handle gracefully.
_ => {
return Err(RunnerError {
error: Error::<T>::GasPriceTooLow,
weight,
})
}
};
}
} else {
// Gas price check is skipped for non-transactional calls or creates
Default::default()
};

// After eip-1559 we make sure the account can pay both the evm execution and priority fees.
let total_fee =
Expand All @@ -233,10 +231,8 @@ where
})?;

// Deduct fee from the `source` account. Returns `None` if `total_fee` is Zero.
log::info!(target: "rpc", "bear: --- Before withdraw, total_fee: {:?}", total_fee);
let fee = T::OnChargeTransaction::withdraw_fee(&source, total_fee)
.map_err(|e| RunnerError { error: e, weight })?;
log::info!(target: "rpc", "bear: --- After withdraw");

// Execute the EVM call.
let vicinity = Vicinity {
Expand Down Expand Up @@ -426,7 +422,6 @@ where
config: &evm::Config,
) -> Result<CallInfo, RunnerError<Self::Error>> {
if validate {
log::info!(target: "rpc", "bear: --- Ready to validate");
Self::validate(
source,
Some(target),
Expand All @@ -443,7 +438,6 @@ where
config,
)?;
}
log::info!(target: "rpc", "bear: --- Pass validation");
let precompiles = T::PrecompilesValue::get();
Self::execute(
source,
Expand Down Expand Up @@ -476,7 +470,6 @@ where
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>> {
if validate {
log::info!(target: "rpc", "bear: --- Ready to validate");
Self::validate(
source,
None,
Expand All @@ -492,7 +485,6 @@ where
proof_size_base_cost,
config,
)?;
log::info!(target: "rpc", "bear: --- Pass validation");
}
let precompiles = T::PrecompilesValue::get();
Self::execute(
Expand Down
2 changes: 0 additions & 2 deletions primitives/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ evm = { workspace = true, features = ["with-codec"] }
num_enum = { workspace = true, default-features = false }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
# Substrate
frame-support = { workspace = true }
Expand All @@ -27,7 +26,6 @@ sp-std = { workspace = true }
default = ["std"]
std = [
"evm/std",
"log/std",
"evm/with-serde",
"num_enum/std",
"serde/std",
Expand Down
1 change: 0 additions & 1 deletion primitives/evm/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ impl<'config, E: From<TransactionValidationError>> CheckEvmTransaction<'config,
if self.config.is_transactional || fee > U256::zero() {
let total_payment = self.transaction.value.saturating_add(fee);
if who.balance < total_payment {
log::info!(target: "rpc", "bear: --- balance too low, is_transactional: {:?}, fee: {:?}, balance: {:?}, total_payment: {:?}", self.config.is_transactional ,fee, who.balance, total_payment);
return Err(TransactionValidationError::BalanceTooLow.into());
}
}
Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
log = { workspace = true }

# Substrate
sp-api = { workspace = true }
Expand Down Expand Up @@ -69,7 +68,6 @@ with-paritydb-weights = []
std = [
"scale-codec/std",
"scale-info/std",
"log/std",
# Substrate
"sp-api/std",
"sp-block-builder/std",
Expand Down
5 changes: 0 additions & 5 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,6 @@ impl_runtime_apis! {
);
let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);

log::info!(target: "rpc", "bear: --- Ready to call the runner");
sp_std::if_std! {
println!("bear: --- Ready to call the runner");
}
<Runtime as pallet_evm::Config>::Runner::call(
from,
to,
Expand Down Expand Up @@ -757,7 +753,6 @@ impl_runtime_apis! {
);
let (weight_limit, proof_size_base_cost) = pallet_ethereum::Pallet::<Runtime>::transaction_weight(&transaction_data);

log::info!(target: "rpc", "bear: --- Ready to create the runner");
<Runtime as pallet_evm::Config>::Runner::create(
from,
data,
Expand Down
3 changes: 1 addition & 2 deletions ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"fmt": "prettier ./tests --write",
"build": "truffle compile",
"test": "mocha -r ts-node/register 'tests/**/*.ts'",
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'",
"test-s": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/test-contract.ts'"
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'"
},
"author": "",
"license": "ISC",
Expand Down
2 changes: 0 additions & 2 deletions ts-tests/tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describeWithFrontier("Frontier RPC (Contract)", (context) => {
});

it("eth_call contract create should return code", async function () {
console.log("bear: --- this is the second test case");
expect(
await context.web3.eth.call({
data: TEST_CONTRACT_BYTECODE,
Expand All @@ -66,7 +65,6 @@ describeWithFrontier("Frontier RPC (Contract)", (context) => {
});

it("eth_call at missing block returns error", async function () {
console.log("bear: --- this is the third test case");
const nonExistingBlockNumber = "999999";
return expect(
context.web3.eth.call(
Expand Down
1 change: 0 additions & 1 deletion ts-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export async function startFrontierNode(provider?: string): Promise<{
`--no-prometheus`,
`--sealing=Manual`,
`--no-grandpa`,
`--wasm-runtime-overrides=/home/bear/coding/rust-space/frontier/template/node/overridden-runtimes/`,
`--force-authoring`,
`-l${FRONTIER_LOG}`,
`--port=${PORT}`,
Expand Down

0 comments on commit 30c684c

Please sign in to comment.