Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the runtime-transact #1428

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ darwinia-asset-limit = { path = "pallet/asset-limit", default-featu
darwinia-common-runtime = { path = "runtime/common", default-features = false }
darwinia-deposit = { path = "pallet/deposit", default-features = false }
darwinia-ecdsa-authority = { path = "pallet/ecdsa-authority", default-features = false }
darwinia-ethtx-forwarder = { path = "pallet/ethtx-forwarder", default-features = false }
darwinia-message-gadget = { path = "pallet/message-gadget", default-features = false }
darwinia-precompile-assets = { path = "precompile/assets", default-features = false }
darwinia-precompile-bls12-381 = { path = "precompile/bls12-381", default-features = false }
darwinia-precompile-deposit = { path = "precompile/deposit", default-features = false }
darwinia-precompile-staking = { path = "precompile/staking", default-features = false }
darwinia-precompile-state-storage = { path = "precompile/state-storage", default-features = false }
darwinia-runtime = { path = "runtime/darwinia" }
darwinia-runtime-transact = { path = "pallet/runtime-transact", default-features = false }
darwinia-staking = { path = "pallet/staking", default-features = false }
darwinia-staking-traits = { path = "pallet/staking/traits", default-features = false }
dc-inflation = { path = "core/inflation", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors.workspace = true
description = "EVM transaction from the runtime."
edition.workspace = true
name = "darwinia-runtime-transact"
name = "darwinia-ethtx-forwarder"
readme = "README.md"
version.workspace = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ use sp_std::boxed::Box;
pub use pallet::*;

#[derive(Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub enum RuntimeEthOrigin {
RuntimeTransact(H160),
pub enum ForwardEthOrigin {
ForwardEth(H160),
}

pub fn ensure_runtime_transact<OuterOrigin>(o: OuterOrigin) -> Result<H160, &'static str>
pub fn ensure_forward_transact<OuterOrigin>(o: OuterOrigin) -> Result<H160, &'static str>
where
OuterOrigin: Into<Result<RuntimeEthOrigin, OuterOrigin>>,
OuterOrigin: Into<Result<ForwardEthOrigin, OuterOrigin>>,
{
match o.into() {
Ok(RuntimeEthOrigin::RuntimeTransact(n)) => Ok(n),
Ok(ForwardEthOrigin::ForwardEth(n)) => Ok(n),
_ => Err("bad origin: expected to be an runtime eth origin"),
}
}

pub struct EnsureRuntimeEthOrigin;
impl<O: Into<Result<RuntimeEthOrigin, O>> + From<RuntimeEthOrigin>> EnsureOrigin<O>
impl<O: Into<Result<ForwardEthOrigin, O>> + From<ForwardEthOrigin>> EnsureOrigin<O>
for EnsureRuntimeEthOrigin
{
type Success = H160;
Expand All @@ -70,13 +70,13 @@ impl<O: Into<Result<RuntimeEthOrigin, O>> + From<RuntimeEthOrigin>> EnsureOrigin

fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().map(|o| match o {
RuntimeEthOrigin::RuntimeTransact(id) => id,
ForwardEthOrigin::ForwardEth(id) => id,
})
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(RuntimeEthOrigin::RuntimeTransact(Default::default())))
Ok(O::from(ForwardEthOrigin::ForwardEth(Default::default())))
}
}

Expand All @@ -90,14 +90,14 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::origin]
pub type Origin = RuntimeEthOrigin;
pub type Origin = ForwardEthOrigin;

#[pallet::config]
pub trait Config: frame_system::Config + pallet_evm::Config {
/// Handler for applying an already validated transaction
type ValidatedTransaction: ValidatedTransaction;
/// Origin for the runtime transact
type RuntimeEthOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = H160>;
/// Origin for the forward eth transaction
type ForwardEthOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = H160>;
}

