Skip to content

Commit 2141e00

Browse files
committed
Merge branch 'devnet-ready' into feat/subnet-precompile
2 parents e565825 + 85fa7dd commit 2141e00

File tree

21 files changed

+474
-439
lines changed

21 files changed

+474
-439
lines changed

Cargo.lock

+74-161
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+23-23
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
138138
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
139139
sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
140140
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
141-
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409" }
141+
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
142142
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
143143
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
144144
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
@@ -166,32 +166,32 @@ sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", tag
166166
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
167167

168168
# Frontier
169-
fp-evm = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
170-
fp-rpc = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
171-
fp-self-contained = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false, features = [
169+
fp-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
170+
fp-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
171+
fp-self-contained = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false, features = [
172172
"serde",
173173
] }
174-
fp-account = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
175-
fc-storage = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
176-
fc-db = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
177-
fc-consensus = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
178-
fp-consensus = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
179-
fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
180-
fc-api = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
181-
fc-rpc = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
182-
fc-rpc-core = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
183-
fc-mapping-sync = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
174+
fp-account = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
175+
fc-storage = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
176+
fc-db = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
177+
fc-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
178+
fp-consensus = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
179+
fp-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
180+
fc-api = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
181+
fc-rpc = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
182+
fc-rpc-core = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
183+
fc-mapping-sync = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
184184

185185
# Frontier FRAME
186-
pallet-base-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
187-
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
188-
pallet-ethereum = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
189-
pallet-evm = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
190-
pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
191-
pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
192-
pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
193-
pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
194-
pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", rev = "b8e3025", default-features = false }
186+
pallet-base-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
187+
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
188+
pallet-ethereum = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
189+
pallet-evm = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
190+
pallet-evm-chain-id = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
191+
pallet-evm-precompile-modexp = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
192+
pallet-evm-precompile-sha3fips = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
193+
pallet-evm-precompile-simple = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
194+
pallet-hotfix-sufficients = { git = "https://github.com/gztensor/frontier", rev = "b9c606f9", default-features = false }
195195

196196
#DRAND
197197
pallet-drand = { path = "pallets/drand", default-features = false }

chainspecs/plain_spec_finney.json

+3-1
Large diffs are not rendered by default.

chainspecs/raw_spec_finney.json

+3-1
Large diffs are not rendered by default.

node/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ clap = { workspace = true, features = ["derive"] }
2525
futures = { workspace = true, features = ["thread-pool"] }
2626
scale-codec = { workspace = true }
2727
serde = { workspace = true, features = ["derive"] }
28+
hex = { workspace = true }
2829

2930
# Storage import
3031
memmap2 = { workspace = true }

node/src/chain_spec/code_substitute_2585476.txt

+1
Large diffs are not rendered by default.

node/src/chain_spec/finney.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(clippy::unwrap_used)]
33

44
use super::*;
5+
use hex::FromHex;
56

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

72-
Ok(ChainSpec::builder(
73+
let chain_spec = ChainSpec::builder(
7374
wasm_binary,
7475
Extensions {
7576
bad_blocks: Some(HashSet::new()),
@@ -181,7 +182,25 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
181182
balances_issuance,
182183
))
183184
.with_properties(properties)
184-
.build())
185+
.build();
186+
187+
// Load and set the code substitute to avoid archive node sync panic
188+
// See <https://github.com/opentensor/subtensor/pull/1051>
189+
//
190+
// Need to do it in this hacky way because the ChainSpec builder doesn't support setting it
191+
let code_substitute_2585476_hex = include_bytes!("code_substitute_2585476.txt");
192+
let chain_spec_json = chain_spec.as_json(false).unwrap();
193+
let mut chain_spec_json = serde_json::from_str(&chain_spec_json).unwrap();
194+
sc_chain_spec::set_code_substitute_in_json_chain_spec(
195+
&mut chain_spec_json,
196+
Vec::from_hex(code_substitute_2585476_hex)
197+
.unwrap()
198+
.as_slice(),
199+
2585476,
200+
);
201+
let chain_spec_bytes = chain_spec_json.to_string().into_bytes();
202+
let chain_spec = ChainSpec::from_json_bytes(chain_spec_bytes).unwrap();
203+
Ok(chain_spec)
185204
}
186205

187206
// Configure initial storage state for FRAME modules.

pallets/admin-utils/Cargo.toml

+20-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19-
subtensor-macros.workspace = true
19+
subtensor-macros = { workspace = true }
2020
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
2121
"derive",
2222
] }
@@ -31,6 +31,7 @@ sp-weights = { workspace = true }
3131
substrate-fixed = { workspace = true }
3232
pallet-evm-chain-id = { workspace = true }
3333
pallet-drand = { workspace = true, default-features = false }
34+
sp-consensus-grandpa = { workspace = true }
3435

