Skip to content

Feat/subnet leasing #1582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: devnet-ready
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5a6823f
added proxy/crowdloan/common deps to subtensor pallet
l0r1s Apr 28, 2025
6562024
added new proxy type for lease beneficiary
l0r1s Apr 28, 2025
b6af8c0
wip leasing logic
l0r1s Apr 28, 2025
23d1058
added new overflow error
l0r1s Apr 28, 2025
cd792cd
hooked leasing into coinbase
l0r1s Apr 28, 2025
4f63830
added remove lease benef to ProxyInterface + introduce constant for m…
l0r1s Apr 28, 2025
6101943
added logic to terminate lease + rework logic
l0r1s Apr 28, 2025
97f2af9
wip extrinsics
l0r1s Apr 28, 2025
8b1c1b3
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s Apr 29, 2025
491add2
fix terminate lease ownership transfer
l0r1s Apr 29, 2025
670d528
added tests + update logic
l0r1s Apr 30, 2025
38e5a9b
fix logging
l0r1s Apr 30, 2025
658f297
add missing tests + fix logic
l0r1s Apr 30, 2025
4afac1a
fix ambiguous T::Currency
l0r1s Apr 30, 2025
c9d4e55
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s Apr 30, 2025
e64d8e5
fix refund
l0r1s May 1, 2025
b240390
fix tests following refund update
l0r1s May 1, 2025
d22b83f
added cost to lease struct
l0r1s May 1, 2025
aea283d
added check for refunded contributors
l0r1s May 1, 2025
d259d41
added missing documentation
l0r1s May 1, 2025
af04345
commit Cargo.lock
l0r1s May 1, 2025
55d2298
fix mock for admin-utils
l0r1s May 1, 2025
2d1050f
commit Cargo.lock
l0r1s May 1, 2025
699f970
cargo fix
l0r1s May 1, 2025
3659a2a
fix hotkey ownership when terminating lease
l0r1s May 2, 2025
7b9ded2
wrong file for clippy allow
l0r1s May 2, 2025
723c064
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s May 2, 2025
5ab8843
wrong file for clippy allow undo
l0r1s May 2, 2025
98fe3e8
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s May 8, 2025
6c8ba5d
fix mocks missing MaxContributors
l0r1s May 8, 2025
cc386ac
fix setup_crowdloan in test
l0r1s May 8, 2025
5da8a1f
distribute lease dividends only at interval
l0r1s May 8, 2025
a977440
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s May 12, 2025
eec531a
added benchmarks for leasing
l0r1s May 12, 2025
5542e0a
fix leasing shares removal
l0r1s May 12, 2025
b858aee
add correct weight and weight refund for subnet lease
l0r1s May 12, 2025
25fac46
commit Cargo.lock
l0r1s May 12, 2025
3e69fc7
commit Cargo.lock
l0r1s May 12, 2025
fc2d6a5
fix issue with LeaseDividendsDistributionInterval
l0r1s May 12, 2025
05fb70c
fix zepter issues
l0r1s May 12, 2025
b66cec2
debug gh action
l0r1s May 12, 2025
98aaeaa
try to use fork ref for clean merges check
l0r1s May 12, 2025
700e918
try to fix the run-benchmarks workflow
l0r1s May 12, 2025
96ae67c
disallow skipping benchmarks for PR from forks
l0r1s May 12, 2025
812bc59
extract subnet leasing weights + match to if let else
l0r1s May 13, 2025
b92c4b6
from if let else to let else
l0r1s May 13, 2025
0b9e977
bump spec version to 269
l0r1s May 13, 2025
2c2842c
Merge branch 'devnet-ready' into feat/subnet-leasing
l0r1s May 15, 2025
b81b1fd
make lease benchmarks as extra to avoid failure due to parameter
l0r1s May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .github/workflows/require-clean-merges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
else
echo "MERGE_BRANCHES=devnet-ready devnet testnet main" >> $GITHUB_ENV
fi

- name: Add Fork Remote and Fetch PR Branch
if: github.event.pull_request.head.repo.fork == true
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
PR_FORK="${{ github.event.pull_request.head.repo.clone_url }}"
git remote add fork $PR_FORK
git fetch --no-tags --prune fork $PR_BRANCH

- name: Check Merge Cleanliness
run: |
Expand All @@ -42,25 +50,33 @@ jobs:
echo "Fetching all branches..."
git fetch --all --prune