#[pallet::error]
Expand All @@ -109,7 +109,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T>
where
OriginFor<T>: Into<Result<RuntimeEthOrigin, OriginFor<T>>>,
OriginFor<T>: Into<Result<ForwardEthOrigin, OriginFor<T>>>,
{
//This call can only be used at runtime and is not available to EOA users.
#[pallet::call_index(0)]
Expand All @@ -119,11 +119,11 @@ pub mod pallet {
transaction_data.gas_limit.unique_saturated_into()
}, true)
})]
pub fn runtime_transact(
pub fn forward_transact(
origin: OriginFor<T>,
mut transaction: Box<Transaction>,
) -> DispatchResultWithPostInfo {
let source = ensure_runtime_transact(origin)?;
let source = ensure_forward_transact(origin)?;
let (who, _) = pallet_evm::Pallet::<T>::account_basic(&source);
let base_fee = T::FeeCalculator::min_gas_price().0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//! Test utilities

pub use crate as darwinia_runtime_transact;
pub use crate as darwinia_ethtx_forwarder;

// crates.io
use sha3::Digest;
Expand Down Expand Up @@ -131,7 +131,7 @@ impl pallet_ethereum::Config for Runtime {
}

impl crate::Config for Runtime {
type RuntimeEthOrigin = crate::EnsureRuntimeEthOrigin;
type ForwardEthOrigin = crate::EnsureRuntimeEthOrigin;
type ValidatedTransaction = pallet_ethereum::ValidatedTransaction<Self>;
}

Expand All @@ -142,7 +142,7 @@ frame_support::construct_runtime! {
Balances: pallet_balances,
EVM: pallet_evm,
Ethereum: pallet_ethereum,
RuntimeTransact: darwinia_runtime_transact,
EthTxForwarder: darwinia_ethtx_forwarder,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

// darwinia
use crate::{mock::*, tests::*, RuntimeEthOrigin};
use crate::{mock::*, tests::*, ForwardEthOrigin};
use ethereum::EIP1559Transaction;
// frontier
use fp_evm::FeeCalculator;
Expand Down Expand Up @@ -48,8 +48,8 @@ fn test_eip1559_transaction_works() {
.execute_with(|| {
let unsigned_tx = eip1559_erc20_creation_unsigned_transaction();
let t = unsigned_tx.sign(&alice.private_key, None);
assert_ok!(RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
assert_ok!(EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(t)
));
assert!(System::events()
Expand All @@ -70,8 +70,8 @@ fn test_eip1559_transaction_with_auto_nonce() {
unsigned_tx.nonce = U256::MAX;
let t = unsigned_tx.sign(&alice.private_key, None);

assert_ok!(RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
assert_ok!(EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(t)
));
assert!(System::events()
Expand All @@ -93,8 +93,8 @@ fn test_eip1559_transaction_with_auto_gas_price() {
<Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price().0 - 1;
let t = unsigned_tx.sign(&alice.private_key, None);

assert_ok!(RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
assert_ok!(EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(t)
));
assert!(System::events()
Expand All @@ -111,8 +111,8 @@ fn test_eip1559_transaction_with_sufficient_balance() {
let t = unsigned_tx.sign(&alice.private_key, None);

assert_err!(
RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(t.clone())
),
DispatchError::Module(ModuleError {
Expand All @@ -122,10 +122,10 @@ fn test_eip1559_transaction_with_sufficient_balance() {
})
);

let fee = RuntimeTransact::total_payment((&t).into());
let fee = EthTxForwarder::total_payment((&t).into());
let _ = Balances::deposit_creating(&alice.address, fee.as_u64());
assert_ok!(RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
assert_ok!(EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(t)
));
assert!(System::events()
Expand Down Expand Up @@ -165,8 +165,8 @@ fn test_eip1559_transaction_with_valid_signature() {
213, 144, 24, 205, 4, 67, 173, 192, 144, 53, 144, 193, 107, 2, 176,
]),
};
assert_ok!(RuntimeTransact::runtime_transact(
RuntimeEthOrigin::RuntimeTransact(alice.address).into(),
assert_ok!(EthTxForwarder::forward_transact(
ForwardEthOrigin::ForwardEth(alice.address).into(),
Box::new(Transaction::EIP1559(t))
));

Expand Down
Loading