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

Enable pallet-account on shibuya #913

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "r

# Astar pallets & modules
# (wasm)
pallet-account = { git = "https://github.com/AstarNetwork/astar-frame", branch = "feature/pallet-account", default-features = false }
pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false }
pallet-collator-selection = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false }
pallet-custom-signatures = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fp-self-contained = { workspace = true }
frame-executive = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-account = { workspace = true }
pallet-assets = { workspace = true }
pallet-aura = { workspace = true }
pallet-balances = { workspace = true }
Expand Down Expand Up @@ -103,6 +104,7 @@ std = [
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"pallet-account/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-balances/std",
Expand Down
28 changes: 27 additions & 1 deletion runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,28 @@ parameter_types! {
pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS);
}

/// Ensure that the origin is EVM compatible.
pub struct EnsureEvmOrigin;
impl<OuterOrigin> pallet_evm::EnsureAddressOrigin<OuterOrigin> for EnsureEvmOrigin
where
OuterOrigin: Into<Result<pallet_account::NativeAndEVM, OuterOrigin>>
+ From<pallet_account::NativeAndEVM>,
{
type Success = ();
fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<(), OuterOrigin> {
origin.into().and_then(|o| match o {
pallet_account::NativeAndEVM::H160(a) if *address == a => Ok(()),
r => Err(OuterOrigin::from(r)),
})
}
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = BaseFee;
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Runtime>;
type CallOrigin = pallet_evm::EnsureAddressRoot<AccountId>;
type CallOrigin = EnsureEvmOrigin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remain root - it's only related to who can call the actual pallet-evm extrinsics (which should be no one), it won't help with signature verification in pallet-ethereum.

The whole point of switching away from pallet-evm is to still emit relevant events for EVM indexers. It's all described in the BL ticket.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach makes possible substrate users call EVM without any changes in frontier, didn’t it good enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, details are in the backlog item.

type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
type AddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type Currency = Balances;
Expand Down Expand Up @@ -925,6 +941,15 @@ impl pallet_proxy::Config for Runtime {
type AnnouncementDepositFactor = ConstU128<{ MILLIAST * 660 }>;
}

impl pallet_account::Config for Runtime {
type CustomOrigin = pallet_account::NativeAndEVM;
type CustomOriginKind = pallet_account::NativeAndEVMKind;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = ();
}

// TODO: remove this once https://github.com/paritytech/substrate/issues/12161 is resolved
#[rustfmt::skip]
construct_runtime!(
Expand Down Expand Up @@ -958,6 +983,7 @@ construct_runtime!(
TechnicalCommittee: pallet_collective::<Instance2>,
Treasury: pallet_treasury,
Xvm: pallet_xvm,
Account: pallet_account,
Proxy: pallet_proxy,
Preimage: pallet_preimage,
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ frame-executive = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-rpc-runtime-api = { workspace = true }
pallet-account = { workspace = true }
pallet-assets = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
Expand Down Expand Up @@ -150,6 +151,7 @@ std = [
"frame-executive/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"pallet-account/std",
"pallet-authorship/std",
"pallet-aura/std",
"pallet-assets/std",
Expand Down
30 changes: 28 additions & 2 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shibuya"),
impl_name: create_runtime_str!("shibuya"),
authoring_version: 1,
spec_version: 96,
spec_version: 97,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -836,12 +836,28 @@ parameter_types! {
pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS);
}

/// Ensure that the origin is EVM compatible.
pub struct EnsureEvmOrigin;
impl<OuterOrigin> pallet_evm::EnsureAddressOrigin<OuterOrigin> for EnsureEvmOrigin
where
OuterOrigin: Into<Result<pallet_account::NativeAndEVM, OuterOrigin>>
+ From<pallet_account::NativeAndEVM>,
{
type Success = ();
fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<(), OuterOrigin> {
origin.into().and_then(|o| match o {
pallet_account::NativeAndEVM::H160(a) if *address == a => Ok(()),
r => Err(OuterOrigin::from(r)),
})
}
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = BaseFee;
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type WeightPerGas = WeightPerGas;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Runtime>;
type CallOrigin = pallet_evm::EnsureAddressRoot<AccountId>;
type CallOrigin = EnsureEvmOrigin;
type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
type AddressMapping = pallet_evm::HashedAddressMapping<BlakeTwo256>;
type Currency = Balances;
Expand Down Expand Up @@ -1176,6 +1192,15 @@ impl pallet_xc_asset_config::Config for Runtime {
type WeightInfo = pallet_xc_asset_config::weights::SubstrateWeight<Self>;
}

impl pallet_account::Config for Runtime {
type CustomOrigin = pallet_account::NativeAndEVM;
type CustomOriginKind = pallet_account::NativeAndEVMKind;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = ();
}

construct_runtime!(
pub struct Runtime where
Block = Block,
Expand Down Expand Up @@ -1228,6 +1253,7 @@ construct_runtime!(
Preimage: pallet_preimage = 84,

Xvm: pallet_xvm = 90,
Account: pallet_account= 91,

Sudo: pallet_sudo = 99,
}
Expand Down