if [[ "${{github.event.pull_request.head.repo.fork}}" == "true" ]]; then
PR_BRANCH_REF="fork/$PR_BRANCH"
echo "Using fork reference: $PR_BRANCH_REF"
else
PR_BRANCH_REF="origin/$PR_BRANCH"
echo "Using origin reference: $PR_BRANCH_REF"
fi

echo "Checking out PR branch: $PR_BRANCH"
git checkout $PR_BRANCH
git reset --hard origin/$PR_BRANCH
git checkout $PR_BRANCH_REF
git reset --hard $PR_BRANCH_REF

# Configure a temporary Git identity to allow merging
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"

for branch in $MERGE_BRANCHES; do
echo "Checking merge from $branch into $PR_BRANCH..."
echo "Checking merge from $branch into $PR_BRANCH_REF..."

# Ensure PR branch is up to date
git reset --hard origin/$PR_BRANCH
git reset --hard $PR_BRANCH_REF

# Merge without committing to check for conflicts
if git merge --no-commit --no-ff origin/$branch; then
echo "✅ Merge from $branch into $PR_BRANCH is clean."
echo "✅ Merge from $branch into $PR_BRANCH_REF is clean."
else
echo "❌ Merge conflict detected when merging $branch into $PR_BRANCH"
echo "❌ Merge conflict detected when merging $branch into $PR_BRANCH_REF"
exit 1
fi

Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/run-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ jobs:
if: ${{ env.SKIP_BENCHMARKS != '1' }}
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Install GitHub CLI
if: ${{ env.SKIP_BENCHMARKS != '1' }}
# We disallow skipping benchmarks for PRs from forks to avoid exposing secrets
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
sudo apt-get update
sudo apt-get install -y gh
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token

- name: Check skip label
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand All @@ -50,7 +52,7 @@ jobs:
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler

- name: Check skip label
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand All @@ -66,7 +68,7 @@ jobs:
toolchain: stable

- name: Check skip label
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand All @@ -81,7 +83,7 @@ jobs:
key: bench-${{ hashFiles('**/Cargo.lock') }}

- name: Check skip label
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand All @@ -95,7 +97,7 @@ jobs:
cargo build --profile production -p node-subtensor --features runtime-benchmarks

- name: Check skip label
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand All @@ -110,7 +112,7 @@ jobs:
./scripts/benchmark_action.sh

- name: Check skip label after run
if: ${{ env.SKIP_BENCHMARKS != '1' }}
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && env.SKIP_BENCHMARKS != '1' }}
run: |
labels=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name')
if echo "$labels" | grep -q "skip-validate-benchmarks"; then
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum ProxyType {
RootWeights,
ChildKeys,
SudoUncheckedSetCode,
SubnetLeaseBeneficiary, // Used to operate the leased subnet
}

