Skip to content

Commit

Permalink
Merge branch 'devnet-ready' into feat/subnet-precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
open-junius committed Dec 20, 2024
2 parents e565825 + 85fa7dd commit 2141e00
Show file tree
Hide file tree
Showing 21 changed files with 474 additions and 439 deletions.
235 changes: 74 additions & 161 deletions Cargo.lock

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
Expand Down Expand Up @@ -166,32 +166,32 @@ sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }

# Frontier
fp-evm = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fp-rpc = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fp-self-contained = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false, features = [
fp-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fp-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fp-self-contained = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false, features = [
"serde",
] }
fp-account = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-storage = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-db = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-consensus = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fp-consensus = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-api = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-rpc = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-rpc-core = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fc-mapping-sync = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
fp-account = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-storage = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-db = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fp-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-api = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-rpc-core = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
fc-mapping-sync = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }

# Frontier FRAME
pallet-base-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-ethereum = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-evm = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
pallet-base-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-ethereum = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }

#DRAND
pallet-drand = { path = "pallets/drand", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion chainspecs/plain_spec_finney.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion chainspecs/raw_spec_finney.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ clap = { workspace = true, features = ["derive"] }
futures = { workspace = true, features = ["thread-pool"] }
scale-codec = { workspace = true }
serde = { workspace = true, features = ["derive"] }
hex = { workspace = true }

# Storage import
memmap2 = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/code_substitute_2585476.txt

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions node/src/chain_spec/finney.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(clippy::unwrap_used)]

use super::*;
use hex::FromHex;

pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
Expand Down Expand Up @@ -69,7 +70,7 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 42.into());

Ok(ChainSpec::builder(
let chain_spec = ChainSpec::builder(
wasm_binary,
Extensions {
bad_blocks: Some(HashSet::new()),
Expand Down Expand Up @@ -181,7 +182,25 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
balances_issuance,
))
.with_properties(properties)
.build())
.build();

// Load and set the code substitute to avoid archive node sync panic
// See <https://github.com/opentensor/subtensor/pull/1051>
//
// Need to do it in this hacky way because the ChainSpec builder doesn't support setting it
let code_substitute_2585476_hex = include_bytes!("code_substitute_2585476.txt");
let chain_spec_json = chain_spec.as_json(false).unwrap();
let mut chain_spec_json = serde_json::from_str(&chain_spec_json).unwrap();
sc_chain_spec::set_code_substitute_in_json_chain_spec(
&mut chain_spec_json,
Vec::from_hex(code_substitute_2585476_hex)
.unwrap()
.as_slice(),
2585476,
);
let chain_spec_bytes = chain_spec_json.to_string().into_bytes();
let chain_spec = ChainSpec::from_json_bytes(chain_spec_bytes).unwrap();
Ok(chain_spec)
}

// Configure initial storage state for FRAME modules.
Expand Down
34 changes: 20 additions & 14 deletions pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
subtensor-macros.workspace = true
subtensor-macros = { workspace = true }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
Expand All @@ -31,6 +31,7 @@ sp-weights = { workspace = true }
substrate-fixed = { workspace = true }
pallet-evm-chain-id = { workspace = true }
pallet-drand = { workspace = true, default-features = false }
sp-consensus-grandpa = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true }
Expand All @@ -39,6 +40,7 @@ sp-tracing = { workspace = true }
sp-consensus-aura = { workspace = true }
pallet-balances = { workspace = true, features = ["std"] }
pallet-scheduler = { workspace = true }
pallet-grandpa = { workspace = true }
sp-std = { workspace = true }

[features]
Expand All @@ -48,39 +50,43 @@ std = [
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"pallet-subtensor/std",
"sp-consensus-aura/std",
"log/std",
"pallet-balances/std",
"pallet-drand/std",
"pallet-evm-chain-id/std",
"pallet-grandpa/std",
"pallet-scheduler/std",
"sp-runtime/std",
"sp-tracing/std",
"sp-weights/std",
"log/std",
"pallet-subtensor/std",
"scale-info/std",
"sp-consensus-aura/std",
"sp-consensus-grandpa/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"sp-tracing/std",
"sp-weights/std",
"substrate-fixed/std",
"pallet-drand/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-subtensor/runtime-benchmarks",
"pallet-drand/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-drand/runtime-benchmarks"
"pallet-subtensor/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-drand/try-runtime",
"pallet-evm-chain-id/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-scheduler/try-runtime",
"sp-runtime/try-runtime",
"pallet-subtensor/try-runtime",
"pallet-drand/try-runtime"
"sp-runtime/try-runtime",
]
17 changes: 16 additions & 1 deletion pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Benchmarking setup
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::arithmetic_side_effects)]
use super::*;

extern crate alloc;
use alloc::vec::Vec;

#[allow(unused)]
use crate::Pallet as AdminUtils;
Expand All @@ -10,6 +12,8 @@ use frame_benchmarking::v2::*;
use frame_support::BoundedVec;
use frame_system::RawOrigin;

use super::*;

