Skip to content

Commit

Permalink
pallet-revive: Add stateful address mapping (#6096)
Browse files Browse the repository at this point in the history
Fixes #5576

This allows contracts to be used with an AccountId32 through normal
extrinsics and not only through the eth compat layer. It works by adding
a new extrinsic `map_account` that lets people register their
AccountId32.

---------

Co-authored-by: command-bot <>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Cyrill Leutwiler <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 5a14285 commit 0796326
Show file tree
Hide file tree
Showing 15 changed files with 1,235 additions and 674 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ impl pallet_revive::Config for Runtime {
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type AddressMapper = pallet_revive::DefaultAddressMapper;
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<false>;
Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_6096.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: 'pallet-revive: Add stateful address mapping'
doc:
- audience:
- Runtime Dev
description: |-
Fixes #5576

This allows contracts to be used with an AccountId32 through normal extrinsics and not only through the eth compat layer. It works by adding a new extrinsic `map_account` that lets people register their AccountId32.
crates:
- name: pallet-revive-fixtures
bump: minor
- name: pallet-revive-mock-network
bump: patch
- name: pallet-revive
bump: major
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ impl pallet_revive::Config for Runtime {
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type AddressMapper = pallet_revive::DefaultAddressMapper;
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type UnsafeUnstableInterface = ConstBool<false>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use common::input;
use uapi::{HostFn, HostFnImpl as api};

const ETH_ALICE: [u8; 20] = [1u8; 20];
const ALICE_FALLBACK: [u8; 20] = [1u8; 20];

/// Load input data and perform the action specified by the input.
/// If `delegate_call` is true, then delegate call into the contract.
Expand All @@ -44,7 +44,7 @@ fn load_input(delegate_call: bool) {
},
// 3 = Terminate
3 => {
api::terminate(&ETH_ALICE);
api::terminate(&ALICE_FALLBACK);
},
// Everything else is a noop
_ => {},
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/fixtures/contracts/self_destruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use common::input;
use uapi::{HostFn, HostFnImpl as api};

const ETH_DJANGO: [u8; 20] = [4u8; 20];
const DJANGO_FALLBACK: [u8; 20] = [4u8; 20];

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand Down Expand Up @@ -52,6 +52,6 @@ pub extern "C" fn call() {
.unwrap();
} else {
// Try to terminate and give balance to django.
api::terminate(&ETH_DJANGO);
api::terminate(&DJANGO_FALLBACK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![no_std]
#![no_main]

extern crate common;
use uapi::{HostFn, HostFnImpl as api};

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
let eve = [5u8; 20];
api::terminate(&eve);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use frame_support::derive_impl;

#[derive_impl(pallet_revive::config_preludes::TestDefaultConfig)]
impl pallet_revive::Config for Runtime {
type AddressMapper = pallet_revive::DefaultAddressMapper;
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
type Currency = Balances;
type Time = super::Timestamp;
type Xcm = pallet_xcm::Pallet<Self>;
Expand Down
Loading

0 comments on commit 0796326

Please sign in to comment.