Skip to content

Commit 9931800

Browse files
committed
Encapsulate precompiles into crate
1 parent 61cddb6 commit 9931800

26 files changed

+4142
-118
lines changed

Cargo.lock

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,15 @@ rayon = "1.10"
2323

2424
[workspace]
2525
members = [
26-
"node",
27-
"pallets/commitments",
28-
"pallets/subtensor",
29-
"pallets/admin-utils",
30-
"pallets/collective",
31-
"pallets/registry",
32-
"primitives/*",
33-
"runtime",
34-
"support/tools",
35-
"support/macros",
36-
"support/linting",
37-
"support/procedural-fork",
38-
"pallets/drand",
26+
"common",
27+
"node",
28+
"pallets/*",
29+
"precompiles",
30+
"primitives/*",
31+
"runtime",
32+
"common",
33+
"support/*",
3934
]
40-
exclude = ["support/procedural-fork"]
4135
resolver = "2"
4236

4337
[workspace.lints.clippy]
@@ -46,14 +40,27 @@ arithmetic-side-effects = "deny"
4640
type_complexity = "allow"
4741
unwrap-used = "deny"
4842
manual_inspect = "allow"
49-
useless_conversion = "allow" # until polkadot is patched
43+
useless_conversion = "allow" # until polkadot is patched
5044

5145
[workspace.dependencies]
46+
pallet-admin-utils = { default-features = false, path = "pallets/admin-utils" }
47+
pallet-collective = { default-features = false, path = "pallets/collective" }
48+
pallet-commitments = { default-features = false, path = "pallets/commitments" }
49+
pallet-registry = { default-features = false, path = "pallets/registry" }
50+
pallet-subtensor = { default-features = false, path = "pallets/subtensor" }
51+
subtensor-custom-rpc-runtime-api = { default-features = false, path = "pallets/subtensor/runtime-api" }
52+
subtensor-precompiles = { default-features = false, path = "precompiles" }
53+
subtensor-runtime-common = { default-features = false, path = "common" }
54+
5255
async-trait = "0.1"
5356
cargo-husky = { version = "1", default-features = false }
5457
clap = "4.5.4"
55-
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
56-
ed25519-dalek = { version = "2.1.0", default-features = false, features = ["alloc"] }
58+
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
59+
"derive",
60+
] }
61+
ed25519-dalek = { version = "2.1.0", default-features = false, features = [
62+
"alloc",
63+
] }
5764
enumflags2 = "0.7.9"
5865
futures = "0.3.30"
5966
hex = { version = "0.4", default-features = false }
@@ -64,7 +71,9 @@ memmap2 = "0.9.4"
6471
ndarray = { version = "0.15.6", default-features = false }
6572
parity-util-mem = "0.12.0"
6673
rand = "0.8.5"
67-
scale-codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] }
74+
scale-codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
75+
"derive",
76+
] }
6877
scale-info = { version = "2.11.2", default-features = false }
6978
serde = { version = "1.0.214", default-features = false }
7079
serde-tuple-vec-map = { version = "1.0.1", default-features = false }
@@ -74,11 +83,11 @@ serde_with = { version = "=2.0.0", default-features = false }
7483
smallvec = "1.13.2"
7584
litep2p = { git = "https://github.com/paritytech/litep2p", tag = "v0.7.0" }
7685
syn = { version = "2.0.87", features = [
77-
"full",
78-
"visit-mut",
79-
"visit",
80-
"extra-traits",
81-
"parsing",
86+
"full",
87+
"visit-mut",
88+
"visit",
89+
"extra-traits",
90+
"parsing",
8291
] }
8392
quote = "1"
8493
proc-macro2 = { version = "1", features = ["span-locations"] }
@@ -181,7 +190,9 @@ fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "635bdac8
181190
fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
182191
fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
183192
fc-api = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
184-
fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false, features = ["rpc-binary-search-estimate"]}
193+
fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false, features = [
194+
"rpc-binary-search-estimate",
195+
] }
185196
fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
186197
fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
187198
precompile-utils = { git = "https://github.com/opentensor/frontier", rev = "635bdac882", default-features = false }
@@ -199,21 +210,34 @@ pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", re
199210

