Skip to content

Commit

Permalink
Setup runtimes for release v1.2.0 (#745)
Browse files Browse the repository at this point in the history
* update types to 0.5.9

* cleanup runtime and add precompiles and services pallets

* Rename webb to tangle precompiles

---------

Co-authored-by: drewstone <[email protected]>
  • Loading branch information
1xstj and drewstone authored Aug 26, 2024
1 parent 5b06765 commit 3ebd49b
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 44 deletions.
11 changes: 11 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 node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ fn mainnet_genesis(
.collect();
RuntimeGenesisConfig {
system: SystemConfig { ..Default::default() },
assets: Default::default(),
sudo: SudoConfig { key: Some(root_key) },
balances: BalancesConfig { balances: endowed_accounts.to_vec() },
vesting: VestingConfig {
Expand Down
6 changes: 3 additions & 3 deletions pallets/services/src/mock_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ pub type DefaultPrecompiles = (
PrecompileAt<AddressU64<1026>, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>,
);

pub type WebbPrecompiles<R> = PrecompileSetBuilder<
pub type TanglePrecompiles<R> = PrecompileSetBuilder<
R,
(PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<2095>), DefaultPrecompiles>,),
>;

parameter_types! {
pub const MinimumPeriod: u64 = 6000 / 2;

pub PrecompilesValue: WebbPrecompiles<Runtime> = WebbPrecompiles::<_>::new();
pub PrecompilesValue: TanglePrecompiles<Runtime> = TanglePrecompiles::<_>::new();
}

impl pallet_timestamp::Config for Runtime {
Expand Down Expand Up @@ -201,7 +201,7 @@ impl pallet_evm::Config for Runtime {
type AddressMapping = HashedAddressMapping<BlakeTwo256>;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = WebbPrecompiles<Runtime>;
type PrecompilesType = TanglePrecompiles<Runtime>;
type PrecompilesValue = PrecompilesValue;
type ChainId = ChainId;
type BlockGasLimit = BlockGasLimit;
Expand Down
4 changes: 2 additions & 2 deletions precompiles/multi-asset-delegation/MultiAssetDelegation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity >=0.8.3;

/// @dev The MultiAssetDelegation contract's address.
address constant MULTI_ASSET_DELEGATION = 0x0000000000000000000000000000000000000809;
address constant MULTI_ASSET_DELEGATION = 0x0000000000000000000000000000000000000822;

/// @dev The MultiAssetDelegation contract's instance.
MultiAssetDelegation constant MULTI_ASSET_DELEGATION_CONTRACT = MultiAssetDelegation(MULTI_ASSET_DELEGATION);

/// @author The Tangle Team
/// @title Pallet MultiAssetDelegation Interface
/// @title The interface through which solidity contracts will interact with the MultiAssetDelegation pallet
/// @custom:address 0x0000000000000000000000000000000000000809
/// @custom:address 0x0000000000000000000000000000000000000822
interface MultiAssetDelegation {
/// @dev Join as an operator with a bond amount.
/// @param bondAmount The amount to bond as an operator.
Expand Down
7 changes: 7 additions & 0 deletions precompiles/utils/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,10 @@ fn evm_data_solidity_types() {
// Struct encode like tuples
assert_eq!(MultiLocation::signature(), "(uint8,bytes[])");
}

// #[test]
// fn calculate_precompile_address() {
// use crate::precompile_set::AddressU64;
// let address = H160::from_low_u64_be(2082);
// println!("Address {:?}", address);
// }
35 changes: 26 additions & 9 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ scale-info = { workspace = true }
serde = { workspace = true }
static_assertions = { workspace = true }

# Webb Substrate Dependencies
pallet-airdrop-claims = { workspace = true }

# Substrate dependencies
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
Expand Down Expand Up @@ -70,7 +67,7 @@ pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-staking-reward-curve = { workspace = true }
pallet-treasury = { workspace = true }

pallet-assets = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-identity = { workspace = true }
Expand All @@ -86,12 +83,17 @@ pallet-multisig = { workspace = true }
pallet-vesting = { workspace = true }

# Tangle dependencies
tangle-primitives = { workspace = true }
pallet-airdrop-claims = { workspace = true }
pallet-services = { workspace = true }
pallet-services-rpc-runtime-api = { workspace = true }
tangle-primitives = { workspace = true, features = ["verifying"] }
tangle-crypto-primitives = { workspace = true }
pallet-multi-asset-delegation = { workspace = true }

# Frontier dependencies
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
fp-evm = { workspace = true }

# Frontier FRAME dependencies
pallet-base-fee = { workspace = true }
Expand All @@ -108,10 +110,10 @@ pallet-evm-precompile-ed25519 = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }

pallet-evm-precompileset-assets-erc20 = { workspace = true }
pallet-hotfix-sufficients = { workspace = true }

## Moonbeam precompiles
## Tangle precompiles
pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-call-permit = { workspace = true }
pallet-evm-precompile-democracy = { workspace = true }
Expand All @@ -120,6 +122,11 @@ pallet-evm-precompile-proxy = { workspace = true }
pallet-evm-precompile-registry = { workspace = true }
pallet-evm-precompile-staking = { workspace = true }
pallet-evm-precompile-vesting = { workspace = true }
pallet-evm-precompile-verify-ecdsa-secp256k1-signature = { workspace = true }
pallet-evm-precompile-verify-ecdsa-secp256r1-signature = { workspace = true }
pallet-evm-precompile-verify-ecdsa-stark-signature = { workspace = true }
pallet-evm-precompile-verify-schnorr-signatures = { workspace = true }
pallet-evm-precompile-verify-bls381-signature = { workspace = true }
pallet-evm-precompile-multi-asset-delegation = { workspace = true }
precompile-utils = { workspace = true }

Expand Down Expand Up @@ -207,15 +214,19 @@ std = [
"pallet-identity/std",
"frame-system-benchmarking?/std",
"sp-storage/std",
"pallet-assets/std",

# Tangle dependencies
# Tangle dependencies
"tangle-primitives/std",
"tangle-crypto-primitives/std",

"pallet-services/std",
"pallet-multi-asset-delegation/std",
"pallet-services-rpc-runtime-api/std",

# Frontier
"fp-rpc/std",
"fp-self-contained/std",
"fp-evm/std",

# Frontier FRAME
"pallet-base-fee/std",
Expand All @@ -237,6 +248,7 @@ std = [
"evm-tracer/std",
"rpc-primitives-debug/std",
"rpc-primitives-txpool/std",
"pallet-evm-precompileset-assets-erc20/std",

# Tangle precompiles
"pallet-evm-precompile-preimage/std",
Expand All @@ -248,6 +260,11 @@ std = [
"pallet-evm-precompile-staking/std",
"pallet-evm-precompile-vesting/std",
"pallet-evm-precompile-multi-asset-delegation/std",
"pallet-evm-precompile-verify-ecdsa-secp256k1-signature/std",
"pallet-evm-precompile-verify-ecdsa-secp256r1-signature/std",
"pallet-evm-precompile-verify-ecdsa-stark-signature/std",
"pallet-evm-precompile-verify-schnorr-signatures/std",
"pallet-evm-precompile-verify-bls381-signature/std",
]
integration-tests = ["tangle-primitives/integration-tests"]
with-rocksdb-weights = []
Expand Down
28 changes: 25 additions & 3 deletions runtime/mainnet/src/frontier_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,41 @@
// limitations under the License.

use crate::{
precompiles::{PrecompileName, WebbPrecompiles},
precompiles::{PrecompileName, TanglePrecompiles},
*,
};
use frame_support::{pallet_prelude::*, parameter_types, traits::FindAuthor, weights::Weight};
use sp_core::{crypto::ByteArray, H160, U256};
use sp_runtime::{traits::BlakeTwo256, ConsensusEngineId, Permill};
use sp_std::{marker::PhantomData, prelude::*};
// Frontier
use crate::precompiles::ASSET_PRECOMPILE_ADDRESS_PREFIX;
use pallet_ethereum::PostLogContent;
use pallet_evm::HashedAddressMapping;
use pallet_evm_precompileset_assets_erc20::AddressToAssetId;
use tangle_primitives::evm::WEIGHT_PER_GAS;
impl pallet_evm_chain_id::Config for Runtime {}

impl AddressToAssetId<AssetId> for Runtime {
fn address_to_asset_id(address: H160) -> Option<AssetId> {
let mut data = [0u8; 16];
let address_bytes: [u8; 20] = address.into();
if ASSET_PRECOMPILE_ADDRESS_PREFIX.eq(&address_bytes[0..4]) {
data.copy_from_slice(&address_bytes[4..20]);
Some(u128::from_be_bytes(data))
} else {
None
}
}

fn asset_id_to_address(asset_id: AssetId) -> H160 {
let mut data = [0u8; 20];
data[0..4].copy_from_slice(ASSET_PRECOMPILE_ADDRESS_PREFIX);
data[4..20].copy_from_slice(&asset_id.to_be_bytes());
H160::from(data)
}
}

pub struct FindAuthorTruncated<F>(PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
Expand Down Expand Up @@ -129,7 +151,7 @@ parameter_types! {
/// )
pub const GasLimitPovSizeRatio: u64 = 4;
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
pub PrecompilesValue: WebbPrecompiles<Runtime> = WebbPrecompiles::<_>::new();
pub PrecompilesValue: TanglePrecompiles<Runtime> = TanglePrecompiles::<_>::new();
pub SuicideQuickClearLimit: u32 = 0;
}

Expand All @@ -143,7 +165,7 @@ impl pallet_evm::Config for Runtime {
type AddressMapping = HashedAddressMapping<BlakeTwo256>;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = WebbPrecompiles<Self>;
type PrecompilesType = TanglePrecompiles<Self>;
type PrecompilesValue = PrecompilesValue;
type ChainId = EVMChainId;
type BlockGasLimit = BlockGasLimit;
Expand Down
Loading

0 comments on commit 3ebd49b

Please sign in to comment.