impl Default for ProxyType {
Expand Down
8 changes: 8 additions & 0 deletions pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pallet-balances = { workspace = true, features = ["std"] }
pallet-scheduler = { workspace = true }
pallet-grandpa = { workspace = true }
sp-std = { workspace = true }
pallet-crowdloan = { workspace = true, default-features = false }
pallet-preimage = { workspace = true, default-features = false }

[features]
default = ["std"]
Expand All @@ -57,6 +59,8 @@ std = [
"pallet-grandpa/std",
"pallet-scheduler/std",
"pallet-subtensor/std",
"pallet-crowdloan/std",
"pallet-preimage/std",
"scale-info/std",
"sp-consensus-aura/std",
"sp-consensus-grandpa/std",
Expand All @@ -77,6 +81,8 @@ runtime-benchmarks = [
"pallet-grandpa/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-subtensor/runtime-benchmarks",
"pallet-crowdloan/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
Expand All @@ -88,5 +94,7 @@ try-runtime = [
"pallet-grandpa/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-subtensor/try-runtime",
"pallet-crowdloan/try-runtime",
"pallet-preimage/try-runtime",
"sp-runtime/try-runtime",
]
46 changes: 45 additions & 1 deletion pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]

use frame_support::{
assert_ok, derive_impl, parameter_types,
PalletId, assert_ok, derive_impl, parameter_types,
traits::{Everything, Hooks, PrivilegeCmp},
weights,
};
Expand Down Expand Up @@ -32,6 +32,8 @@ frame_support::construct_runtime!(
Drand: pallet_drand::{Pallet, Call, Storage, Event<T>} = 6,
Grandpa: pallet_grandpa = 7,
EVMChainId: pallet_evm_chain_id = 8,
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 9,
Crowdloan: pallet_crowdloan::{Pallet, Call, Storage, Event<T>} = 10,
}
);

Expand Down Expand Up @@ -140,6 +142,7 @@ parameter_types! {
pub const InitialTaoWeight: u64 = u64::MAX/10; // 10% global weight.
pub const InitialEmaPriceHalvingPeriod: u64 = 201_600_u64; // 4 weeks
pub const DurationOfStartCall: u64 = 7 * 24 * 60 * 60 / 12; // 7 days
pub const LeaseDividendsDistributionInterval: u32 = 100; // 100 blocks
}

impl pallet_subtensor::Config for Test {
Expand Down Expand Up @@ -209,6 +212,47 @@ impl pallet_subtensor::Config for Test {
type InitialTaoWeight = InitialTaoWeight;
type InitialEmaPriceHalvingPeriod = InitialEmaPriceHalvingPeriod;
type DurationOfStartCall = DurationOfStartCall;
type ProxyInterface = ();
type LeaseDividendsDistributionInterval = LeaseDividendsDistributionInterval;
}

parameter_types! {
pub const PreimageMaxSize: u32 = 4096 * 1024;
pub const PreimageBaseDeposit: Balance = 1;
pub const PreimageByteDeposit: Balance = 1;
}

impl pallet_preimage::Config for Test {
type WeightInfo = pallet_preimage::weights::SubstrateWeight<Test>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type ManagerOrigin = EnsureRoot<AccountId>;
type Consideration = ();
}

parameter_types! {
pub const CrowdloanPalletId: PalletId = PalletId(*b"bt/cloan");
pub const MinimumDeposit: u64 = 50;
pub const AbsoluteMinimumContribution: u64 = 10;
pub const MinimumBlockDuration: u64 = 20;
pub const MaximumBlockDuration: u64 = 100;
pub const RefundContributorsLimit: u32 = 5;
pub const MaxContributors: u32 = 10;
}

impl pallet_crowdloan::Config for Test {
type PalletId = CrowdloanPalletId;
type Currency = Balances;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_crowdloan::weights::SubstrateWeight<Test>;
type Preimages = Preimage;
type MinimumDeposit = MinimumDeposit;
type AbsoluteMinimumContribution = AbsoluteMinimumContribution;
type MinimumBlockDuration = MinimumBlockDuration;
type MaximumBlockDuration = MaximumBlockDuration;
type RefundContributorsLimit = RefundContributorsLimit;
type MaxContributors = MaxContributors;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
Expand Down
20 changes: 16 additions & 4 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ".
pallet-drand = { path = "../drand", default-features = false }
pallet-membership = { workspace = true }
hex-literal = { workspace = true }
num-traits = { version = "0.2.19", default-features = false, features = ["libm"] }
num-traits = { version = "0.2.19", default-features = false, features = [
"libm",
] }
tle = { workspace = true, default-features = false }
ark-bls12-381 = { workspace = true, default-features = false }
ark-serialize = { workspace = true, default-features = false }
w3f-bls = { workspace = true, default-features = false }
sha2 = { workspace = true }
rand_chacha = { workspace = true }
pallet-crowdloan = { workspace = true, default-features = false }
pallet-proxy = { workspace = true, default-features = false }
subtensor-runtime-common = { workspace = true, default-features = false }

[dev-dependencies]
pallet-balances = { workspace = true, features = ["std"] }
Expand Down Expand Up @@ -109,7 +114,10 @@ std = [
"rand_chacha/std",
"safe-math/std",
"sha2/std",
"share-pool/std"
"share-pool/std",
"pallet-proxy/std",
"pallet-crowdloan/std",
"subtensor-runtime-common/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -122,7 +130,9 @@ runtime-benchmarks = [
"pallet-collective/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-drand/runtime-benchmarks"
"pallet-drand/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-crowdloan/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
Expand All @@ -135,7 +145,9 @@ try-runtime = [
"pallet-utility/try-runtime",
"sp-runtime/try-runtime",
"pallet-collective/try-runtime",
"pallet-drand/try-runtime"
"pallet-drand/try-runtime",
"pallet-proxy/try-runtime",
"pallet-crowdloan/try-runtime",
]
pow-faucet = []
fast-blocks = []
Loading
Loading