200211
#DRAND
201212
pallet-drand = { path = "pallets/drand", default-features = false }
202-
sp-crypto-ec-utils = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", features = ["bls12-381"] }
203-
getrandom = { version = "0.2.15", features = ["custom"], default-features = false }
204-
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
213+
sp-crypto-ec-utils = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", features = [
214+
"bls12-381",
215+
] }
216+
getrandom = { version = "0.2.15", features = [
217+
"custom",
218+
], default-features = false }
219+
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2409", default-features = false }
205220
w3f-bls = { version = "=0.1.3", default-features = false }
206-
ark-crypto-primitives = { version = "0.4.0", default-features = false, features = [ "r1cs", "snark" ] }
207-
ark-scale = { version = "0.0.11", default-features = false, features = ["hazmat"] }
221+
ark-crypto-primitives = { version = "0.4.0", default-features = false, features = [
222+
"r1cs",
223+
"snark",
224+
] }
225+
ark-scale = { version = "0.0.11", default-features = false, features = [
226+
"hazmat",
227+
] }
208228
sp-ark-bls12-381 = { git = "https://github.com/paritytech/substrate-curves", default-features = false }
209-
ark-bls12-381 = { version = "0.4.0", features = ["curve"], default-features = false }
210-
ark-serialize = { version = "0.4.0", features = [ "derive" ], default-features = false }
229+
ark-bls12-381 = { version = "0.4.0", features = [
230+
"curve",
231+
], default-features = false }
232+
ark-serialize = { version = "0.4.0", features = [
233+
"derive",
234+
], default-features = false }
211235
ark-ff = { version = "0.4.0", default-features = false }
212236
ark-ec = { version = "0.4.0", default-features = false }
213237
ark-std = { version = "0.4.0", default-features = false }
214238
anyhow = "1.0.81"
215239
sha2 = { version = "0.10.8", default-features = false }
216-
rand_chacha = { version = "0.3.1", default-features = false }
240+
rand_chacha = { version = "0.3.1", default-features = false }
217241
tle = { git = "https://github.com/ideal-lab5/timelock", rev = "5416406cfd32799e31e1795393d4916894de4468", default-features = false }
218242

219243
frame-metadata = "16"
@@ -232,11 +256,11 @@ codegen-units = 1
232256
[features]
233257
default = []
234258
try-runtime = [
235-
"node-subtensor/try-runtime",
236-
"node-subtensor-runtime/try-runtime",
259+
"node-subtensor/try-runtime",
260+
"node-subtensor-runtime/try-runtime",
237261
]
238262
runtime-benchmarks = [
239-
"node-subtensor/runtime-benchmarks",
240-
"node-subtensor-runtime/runtime-benchmarks",
263+
"node-subtensor/runtime-benchmarks",
264+
"node-subtensor-runtime/runtime-benchmarks",
241265
]
242266
metadata-hash = ["node-subtensor-runtime/metadata-hash"]

common/Cargo.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "subtensor-runtime-common"
3+
version = "0.1.0"
4+
edition = "2024"
5+
authors = ["Opentensor Foundation <https://github.com/opentensor/>"]
6+
homepage = "https://opentensor.ai/"
7+
publish = false
8+
repository = "https://github.com/opentensor/subtensor/"
9+
10+
[package.metadata.docs.rs]
11+
targets = ["x86_64-unknown-linux-gnu"]
12+
13+
[dependencies]
14+
codec = { workspace = true }
15+
frame-support = { workspace = true }
16+
scale-info = { workspace = true }
17+
sp-runtime = { workspace = true }
18+
sp-core = { workspace = true }
19+
20+
[lints]
21+
workspace = true
22+
23+
[features]
24+
default = ["std"]
25+
fast-blocks = []
26+
std = [
27+
"codec/std",
28+
"frame-support/std",
29+
"scale-info/std",
30+
"sp-core/std",
31+
"sp-runtime/std",
32+
]

