Skip to content

Commit

Permalink
tweak logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Jan 9, 2025
1 parent 7224e3a commit 556bda2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
1 change: 0 additions & 1 deletion substrate/frame/revive/rpc/examples/js/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ if (geth) {
child.unref()
await new Promise((resolve) => setTimeout(resolve, 500))
}

const rpcUrl = proxy
? 'http://localhost:8080'
: westend
Expand Down
4 changes: 1 addition & 3 deletions substrate/frame/revive/rpc/examples/js/src/piggy-bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseEther } from 'viem'

const hash = await walletClient.deployContract({
abi: PiggyBankAbi,
bytecode: getByteCode('piggyBank'),
bytecode: getByteCode('PiggyBank'),
})
const deployReceipt = await walletClient.waitForTransactionReceipt({ hash })
const contractAddress = deployReceipt.contractAddress
Expand All @@ -31,9 +31,7 @@ assert(contractAddress, 'Contract address should be set')
value: parseEther('10'),
})

request.nonce = 0
const hash = await walletClient.writeContract(request)

const receipt = await walletClient.waitForTransactionReceipt({ hash })
console.log(`Deposit receipt: ${receipt.status}`)
}
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ impl Client {
number: header.number.into(),
timestamp: timestamp.into(),
difficulty: Some(0u32.into()),
base_fee_per_gas: Some(crate::GAS_PRICE.into()),
gas_limit,
gas_used,
receipts_root: extrinsics_root,
Expand Down
12 changes: 10 additions & 2 deletions substrate/frame/revive/src/evm/api/rpc_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ impl GenericTransaction {
value: Some(tx.value),
to: Some(tx.to),
gas: Some(tx.gas),
gas_price: Some(tx.max_fee_per_blob_gas),
gas_price: Some(
U256::from(crate::GAS_PRICE)
.saturating_add(tx.max_priority_fee_per_gas)
.max(tx.max_fee_per_blob_gas),
),
access_list: Some(tx.access_list),
blob_versioned_hashes: tx.blob_versioned_hashes,
max_fee_per_blob_gas: Some(tx.max_fee_per_blob_gas),
Expand All @@ -209,7 +213,11 @@ impl GenericTransaction {
value: Some(tx.value),
to: tx.to,
gas: Some(tx.gas),
gas_price: Some(tx.gas_price),
gas_price: Some(
U256::from(crate::GAS_PRICE)
.saturating_add(tx.max_priority_fee_per_gas)
.max(tx.max_fee_per_gas),
),
access_list: Some(tx.access_list),
max_fee_per_gas: Some(tx.max_fee_per_gas),
max_priority_fee_per_gas: Some(tx.max_priority_fee_per_gas),
Expand Down
16 changes: 8 additions & 8 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
/// This let us calculate the gas estimate for a transaction with the formula:
/// `estimate_gas = substrate_fee / gas_price`.
///
/// The chosen constant value is balanced to ensure:
/// - It is not too high, allowing components (ref_time, proof_size, and deposit) to be encoded in
/// the lower digits of the gas value.
/// - It is not too low, enabling users to adjust the gas price to define a tip.
pub const GAS_PRICE: u32 = 1_000u32;
/// The chosen constant value is:
/// - Not too high, ensuring the gas value is large enough (at least 7 digits) to encode the
/// ref_time, proof_size, and deposit into the less significant (6 lower) digits of the gas value.
/// - Not too low, enabling users to adjust the gas price to define a tip.
pub const GAS_PRICE: u32 = 100_000u32;

/// Convert a `Balance` into a gas value, using the fixed `GAS_PRICE`.
/// The gas is calculated as `balance / GAS_PRICE`, rounded up to the nearest integer.
Expand Down Expand Up @@ -401,7 +401,7 @@ pub trait EthExtra {
Default::default(),
)
.into();
log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}");
log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: gas_price: {gas_price:?}, encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}");

// The fees from the Ethereum transaction should be greater or equal to the actual fees paid
// by the account.
Expand All @@ -411,12 +411,12 @@ pub trait EthExtra {
}

if eth_fee_no_tip > actual_fee.saturating_mul(2u32.into()) {
log::debug!(target: LOG_TARGET, "actual fees {actual_fee:?} too high, base eth fees: {eth_fee_no_tip:?}");
log::debug!(target: LOG_TARGET, "actual fees: {actual_fee:?} too high, base eth fees: {eth_fee_no_tip:?}");
return Err(InvalidTransaction::Call.into())
}

let tip = eth_fee.saturating_sub(eth_fee_no_tip);
log::debug!(target: LOG_TARGET, "Created checked Ethereum transaction with nonce {nonce:?} and tip: {tip:?}");
log::debug!(target: LOG_TARGET, "Created checked Ethereum transaction with nonce: {nonce:?} and tip: {tip:?}");
Ok(CheckedExtrinsic {
format: ExtrinsicFormat::Signed(signer.into(), Self::get_eth_extension(nonce, tip)),
function,
Expand Down
8 changes: 3 additions & 5 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1420,19 +1420,17 @@ where
0u32.into(),
)
.into();
let eth_gas = gas_from_fee(fee);
let raw_eth_gas = gas_from_fee(fee);
let eth_gas =
T::EthGasEncoder::encode(eth_gas, result.gas_required, result.storage_deposit);
T::EthGasEncoder::encode(raw_eth_gas, result.gas_required, result.storage_deposit);

if eth_gas == result.eth_gas {
log::trace!(target: LOG_TARGET, "bare_eth_call: encoded_len: {encoded_len:?} eth_gas: {eth_gas:?}");
log::debug!(target: LOG_TARGET, "bare_eth_call: raw_eth_gas: {raw_eth_gas:?} eth_gas: {eth_gas:?}");
break;
}
result.eth_gas = eth_gas;
tx.gas = Some(eth_gas.into());
log::debug!(target: LOG_TARGET, "Adjusting Eth gas to: {eth_gas:?}");
}

Ok(result)
}

Expand Down

0 comments on commit 556bda2

Please sign in to comment.