diff --git a/Cargo.lock b/Cargo.lock index f70c3dc20c..68a6bc0c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,11 +972,11 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.4.0" +version = "3.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +checksum = "5fd03604047cee9b6ce9de9f70c6cd540a0520c813cbd49bae61f33ab80ed1dc" dependencies = [ - "event-listener 5.4.0", + "event-listener 5.4.1", "event-listener-strategy", "pin-project-lite", ] @@ -1005,7 +1005,7 @@ dependencies = [ "async-task", "blocking", "cfg-if", - "event-listener 5.4.0", + "event-listener 5.4.1", "futures-lite", "rustix 1.0.8", ] @@ -1544,9 +1544,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" [[package]] name = "cc" -version = "1.2.30" +version = "1.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" +checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" dependencies = [ "jobserver", "libc", @@ -3041,9 +3041,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "5.4.0" +version = "5.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" dependencies = [ "concurrent-queue", "parking", @@ -3056,14 +3056,14 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" dependencies = [ - "event-listener 5.4.0", + "event-listener 5.4.1", "pin-project-lite", ] [[package]] name = "evm" version = "0.42.0" -source = "git+https://github.com/rust-ethereum/evm?branch=v0.x#6ca5a72bc8942f4860137155dd9033526fd362a5" +source = "git+https://github.com/rust-ethereum/evm?rev=6ca5a72bc8942f4860137155dd9033526fd362a5#6ca5a72bc8942f4860137155dd9033526fd362a5" dependencies = [ "auto_impl", "environmental", @@ -3083,7 +3083,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.42.0" -source = "git+https://github.com/rust-ethereum/evm?branch=v0.x#6ca5a72bc8942f4860137155dd9033526fd362a5" +source = "git+https://github.com/rust-ethereum/evm?rev=6ca5a72bc8942f4860137155dd9033526fd362a5#6ca5a72bc8942f4860137155dd9033526fd362a5" dependencies = [ "parity-scale-codec", "primitive-types 0.13.1", @@ -3094,7 +3094,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.42.0" -source = "git+https://github.com/rust-ethereum/evm?branch=v0.x#6ca5a72bc8942f4860137155dd9033526fd362a5" +source = "git+https://github.com/rust-ethereum/evm?rev=6ca5a72bc8942f4860137155dd9033526fd362a5#6ca5a72bc8942f4860137155dd9033526fd362a5" dependencies = [ "environmental", "evm-core", @@ -3105,7 +3105,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.42.0" -source = "git+https://github.com/rust-ethereum/evm?branch=v0.x#6ca5a72bc8942f4860137155dd9033526fd362a5" +source = "git+https://github.com/rust-ethereum/evm?rev=6ca5a72bc8942f4860137155dd9033526fd362a5#6ca5a72bc8942f4860137155dd9033526fd362a5" dependencies = [ "auto_impl", "environmental", @@ -3205,7 +3205,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "async-trait", "fp-storage", @@ -3217,7 +3217,7 @@ dependencies = [ [[package]] name = "fc-aura" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fc-rpc", "fp-storage", @@ -3230,10 +3230,26 @@ dependencies = [ "sp-timestamp", ] +[[package]] +name = "fc-babe" +version = "1.0.0-dev" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" +dependencies = [ + "fc-rpc", + "sc-client-api", + "sc-consensus-babe", + "sp-api", + "sp-blockchain", + "sp-consensus-babe", + "sp-inherents", + "sp-runtime", + "sp-timestamp", +] + [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "async-trait", "fp-consensus", @@ -3249,7 +3265,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "async-trait", "ethereum", @@ -3279,7 +3295,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fc-db", "fc-storage", @@ -3302,7 +3318,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -3353,7 +3369,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -3368,7 +3384,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -3474,6 +3490,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "fixedbitset" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" + [[package]] name = "flume" version = "0.11.1" @@ -3542,7 +3564,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "hex", "impl-serde 0.5.0", @@ -3561,7 +3583,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "parity-scale-codec", @@ -3572,7 +3594,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -3584,7 +3606,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "environmental", "evm", @@ -3600,7 +3622,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -3616,7 +3638,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "frame-support", "parity-scale-codec", @@ -3628,7 +3650,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "parity-scale-codec", "serde", @@ -3738,6 +3760,33 @@ dependencies = [ "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "frame-election-provider-solution-type" +version = "16.1.1" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "frame-election-provider-support" +version = "40.1.1" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-election-provider-solution-type", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-npos-elections", + "sp-runtime", +] + [[package]] name = "frame-executive" version = "40.0.1" @@ -4054,9 +4103,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" dependencies = [ "fastrand", "futures-core", @@ -6743,6 +6792,7 @@ dependencies = [ "cumulus-primitives-proof-size-hostfunction", "fc-api", "fc-aura", + "fc-babe", "fc-consensus", "fc-db", "fc-mapping-sync", @@ -6759,6 +6809,7 @@ dependencies = [ "futures", "hex", "jsonrpsee", + "log", "memmap2 0.9.7", "node-subtensor-runtime", "num-traits", @@ -6776,6 +6827,8 @@ dependencies = [ "sc-client-api", "sc-consensus", "sc-consensus-aura", + "sc-consensus-babe", + "sc-consensus-babe-rpc", "sc-consensus-grandpa", "sc-consensus-grandpa-rpc", "sc-consensus-manual-seal", @@ -6798,7 +6851,9 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-aura", + "sp-consensus-babe", "sp-consensus-grandpa", + "sp-consensus-slots", "sp-core", "sp-crypto-ec-utils 0.15.0", "sp-inherents", @@ -6828,6 +6883,7 @@ dependencies = [ "fp-rpc", "fp-self-contained", "frame-benchmarking", + "frame-election-provider-support", "frame-executive", "frame-metadata 20.0.0", "frame-metadata-hash-extension", @@ -6841,28 +6897,42 @@ dependencies = [ "log", "pallet-admin-utils", "pallet-aura", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-bags-list", "pallet-balances", "pallet-base-fee", "pallet-collective", "pallet-commitments", "pallet-crowdloan", "pallet-drand", + "pallet-election-provider-multi-phase", "pallet-ethereum", "pallet-evm", "pallet-evm-chain-id", "pallet-evm-precompile-modexp", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", + "pallet-fast-unstake", "pallet-grandpa", "pallet-hotfix-sufficients", "pallet-insecure-randomness-collective-flip", "pallet-membership", "pallet-multisig", + "pallet-nomination-pools", + "pallet-nomination-pools-runtime-api", + "pallet-offences", "pallet-preimage", "pallet-proxy 38.0.0", "pallet-registry", "pallet-safe-mode", "pallet-scheduler", + "pallet-session", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-staking-reward-fn", + "pallet-staking-runtime-api", "pallet-subtensor", "pallet-subtensor-swap", "pallet-subtensor-swap-runtime-api", @@ -6879,15 +6949,21 @@ dependencies = [ "sha2 0.10.9", "smallvec", "sp-api", + "sp-authority-discovery", "sp-block-builder", "sp-consensus-aura", + "sp-consensus-babe", + "sp-consensus-grandpa", + "sp-consensus-slots", "sp-core", "sp-genesis-builder", "sp-inherents", "sp-io", + "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-session", + "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6)", "sp-storage 22.0.0", "sp-tracing 17.1.0", @@ -7225,7 +7301,7 @@ dependencies = [ "expander", "indexmap 2.10.0", "itertools 0.11.0", - "petgraph", + "petgraph 0.6.5", "proc-macro-crate 3.3.0", "proc-macro2", "quote", @@ -7287,6 +7363,21 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-authority-discovery" +version = "40.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-support", + "frame-system", + "pallet-session", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-authority-discovery", + "sp-runtime", +] + [[package]] name = "pallet-authorship" version = "40.0.0" @@ -7300,6 +7391,50 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-babe" +version = "40.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-consensus-babe", + "sp-core", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", +] + +[[package]] +name = "pallet-bags-list" +version = "39.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "aquamarine", + "docify", + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-tracing 17.1.0", +] + [[package]] name = "pallet-balances" version = "41.1.0" @@ -7319,7 +7454,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "frame-support", @@ -7427,10 +7562,45 @@ dependencies = [ "w3f-bls", ] +[[package]] +name = "pallet-election-provider-multi-phase" +version = "39.2.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-election-provider-support-benchmarking", + "parity-scale-codec", + "rand 0.8.5", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-npos-elections", + "sp-runtime", + "strum 0.26.3", +] + +[[package]] +name = "pallet-election-provider-support-benchmarking" +version = "39.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-system", + "parity-scale-codec", + "sp-npos-elections", + "sp-runtime", +] + [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "ethereum", "ethereum-types 0.15.1", @@ -7453,7 +7623,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "cumulus-primitives-storage-weight-reclaim", "environmental", @@ -7477,7 +7647,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "frame-support", "frame-system", @@ -7488,7 +7658,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "sp-core", @@ -7498,7 +7668,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "frame-support", @@ -7510,7 +7680,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "num", @@ -7519,7 +7689,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "tiny-keccak", @@ -7528,13 +7698,31 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "fp-evm", "ripemd", "sp-io", ] +[[package]] +name = "pallet-fast-unstake" +version = "39.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", +] + [[package]] name = "pallet-grandpa" version = "40.0.0" @@ -7560,7 +7748,7 @@ dependencies = [ [[package]] name = "pallet-hotfix-sufficients" version = "1.0.0" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "frame-benchmarking", "frame-support", @@ -7610,6 +7798,49 @@ dependencies = [ "scale-info", ] +[[package]] +name = "pallet-nomination-pools" +version = "38.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-tracing 17.1.0", +] + +[[package]] +name = "pallet-nomination-pools-runtime-api" +version = "36.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "pallet-nomination-pools", + "parity-scale-codec", + "sp-api", +] + +[[package]] +name = "pallet-offences" +version = "39.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", + "sp-staking", +] + [[package]] name = "pallet-preimage" version = "40.0.0" @@ -7740,6 +7971,58 @@ dependencies = [ "sp-trie", ] +[[package]] +name = "pallet-staking" +version = "40.1.1" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "rand_chacha 0.3.1", + "scale-info", + "serde", + "sp-application-crypto", + "sp-io", + "sp-runtime", + "sp-staking", +] + +[[package]] +name = "pallet-staking-reward-curve" +version = "12.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "proc-macro-crate 3.3.0", + "proc-macro2", + "quote", + "syn 2.0.104", +] + +[[package]] +name = "pallet-staking-reward-fn" +version = "22.0.1" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "log", + "sp-arithmetic", +] + +[[package]] +name = "pallet-staking-runtime-api" +version = "26.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "parity-scale-codec", + "sp-api", + "sp-staking", +] + [[package]] name = "pallet-subtensor" version = "4.0.0-dev" @@ -8213,7 +8496,17 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ - "fixedbitset", + "fixedbitset 0.4.2", + "indexmap 2.10.0", +] + +[[package]] +name = "petgraph" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" +dependencies = [ + "fixedbitset 0.5.7", "indexmap 2.10.0", ] @@ -8623,9 +8916,9 @@ checksum = "23eff02c070c70f31878a3d915e88a914ecf3e153741e2fb572dde28cce20fde" [[package]] name = "polling" -version = "3.9.0" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee9b2fa7a4517d2c91ff5bc6c297a427a96749d15f98fcdbb22c05571a4d4b7" +checksum = "b5bd19146350fe804f7cb2669c851c03d69da628803dab0d98018142aaa5d829" dependencies = [ "cfg-if", "concurrent-queue", @@ -8691,7 +8984,7 @@ dependencies = [ [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "environmental", "evm", @@ -8715,7 +9008,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/opentensor/frontier?rev=c591df98c524e1599c45f93cf4685248088ac014#c591df98c524e1599c45f93cf4685248088ac014" +source = "git+https://github.com/opentensor/frontier?rev=830e61f370d88f7ace1c5a5659dd58db75a19844#830e61f370d88f7ace1c5a5659dd58db75a19844" dependencies = [ "case", "num_enum", @@ -8998,7 +9291,7 @@ dependencies = [ "log", "multimap", "once_cell", - "petgraph", + "petgraph 0.7.1", "prettyplease", "prost 0.13.5", "prost-types", @@ -9566,9 +9859,9 @@ dependencies = [ [[package]] name = "ruint" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11256b5fe8c68f56ac6f39ef0720e592f33d2367a4782740d9c9142e889c7fb4" +checksum = "9ecb38f82477f20c5c3d62ef52d7c4e536e38ea9b73fb570a20c5cae0e14bcf6" dependencies = [ "alloy-rlp", "ark-ff 0.3.0", @@ -10167,6 +10460,28 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "sc-consensus-babe-rpc" +version = "0.49.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "futures", + "jsonrpsee", + "sc-consensus-babe", + "sc-consensus-epochs", + "sc-rpc-api", + "serde", + "sp-api", + "sp-application-crypto", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-core", + "sp-keystore", + "sp-runtime", + "thiserror 1.0.69", +] + [[package]] name = "sc-consensus-epochs" version = "0.48.0" @@ -11446,9 +11761,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.141" +version = "1.0.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" +checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" dependencies = [ "itoa", "memchr", @@ -11600,9 +11915,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" dependencies = [ "libc", ] @@ -11710,7 +12025,7 @@ dependencies = [ "derive_more 0.99.20", "ed25519-zebra", "either", - "event-listener 5.4.0", + "event-listener 5.4.1", "fnv", "futures-lite", "futures-util", @@ -11759,7 +12074,7 @@ dependencies = [ "bs58", "derive_more 0.99.20", "either", - "event-listener 5.4.0", + "event-listener 5.4.1", "fnv", "futures-channel", "futures-lite", @@ -12079,7 +12394,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -12175,7 +12490,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "proc-macro2", "quote", @@ -12185,7 +12500,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "environmental", "parity-scale-codec", @@ -12304,6 +12619,19 @@ dependencies = [ "sp-application-crypto", ] +[[package]] +name = "sp-npos-elections" +version = "36.2.0" +source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2503-6#598feddb893f5ad3923a62e41a2f179b6e10c30c" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-core", + "sp-runtime", +] + [[package]] name = "sp-offchain" version = "36.0.0" @@ -12365,7 +12693,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -12402,7 +12730,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "Inflector", "expander", @@ -12504,12 +12832,12 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "impl-serde 0.5.0", "parity-scale-codec", @@ -12545,7 +12873,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "parity-scale-codec", "regex", @@ -12642,7 +12970,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#177b03958c766fe053f28424ee6f6748644bb794" +source = "git+https://github.com/paritytech/polkadot-sdk#59fb2e7482d471a7ec4e8d3b30499497efa7b34c" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -12732,7 +13060,7 @@ dependencies = [ "crc", "crossbeam-queue", "either", - "event-listener 5.4.0", + "event-listener 5.4.1", "futures-core", "futures-intrusive", "futures-io", @@ -13710,9 +14038,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.47.0" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", @@ -13779,9 +14107,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.15" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" dependencies = [ "bytes", "futures-core", @@ -15530,9 +15858,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +checksum = "bdbb9122ea75b11bf96e7492afb723e8a7fbe12c67417aa95e7e3d18144d37cd" dependencies = [ "yoke", "zerofrom", diff --git a/Cargo.toml b/Cargo.toml index 33df163f67..1d747b529a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,7 +113,6 @@ expander = "2" ahash = { version = "0.8", default-features = false } regex = { version = "1.11.1", default-features = false } - frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } frame-executive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } @@ -127,6 +126,7 @@ frame-metadata = { version = "20.0.0", default-features = false } pallet-proxy = { path = "pallets/proxy", default-features = false } pallet-utility = { path = "pallets/utility", default-features = false } +pallet-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } @@ -143,11 +143,29 @@ pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } pallet-root-testing = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +# NPoS +frame-election-provider-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-bags-list = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-fast-unstake = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-nomination-pools = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-session = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-staking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-staking-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-staking-reward-fn = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-staking-reward-curve = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +pallet-offences = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } + sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sc-consensus-babe-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-consensus-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sc-chain-spec-derive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } @@ -167,11 +185,16 @@ sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk.g sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sp-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sp-staking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sp-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } +sp-npos-elections = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } @@ -200,34 +223,35 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot- cumulus-primitives-proof-size-hostfunction = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-6", default-features = false } # Frontier -fp-evm = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fp-rpc = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fp-self-contained = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fp-account = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-storage = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-db = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-api = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-aura = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -precompile-utils = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } +fp-evm = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fp-rpc = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fp-self-contained = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fp-account = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-storage = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-db = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-api = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-aura = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-babe = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +precompile-utils = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } # Frontier FRAME -pallet-base-fee = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-ethereum = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-precompile-dispatch = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-chain-id = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-evm-precompile-bn128 = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } -pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", rev = "c591df98c524e1599c45f93cf4685248088ac014", default-features = false } +pallet-base-fee = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-ethereum = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-chain-id = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-evm-precompile-bn128 = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } +pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", rev = "830e61f370d88f7ace1c5a5659dd58db75a19844", default-features = false } #DRAND pallet-drand = { path = "pallets/drand", default-features = false } diff --git a/node/Cargo.toml b/node/Cargo.toml index 3696e78f21..24bc79d0b9 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -20,6 +20,7 @@ targets = ["x86_64-unknown-linux-gnu"] name = "node-subtensor" [dependencies] +log.workspace = true async-trait.workspace = true clap = { workspace = true, features = ["derive"] } futures = { workspace = true, features = ["thread-pool"] } @@ -30,7 +31,11 @@ hex.workspace = true memmap2.workspace = true serde_json.workspace = true +sc-chain-spec-derive.workspace = true sc-cli.workspace = true +sc-consensus-babe.workspace = true +sp-consensus.workspace = true +sp-consensus-slots.workspace = true sp-core.workspace = true sc-executor.workspace = true sc-service.workspace = true @@ -42,12 +47,12 @@ sc-offchain.workspace = true sc-network.workspace = true sc-consensus-aura.workspace = true sp-consensus-aura.workspace = true -sp-consensus.workspace = true +sp-consensus-babe.workspace = true +sc-consensus-babe-rpc.workspace = true sc-consensus.workspace = true sc-consensus-grandpa.workspace = true sc-consensus-grandpa-rpc.workspace = true sp-consensus-grandpa.workspace = true -sc-chain-spec-derive.workspace = true sc-chain-spec.workspace = true sc-consensus-slots.workspace = true sc-client-api.workspace = true @@ -89,12 +94,14 @@ frame-benchmarking.workspace = true frame-benchmarking-cli.workspace = true # Needed for Frontier +fc-mapping-sync.workspace = true +fc-storage.workspace = true +fc-babe.workspace = true sc-consensus-manual-seal.workspace = true sc-network-sync.workspace = true substrate-prometheus-endpoint.workspace = true # Frontier -fc-storage.workspace = true fc-db.workspace = true fc-consensus.workspace = true fc-api.workspace = true @@ -102,7 +109,6 @@ fc-rpc = { workspace = true, features = ["rpc-binary-search-estimate"] } fc-rpc-core.workspace = true fp-rpc.workspace = true fc-aura.workspace = true -fc-mapping-sync.workspace = true fp-consensus.workspace = true num-traits = { workspace = true, features = ["std"] } @@ -118,9 +124,6 @@ pallet-subtensor-swap-runtime-api = { workspace = true, features = ["std"] } substrate-build-script-utils.workspace = true [features] -default = ["rocksdb", "sql", "txpool"] -fast-blocks = ["node-subtensor-runtime/fast-blocks"] -sql = ["fc-db/sql", "fc-mapping-sync/sql"] rocksdb = [ "sc-service/rocksdb", "fc-db/rocksdb", @@ -129,6 +132,12 @@ rocksdb = [ "frame-benchmarking-cli/rocksdb", "sc-cli/rocksdb", ] +default = ["rocksdb", "sql", "txpool"] +fast-blocks = [ + "node-subtensor-runtime/fast-blocks", + "subtensor-runtime-common/fast-blocks" +] +sql = ["fc-db/sql", "fc-mapping-sync/sql"] txpool = ["fc-rpc/txpool", "fc-rpc-core/txpool"] # Dependencies that are only required if runtime benchmarking should be build. diff --git a/node/src/cli.rs b/node/src/cli.rs index d9744d44df..e46c71857b 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -1,5 +1,14 @@ -use crate::ethereum::EthConfiguration; +use crate::{ + client::{FullBackend, FullClient}, + consensus::{AuraConsensus, BabeConsensus}, + ethereum::{EthConfiguration, FrontierBackend}, + service::new_chain_ops, +}; +use node_subtensor_runtime::opaque::Block; use sc_cli::RunCmd; +use sc_consensus::BasicQueue; +use sc_service::{Configuration, TaskManager}; +use std::sync::Arc; #[derive(Debug, clap::Parser)] pub struct Cli { @@ -13,6 +22,15 @@ pub struct Cli { #[arg(long, value_enum, ignore_case = true)] pub sealing: Option, + /// Whether to try Aura or Babe consensus on first start. + /// + /// After starting, the consensus used by the node will automatically + /// switch to whatever is required to continue validating / syncing. + /// + /// TODO: Remove this after the Babe transition has settled. + #[arg(long, value_enum, ignore_case = true, default_value_t=SupportedConsensusMechanism::default())] + pub initial_consensus: SupportedConsensusMechanism, + #[command(flatten)] pub eth: EthConfiguration, } @@ -63,3 +81,37 @@ pub enum Sealing { /// Seal when transaction is executed. Instant, } + +/// Supported consensus mechanisms. +#[derive(Copy, Clone, Debug, Default, clap::ValueEnum)] +pub enum SupportedConsensusMechanism { + // Babe + Babe, + /// Aura + #[default] + Aura, +} + +// Convinience methods for static dispatch of different service methods with +// different consensus mechanisms. +impl SupportedConsensusMechanism { + pub fn new_chain_ops( + &self, + config: &mut Configuration, + eth_config: &EthConfiguration, + ) -> Result< + ( + Arc, + Arc, + BasicQueue, + TaskManager, + FrontierBackend, + ), + sc_service::Error, + > { + match self { + SupportedConsensusMechanism::Aura => new_chain_ops::(config, eth_config), + SupportedConsensusMechanism::Babe => new_chain_ops::(config, eth_config), + } + } +} diff --git a/node/src/command.rs b/node/src/command.rs index f35664f8b0..eb261bedfa 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -1,13 +1,16 @@ +use std::sync::{Arc, atomic::AtomicBool}; + use crate::{ chain_spec, - cli::{Cli, Subcommand}, + cli::{Cli, Subcommand, SupportedConsensusMechanism}, + consensus::BabeConsensus, ethereum::db_config_dir, service, }; use fc_db::{DatabaseSource, kv::frontier_database_dir}; -use clap::{CommandFactory, FromArgMatches, parser::ValueSource}; -use futures::TryFutureExt; +use crate::consensus::AuraConsensus; +use clap::{ArgMatches, CommandFactory, FromArgMatches, parser::ValueSource}; use node_subtensor_runtime::Block; use sc_cli::SubstrateCli; use sc_service::{ @@ -70,7 +73,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|mut config| { let (client, _, import_queue, task_manager, _) = - service::new_chain_ops(&mut config, &cli.eth)?; + cli.initial_consensus.new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, import_queue), task_manager)) }) } @@ -78,7 +81,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|mut config| { let (client, _, _, task_manager, _) = - service::new_chain_ops(&mut config, &cli.eth)?; + cli.initial_consensus.new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, config.database), task_manager)) }) } @@ -86,7 +89,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|mut config| { let (client, _, _, task_manager, _) = - service::new_chain_ops(&mut config, &cli.eth)?; + cli.initial_consensus.new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, config.chain_spec), task_manager)) }) } @@ -94,7 +97,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|mut config| { let (client, _, import_queue, task_manager, _) = - service::new_chain_ops(&mut config, &cli.eth)?; + cli.initial_consensus.new_chain_ops(&mut config, &cli.eth)?; Ok((cmd.run(client, import_queue), task_manager)) }) } @@ -148,7 +151,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|mut config| { let (client, backend, _, task_manager, _) = - service::new_chain_ops(&mut config, &cli.eth)?; + cli.initial_consensus.new_chain_ops(&mut config, &cli.eth)?; let aux_revert = Box::new(move |client, _, blocks| { sc_consensus_grandpa::revert(client, blocks)?; Ok(()) @@ -177,7 +180,7 @@ pub fn run() -> sc_cli::Result<()> { } = crate::service::new_partial( &config, &cli.eth, - crate::service::build_manual_seal_import_queue, + Box::new(crate::service::build_manual_seal_import_queue), )?; // This switch needs to be in the client, since the client decides @@ -229,36 +232,107 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| cmd.run::(&config)) } + // Start with the initial consensus type asked. None => { - let runner = cli.create_runner(&cli.run)?; - runner.run_node_until_exit(|config| async move { - let mut config = override_default_heap_pages(config, 60_000); + let arg_matches = Cli::command().get_matches(); + let cli = Cli::from_args(); + match cli.initial_consensus { + SupportedConsensusMechanism::Babe => start_babe_service(&arg_matches), + SupportedConsensusMechanism::Aura => start_aura_service(&arg_matches), + } + } + } +} - // If the operator did **not** supply `--rpc-rate-limit`, disable the limiter. - if cli.run.rpc_params.rpc_rate_limit.is_none() { - config.rpc.rate_limit = None; - } - // If the operator did **not** supply `--rpc-max-subscriptions-per-connection` set to high value. - config.rpc.max_subs_per_conn = - match arg_matches.value_source("rpc_max_subscriptions_per_connection") { - Some(ValueSource::CommandLine) => { - cli.run.rpc_params.rpc_max_subscriptions_per_connection - } - _ => 10000, - }; - // If the operator did **not** supply `--rpc-max-connections` set to high value. - config.rpc.max_connections = match arg_matches.value_source("rpc_max_connections") { - Some(ValueSource::CommandLine) => cli.run.rpc_params.rpc_max_connections, - _ => 10000, - }; - service::build_full(config, cli.eth, cli.sealing) - .map_err(Into::into) - .await - }) +fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> { + let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches"); + let runner = cli.create_runner(&cli.run)?; + match runner.run_node_until_exit(|config| async move { + let config = customise_config(arg_matches, config); + service::build_full::(config, cli.eth, cli.sealing, None).await + }) { + Ok(_) => Ok(()), + Err(e) => { + // Handle node needs to be in Aura mode. + if matches!( + e, + sc_service::Error::Client(sp_blockchain::Error::VersionInvalid(ref msg)) + if msg == "Unsupported or invalid BabeApi version" + ) { + log::info!( + "💡 Chain is using Aura consensus. Switching to Aura service until Babe block is detected.", + ); + start_aura_service(arg_matches) + // Handle Aura service still has DB lock. This never has been observed to take more + // than 1s to drop. + } else if matches!(e, sc_service::Error::Client(sp_blockchain::Error::Backend(ref msg)) + if msg.starts_with("IO error: lock hold by current process")) + { + log::info!("Failed to aquire DB lock, trying again in 1s..."); + std::thread::sleep(std::time::Duration::from_secs(1)); + return start_babe_service(arg_matches); + // Unknown error, return it. + } else { + Err(e.into()) + } + } + } +} + +fn start_aura_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> { + let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches"); + let runner = cli.create_runner(&cli.run)?; + + // Unlike when the Babe node fails to build due to missing BabeApi in the runtime, + // there is no way to detect the exit reason for the Aura node when it encounters a Babe block. + // + // Passing this atomic bool is a hacky solution, allowing the node to set it to true to indicate + // a Babe service should be spawned on exit instead of a regular shutdown. + let babe_switch = Arc::new(AtomicBool::new(false)); + let babe_switch_clone = babe_switch.clone(); + match runner.run_node_until_exit(|config| async move { + let config = customise_config(arg_matches, config); + service::build_full::(config, cli.eth, cli.sealing, Some(babe_switch_clone)) + .await + }) { + Ok(()) => Ok(()), + Err(e) => { + if babe_switch.load(std::sync::atomic::Ordering::Relaxed) { + start_babe_service(arg_matches) + } else { + Err(e.into()) + } } } } +fn customise_config(arg_matches: &ArgMatches, config: Configuration) -> Configuration { + let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches"); + + let mut config = override_default_heap_pages(config, 60_000); + + // If the operator did **not** supply `--rpc-rate-limit`, disable the limiter. + if cli.run.rpc_params.rpc_rate_limit.is_none() { + config.rpc.rate_limit = None; + } + + // If the operator did **not** supply `--rpc-max-subscriptions-per-connection` set to high value. + config.rpc.max_subs_per_conn = match arg_matches + .value_source("rpc-max-subscriptions-per-connection") + { + Some(ValueSource::CommandLine) => cli.run.rpc_params.rpc_max_subscriptions_per_connection, + _ => 10000, + }; + + // If the operator did **not** supply `--rpc-max-connections` set to high value. + config.rpc.max_connections = match arg_matches.value_source("rpc-max-connections") { + Some(ValueSource::CommandLine) => cli.run.rpc_params.rpc_max_connections, + _ => 10000, + }; + + config +} + /// Override default heap pages fn override_default_heap_pages(config: Configuration, pages: u64) -> Configuration { Configuration { diff --git a/node/src/conditional_evm_block_import.rs b/node/src/conditional_evm_block_import.rs new file mode 100644 index 0000000000..b6ba445c1f --- /dev/null +++ b/node/src/conditional_evm_block_import.rs @@ -0,0 +1,70 @@ +use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResult}; +use sp_consensus::Error as ConsensusError; +use sp_runtime::traits::{Block as BlockT, Header}; +use std::marker::PhantomData; + +pub struct ConditionalEVMBlockImport { + inner: I, + frontier_block_import: F, + _marker: PhantomData, +} + +impl Clone for ConditionalEVMBlockImport +where + B: BlockT, + I: Clone + BlockImport, + F: Clone + BlockImport, +{ + fn clone(&self) -> Self { + ConditionalEVMBlockImport { + inner: self.inner.clone(), + frontier_block_import: self.frontier_block_import.clone(), + _marker: PhantomData, + } + } +} + +impl ConditionalEVMBlockImport +where + B: BlockT, + I: BlockImport, + I::Error: Into, + F: BlockImport, + F::Error: Into, +{ + pub fn new(inner: I, frontier_block_import: F) -> Self { + Self { + inner, + frontier_block_import, + _marker: PhantomData, + } + } +} + +#[async_trait::async_trait] +impl BlockImport for ConditionalEVMBlockImport +where + B: BlockT, + I: BlockImport + Send + Sync, + I::Error: Into, + F: BlockImport + Send + Sync, + F::Error: Into, +{ + type Error = ConsensusError; + + async fn check_block(&self, block: BlockCheckParams) -> Result { + self.inner.check_block(block).await.map_err(Into::into) + } + + async fn import_block(&self, block: BlockImportParams) -> Result { + // 4345556 - mainnet runtime upgrade block with Frontier + if *block.header.number() < 4345557u32.into() { + self.inner.import_block(block).await.map_err(Into::into) + } else { + self.frontier_block_import + .import_block(block) + .await + .map_err(Into::into) + } + } +} diff --git a/node/src/consensus/aura_consensus.rs b/node/src/consensus/aura_consensus.rs new file mode 100644 index 0000000000..b8f4326fdf --- /dev/null +++ b/node/src/consensus/aura_consensus.rs @@ -0,0 +1,218 @@ +use crate::consensus::{ConsensusMechanism, StartAuthoringParams}; +use crate::{ + client::{FullBackend, FullClient}, + conditional_evm_block_import::ConditionalEVMBlockImport, + ethereum::EthConfiguration, + service::{BIQ, FullSelectChain, GrandpaBlockImport}, +}; +use fc_consensus::FrontierBlockImport; +use jsonrpsee::tokio; +use node_subtensor_runtime::opaque::Block; +use sc_client_api::{AuxStore, BlockOf}; +use sc_consensus::{BlockImport, BoxBlockImport}; +use sc_consensus_grandpa::BlockNumberOps; +use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, InherentDataProviderExt}; +use sc_service::{Configuration, TaskManager}; +use sc_telemetry::TelemetryHandle; +use sc_transaction_pool::TransactionPoolHandle; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::{HeaderBackend, HeaderMetadata}; +use sp_consensus::{Environment, Proposer, SelectChain, SyncOracle}; +use sp_consensus_aura::sr25519::AuthorityId; +use sp_consensus_aura::{AuraApi, sr25519::AuthorityPair as AuraPair}; +use sp_consensus_slots::SlotDuration; +use sp_inherents::CreateInherentDataProviders; +use sp_keystore::KeystorePtr; +use sp_runtime::traits::NumberFor; +use std::{error::Error, sync::Arc}; + +pub struct AuraConsensus; + +impl ConsensusMechanism for AuraConsensus { + type InherentDataProviders = ( + sp_consensus_aura::inherents::InherentDataProvider, + sp_timestamp::InherentDataProvider, + ); + + fn start_authoring( + self, + task_manager: &mut TaskManager, + params: StartAuthoringParams, + ) -> Result<(), sp_consensus::Error> + where + C: ProvideRuntimeApi + + BlockOf + + AuxStore + + HeaderBackend + + HeaderMetadata + + Send + + Sync + + 'static, + C::Api: AuraApi, + SC: SelectChain + 'static, + I: BlockImport + Send + Sync + 'static, + PF: Environment + Send + Sync + 'static, + PF::Proposer: Proposer, + SO: SyncOracle + Send + Sync + Clone + 'static, + L: sc_consensus::JustificationSyncLink + 'static, + CIDP: CreateInherentDataProviders + Send + Sync + 'static, + CIDP::InherentDataProviders: InherentDataProviderExt + Send, + BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static, + Error: std::error::Error + Send + From + From + 'static, + { + let aura = sc_consensus_aura::start_aura::( + sc_consensus_aura::StartAuraParams { + slot_duration: params.slot_duration, + client: params.client, + select_chain: params.select_chain, + block_import: params.block_import, + proposer_factory: params.proposer_factory, + sync_oracle: params.sync_oracle, + justification_sync_link: params.justification_sync_link, + create_inherent_data_providers: params.create_inherent_data_providers, + force_authoring: params.force_authoring, + backoff_authoring_blocks: params.backoff_authoring_blocks, + keystore: params.keystore, + block_proposal_slot_portion: params.block_proposal_slot_portion, + max_block_proposal_slot_portion: params.max_block_proposal_slot_portion, + telemetry: params.telemetry, + compatibility_mode: Default::default(), + }, + )?; + + // the AURA authoring task is considered essential, i.e. if it + // fails we take down the service with it. + task_manager + .spawn_essential_handle() + .spawn_blocking("aura", Some("block-authoring"), aura); + + Ok(()) + } + + fn frontier_consensus_data_provider( + client: Arc, + ) -> Result>, sp_blockchain::Error> { + Ok(Box::new(fc_aura::AuraConsensusDataProvider::new(client))) + } + + fn create_inherent_data_providers( + slot_duration: SlotDuration, + ) -> Result> { + let current = sp_timestamp::InherentDataProvider::from_system_time(); + let next_slot = current + .timestamp() + .as_millis() + .saturating_add(slot_duration.as_millis()); + let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into()); + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + } + + fn new() -> Self { + Self {} + } + + fn build_biq(&mut self) -> Result + where + NumberFor: BlockNumberOps, + { + let build_import_queue = Box::new( + move |client: Arc, + _backend: Arc, + config: &Configuration, + _eth_config: &EthConfiguration, + task_manager: &TaskManager, + telemetry: Option, + grandpa_block_import: GrandpaBlockImport, + _transaction_pool: Arc>| { + let conditional_block_import = ConditionalEVMBlockImport::new( + grandpa_block_import.clone(), + FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()), + ); + + let slot_duration = sc_consensus_aura::slot_duration(&*client)?; + let create_inherent_data_providers = move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = + sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + }; + + let import_queue = super::aura_wrapped_import_queue::import_queue( + sc_consensus_aura::ImportQueueParams { + block_import: conditional_block_import.clone(), + justification_import: Some(Box::new(grandpa_block_import.clone())), + client, + create_inherent_data_providers, + spawner: &task_manager.spawn_essential_handle(), + registry: config.prometheus_registry(), + check_for_equivocation: Default::default(), + telemetry, + compatibility_mode: sc_consensus_aura::CompatibilityMode::None, + }, + ) + .map_err::(Into::into)?; + + Ok(( + import_queue, + Box::new(conditional_block_import) as BoxBlockImport, + )) + }, + ); + + Ok(build_import_queue) + } + + fn slot_duration(&self, client: &FullClient) -> Result { + sc_consensus_aura::slot_duration(client).map_err(Into::into) + } + + fn spawn_essential_handles( + &self, + task_manager: &mut TaskManager, + client: Arc, + triggered: Option>, + ) -> Result<(), sc_service::Error> { + let client_clone = client.clone(); + let triggered_clone = triggered.clone(); + let slot_duration = self.slot_duration(&client)?; + task_manager.spawn_essential_handle().spawn( + "babe-switch", + None, + Box::pin(async move { + let client = client_clone; + let triggered = triggered_clone; + loop { + // Check if the runtime is Babe once per block. + if let Ok(c) = sc_consensus_babe::configuration(&*client) { + if !c.authorities.is_empty() { + log::info!("Babe runtime detected! Intentionally failing the essential handle `babe-switch` to trigger switch to Babe service."); + if let Some(triggered) = triggered { + triggered.store(true, std::sync::atomic::Ordering::SeqCst); + }; + break; + } + }; + tokio::time::sleep(slot_duration.as_duration()).await; + } + })); + Ok(()) + } + + fn rpc_methods( + &self, + _client: Arc, + _keystore: KeystorePtr, + _select_chain: FullSelectChain, + ) -> Result, sc_service::Error> { + // Aura requires no special RPC methods. + Ok(Default::default()) + } +} diff --git a/node/src/consensus/aura_wrapped_import_queue.rs b/node/src/consensus/aura_wrapped_import_queue.rs new file mode 100644 index 0000000000..c6433d8dd6 --- /dev/null +++ b/node/src/consensus/aura_wrapped_import_queue.rs @@ -0,0 +1,136 @@ +use sc_client_api::AuxStore; +use sc_client_api::BlockOf; +use sc_client_api::UsageProvider; +use sc_consensus::BlockImport; +use sc_consensus::BlockImportParams; +use sc_consensus::Verifier; +use sc_consensus::{BasicQueue, DefaultImportQueue}; +use sc_consensus_aura::AuraVerifier; +use sc_consensus_aura::CheckForEquivocation; +use sc_consensus_aura::ImportQueueParams; +use sc_consensus_slots::InherentDataProviderExt; +use sc_telemetry::TelemetryHandle; +use sp_api::ApiExt; +use sp_api::ProvideRuntimeApi; +use sp_block_builder::BlockBuilder as BlockBuilderApi; +use sp_blockchain::HeaderBackend; +use sp_consensus::error::Error as ConsensusError; +use sp_consensus_aura::AuraApi; +use sp_consensus_aura::sr25519::AuthorityId; +use sp_consensus_aura::sr25519::AuthorityPair; +use sp_consensus_babe::BABE_ENGINE_ID; +use sp_inherents::CreateInherentDataProviders; +use sp_runtime::Digest; +use sp_runtime::DigestItem; +use sp_runtime::traits::NumberFor; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use std::sync::Arc; + +/// A wrapped Aura verifier which will stall verification if it encounters a +/// Babe block, rather than error out. +/// +/// This is required to prevent rapid validation failure and subsequent +/// re-fetching of the same block from peers, which triggers the peers to +/// blacklist the offending node and refuse to connect with them until they +/// are restarted +struct AuraWrappedVerifier { + inner: AuraVerifier, + _phantom: std::marker::PhantomData, +} + +impl AuraWrappedVerifier { + pub fn new( + client: Arc, + create_inherent_data_providers: CIDP, + telemetry: Option, + check_for_equivocation: CheckForEquivocation, + compatibility_mode: sc_consensus_aura::CompatibilityMode, + ) -> Self { + let verifier_params = sc_consensus_aura::BuildVerifierParams:: { + client, + create_inherent_data_providers, + telemetry, + check_for_equivocation, + compatibility_mode, + }; + let verifier = + sc_consensus_aura::build_verifier::(verifier_params); + + AuraWrappedVerifier { + inner: verifier, + _phantom: std::marker::PhantomData, + } + } +} + +#[async_trait::async_trait] +impl Verifier for AuraWrappedVerifier> +where + C: ProvideRuntimeApi + Send + Sync + sc_client_api::backend::AuxStore, + C::Api: BlockBuilderApi + AuraApi + ApiExt, + CIDP: CreateInherentDataProviders + Send + Sync, + CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync, +{ + async fn verify(&self, block: BlockImportParams) -> Result, String> { + let number: NumberFor = *block.post_header().number(); + log::debug!("Verifying block: {:?}", number); + if is_babe_digest(block.header.digest()) { + // TODO: Use a BabeVerifier to verify Babe blocks. This will + // prevent rapid validation failure and subsequent re-fetching + // of the same block from peers, which triggers the peers to + // blacklist the offending node and refuse to connect with them until they + // are restarted. + // + // Unfortunately, BabeVerifier construction logic is NOT public outside of + // its crate in vanilla Polkadot SDK, so we are unable to use it until we + // migrate to our Polkadot SDK fork. + self.inner.verify(block).await + } else { + self.inner.verify(block).await + } + } +} + +/// Start an import queue for the Aura consensus algorithm. +pub fn import_queue( + params: ImportQueueParams, +) -> Result, sp_consensus::Error> +where + B: BlockT, + C::Api: BlockBuilderApi + AuraApi + ApiExt, + C: 'static + + ProvideRuntimeApi + + BlockOf + + Send + + Sync + + AuxStore + + UsageProvider + + HeaderBackend, + I: BlockImport + Send + Sync + 'static, + S: sp_core::traits::SpawnEssentialNamed, + CIDP: CreateInherentDataProviders + Sync + Send + 'static, + CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync, +{ + let verifier = AuraWrappedVerifier::>::new( + params.client, + params.create_inherent_data_providers, + params.telemetry, + params.check_for_equivocation, + params.compatibility_mode, + ); + + Ok(BasicQueue::new( + verifier, + Box::new(params.block_import), + params.justification_import, + params.spawner, + params.registry, + )) +} + +fn is_babe_digest(digest: &Digest) -> bool { + digest + .logs() + .iter() + .any(|d| matches!(d, DigestItem::PreRuntime(engine_id, _) if engine_id == &BABE_ENGINE_ID)) +} diff --git a/node/src/consensus/babe_consensus.rs b/node/src/consensus/babe_consensus.rs new file mode 100644 index 0000000000..723bc7f7b7 --- /dev/null +++ b/node/src/consensus/babe_consensus.rs @@ -0,0 +1,231 @@ +use crate::consensus::ConsensusMechanism; +use crate::consensus::StartAuthoringParams; +use crate::{ + client::{FullBackend, FullClient}, + conditional_evm_block_import::ConditionalEVMBlockImport, + ethereum::EthConfiguration, + service::{BIQ, FullSelectChain, GrandpaBlockImport}, +}; +use fc_consensus::FrontierBlockImport; +use jsonrpsee::Methods; +use node_subtensor_runtime::opaque::Block; +use sc_client_api::{AuxStore, BlockOf}; +use sc_consensus::{BlockImport, BoxBlockImport}; +use sc_consensus_babe::{BabeLink, BabeWorkerHandle}; +use sc_consensus_babe_rpc::{Babe, BabeApiServer}; +use sc_consensus_grandpa::BlockNumberOps; +use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, InherentDataProviderExt}; +use sc_service::{Configuration, TaskManager}; +use sc_telemetry::TelemetryHandle; +use sc_transaction_pool::TransactionPoolHandle; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::{HeaderBackend, HeaderMetadata}; +use sp_consensus::{Environment, Proposer, SelectChain, SyncOracle}; +use sp_consensus_aura::AuraApi; +use sp_consensus_aura::sr25519::AuthorityId; +use sp_consensus_babe::BabeApi; +use sp_consensus_slots::SlotDuration; +use sp_inherents::CreateInherentDataProviders; +use sp_keystore::KeystorePtr; +use sp_runtime::traits::NumberFor; +use std::{error::Error, sync::Arc}; + +pub struct BabeConsensus { + babe_link: Option>, + babe_worker_handle: Option>, +} + +impl ConsensusMechanism for BabeConsensus { + type InherentDataProviders = ( + sp_consensus_babe::inherents::InherentDataProvider, + sp_timestamp::InherentDataProvider, + ); + + fn start_authoring( + self, + task_manager: &mut TaskManager, + params: StartAuthoringParams, + ) -> Result<(), sp_consensus::Error> + where + C: ProvideRuntimeApi + + BlockOf + + AuxStore + + HeaderBackend + + HeaderMetadata + + Send + + Sync + + 'static, + C::Api: AuraApi + BabeApi, + SC: SelectChain + 'static, + I: BlockImport + Send + Sync + 'static, + PF: Environment + Send + Sync + 'static, + PF::Proposer: Proposer, + SO: SyncOracle + Send + Sync + Clone + 'static, + L: sc_consensus::JustificationSyncLink + 'static, + CIDP: CreateInherentDataProviders + Send + Sync + 'static, + CIDP::InherentDataProviders: InherentDataProviderExt + Send, + BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static, + Error: std::error::Error + Send + From + From + 'static, + { + let babe = sc_consensus_babe::start_babe::( + sc_consensus_babe::BabeParams { + keystore: params.keystore, + client: params.client, + select_chain: params.select_chain, + env: params.proposer_factory, + block_import: params.block_import, + sync_oracle: params.sync_oracle, + justification_sync_link: params.justification_sync_link, + create_inherent_data_providers: params.create_inherent_data_providers, + force_authoring: params.force_authoring, + backoff_authoring_blocks: params.backoff_authoring_blocks, + babe_link: self + .babe_link + .expect("Must build the import queue before starting authoring."), + block_proposal_slot_portion: params.block_proposal_slot_portion, + max_block_proposal_slot_portion: params.max_block_proposal_slot_portion, + telemetry: params.telemetry, + }, + )?; + + // the BABE authoring task is considered essential, i.e. if it + // fails we take down the service with it. + task_manager.spawn_essential_handle().spawn_blocking( + "babe-proposer", + Some("block-authoring"), + babe, + ); + + Ok(()) + } + + fn frontier_consensus_data_provider( + client: Arc, + ) -> Result>, sp_blockchain::Error> { + Ok(Box::new(fc_babe::BabeConsensusDataProvider::new(client)?)) + } + + fn create_inherent_data_providers( + slot_duration: SlotDuration, + ) -> Result> { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = + sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + } + + fn new() -> Self { + Self { + babe_link: None, + babe_worker_handle: None, + } + } + + fn build_biq(&mut self) -> Result + where + NumberFor: BlockNumberOps, + { + let build_import_queue = Box::new( + move |client: Arc, + backend: Arc, + config: &Configuration, + _eth_config: &EthConfiguration, + task_manager: &TaskManager, + telemetry: Option, + grandpa_block_import: GrandpaBlockImport, + transaction_pool: Arc>| { + let (babe_import, babe_link) = sc_consensus_babe::block_import( + sc_consensus_babe::configuration(&*client)?, + grandpa_block_import.clone(), + client.clone(), + )?; + + let conditional_block_import = ConditionalEVMBlockImport::new( + babe_import.clone(), + FrontierBlockImport::new(babe_import.clone(), client.clone()), + ); + + let slot_duration = babe_link.config().slot_duration(); + let create_inherent_data_providers = move |_, ()| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + let slot = + sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration( + *timestamp, + slot_duration, + ); + Ok((slot, timestamp)) + }; + + let (import_queue, babe_worker_handle) = + sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams { + link: babe_link.clone(), + block_import: conditional_block_import.clone(), + justification_import: Some(Box::new(grandpa_block_import)), + client, + select_chain: sc_consensus::LongestChain::new(backend.clone()), + create_inherent_data_providers, + spawner: &task_manager.spawn_essential_handle(), + registry: config.prometheus_registry(), + telemetry, + offchain_tx_pool_factory: OffchainTransactionPoolFactory::new( + transaction_pool, + ), + })?; + + self.babe_link = Some(babe_link); + self.babe_worker_handle = Some(babe_worker_handle); + Ok((import_queue, Box::new(babe_import) as BoxBlockImport)) + }, + ); + + Ok(build_import_queue) + } + + fn slot_duration(&self, _client: &FullClient) -> Result { + if let Some(ref babe_link) = self.babe_link { + Ok(babe_link.config().slot_duration()) + } else { + Err(sc_service::Error::Other( + "Babe link not initialized. Ensure that the import queue has been built before calling slot_duration.".to_string() + )) + } + } + + fn spawn_essential_handles( + &self, + _task_manager: &mut TaskManager, + _client: Arc, + _triggered: Option>, + ) -> Result<(), sc_service::Error> { + // No additional Babe handles required. + Ok(()) + } + + fn rpc_methods( + &self, + client: Arc, + keystore: KeystorePtr, + select_chain: FullSelectChain, + ) -> Result, sc_service::Error> { + if let Some(ref babe_worker_handle) = self.babe_worker_handle { + Ok(vec![ + Babe::new( + client.clone(), + babe_worker_handle.clone(), + keystore, + select_chain, + ) + .into_rpc() + .into(), + ]) + } else { + Err(sc_service::Error::Other( + "Babe link not initialized. Ensure that the import queue has been built before calling slot_duration.".to_string() + )) + } + } +} diff --git a/node/src/consensus/consensus_mechanism.rs b/node/src/consensus/consensus_mechanism.rs new file mode 100644 index 0000000000..d5efb642b3 --- /dev/null +++ b/node/src/consensus/consensus_mechanism.rs @@ -0,0 +1,136 @@ +use jsonrpsee::Methods; +use node_subtensor_runtime::opaque::Block; +use sc_client_api::AuxStore; +use sc_client_api::BlockOf; +use sc_consensus::BlockImport; +use sc_consensus_aura::AuraApi; +use sc_consensus_slots::BackoffAuthoringBlocksStrategy; +use sc_consensus_slots::InherentDataProviderExt; +use sc_consensus_slots::SlotProportion; +use sc_service::{TaskManager, error::Error as ServiceError}; +use sc_telemetry::TelemetryHandle; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_blockchain::HeaderMetadata; +use sp_consensus::Proposer; +use sp_consensus::SyncOracle; +use sp_consensus::{Environment, SelectChain}; +use sp_consensus_aura::sr25519::AuthorityId as AuraAuthorityId; +use sp_consensus_babe::BabeApi; +use sp_consensus_slots::SlotDuration; +use sp_inherents::CreateInherentDataProviders; +use sp_keystore::KeystorePtr; +use sp_runtime::traits::NumberFor; +use std::sync::Arc; +use std::sync::atomic::AtomicBool; + +use crate::client::FullClient; +use crate::service::BIQ; +use crate::service::FullSelectChain; + +pub struct StartAuthoringParams { + /// The duration of a slot. + pub slot_duration: SlotDuration, + /// The client to interact with the chain. + pub client: Arc, + /// A select chain implementation to select the best block. + pub select_chain: SC, + /// The block import. + pub block_import: I, + /// The proposer factory to build proposer instances. + pub proposer_factory: PF, + /// The sync oracle that can give us the current sync status. + pub sync_oracle: SO, + /// Hook into the sync module to control the justification sync process. + pub justification_sync_link: L, + /// Something that can create the inherent data providers. + pub create_inherent_data_providers: CIDP, + /// Should we force the authoring of blocks? + pub force_authoring: bool, + /// The backoff strategy when we miss slots. + pub backoff_authoring_blocks: Option, + /// The keystore used by the node. + pub keystore: KeystorePtr, + /// The proportion of the slot dedicated to proposing. + /// + /// The block proposing will be limited to this proportion of the slot from the starting of the + /// slot. However, the proposing can still take longer when there is some lenience factor + /// applied, because there were no blocks produced for some slots. + pub block_proposal_slot_portion: SlotProportion, + /// The maximum proportion of the slot dedicated to proposing with any lenience factor applied + /// due to no blocks being produced. + pub max_block_proposal_slot_portion: Option, + /// Telemetry instance used to report telemetry metrics. + pub telemetry: Option, +} + +/// All consensus mechanism specific node logic should be covered by this trait, +/// so files like service.rs and rpc.rs can be generic over consensus mechanisms. +pub trait ConsensusMechanism { + /// IDPs inserted into the block by the ConsensusMechanism. + type InherentDataProviders: sp_inherents::InherentDataProvider + + sc_consensus_slots::InherentDataProviderExt + + 'static; + + /// Creates a new instance of the ConsensusMechanism. + fn new() -> Self; + + /// Builds a `BIQ` that uses the ConsensusMechanism. + fn build_biq(&mut self) -> Result; + + /// Returns the slot duration. + fn slot_duration(&self, client: &FullClient) -> Result; + + /// Creates IDPs for the consensus mechanism. + fn create_inherent_data_providers( + slot_duration: SlotDuration, + ) -> Result>; + + /// Creates the frontier consensus data provider with this mechanism. + fn frontier_consensus_data_provider( + client: Arc, + ) -> Result>, sp_blockchain::Error>; + + /// Starts authoring process for the consensus mechanism. + fn start_authoring( + self, + task_manager: &mut TaskManager, + params: StartAuthoringParams, + ) -> Result<(), sp_consensus::Error> + where + C: ProvideRuntimeApi + + BlockOf + + AuxStore + + HeaderBackend + + HeaderMetadata + + Send + + Sync + + 'static, + C::Api: AuraApi + BabeApi, + SC: SelectChain + 'static, + I: BlockImport + Send + Sync + 'static, + PF: Environment + Send + Sync + 'static, + PF::Proposer: Proposer, + SO: SyncOracle + Send + Sync + Clone + 'static, + L: sc_consensus::JustificationSyncLink + 'static, + CIDP: CreateInherentDataProviders + Send + Sync + 'static, + CIDP::InherentDataProviders: InherentDataProviderExt + Send, + BS: BackoffAuthoringBlocksStrategy> + Send + Sync + 'static, + Error: std::error::Error + Send + From + From + 'static; + + /// Spawns any consensus mechanism specific essential handles. + fn spawn_essential_handles( + &self, + task_manager: &mut TaskManager, + client: Arc, + triggered: Option>, + ) -> Result<(), ServiceError>; + + /// Returns any consensus mechanism specific rpc methods to register. + fn rpc_methods( + &self, + client: Arc, + keystore: KeystorePtr, + select_chain: FullSelectChain, + ) -> Result, sc_service::Error>; +} diff --git a/node/src/consensus/mod.rs b/node/src/consensus/mod.rs new file mode 100644 index 0000000000..98dc2aa28f --- /dev/null +++ b/node/src/consensus/mod.rs @@ -0,0 +1,9 @@ +mod aura_consensus; +mod aura_wrapped_import_queue; +mod babe_consensus; +mod consensus_mechanism; + +pub use aura_consensus::AuraConsensus; +pub use babe_consensus::BabeConsensus; +pub use consensus_mechanism::ConsensusMechanism; +pub use consensus_mechanism::StartAuthoringParams; diff --git a/node/src/ethereum.rs b/node/src/ethereum.rs index 9179f30598..854826f18e 100644 --- a/node/src/ethereum.rs +++ b/node/src/ethereum.rs @@ -1,5 +1,4 @@ -use fc_aura::AuraConsensusDataProvider; -pub use fc_consensus::FrontierBlockImport; +use crate::rpc::EthDeps; use fc_rpc::{ Debug, DebugApiServer, Eth, EthApiServer, EthConfig, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub, EthPubSubApiServer, EthSigner, EthTask, Net, NetApiServer, Web3, @@ -28,7 +27,6 @@ use std::{ }; use crate::client::{FullBackend, FullClient}; -use crate::rpc::EthDeps; pub type FrontierBackend = fc_db::Backend; @@ -198,6 +196,7 @@ pub async fn spawn_frontier_tasks( fn extend_rpc_aet_api( io: &mut RpcModule<()>, deps: &EthDeps, + pending_consensus_data_provider: Option>>, ) -> Result<(), Box> where P: TransactionPool< @@ -233,9 +232,7 @@ where deps.execute_gas_limit_multiplier, deps.forced_parent_hashes.clone(), deps.pending_create_inherent_data_providers.clone(), - Some(Box::new(AuraConsensusDataProvider::new( - deps.client.clone(), - ))), + pending_consensus_data_provider, ) .replace_config::() .into_rpc(), @@ -393,6 +390,7 @@ pub fn create_eth( fc_mapping_sync::EthereumBlockNotification, >, >, + pending_consensus_data_provider: Option>>, ) -> Result, Box> where P: TransactionPool< @@ -406,7 +404,7 @@ where CIDP: CreateInherentDataProviders + Send + Clone + 'static, EC: EthConfig, { - extend_rpc_aet_api::(&mut io, &deps)?; + extend_rpc_aet_api::(&mut io, &deps, pending_consensus_data_provider)?; extend_rpc_eth_filter::(&mut io, &deps)?; extend_rpc_eth_pubsub::( &mut io, diff --git a/node/src/lib.rs b/node/src/lib.rs index 81cae51451..c447a07309 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -1,6 +1,8 @@ pub mod chain_spec; pub mod cli; pub mod client; +pub mod conditional_evm_block_import; +pub mod consensus; pub mod ethereum; pub mod rpc; pub mod service; diff --git a/node/src/main.rs b/node/src/main.rs index bb8cd8e8bc..64f25acc67 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -1,16 +1,17 @@ //! Substrate Node Subtensor CLI library. #![warn(missing_docs)] -mod chain_spec; -#[macro_use] -mod service; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; +mod chain_spec; mod cli; mod client; mod command; +mod conditional_evm_block_import; +mod consensus; mod ethereum; mod rpc; +mod service; fn main() -> sc_cli::Result<()> { command::run() diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 7f4f969bec..e34826462f 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -5,14 +5,19 @@ #![warn(missing_docs)] -use std::{collections::BTreeMap, sync::Arc}; +use std::sync::Arc; use futures::channel::mpsc; -pub use fc_rpc::EthBlockDataCacheTask; +use crate::{ + client::{FullBackend, FullClient}, + ethereum::create_eth, +}; +use fc_rpc::EthBlockDataCacheTask; pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool}; -use fc_storage::StorageOverride; -use jsonrpsee::RpcModule; +/// Frontier DB backend type. +pub use fc_storage::StorageOverride; +use jsonrpsee::{Methods, RpcModule}; use node_subtensor_runtime::opaque::Block; use sc_consensus_manual_seal::EngineCommand; use sc_network::service::traits::NetworkService; @@ -22,13 +27,9 @@ use sc_transaction_pool_api::TransactionPool; use sp_core::H256; use sp_inherents::CreateInherentDataProviders; use sp_runtime::{OpaqueExtrinsic, traits::BlakeTwo256, traits::Block as BlockT}; +use std::collections::BTreeMap; use subtensor_runtime_common::Hash; -use crate::{ - client::{FullBackend, FullClient}, - ethereum::create_eth, -}; - /// Extra dependencies for Ethereum compatibility. pub struct EthDeps { /// The client instance to use. @@ -103,6 +104,10 @@ pub fn create_full( fc_mapping_sync::EthereumBlockNotification, >, >, + frontier_pending_consensus_data_provider: Box< + dyn fc_rpc::pending::ConsensusDataProvider, + >, + other_methods: &[Methods], ) -> Result, Box> where P: TransactionPool< @@ -136,7 +141,7 @@ where module.merge(Swap::new(client.clone()).into_rpc())?; module.merge(System::new(client.clone(), pool.clone()).into_rpc())?; - module.merge(TransactionPayment::new(client).into_rpc())?; + module.merge(TransactionPayment::new(client.clone()).into_rpc())?; // Extend this RPC with a custom API by using the following syntax. // `YourRpcStruct` should have a reference to a client, which is needed @@ -151,12 +156,18 @@ where )?; } + // Other methods provided by the caller + for m in other_methods { + module.merge(m.clone())?; + } + // Ethereum compatibility RPCs let module = create_eth::<_, _, _, DefaultEthConfig>( module, eth, subscription_task_executor, pubsub_notification_sinks, + Some(frontier_pending_consensus_data_provider), )?; Ok(module) diff --git a/node/src/service.rs b/node/src/service.rs index ca23ddb03b..9bf3056b54 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,48 +1,60 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. +use crate::consensus::ConsensusMechanism; use futures::{FutureExt, channel::mpsc, future}; use node_subtensor_runtime::{RuntimeApi, TransactionConverter, opaque::Block}; use sc_chain_spec::ChainType; use sc_client_api::{Backend as BackendT, BlockBackend}; -use sc_consensus::{ - BasicQueue, BlockCheckParams, BlockImport, BlockImportParams, BoxBlockImport, ImportResult, -}; +use sc_consensus::{BasicQueue, BoxBlockImport}; use sc_consensus_grandpa::BlockNumberOps; use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging; +use sc_consensus_slots::SlotProportion; use sc_network::config::SyncMode; use sc_network_sync::strategy::warp::{WarpSyncConfig, WarpSyncProvider}; use sc_service::{Configuration, PartialComponents, TaskManager, error::Error as ServiceError}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, log}; use sc_transaction_pool::TransactionPoolHandle; use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use sp_consensus::Error as ConsensusError; -use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use sp_core::H256; -use sp_runtime::traits::{Block as BlockT, Header, NumberFor}; +use sp_runtime::traits::{Block as BlockT, NumberFor}; use std::collections::HashSet; use std::str::FromStr; +use std::sync::atomic::AtomicBool; use std::{cell::RefCell, path::Path}; -use std::{marker::PhantomData, sync::Arc, time::Duration}; +use std::{sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; use crate::cli::Sealing; use crate::client::{FullBackend, FullClient, HostFunctions, RuntimeExecutor}; use crate::ethereum::{ - BackendType, EthConfiguration, FrontierBackend, FrontierBlockImport, FrontierPartialComponents, - StorageOverride, StorageOverrideHandler, db_config_dir, new_frontier_partial, - spawn_frontier_tasks, + BackendType, EthConfiguration, FrontierBackend, FrontierPartialComponents, StorageOverride, + StorageOverrideHandler, db_config_dir, new_frontier_partial, spawn_frontier_tasks, }; /// The minimum period of blocks on which justifications will be /// imported and generated. const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512; -type FullSelectChain = sc_consensus::LongestChain; -type GrandpaBlockImport = +pub type FullSelectChain = sc_consensus::LongestChain; +pub type GrandpaBlockImport = sc_consensus_grandpa::GrandpaBlockImport; type GrandpaLinkHalf = sc_consensus_grandpa::LinkHalf; - -pub fn new_partial( +#[allow(clippy::upper_case_acronyms)] +pub type BIQ<'a> = Box< + dyn FnOnce( + Arc, + Arc, + &Configuration, + &EthConfiguration, + &TaskManager, + Option, + GrandpaBlockImport, + Arc>, + ) -> Result<(BasicQueue, BoxBlockImport), sc_service::Error> + + 'a, +>; + +pub fn new_partial( config: &Configuration, eth_config: &EthConfiguration, build_import_queue: BIQ, @@ -62,17 +74,7 @@ pub fn new_partial( ), >, ServiceError, -> -where - BIQ: FnOnce( - Arc, - &Configuration, - &EthConfiguration, - &TaskManager, - Option, - GrandpaBlockImport, - ) -> Result<(BasicQueue, BoxBlockImport), ServiceError>, -{ +> { let telemetry = config .telemetry_endpoints .clone() @@ -166,15 +168,6 @@ where } }; - let (import_queue, block_import) = build_import_queue( - client.clone(), - config, - eth_config, - &task_manager, - telemetry.as_ref().map(|x| x.handle()), - grandpa_block_import, - )?; - let transaction_pool = Arc::from( sc_transaction_pool::Builder::new( task_manager.spawn_essential_handle(), @@ -186,6 +179,17 @@ where .build(), ); + let (import_queue, block_import) = build_import_queue( + client.clone(), + backend.clone(), + config, + eth_config, + &task_manager, + telemetry.as_ref().map(|x| x.handle()), + grandpa_block_import, + transaction_pool.clone(), + )?; + Ok(PartialComponents { client, backend, @@ -204,131 +208,24 @@ where }) } -pub struct ConditionalEVMBlockImport { - inner: I, - frontier_block_import: F, - _marker: PhantomData, -} - -impl Clone for ConditionalEVMBlockImport -where - B: BlockT, - I: Clone + BlockImport, - F: Clone + BlockImport, -{ - fn clone(&self) -> Self { - ConditionalEVMBlockImport { - inner: self.inner.clone(), - frontier_block_import: self.frontier_block_import.clone(), - _marker: PhantomData, - } - } -} - -impl ConditionalEVMBlockImport -where - B: BlockT, - I: BlockImport, - I::Error: Into, - F: BlockImport, - F::Error: Into, -{ - pub fn new(inner: I, frontier_block_import: F) -> Self { - Self { - inner, - frontier_block_import, - _marker: PhantomData, - } - } -} - -#[async_trait::async_trait] -impl BlockImport for ConditionalEVMBlockImport -where - B: BlockT, - I: BlockImport + Send + Sync, - I::Error: Into, - F: BlockImport + Send + Sync, - F::Error: Into, -{ - type Error = ConsensusError; - - async fn check_block(&self, block: BlockCheckParams) -> Result { - self.inner.check_block(block).await.map_err(Into::into) - } - - async fn import_block(&self, block: BlockImportParams) -> Result { - // 4345556 - mainnet runtime upgrade block with Frontier - if *block.header.number() < 4345557u32.into() { - self.inner.import_block(block).await.map_err(Into::into) - } else { - self.frontier_block_import - .import_block(block) - .await - .map_err(Into::into) - } - } -} - -/// Build the import queue for the template runtime (aura + grandpa). -pub fn build_aura_grandpa_import_queue( - client: Arc, - config: &Configuration, - _eth_config: &EthConfiguration, - task_manager: &TaskManager, - telemetry: Option, - grandpa_block_import: GrandpaBlockImport, -) -> Result<(BasicQueue, BoxBlockImport), ServiceError> -where - NumberFor: BlockNumberOps, -{ - let conditional_block_import = ConditionalEVMBlockImport::new( - grandpa_block_import.clone(), - FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()), - ); - - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - let create_inherent_data_providers = move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - let slot = - sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - Ok((slot, timestamp)) - }; - - let import_queue = sc_consensus_aura::import_queue::( - sc_consensus_aura::ImportQueueParams { - block_import: conditional_block_import.clone(), - justification_import: Some(Box::new(grandpa_block_import.clone())), - client, - create_inherent_data_providers, - spawner: &task_manager.spawn_essential_handle(), - registry: config.prometheus_registry(), - check_for_equivocation: Default::default(), - telemetry, - compatibility_mode: sc_consensus_aura::CompatibilityMode::None, - }, - ) - .map_err::(Into::into)?; - - Ok((import_queue, Box::new(conditional_block_import))) -} - /// Build the import queue for the template runtime (manual seal). +#[allow(clippy::too_many_arguments)] +#[cfg(feature = "runtime-benchmarks")] pub fn build_manual_seal_import_queue( client: Arc, + _backend: Arc, config: &Configuration, _eth_config: &EthConfiguration, task_manager: &TaskManager, _telemetry: Option, grandpa_block_import: GrandpaBlockImport, + _transaction_pool_handle: Arc>, ) -> Result<(BasicQueue, BoxBlockImport), ServiceError> { - let conditional_block_import = ConditionalEVMBlockImport::new( - grandpa_block_import.clone(), - FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()), - ); + let conditional_block_import = + crate::conditional_evm_block_import::ConditionalEVMBlockImport::new( + grandpa_block_import.clone(), + fc_consensus::FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()), + ); Ok(( sc_consensus_manual_seal::import_queue( Box::new(conditional_block_import.clone()), @@ -340,14 +237,16 @@ pub fn build_manual_seal_import_queue( } /// Builds a new service for a full client. -pub async fn new_full( +pub async fn new_full( mut config: Configuration, eth_config: EthConfiguration, sealing: Option, + custom_service_signal: Option>, ) -> Result where NumberFor: BlockNumberOps, NB: sc_network::NetworkBackend::Hash>, + CM: ConsensusMechanism, { // Substrate doesn't seem to support fast sync option in our configuration. if matches!(config.network.sync_mode, SyncMode::LightState { .. }) { @@ -358,11 +257,8 @@ where return Err(ServiceError::Other("Unsupported sync mode".to_string())); } - let build_import_queue = if sealing.is_some() { - build_manual_seal_import_queue - } else { - build_aura_grandpa_import_queue - }; + let mut consensus_mechanism = CM::new(); + let build_import_queue = consensus_mechanism.build_biq()?; let PartialComponents { client, @@ -375,6 +271,12 @@ where other: (mut telemetry, block_import, grandpa_link, frontier_backend, storage_override), } = new_partial(&config, ð_config, build_import_queue)?; + consensus_mechanism.spawn_essential_handles( + &mut task_manager, + client.clone(), + custom_service_signal, + )?; + let FrontierPartialComponents { filter_pool, fee_history_cache, @@ -530,21 +432,15 @@ where prometheus_registry.clone(), )); - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - let pending_create_inherent_data_providers = move |_, ()| async move { - let current = sp_timestamp::InherentDataProvider::from_system_time(); - let next_slot = current - .timestamp() - .as_millis() - .saturating_add(slot_duration.as_millis()); - let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into()); - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - Ok((slot, timestamp)) - }; + let slot_duration = consensus_mechanism.slot_duration(&client)?; + let pending_create_inherent_data_providers = + move |_, ()| async move { CM::create_inherent_data_providers(slot_duration) }; + let rpc_methods = consensus_mechanism.rpc_methods( + client.clone(), + keystore_container.keystore(), + select_chain.clone(), + )?; Box::new(move |subscription_task_executor| { let eth_deps = crate::rpc::EthDeps { client: client.clone(), @@ -583,6 +479,8 @@ where deps, subscription_task_executor, pubsub_notification_sinks.clone(), + CM::frontier_consensus_data_provider(client.clone())?, + rpc_methods.as_slice(), ) .map_err(Into::into) }) @@ -624,7 +522,7 @@ where sealing, client, transaction_pool, - select_chain, + select_chain.clone(), block_import, &task_manager, prometheus_registry.as_ref(), @@ -644,18 +542,13 @@ where telemetry.as_ref().map(|x| x.handle()), ); - let slot_duration = sc_consensus_aura::slot_duration(&*client)?; - let create_inherent_data_providers = move |_, ()| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); - Ok((slot, timestamp)) - }; + let slot_duration = consensus_mechanism.slot_duration(&client)?; + let create_inherent_data_providers = + move |_, ()| async move { CM::create_inherent_data_providers(slot_duration) }; - let aura = sc_consensus_aura::start_aura::( - sc_consensus_aura::StartAuraParams { + consensus_mechanism.start_authoring( + &mut task_manager, + crate::consensus::StartAuthoringParams { slot_duration, client, select_chain, @@ -667,17 +560,11 @@ where force_authoring, backoff_authoring_blocks, keystore: keystore_container.keystore(), - block_proposal_slot_portion: sc_consensus_aura::SlotProportion::new(2f32 / 3f32), + block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32), max_block_proposal_slot_portion: None, telemetry: telemetry.as_ref().map(|x| x.handle()), - compatibility_mode: sc_consensus_aura::CompatibilityMode::None, }, )?; - // the AURA authoring task is considered essential, i.e. if it - // fails we take down the service with it. - task_manager - .spawn_essential_handle() - .spawn_blocking("aura", Some("block-authoring"), aura); } if enable_grandpa { @@ -731,22 +618,35 @@ where Ok(task_manager) } -pub async fn build_full( +pub async fn build_full( config: Configuration, eth_config: EthConfiguration, sealing: Option, + custom_service_signal: Option>, ) -> Result { match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => { - new_full::>(config, eth_config, sealing).await + new_full::, CM>( + config, + eth_config, + sealing, + custom_service_signal, + ) + .await } sc_network::config::NetworkBackendType::Litep2p => { - new_full::(config, eth_config, sealing).await + new_full::( + config, + eth_config, + sealing, + custom_service_signal, + ) + .await } } } -pub fn new_chain_ops( +pub fn new_chain_ops( config: &mut Configuration, eth_config: &EthConfiguration, ) -> Result< @@ -760,6 +660,7 @@ pub fn new_chain_ops( ServiceError, > { config.keystore = sc_service::config::KeystoreConfig::InMemory; + let mut consensus_mechanism = CM::new(); let PartialComponents { client, backend, @@ -767,7 +668,7 @@ pub fn new_chain_ops( task_manager, other, .. - } = new_partial(config, eth_config, build_aura_grandpa_import_queue)?; + } = new_partial(config, eth_config, consensus_mechanism.build_biq()?)?; Ok((client, backend, import_queue, task_manager, other.3)) } @@ -796,7 +697,7 @@ fn run_manual_seal_authorship( thread_local!(static TIMESTAMP: RefCell = const { RefCell::new(0) }); /// Provide a mock duration starting at 0 in millisecond for timestamp inherent. - /// Each call will increment timestamp by slot_duration making Aura think time has passed. + /// Each call will increment timestamp by slot_duration making the consensus logic think time has passed. struct MockTimestampInherentDataProvider; #[async_trait::async_trait] diff --git a/pallets/collective/src/lib.rs b/pallets/collective/src/lib.rs index 4a3aea5a30..f4f531e206 100644 --- a/pallets/collective/src/lib.rs +++ b/pallets/collective/src/lib.rs @@ -42,6 +42,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![recursion_limit = "128"] +use codec::DecodeWithMemTracking; use frame_support::{ dispatch::{DispatchResultWithPostInfo, GetDispatchInfo, Pays, PostDispatchInfo}, ensure, diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 5479789077..d4055346cd 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -157,4 +157,6 @@ try-runtime = [ "pallet-crowdloan/try-runtime", ] pow-faucet = [] -fast-blocks = [] +fast-blocks = [ + "subtensor-runtime-common/fast-blocks" +] diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index a2bf29c87a..d7e9b9ab1e 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -413,7 +413,7 @@ mod dispatches { /// - Attempting to set weights with max value exceeding limit. /// #[pallet::call_index(8)] - #[pallet::weight((Weight::from_parts(2_033_000, 0) + #[pallet::weight((Weight::from_parts(2_684_000, 0) .saturating_add(T::DbWeight::get().reads(0_u64)) .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] pub fn set_tao_weights( @@ -1045,7 +1045,7 @@ mod dispatches { /// #[pallet::call_index(69)] #[pallet::weight(( - Weight::from_parts(4_690_000, 0) + Weight::from_parts(3_475_000, 0) .saturating_add(T::DbWeight::get().reads(0)) .saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, @@ -1327,7 +1327,7 @@ mod dispatches { /// - Consider adding checks to prevent scheduling too far into the future. /// TODO: Benchmark this call #[pallet::call_index(73)] - #[pallet::weight((Weight::from_parts(47_820_000, 0) + #[pallet::weight((Weight::from_parts(27_920_000, 0) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Operational, Pays::Yes))] pub fn schedule_swap_coldkey( @@ -1575,7 +1575,7 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(83)] - #[pallet::weight((Weight::from_parts(21_160_000, 0) + #[pallet::weight((Weight::from_parts(28_910_000, 0) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(0)), DispatchClass::Operational, Pays::Yes))] pub fn unstake_all(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -1608,7 +1608,7 @@ mod dispatches { /// * `TxRateLimitExceeded`: /// - Thrown if key has hit transaction rate limit #[pallet::call_index(84)] - #[pallet::weight((Weight::from_parts(291_600_000, 0) + #[pallet::weight((Weight::from_parts(395_800_000, 0) .saturating_add(T::DbWeight::get().reads(33)) .saturating_add(T::DbWeight::get().writes(16)), DispatchClass::Operational, Pays::Yes))] pub fn unstake_all_alpha(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult { @@ -2075,7 +2075,7 @@ mod dispatches { /// at which or better (higher) the staking should execute. /// Without limit_price it remove all the stake similar to `remove_stake` extrinsic #[pallet::call_index(103)] - #[pallet::weight((Weight::from_parts(317_700_000, 10142) + #[pallet::weight((Weight::from_parts(421_500_000, 10142) .saturating_add(T::DbWeight::get().reads(30_u64)) .saturating_add(T::DbWeight::get().writes(14_u64)), DispatchClass::Normal, Pays::Yes))] pub fn remove_stake_full_limit( @@ -2156,7 +2156,7 @@ mod dispatches { /// Emits a `SymbolUpdated` event on success. #[pallet::call_index(112)] #[pallet::weight(( - Weight::from_parts(19_290_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), + Weight::from_parts(28_910_000, 0).saturating_add(T::DbWeight::get().reads_writes(4, 1)), DispatchClass::Operational, Pays::Yes ))] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 598dab5edf..7c56ff48e3 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -44,6 +44,7 @@ frame-metadata-hash-extension.workspace = true sp-api.workspace = true sp-block-builder.workspace = true sp-consensus-aura.workspace = true +sp-consensus-babe.workspace = true sp-core.workspace = true sp-storage.workspace = true sp-genesis-builder.workspace = true @@ -54,6 +55,7 @@ sp-session.workspace = true sp-std.workspace = true sp-transaction-pool.workspace = true sp-version.workspace = true +sp-authority-discovery.workspace = true subtensor-runtime-common.workspace = true subtensor-precompiles.workspace = true @@ -93,6 +95,27 @@ pallet-registry.workspace = true # Metadata commitment pallet pallet-commitments.workspace = true +# NPoS +frame-election-provider-support = { workspace = true } +pallet-authority-discovery = { workspace = true } +pallet-babe = { workspace = true } +pallet-bags-list = { workspace = true } +pallet-staking = { workspace = true } +pallet-staking-runtime-api = { workspace = true } +pallet-session = { workspace = true } +pallet-fast-unstake = { workspace = true } +pallet-nomination-pools = { workspace = true } +pallet-nomination-pools-runtime-api = { workspace = true } +pallet-offences = { workspace = true } +pallet-authorship = { workspace = true } +pallet-election-provider-multi-phase = { workspace = true } +pallet-staking-reward-fn = { workspace = true } +pallet-staking-reward-curve = { workspace = true } +sp-staking = { workspace = true } +sp-npos-elections = { workspace = true } +sp-consensus-slots = { workspace = true } +sp-consensus-grandpa = { workspace = true } + # Frontier fp-evm.workspace = true fp-rpc.workspace = true @@ -152,11 +175,6 @@ std = [ "frame-system/std", "frame-try-runtime/std", "pallet-subtensor/std", - "pallet-subtensor-swap/std", - "pallet-subtensor-swap-runtime-api/std", - "substrate-fixed/std", - "subtensor-swap-interface/std", - "pallet-aura/std", "pallet-balances/std", "pallet-grandpa/std", "pallet-insecure-randomness-collective-flip/std", @@ -174,7 +192,6 @@ std = [ "precompile-utils/std", "sp-api/std", "sp-block-builder/std", - "sp-consensus-aura/std", "sp-core/std", "sp-inherents/std", "sp-offchain/std", @@ -199,6 +216,24 @@ std = [ "subtensor-precompiles/std", "subtensor-runtime-common/std", "pallet-crowdloan/std", + "pallet-babe/std", + "pallet-session/std", + "pallet-staking/std", + "pallet-election-provider-multi-phase/std", + "frame-election-provider-support/std", + "pallet-authority-discovery/std", + "pallet-authorship/std", + "pallet-bags-list/std", + "pallet-fast-unstake/std", + "pallet-nomination-pools-runtime-api/std", + "pallet-nomination-pools/std", + "pallet-offences/std", + "pallet-staking-reward-fn/std", + "pallet-staking-runtime-api/std", + "sp-authority-discovery/std", + "sp-consensus-babe/std", + "sp-npos-elections/std", + "sp-staking/std", # Frontier "fp-evm/std", "fp-rpc/std", @@ -221,6 +256,14 @@ std = [ "rand_chacha/std", "sha2/std", "w3f-bls/std", + "pallet-aura/std", + "sp-consensus-aura/std", + "sp-consensus-grandpa/std", + "sp-consensus-slots/std", + "substrate-fixed/std", + "pallet-subtensor-swap/std", + "pallet-subtensor-swap-runtime-api/std", + "subtensor-swap-interface/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -230,12 +273,10 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "pallet-transaction-payment/runtime-benchmarks", "pallet-utility/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-safe-mode/runtime-benchmarks", "pallet-subtensor/runtime-benchmarks", - "pallet-subtensor-swap/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-membership/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", @@ -247,12 +288,23 @@ runtime-benchmarks = [ "pallet-scheduler/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-crowdloan/runtime-benchmarks", + "pallet-babe/runtime-benchmarks", + "pallet-staking/runtime-benchmarks", + "pallet-election-provider-multi-phase/runtime-benchmarks", + "frame-election-provider-support/runtime-benchmarks", + "pallet-bags-list/runtime-benchmarks", + "pallet-fast-unstake/runtime-benchmarks", + "pallet-nomination-pools/runtime-benchmarks", + "pallet-offences/runtime-benchmarks", + "sp-staking/runtime-benchmarks", # EVM + Frontier "pallet-ethereum/runtime-benchmarks", "pallet-evm/runtime-benchmarks", "pallet-hotfix-sufficients/runtime-benchmarks", "pallet-drand/runtime-benchmarks", + "pallet-transaction-payment/runtime-benchmarks", + "pallet-subtensor-swap/runtime-benchmarks", # Smart Tx fees pallet "subtensor-transaction-fee/runtime-benchmarks", @@ -262,7 +314,6 @@ try-runtime = [ "frame-executive/try-runtime", "frame-system/try-runtime", "frame-support/try-runtime", - "pallet-aura/try-runtime", "pallet-sudo/try-runtime", "pallet-balances/try-runtime", "pallet-grandpa/try-runtime", @@ -284,6 +335,17 @@ try-runtime = [ "pallet-commitments/try-runtime", "pallet-registry/try-runtime", "pallet-crowdloan/try-runtime", + "pallet-babe/try-runtime", + "pallet-session/try-runtime", + "pallet-staking/try-runtime", + "pallet-election-provider-multi-phase/try-runtime", + "frame-election-provider-support/try-runtime", + "pallet-authority-discovery/try-runtime", + "pallet-authorship/try-runtime", + "pallet-bags-list/try-runtime", + "pallet-fast-unstake/try-runtime", + "pallet-nomination-pools/try-runtime", + "pallet-offences/try-runtime", # EVM + Frontier "fp-self-contained/try-runtime", @@ -292,5 +354,6 @@ try-runtime = [ "pallet-evm/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-drand/try-runtime", + "pallet-aura/try-runtime", ] metadata-hash = ["substrate-wasm-builder/metadata-hash"] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index dde492960b..0984bb564a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -25,9 +25,7 @@ use frame_support::{ }; use frame_system::{EnsureNever, EnsureRoot, EnsureRootWithSuccess, RawOrigin}; use pallet_commitments::{CanCommit, OnMetadataCommitment}; -use pallet_grandpa::{ - AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, fg_primitives, -}; +use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives}; use pallet_registry::CanRegisterIdentity; use pallet_subtensor::rpc_info::{ delegate_info::DelegateInfo, @@ -40,6 +38,8 @@ use pallet_subtensor::rpc_info::{ }; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_consensus_babe::BabeConfiguration; +use sp_consensus_babe::BabeEpochConfiguration; use sp_core::{ H160, H256, OpaqueMetadata, U256, crypto::{ByteArray, KeyTypeId}, @@ -49,8 +49,8 @@ use sp_runtime::generic::Era; use sp_runtime::{ AccountId32, ApplyExtrinsicResult, ConsensusEngineId, generic, impl_opaque_keys, traits::{ - AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, NumberFor, - One, PostDispatchInfoOf, UniqueSaturatedInto, Verify, + AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, One, + PostDispatchInfoOf, UniqueSaturatedInto, Verify, }, transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError}, }; @@ -1851,7 +1851,7 @@ impl_runtime_apis! { } impl fg_primitives::GrandpaApi for Runtime { - fn grandpa_authorities() -> GrandpaAuthorityList { + fn grandpa_authorities() -> Vec<(GrandpaId, u64)> { Grandpa::grandpa_authorities() } @@ -1860,18 +1860,23 @@ impl_runtime_apis! { } fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: fg_primitives::EquivocationProof< + equivocation_proof: fg_primitives::EquivocationProof< ::Hash, - NumberFor, + sp_runtime::traits::NumberFor, >, - _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, + key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, ) -> Option<()> { - None + let key_owner_proof = key_owner_proof.decode()?; + + Grandpa::submit_unsigned_equivocation_report( + equivocation_proof, + key_owner_proof, + ) } fn generate_key_ownership_proof( _set_id: fg_primitives::SetId, - _authority_id: GrandpaId, + _authority_id: fg_primitives::AuthorityId, ) -> Option { // NOTE: this is the only implementation possible since we've // defined our key owner proof type as a bottom type (i.e. a type @@ -2362,6 +2367,60 @@ impl_runtime_apis! { } } + impl sp_consensus_babe::BabeApi for Runtime { + fn configuration() -> BabeConfiguration { + let config = BabeEpochConfiguration::default(); + BabeConfiguration { + slot_duration: Default::default(), + epoch_length: Default::default(), + authorities: vec![], + randomness: Default::default(), + c: config.c, + allowed_slots: config.allowed_slots, + + } + } + + fn current_epoch_start() -> sp_consensus_babe::Slot { + Default::default() + } + + fn current_epoch() -> sp_consensus_babe::Epoch { + sp_consensus_babe::Epoch { + epoch_index: Default::default(), + start_slot: Default::default(), + duration: Default::default(), + authorities: vec![], + randomness: Default::default(), + config: BabeEpochConfiguration::default(), + } + } + + fn next_epoch() -> sp_consensus_babe::Epoch { + sp_consensus_babe::Epoch { + epoch_index: Default::default(), + start_slot: Default::default(), + duration: Default::default(), + authorities: vec![], + randomness: Default::default(), + config: BabeEpochConfiguration::default(), + } + } + + fn generate_key_ownership_proof( + _slot: sp_consensus_babe::Slot, + _authority_id: sp_consensus_babe::AuthorityId, + ) -> Option { + None + } + + fn submit_report_equivocation_unsigned_extrinsic( + _equivocation_proof: sp_consensus_babe::EquivocationProof<::Header>, + _key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof, + ) -> Option<()> { + None + } + } impl pallet_subtensor_swap_runtime_api::SwapRuntimeApi for Runtime { fn current_alpha_price(netuid: u16) -> u64 { diff --git a/zepter.yaml b/zepter.yaml index e448fa228c..681f802066 100644 --- a/zepter.yaml +++ b/zepter.yaml @@ -12,7 +12,7 @@ workflows: # Check that `A` activates the features of `B`. "propagate-feature", # These are the features to check: - "--features=try-runtime,runtime-benchmarks,std,sql,rocksdb,txpool", + "--features=try-runtime,runtime-benchmarks,std,sql,rocksdb,txpool,fast-blocks", # Do not try to add a new section into `[features]` of `A` only because `B` expose that feature. There are edge-cases where this is still needed, but we can add them manually. "--left-side-feature-missing=ignore", # Ignore the case that `A` it outside of the workspace. Otherwise it will report errors in external dependencies that we have no influence on.