common/src/lib.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
3+
use codec::{Decode, Encode, MaxEncodedLen};
4+
use scale_info::TypeInfo;
5+
use sp_runtime::{
6+
MultiSignature,
7+
traits::{IdentifyAccount, Verify},
8+
};
9+
10+
/// Balance of an account.
11+
pub type Balance = u64;
12+
13+
/// An index to a block.
14+
pub type BlockNumber = u32;
15+
16+
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
17+
pub type Signature = MultiSignature;
18+
19+
/// Some way of identifying an account on the chain. We intentionally make it equivalent to the
20+
/// public key of our transaction signing scheme.
21+
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
22+
23+
/// Index of a transaction in the chain.
24+
pub type Index = u32;
25+
26+
/// A hash of some data used by the chain.
27+
pub type Hash = sp_core::H256;
28+
29+
pub type Nonce = u32;
30+
31+
/// Transfers below SMALL_TRANSFER_LIMIT are considered small transfers
32+
pub const SMALL_TRANSFER_LIMIT: Balance = 500_000_000; // 0.5 TAO
33+
34+
#[derive(
35+
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo,
36+
)]
37+
pub enum ProxyType {
38+
Any,
39+
Owner, // Subnet owner Calls
40+
NonCritical,
41+
NonTransfer,
42+
Senate,
43+
NonFungibile, // Nothing involving moving TAO
44+
Triumvirate,
45+
Governance, // Both above governance
46+
Staking,
47+
Registration,
48+
Transfer,
49+
SmallTransfer,
50+
RootWeights,
51+
ChildKeys,
52+
SudoUncheckedSetCode,
53+
}
54+
55+
impl Default for ProxyType {
56+
// allow all Calls; required to be most permissive
57+
fn default() -> Self {
58+
Self::Any
59+
}
60+
}
61+
62+
pub mod time {
63+
use super::*;
64+
65+
/// This determines the average expected block time that we are targeting. Blocks will be
66+
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
67+
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
68+
/// slot_duration()`.
69+
///
70+
/// Change this to adjust the block time.
71+
#[cfg(not(feature = "fast-blocks"))]
72+
pub const MILLISECS_PER_BLOCK: u64 = 12000;
73+
74+
/// Fast blocks for development
75+
#[cfg(feature = "fast-blocks")]
76+
pub const MILLISECS_PER_BLOCK: u64 = 250;
77+
78+
// NOTE: Currently it is not possible to change the slot duration after the chain has started.
79+
// Attempting to do so will brick block production.
80+
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
81+
82+
// Time is measured by number of blocks.
83+
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
84+
pub const HOURS: BlockNumber = MINUTES * 60;
85+
pub const DAYS: BlockNumber = HOURS * 24;
86+
}

precompiles/Cargo.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[package]
2+
name = "subtensor-precompiles"
3+
version = "0.1.0"
4+
edition = "2024"
5+
authors = ["Opentensor Foundation <https://github.com/opentensor/>"]
6+
homepage = "https://opentensor.ai/"
7+
publish = false
8+
repository = "https://github.com/opentensor/subtensor/"
9+
10+
[package.metadata.docs.rs]
11+
targets = ["x86_64-unknown-linux-gnu"]
12+
13+
[dependencies]
14+
ed25519-dalek = { workspace = true }
15+
fp-evm = { workspace = true }
16+
frame-support = { workspace = true }
17+
frame-system = { workspace = true }
18+
log = { workspace = true }
19+
pallet-balances = { workspace = true }
20+
pallet-evm = { workspace = true }
21+
pallet-evm-precompile-modexp = { workspace = true }
22+
pallet-evm-precompile-sha3fips = { workspace = true }
23+
pallet-evm-precompile-simple = { workspace = true }
24+
pallet-proxy = { workspace = true }
25+
precompile-utils = { workspace = true }
26+
sp-core = { workspace = true }
27+
sp-runtime = { workspace = true }
28+
sp-std = { workspace = true }
29+
subtensor-runtime-common = { workspace = true }
30+
31+
pallet-subtensor = { workspace = true }
32+
pallet-admin-utils = { workspace = true }
33+
34+
[lints]
35+
workspace = true
36+
37+
[features]
38+
default = ["std"]
39+
std = [
40+
"ed25519-dalek/std",
41+
"fp-evm/std",
42+
"frame-support/std",
43+
"frame-system/std",
44+
"log/std",
45+
"pallet-admin-utils/std",
46+
"pallet-balances/std",
47+
"pallet-evm-precompile-modexp/std",
48+
"pallet-evm-precompile-sha3fips/std",
49+
"pallet-evm-precompile-simple/std",
50+
"pallet-evm/std",
51+
"pallet-proxy/std",
52+
"pallet-subtensor/std",
53+
"precompile-utils/std",
54+
"sp-core/std",
55+
"sp-runtime/std",
56+
"sp-std/std",
57+
"subtensor-runtime-common/std",
58+
]

0 commit comments

Comments
 (0)