3536
[dev-dependencies]
3637
sp-core = { workspace = true }
@@ -39,6 +40,7 @@ sp-tracing = { workspace = true }
3940
sp-consensus-aura = { workspace = true }
4041
pallet-balances = { workspace = true, features = ["std"] }
4142
pallet-scheduler = { workspace = true }
43+
pallet-grandpa = { workspace = true }
4244
sp-std = { workspace = true }
4345

4446
[features]
@@ -48,39 +50,43 @@ std = [
4850
"frame-benchmarking?/std",
4951
"frame-support/std",
5052
"frame-system/std",
51-
"scale-info/std",
52-
"pallet-subtensor/std",
53-
"sp-consensus-aura/std",
53+
"log/std",
5454
"pallet-balances/std",
55+
"pallet-drand/std",
5556
"pallet-evm-chain-id/std",
57+
"pallet-grandpa/std",
5658
"pallet-scheduler/std",
57-
"sp-runtime/std",
58-
"sp-tracing/std",
59-
"sp-weights/std",
60-
"log/std",
59+
"pallet-subtensor/std",
60+
"scale-info/std",
61+
"sp-consensus-aura/std",
62+
"sp-consensus-grandpa/std",
6163
"sp-core/std",
6264
"sp-io/std",
65+
"sp-runtime/std",
6366
"sp-std/std",
67+
"sp-tracing/std",
68+
"sp-weights/std",
6469
"substrate-fixed/std",
65-
"pallet-drand/std"
6670
]
6771
runtime-benchmarks = [
6872
"frame-benchmarking/runtime-benchmarks",
6973
"frame-support/runtime-benchmarks",
7074
"frame-system/runtime-benchmarks",
7175
"pallet-balances/runtime-benchmarks",
72-
"sp-runtime/runtime-benchmarks",
73-
"pallet-subtensor/runtime-benchmarks",
76+
"pallet-drand/runtime-benchmarks",
77+
"pallet-grandpa/runtime-benchmarks",
7478
"pallet-scheduler/runtime-benchmarks",
75-
"pallet-drand/runtime-benchmarks"
79+
"pallet-subtensor/runtime-benchmarks",
80+
"sp-runtime/runtime-benchmarks",
7681
]
7782
try-runtime = [
7883
"frame-support/try-runtime",
7984
"frame-system/try-runtime",
8085
"pallet-balances/try-runtime",
86+
"pallet-drand/try-runtime",
8187
"pallet-evm-chain-id/try-runtime",
88+
"pallet-grandpa/try-runtime",
8289
"pallet-scheduler/try-runtime",
83-
"sp-runtime/try-runtime",
8490
"pallet-subtensor/try-runtime",
85-
"pallet-drand/try-runtime"
91+
"sp-runtime/try-runtime",
8692
]

pallets/admin-utils/src/benchmarking.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Benchmarking setup
22
#![cfg(feature = "runtime-benchmarks")]
33
#![allow(clippy::arithmetic_side_effects)]
4-
use super::*;
4+
5+
extern crate alloc;
6+
use alloc::vec::Vec;
57

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

15+
use super::*;
16+
1317
#[benchmarks]
1418
mod benchmarks {
1519
use super::*;
@@ -33,6 +37,17 @@ mod benchmarks {
3337
_(RawOrigin::Root, value);
3438
}
3539

40+
#[benchmark]
41+
fn schedule_grandpa_change(a: Linear<0, 32>) {
42+
let next_authorities = (1..=a)
43+
.map(|idx| account("Authority", idx, 0u32))
44+
.collect::<Vec<(sp_consensus_grandpa::AuthorityId, u64)>>();
45+
let in_blocks = BlockNumberFor::<T>::from(42u32);
46+
47+
#[extrinsic_call]
48+
_(RawOrigin::Root, next_authorities, in_blocks, None);
49+
}
50+
3651
#[benchmark]
3752
fn sudo_set_default_take() {
3853
#[extrinsic_call]

pallets/admin-utils/src/lib.rs

+63-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

3+
// extern crate alloc;
4+
35
pub use pallet::*;
46
pub mod weights;
57
pub use weights::WeightInfo;
68

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

1017
mod benchmarking;
1118

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

51+
/// Implementation of [`GrandpaInterface`]
52+
type Grandpa: crate::GrandpaInterface<Self>;
53+
4454
/// The identifier type for an authority.
4555
type AuthorityId: Member
4656
+ Parameter
@@ -1238,6 +1248,34 @@ pub mod pallet {
12381248
ChainId::<T>::set(chain_id);
12391249
Ok(())
12401250
}
1251+
1252+
/// A public interface for `pallet_grandpa::Pallet::schedule_grandpa_change`.
1253+
///
1254+
/// Schedule a change in the authorities.
1255+
///
1256+
/// The change will be applied at the end of execution of the block `in_blocks` after the
1257+
/// current block. This value may be 0, in which case the change is applied at the end of
1258+
/// the current block.
1259+
///
1260+
/// If the `forced` parameter is defined, this indicates that the current set has been
1261+
/// synchronously determined to be offline and that after `in_blocks` the given change
1262+
/// should be applied. The given block number indicates the median last finalized block
1263+
/// number and it should be used as the canon block when starting the new grandpa voter.
1264+
///
1265+
/// No change should be signaled while any change is pending. Returns an error if a change
1266+
/// is already pending.
1267+
#[pallet::call_index(59)]
1268+
#[pallet::weight(<T as Config>::WeightInfo::swap_authorities(next_authorities.len() as u32))]
1269+
pub fn schedule_grandpa_change(
1270+
origin: OriginFor<T>,
1271+
// grandpa ID is always the same type, so we don't need to parametrize it via `Config`
1272+
next_authorities: AuthorityList,
1273+
in_blocks: BlockNumberFor<T>,
1274+
forced: Option<BlockNumberFor<T>>,
1275+
) -> DispatchResult {
1276+
ensure_root(origin)?;
1277+
T::Grandpa::schedule_change(next_authorities, in_blocks, forced)
1278+
}
12411279
}
12421280
}
12431281