#[benchmarks]
mod benchmarks {
use super::*;
Expand All @@ -33,6 +37,17 @@ mod benchmarks {
_(RawOrigin::Root, value);
}

#[benchmark]
fn schedule_grandpa_change(a: Linear<0, 32>) {
let next_authorities = (1..=a)
.map(|idx| account("Authority", idx, 0u32))
.collect::<Vec<(sp_consensus_grandpa::AuthorityId, u64)>>();
let in_blocks = BlockNumberFor::<T>::from(42u32);

#[extrinsic_call]
_(RawOrigin::Root, next_authorities, in_blocks, None);
}

#[benchmark]
fn sudo_set_default_take() {
#[extrinsic_call]
Expand Down
64 changes: 63 additions & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#![cfg_attr(not(feature = "std"), no_std)]

// extern crate alloc;

pub use pallet::*;
pub mod weights;
pub use weights::WeightInfo;

use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::{traits::Member, RuntimeAppPublic};
// - we could replace it with Vec<(AuthorityId, u64)>, but we would need
// `sp_consensus_grandpa` for `AuthorityId` anyway
// - we could use a type parameter for `AuthorityId`, but there is
// no sense for this as GRANDPA's `AuthorityId` is not a parameter -- it's always the same
use sp_consensus_grandpa::AuthorityList;
use sp_runtime::{traits::Member, DispatchResult, RuntimeAppPublic};

mod benchmarking;

Expand Down Expand Up @@ -41,6 +48,9 @@ pub mod pallet {
/// Implementation of the AuraInterface
type Aura: crate::AuraInterface<<Self as Config>::AuthorityId, Self::MaxAuthorities>;

/// Implementation of [`GrandpaInterface`]
type Grandpa: crate::GrandpaInterface<Self>;

/// The identifier type for an authority.
type AuthorityId: Member
+ Parameter
Expand Down Expand Up @@ -1238,6 +1248,34 @@ pub mod pallet {
ChainId::<T>::set(chain_id);
Ok(())
}

/// A public interface for `pallet_grandpa::Pallet::schedule_grandpa_change`.
///
/// Schedule a change in the authorities.
///
/// The change will be applied at the end of execution of the block `in_blocks` after the
/// current block. This value may be 0, in which case the change is applied at the end of
/// the current block.
///
/// If the `forced` parameter is defined, this indicates that the current set has been
/// synchronously determined to be offline and that after `in_blocks` the given change
/// should be applied. The given block number indicates the median last finalized block
/// number and it should be used as the canon block when starting the new grandpa voter.
///
/// No change should be signaled while any change is pending. Returns an error if a change
/// is already pending.
#[pallet::call_index(59)]
#[pallet::weight(<T as Config>::WeightInfo::swap_authorities(next_authorities.len() as u32))]
pub fn schedule_grandpa_change(
origin: OriginFor<T>,
// grandpa ID is always the same type, so we don't need to parametrize it via `Config`
next_authorities: AuthorityList,
in_blocks: BlockNumberFor<T>,
forced: Option<BlockNumberFor<T>>,
) -> DispatchResult {
ensure_root(origin)?;
T::Grandpa::schedule_change(next_authorities, in_blocks, forced)
}
}
}

Expand All @@ -1255,3 +1293,27 @@ pub trait AuraInterface<AuthorityId, MaxAuthorities> {
impl<A, M> AuraInterface<A, M> for () {
fn change_authorities(_: BoundedVec<A, M>) {}
}

pub trait GrandpaInterface<Runtime>
where
Runtime: frame_system::Config,
{
fn schedule_change(
next_authorities: AuthorityList,
in_blocks: BlockNumberFor<Runtime>,
forced: Option<BlockNumberFor<Runtime>>,
) -> DispatchResult;
}

impl<R> GrandpaInterface<R> for ()
where
R: frame_system::Config,
{
fn schedule_change(
_next_authorities: AuthorityList,
_in_blocks: BlockNumberFor<R>,
_forced: Option<BlockNumberFor<R>>,
) -> DispatchResult {
Ok(())
}
}
29 changes: 28 additions & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use frame_support::{
use frame_system as system;
use frame_system::{limits, EnsureNever, EnsureRoot};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityList as GrandpaAuthorityList;
use sp_core::U256;
use sp_core::{ConstU64, H256};
use sp_runtime::{
Expand All @@ -29,7 +30,8 @@ frame_support::construct_runtime!(
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>} = 4,
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 5,
Drand: pallet_drand::{Pallet, Call, Storage, Event<T>} = 6,
EVMChainId: pallet_evm_chain_id = 7,
Grandpa: pallet_grandpa = 7,
EVMChainId: pallet_evm_chain_id = 8,
}
);

Expand Down Expand Up @@ -225,6 +227,19 @@ impl system::Config for Test {
type Nonce = u64;
}

impl pallet_grandpa::Config for Test {
type RuntimeEvent = RuntimeEvent;

type KeyOwnerProof = sp_core::Void;

type WeightInfo = ();
type MaxAuthorities = ConstU32<32>;
type MaxSetIdSessionEntries = ConstU64<0>;
type MaxNominators = ConstU32<20>;

type EquivocationReportSystem = ();
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Test {
type MaxLocks = ();
Expand All @@ -249,11 +264,23 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
}
}

pub struct GrandpaInterfaceImpl;
impl crate::GrandpaInterface<Test> for GrandpaInterfaceImpl {
fn schedule_change(
next_authorities: GrandpaAuthorityList,
in_blocks: BlockNumber,
forced: Option<BlockNumber>,
) -> sp_runtime::DispatchResult {
Grandpa::schedule_change(next_authorities, in_blocks, forced)
}
}

impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AuthorityId = AuraId;
type MaxAuthorities = ConstU32<32>;
type Aura = ();
type Grandpa = GrandpaInterfaceImpl;
type Balance = Balance;
type WeightInfo = ();
}
Expand Down
Loading

0 comments on commit 2141e00

Please sign in to comment.