-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #929 from galacticcouncil/fix/evm-base-weight-issue
fix: OutOfGas error for low weight evm transactions
- Loading branch information
Showing
11 changed files
with
671 additions
and
2,340 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use frame_support::weights::Weight; | ||
use pallet_evm::GasWeightMapping; | ||
use sp_core::Get; | ||
|
||
pub struct FixedHydraGasWeightMapping<T>(core::marker::PhantomData<T>); | ||
|
||
/// This implementation is a copy from the `pallet_evm::FixedHydraGasWeightMapping`, | ||
/// with the only modification of substracting the constant ExtrinsicBaseWeight | ||
impl<T: pallet_evm::Config> GasWeightMapping for FixedHydraGasWeightMapping<T> { | ||
fn gas_to_weight(gas: u64, without_base_weight: bool) -> Weight { | ||
//We use this base weight as we don't wanna include the swap weights of normal substrate transactions | ||
//Otherwise transactions with weight smaller than swap would fail with OutOfGas error, during the tx execution | ||
let base_weight = frame_support::weights::constants::ExtrinsicBaseWeight::get(); | ||
let mut weight = T::WeightPerGas::get().saturating_mul(gas); | ||
if without_base_weight { | ||
weight = weight.saturating_sub(base_weight); | ||
} | ||
// Apply a gas to proof size ratio based on BlockGasLimit | ||
let ratio = T::GasLimitPovSizeRatio::get(); | ||
if ratio > 0 { | ||
let proof_size = gas.saturating_div(ratio); | ||
*weight.proof_size_mut() = proof_size; | ||
} | ||
|
||
weight | ||
} | ||
fn weight_to_gas(weight: Weight) -> u64 { | ||
weight.div(T::WeightPerGas::get().ref_time()).ref_time() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {ethers} from 'ethers'; | ||
|
||
async function main() { | ||
// Define the Ethereum RPC URL | ||
const ethereumRpcUrl = "https://ws.nice.hydration.cloud"; // Replace with your Ethereum RPC URL | ||
//const ethereumRpcUrl = "https://rpc.hydradx.cloud"; // Replace with your Ethereum RPC URL | ||
|
||
//const ethereumRpcUrl = "http://127.0.0.1:9988"; // Replace with your Ethereum RPC URL | ||
|
||
// Create a provider using the Ethereum RPC URL | ||
const provider = new ethers.JsonRpcProvider(ethereumRpcUrl); | ||
|
||
try { | ||
// Example: Fetch the Ethereum block number | ||
const blockNumber = await provider.getBlockNumber(); | ||
console.log("Ethereum Block Number:", blockNumber); | ||
|
||
// Example: Fetch the balance of an Ethereum address | ||
const address = "0x222222ff7Be76052e023Ec1a306fCca8F9659D80"; // Replace with the Ethereum address you want to check | ||
const balance = await provider.getBalance(address); | ||
console.log("Ethereum Balance (Wei):", balance.toString()); | ||
|
||
|
||
const privateKey = '42d8d953e4f9246093a33e9ca6daa078501012f784adfe4bbed57918ff13be14'; | ||
const wallet = new ethers.Wallet(privateKey, provider); | ||
|
||
try { | ||
const dispatchContractAddress = '0x0000000000000000000000000000000000000401'; | ||
//const extrinsicData = '0x3b05000000000500000000a0724e18090000000000000000000000000000000000000000000000000000'; // Your extrinsic data | ||
// const extrinsicData = '0xcb0014000000'; // Your extrinsic data | ||
const extrinsicData = '0x4f003679d1d8e31d312a55f7ca994773b6a4fc7a92f07d898ae86bad4f3cab303c49000000000b00a0724e1809'; // Your extrinsic data | ||
|
||
const estimateGasParams = { | ||
from: wallet.address, // The address initiating the transaction | ||
to: dispatchContractAddress, | ||
data: extrinsicData, | ||
value: 0 // If you're not sending any Ether with the transaction | ||
}; | ||
|
||
const estimatedGas = await provider.estimateGas(estimateGasParams); | ||
|
||
console.log("Estimated Gas:", estimatedGas.toString()); | ||
|
||
} catch (error) { | ||
console.error("Error estimating gas:", error); | ||
} | ||
|
||
|
||
|
||
} catch (error) { | ||
console.error("Error:", error); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.