@@ -1255,3 +1293,27 @@ pub trait AuraInterface<AuthorityId, MaxAuthorities> {
12551293
impl<A, M> AuraInterface<A, M> for () {
12561294
fn change_authorities(_: BoundedVec<A, M>) {}
12571295
}
1296+
1297+
pub trait GrandpaInterface<Runtime>
1298+
where
1299+
Runtime: frame_system::Config,
1300+
{
1301+
fn schedule_change(
1302+
next_authorities: AuthorityList,
1303+
in_blocks: BlockNumberFor<Runtime>,
1304+
forced: Option<BlockNumberFor<Runtime>>,
1305+
) -> DispatchResult;
1306+
}
1307+
1308+
impl<R> GrandpaInterface<R> for ()
1309+
where
1310+
R: frame_system::Config,
1311+
{
1312+
fn schedule_change(
1313+
_next_authorities: AuthorityList,
1314+
_in_blocks: BlockNumberFor<R>,
1315+
_forced: Option<BlockNumberFor<R>>,
1316+
) -> DispatchResult {
1317+
Ok(())
1318+
}
1319+
}

pallets/admin-utils/src/tests/mock.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use frame_support::{
88
use frame_system as system;
99
use frame_system::{limits, EnsureNever, EnsureRoot};
1010
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
11+
use sp_consensus_grandpa::AuthorityList as GrandpaAuthorityList;
1112
use sp_core::U256;
1213
use sp_core::{ConstU64, H256};
1314
use sp_runtime::{
@@ -29,7 +30,8 @@ frame_support::construct_runtime!(
2930
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>} = 4,
3031
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 5,
3132
Drand: pallet_drand::{Pallet, Call, Storage, Event<T>} = 6,
32-
EVMChainId: pallet_evm_chain_id = 7,
33+
Grandpa: pallet_grandpa = 7,
34+
EVMChainId: pallet_evm_chain_id = 8,
3335
}
3436
);
3537

@@ -225,6 +227,19 @@ impl system::Config for Test {
225227
type Nonce = u64;
226228
}
227229

230+
impl pallet_grandpa::Config for Test {
231+
type RuntimeEvent = RuntimeEvent;
232+
233+
type KeyOwnerProof = sp_core::Void;
234+
235+
type WeightInfo = ();
236+
type MaxAuthorities = ConstU32<32>;
237+
type MaxSetIdSessionEntries = ConstU64<0>;
238+
type MaxNominators = ConstU32<20>;
239+
240+
type EquivocationReportSystem = ();
241+
}
242+
228243
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
229244
impl pallet_balances::Config for Test {
230245
type MaxLocks = ();
@@ -249,11 +264,23 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
249264
}
250265
}
251266

267+
pub struct GrandpaInterfaceImpl;
268+
impl crate::GrandpaInterface<Test> for GrandpaInterfaceImpl {
269+
fn schedule_change(
270+
next_authorities: GrandpaAuthorityList,
271+
in_blocks: BlockNumber,
272+
forced: Option<BlockNumber>,
273+
) -> sp_runtime::DispatchResult {
274+
Grandpa::schedule_change(next_authorities, in_blocks, forced)
275+
}
276+
}
277+
252278
impl crate::Config for Test {
253279
type RuntimeEvent = RuntimeEvent;
254280
type AuthorityId = AuraId;
255281
type MaxAuthorities = ConstU32<32>;
256282
type Aura = ();
283+
type Grandpa = GrandpaInterfaceImpl;
257284
type Balance = Balance;
258285
type WeightInfo = ();
259286
}

0 commit comments

Comments
 (0)