From 4fdcdbc59687e1baa0bcb858fac8c5c85a5bbcce Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Mon, 10 Nov 2025 19:05:50 -0300 Subject: [PATCH 01/17] fix leasing to distribute alpha only --- pallets/subtensor/src/subnets/leasing.rs | 94 ++++--- pallets/subtensor/src/tests/leasing.rs | 322 +++++++++++++++++------ 2 files changed, 280 insertions(+), 136 deletions(-) diff --git a/pallets/subtensor/src/subnets/leasing.rs b/pallets/subtensor/src/subnets/leasing.rs index cf263a1335..bc8fd352cb 100644 --- a/pallets/subtensor/src/subnets/leasing.rs +++ b/pallets/subtensor/src/subnets/leasing.rs @@ -24,8 +24,7 @@ use frame_system::pallet_prelude::*; use sp_core::blake2_256; use sp_runtime::{Percent, traits::TrailingZeroInput}; use substrate_fixed::types::U64F64; -use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency}; -use subtensor_swap_interface::SwapHandler; +use subtensor_runtime_common::{AlphaCurrency, NetUid}; pub type LeaseId = u32; @@ -130,6 +129,9 @@ impl Pallet { ); SubnetUidToLeaseId::::insert(netuid, lease_id); + // The lease take should be 0% to allow all contributors to receive dividends entirely. + Self::delegate_hotkey(&lease_hotkey, 0); + // Get all the contributions to the crowdloan except for the beneficiary // because its share will be computed as the dividends are distributed let contributions = pallet_crowdloan::Contributions::::iter_prefix(crowdloan_id) @@ -249,9 +251,8 @@ impl Pallet { /// Hook used when the subnet owner's cut is distributed to split the amount into dividends /// for the contributors and the beneficiary in shares relative to their initial contributions. - /// - /// It will ensure the subnet has enough alpha in its liquidity pool before swapping it to tao to be distributed, - /// and if not enough liquidity is available, it will accumulate the dividends for later distribution. + /// It accumulates dividends to be distributed later when the interval for distribution is reached. + /// Distribution is made in alpha and stake to the contributor coldkey and lease hotkey. pub fn distribute_leased_network_dividends(lease_id: LeaseId, owner_cut_alpha: AlphaCurrency) { // Ensure the lease exists let Some(lease) = SubnetLeases::::get(lease_id) else { @@ -290,55 +291,48 @@ impl Pallet { return; } - // Ensure there is enough liquidity to unstake the contributors cut - if let Err(err) = Self::validate_remove_stake( - &lease.coldkey, - &lease.hotkey, - lease.netuid, - total_contributors_cut_alpha, - total_contributors_cut_alpha, - false, - ) { - log::debug!("Couldn't distributing dividends for lease {lease_id}: {err:?}"); - AccumulatedLeaseDividends::::set(lease_id, total_contributors_cut_alpha); - return; - } - - // Unstake the contributors cut from the subnet as tao to the lease coldkey - let tao_unstaked = match Self::unstake_from_subnet( - &lease.hotkey, - &lease.coldkey, - lease.netuid, - total_contributors_cut_alpha, - T::SwapInterface::min_price(), - false, - ) { - Ok(tao_unstaked) => tao_unstaked, - Err(err) => { - log::debug!("Couldn't distributing dividends for lease {lease_id}: {err:?}"); - AccumulatedLeaseDividends::::set(lease_id, total_contributors_cut_alpha); - return; + // We use a storage layer to ensure the distribution is atomic. + if let Err(err) = frame_support::storage::with_storage_layer(|| { + let mut alpha_distributed = AlphaCurrency::ZERO; + + // Distribute the contributors cut to the contributors and accumulate the alpha + // distributed so far to obtain how much alpha is left to distribute to the beneficiary + for (contributor, share) in SubnetLeaseShares::::iter_prefix(lease_id) { + let alpha_for_contributor = share + .saturating_mul(U64F64::from(total_contributors_cut_alpha.to_u64())) + .ceil() + .saturating_to_num::(); + Self::transfer_stake_within_subnet( + &lease.coldkey, + &lease.hotkey, + &contributor, + &lease.hotkey, + lease.netuid, + alpha_for_contributor.into(), + )?; + alpha_distributed = alpha_distributed.saturating_add(alpha_for_contributor.into()); } - }; - // Distribute the contributors cut to the contributors and accumulate the tao - // distributed so far to obtain how much tao is left to distribute to the beneficiary - let mut tao_distributed = TaoCurrency::ZERO; - for (contributor, share) in SubnetLeaseShares::::iter_prefix(lease_id) { - let tao_for_contributor = share - .saturating_mul(U64F64::from(tao_unstaked.to_u64())) - .floor() - .saturating_to_num::(); - Self::add_balance_to_coldkey_account(&contributor, tao_for_contributor); - tao_distributed = tao_distributed.saturating_add(tao_for_contributor.into()); - } + // Distribute the leftover alpha to the beneficiary + let beneficiary_cut_alpha = + total_contributors_cut_alpha.saturating_sub(alpha_distributed); + Self::transfer_stake_within_subnet( + &lease.coldkey, + &lease.hotkey, + &lease.beneficiary, + &lease.hotkey, + lease.netuid, + beneficiary_cut_alpha.into(), + )?; - // Distribute the leftover tao to the beneficiary - let beneficiary_cut_tao = tao_unstaked.saturating_sub(tao_distributed); - Self::add_balance_to_coldkey_account(&lease.beneficiary, beneficiary_cut_tao.into()); + // Reset the accumulated dividends + AccumulatedLeaseDividends::::insert(lease_id, AlphaCurrency::ZERO); - // Reset the accumulated dividends - AccumulatedLeaseDividends::::insert(lease_id, AlphaCurrency::ZERO); + Ok::<(), DispatchError>(()) + }) { + log::debug!("Couldn't distributing dividends for lease {lease_id}: {err:?}"); + AccumulatedLeaseDividends::::set(lease_id, total_contributors_cut_alpha); + }; } fn lease_coldkey(lease_id: LeaseId) -> Result { diff --git a/pallets/subtensor/src/tests/leasing.rs b/pallets/subtensor/src/tests/leasing.rs index 4ffc18230a..0ee268e2b2 100644 --- a/pallets/subtensor/src/tests/leasing.rs +++ b/pallets/subtensor/src/tests/leasing.rs @@ -65,6 +65,9 @@ fn test_register_leased_network_works() { contributor2_share ); + // Ensure the lease hotkey has 0 take from staking + assert_eq!(SubtensorModule::get_hotkey_take(&lease.hotkey), 0); + // Ensure each contributor and beneficiary has been refunded their share of the leftover cap let leftover_cap = cap.saturating_sub(lease.cost); @@ -502,54 +505,84 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { // Setup the correct block to distribute dividends run_to_block(::LeaseDividendsDistributionInterval::get() as u64); - // Get the initial subnet tao after stake and ensure all contributor - // balances are in initial state - let subnet_tao_before = SubnetTAO::::get(lease.netuid); - let contributor1_balance_before = SubtensorModule::get_coldkey_balance(&contributions[0].0); - let contributor2_balance_before = SubtensorModule::get_coldkey_balance(&contributions[1].0); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + // Get the initial alpha for the contributors and beneficiary and ensure they are zero + let contributor1_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ); + assert_eq!(contributor1_alpha_before, AlphaCurrency::ZERO); + let contributor2_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ); + assert_eq!(contributor2_alpha_before, AlphaCurrency::ZERO); + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); // Setup some previously accumulated dividends - let accumulated_dividends = AlphaCurrency::from(5_000_000); + let accumulated_dividends = AlphaCurrency::from(10_000_000_000); AccumulatedLeaseDividends::::insert(lease_id, accumulated_dividends); // Distribute the dividends - let owner_cut_alpha = AlphaCurrency::from(5_000_000); + let owner_cut_alpha = AlphaCurrency::from(5_000_000_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were distributed correctly relative to their shares - let distributed_tao = subnet_tao_before - SubnetTAO::::get(lease.netuid); - let contributor1_balance_delta = SubtensorModule::get_coldkey_balance(&contributions[0].0) - .saturating_sub(contributor1_balance_before); - let contributor2_balance_delta = SubtensorModule::get_coldkey_balance(&contributions[1].0) - .saturating_sub(contributor2_balance_before); - let beneficiary_balance_delta = SubtensorModule::get_coldkey_balance(&beneficiary) - .saturating_sub(beneficiary_balance_before); - + let distributed_alpha = + accumulated_dividends + emissions_share.mul_ceil(owner_cut_alpha.to_u64()).into(); + assert_ne!(distributed_alpha, AlphaCurrency::ZERO); + let contributor1_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ) + .saturating_sub(contributor1_alpha_before); + assert_ne!(contributor1_alpha_delta, AlphaCurrency::ZERO); + let contributor2_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ) + .saturating_sub(contributor2_alpha_before); + assert_ne!(contributor2_alpha_delta, AlphaCurrency::ZERO); + let beneficiary_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ) + .saturating_sub(beneficiary_alpha_before); + assert_ne!(beneficiary_alpha_delta, AlphaCurrency::ZERO); + + // What has been distributed should be equal to the sum of all contributors received alpha assert_eq!( - distributed_tao, - (beneficiary_balance_delta + contributor1_balance_delta + contributor2_balance_delta) - .into() + distributed_alpha, + (beneficiary_alpha_delta + contributor1_alpha_delta + contributor2_alpha_delta).into() ); - let expected_contributor1_balance = + let expected_contributor1_alpha = SubnetLeaseShares::::get(lease_id, contributions[0].0) - .saturating_mul(U64F64::from(distributed_tao.to_u64())) - .floor() + .saturating_mul(U64F64::from(distributed_alpha.to_u64())) + .ceil() .to_num::(); - assert_eq!(contributor1_balance_delta, expected_contributor1_balance); + assert_eq!(contributor1_alpha_delta, expected_contributor1_alpha.into()); - let expected_contributor2_balance = + let expected_contributor2_alpha = SubnetLeaseShares::::get(lease_id, contributions[1].0) - .saturating_mul(U64F64::from(distributed_tao.to_u64())) - .floor() + .saturating_mul(U64F64::from(distributed_alpha.to_u64())) + .ceil() .to_num::(); - assert_eq!(contributor2_balance_delta, expected_contributor2_balance); + assert_eq!(contributor2_alpha_delta, expected_contributor2_alpha.into()); // The beneficiary should have received the remaining dividends - let expected_beneficiary_balance = distributed_tao.to_u64() - - (expected_contributor1_balance + expected_contributor2_balance); - assert_eq!(beneficiary_balance_delta, expected_beneficiary_balance); + let expected_beneficiary_alpha = distributed_alpha.to_u64() + - (expected_contributor1_alpha + expected_contributor2_alpha); + assert_eq!(beneficiary_alpha_delta, expected_beneficiary_alpha.into()); // Ensure nothing was accumulated for later distribution assert_eq!( @@ -584,23 +617,33 @@ fn test_distribute_lease_network_dividends_only_beneficiary_works() { // Setup the correct block to distribute dividends run_to_block(::LeaseDividendsDistributionInterval::get() as u64); - // Get the initial subnet tao after stake and beneficiary balance - let subnet_tao_before = SubnetTAO::::get(lease.netuid); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + // Get the initial alpha for the beneficiary and ensure it is zero + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); // Setup some previously accumulated dividends - let accumulated_dividends = AlphaCurrency::from(5_000_000); + let accumulated_dividends = AlphaCurrency::from(10_000_000_000); AccumulatedLeaseDividends::::insert(lease_id, accumulated_dividends); // Distribute the dividends - let owner_cut_alpha = AlphaCurrency::from(5_000_000); + let owner_cut_alpha = AlphaCurrency::from(5_000_000_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were distributed correctly relative to their shares - let distributed_tao = subnet_tao_before - SubnetTAO::::get(lease.netuid); - let beneficiary_balance_delta = SubtensorModule::get_coldkey_balance(&beneficiary) - .saturating_sub(beneficiary_balance_before); - assert_eq!(distributed_tao, beneficiary_balance_delta.into()); + let distributed_alpha = + accumulated_dividends + emissions_share.mul_ceil(owner_cut_alpha.to_u64()).into(); + assert_ne!(distributed_alpha, AlphaCurrency::ZERO); + let beneficiary_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ) + .saturating_sub(beneficiary_alpha_before); + assert_eq!(beneficiary_alpha_delta, distributed_alpha.into()); // Ensure nothing was accumulated for later distribution assert_eq!( @@ -628,7 +671,7 @@ fn test_distribute_lease_network_dividends_accumulates_if_not_the_correct_block( let end_block = 500; let emissions_share = Percent::from_percent(30); let tao_to_stake = 100_000_000_000; // 100 TAO - let (lease_id, _) = setup_leased_network( + let (lease_id, lease) = setup_leased_network( beneficiary, emissions_share, Some(end_block), @@ -638,31 +681,58 @@ fn test_distribute_lease_network_dividends_accumulates_if_not_the_correct_block( // Setup incorrect block to distribute dividends run_to_block(::LeaseDividendsDistributionInterval::get() as u64 + 1); - // Get the initial subnet tao after stake and ensure all contributor - let contributor1_balance_before = SubtensorModule::get_coldkey_balance(&contributions[0].0); - let contributor2_balance_before = SubtensorModule::get_coldkey_balance(&contributions[1].0); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + // Get the initial alpha for the contributors and beneficiary and ensure they are zero + let contributor1_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ); + assert_eq!(contributor1_alpha_before, AlphaCurrency::ZERO); + let contributor2_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ); + assert_eq!(contributor2_alpha_before, AlphaCurrency::ZERO); + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); // Setup some previously accumulated dividends - let accumulated_dividends = AlphaCurrency::from(5_000_000); + let accumulated_dividends = AlphaCurrency::from(10_000_000_000); AccumulatedLeaseDividends::::insert(lease_id, accumulated_dividends); // Distribute the dividends - let owner_cut_alpha = AlphaCurrency::from(5_000_000); + let owner_cut_alpha = AlphaCurrency::from(5_000_000_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were not distributed assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[0].0), - contributor1_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid + ), + contributor1_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[1].0), - contributor2_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid + ), + contributor2_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&beneficiary), - beneficiary_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid + ), + beneficiary_alpha_before ); // Ensure we correctly accumulated the dividends @@ -711,29 +781,58 @@ fn test_distribute_lease_network_dividends_does_nothing_if_lease_has_ended() { // Run to the end of the lease run_to_block(end_block); - let subnet_tao_before = SubnetTAO::::get(lease.netuid); - let contributor1_balance_before = SubtensorModule::get_coldkey_balance(&contributions[0].0); - let contributor2_balance_before = SubtensorModule::get_coldkey_balance(&contributions[1].0); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + // Get the initial alpha for the contributors and beneficiary and ensure they are zero + let contributor1_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ); + assert_eq!(contributor1_alpha_before, AlphaCurrency::ZERO); + let contributor2_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ); + assert_eq!(contributor2_alpha_before, AlphaCurrency::ZERO); + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); + + // No dividends are present, lease is new let accumulated_dividends_before = AccumulatedLeaseDividends::::get(lease_id); + assert_eq!(accumulated_dividends_before, AlphaCurrency::ZERO); // Try to distribute the dividends - let owner_cut_alpha = AlphaCurrency::from(5_000_000); + let owner_cut_alpha = AlphaCurrency::from(5_000_000_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were not distributed - assert_eq!(SubnetTAO::::get(lease.netuid), subnet_tao_before); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[0].0), - contributor1_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid + ), + contributor1_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[1].0), - contributor2_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid + ), + contributor2_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&beneficiary), - beneficiary_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid + ), + beneficiary_alpha_before ); // Ensure nothing was accumulated for later distribution assert_eq!( @@ -768,28 +867,54 @@ fn test_distribute_lease_network_dividends_accumulates_if_amount_is_too_low() { None, // We don't add any liquidity ); - let subnet_tao_before = SubnetTAO::::get(lease.netuid); - let contributor1_balance_before = SubtensorModule::get_coldkey_balance(&contributions[0].0); - let contributor2_balance_before = SubtensorModule::get_coldkey_balance(&contributions[1].0); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + // Get the initial alpha for the contributors and beneficiary and ensure they are zero + let contributor1_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ); + assert_eq!(contributor1_alpha_before, AlphaCurrency::ZERO); + let contributor2_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ); + assert_eq!(contributor2_alpha_before, AlphaCurrency::ZERO); + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); // Try to distribute the dividends let owner_cut_alpha = AlphaCurrency::from(5_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were not distributed - assert_eq!(SubnetTAO::::get(lease.netuid), subnet_tao_before); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[0].0), - contributor1_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid + ), + contributor1_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[1].0), - contributor2_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid + ), + contributor2_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&beneficiary), - beneficiary_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid + ), + beneficiary_alpha_before ); // Ensure the correct amount of alpha was accumulated for later dividends distribution assert_eq!( @@ -824,28 +949,53 @@ fn test_distribute_lease_network_dividends_accumulates_if_insufficient_liquidity None, // We don't add any liquidity ); - let subnet_tao_before = SubnetTAO::::get(lease.netuid); - let contributor1_balance_before = SubtensorModule::get_coldkey_balance(&contributions[0].0); - let contributor2_balance_before = SubtensorModule::get_coldkey_balance(&contributions[1].0); - let beneficiary_balance_before = SubtensorModule::get_coldkey_balance(&beneficiary); + let contributor1_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid, + ); + assert_eq!(contributor1_alpha_before, AlphaCurrency::ZERO); + let contributor2_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid, + ); + assert_eq!(contributor2_alpha_before, AlphaCurrency::ZERO); + let beneficiary_alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid, + ); + assert_eq!(beneficiary_alpha_before, AlphaCurrency::ZERO); // Try to distribute the dividends let owner_cut_alpha = AlphaCurrency::from(5_000_000); SubtensorModule::distribute_leased_network_dividends(lease_id, owner_cut_alpha); // Ensure the dividends were not distributed - assert_eq!(SubnetTAO::::get(lease.netuid), subnet_tao_before); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[0].0), - contributor1_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[0].0, + lease.netuid + ), + contributor1_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&contributions[1].0), - contributor2_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &contributions[1].0, + lease.netuid + ), + contributor2_alpha_before ); assert_eq!( - SubtensorModule::get_coldkey_balance(&beneficiary), - beneficiary_balance_before + SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( + &lease.hotkey, + &beneficiary, + lease.netuid + ), + beneficiary_alpha_before ); // Ensure the correct amount of alpha was accumulated for later dividends distribution assert_eq!( From 5ac488054fb3be94d300178864174fcdbcff5b9c Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Tue, 11 Nov 2025 20:33:51 -0300 Subject: [PATCH 02/17] add dividends emission event --- pallets/subtensor/src/macros/events.rs | 10 +++++++ pallets/subtensor/src/subnets/leasing.rs | 12 +++++++++ pallets/subtensor/src/tests/leasing.rs | 34 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index c2931024ee..d015205d4d 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -467,5 +467,15 @@ mod events { /// Claim type root_claim_type: RootClaimTypeEnum, }, + + /// Subnet lease dividends have been distributed. + SubnetLeaseDividendsDistributed { + /// The lease ID + lease_id: LeaseId, + /// The contributor + contributor: T::AccountId, + /// The amount of alpha distributed + alpha: AlphaCurrency, + }, } } diff --git a/pallets/subtensor/src/subnets/leasing.rs b/pallets/subtensor/src/subnets/leasing.rs index bc8fd352cb..a202a22a45 100644 --- a/pallets/subtensor/src/subnets/leasing.rs +++ b/pallets/subtensor/src/subnets/leasing.rs @@ -302,6 +302,7 @@ impl Pallet { .saturating_mul(U64F64::from(total_contributors_cut_alpha.to_u64())) .ceil() .saturating_to_num::(); + Self::transfer_stake_within_subnet( &lease.coldkey, &lease.hotkey, @@ -311,6 +312,12 @@ impl Pallet { alpha_for_contributor.into(), )?; alpha_distributed = alpha_distributed.saturating_add(alpha_for_contributor.into()); + + Self::deposit_event(Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor, + alpha: alpha_for_contributor.into(), + }); } // Distribute the leftover alpha to the beneficiary @@ -324,6 +331,11 @@ impl Pallet { lease.netuid, beneficiary_cut_alpha.into(), )?; + Self::deposit_event(Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor: lease.beneficiary.clone(), + alpha: beneficiary_cut_alpha.into(), + }); // Reset the accumulated dividends AccumulatedLeaseDividends::::insert(lease_id, AlphaCurrency::ZERO); diff --git a/pallets/subtensor/src/tests/leasing.rs b/pallets/subtensor/src/tests/leasing.rs index 0ee268e2b2..4c48d2c341 100644 --- a/pallets/subtensor/src/tests/leasing.rs +++ b/pallets/subtensor/src/tests/leasing.rs @@ -537,6 +537,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { let distributed_alpha = accumulated_dividends + emissions_share.mul_ceil(owner_cut_alpha.to_u64()).into(); assert_ne!(distributed_alpha, AlphaCurrency::ZERO); + let contributor1_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( &lease.hotkey, &contributions[0].0, @@ -544,6 +545,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { ) .saturating_sub(contributor1_alpha_before); assert_ne!(contributor1_alpha_delta, AlphaCurrency::ZERO); + let contributor2_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( &lease.hotkey, &contributions[1].0, @@ -551,6 +553,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { ) .saturating_sub(contributor2_alpha_before); assert_ne!(contributor2_alpha_delta, AlphaCurrency::ZERO); + let beneficiary_alpha_delta = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet( &lease.hotkey, &beneficiary, @@ -571,6 +574,14 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { .ceil() .to_num::(); assert_eq!(contributor1_alpha_delta, expected_contributor1_alpha.into()); + assert_eq!( + System::events().get(2).expect("Event not found").event, + RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor: contributions[0].0.into(), + alpha: expected_contributor1_alpha.into(), + },) + ); let expected_contributor2_alpha = SubnetLeaseShares::::get(lease_id, contributions[1].0) @@ -578,11 +589,27 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { .ceil() .to_num::(); assert_eq!(contributor2_alpha_delta, expected_contributor2_alpha.into()); + assert_eq!( + System::events().get(5).expect("Event not found").event, + RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor: contributions[1].0.into(), + alpha: expected_contributor2_alpha.into(), + },) + ); // The beneficiary should have received the remaining dividends let expected_beneficiary_alpha = distributed_alpha.to_u64() - (expected_contributor1_alpha + expected_contributor2_alpha); assert_eq!(beneficiary_alpha_delta, expected_beneficiary_alpha.into()); + assert_eq!( + System::events().get(8).expect("Event not found").event, + RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor: beneficiary.into(), + alpha: expected_beneficiary_alpha.into(), + },) + ); // Ensure nothing was accumulated for later distribution assert_eq!( @@ -644,6 +671,13 @@ fn test_distribute_lease_network_dividends_only_beneficiary_works() { ) .saturating_sub(beneficiary_alpha_before); assert_eq!(beneficiary_alpha_delta, distributed_alpha.into()); + assert_last_event::(RuntimeEvent::SubtensorModule( + Event::SubnetLeaseDividendsDistributed { + lease_id, + contributor: beneficiary.into(), + alpha: distributed_alpha, + }, + )); // Ensure nothing was accumulated for later distribution assert_eq!( From 87b78c5cd7a454b722122bbbfc45e4b5b99f4b5d Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 12 Nov 2025 11:31:54 -0300 Subject: [PATCH 03/17] fix clippy --- pallets/subtensor/src/tests/leasing.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/tests/leasing.rs b/pallets/subtensor/src/tests/leasing.rs index 4c48d2c341..9f8bf4d6bf 100644 --- a/pallets/subtensor/src/tests/leasing.rs +++ b/pallets/subtensor/src/tests/leasing.rs @@ -575,7 +575,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { .to_num::(); assert_eq!(contributor1_alpha_delta, expected_contributor1_alpha.into()); assert_eq!( - System::events().get(2).expect("Event not found").event, + System::events()[2].event, RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { lease_id, contributor: contributions[0].0.into(), @@ -590,7 +590,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { .to_num::(); assert_eq!(contributor2_alpha_delta, expected_contributor2_alpha.into()); assert_eq!( - System::events().get(5).expect("Event not found").event, + System::events()[5].event, RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { lease_id, contributor: contributions[1].0.into(), @@ -603,7 +603,7 @@ fn test_distribute_lease_network_dividends_multiple_contributors_works() { - (expected_contributor1_alpha + expected_contributor2_alpha); assert_eq!(beneficiary_alpha_delta, expected_beneficiary_alpha.into()); assert_eq!( - System::events().get(8).expect("Event not found").event, + System::events()[8].event, RuntimeEvent::SubtensorModule(Event::SubnetLeaseDividendsDistributed { lease_id, contributor: beneficiary.into(), From 5a4f754a8e752d0bb48667586d3071357c387c9d Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Wed, 12 Nov 2025 11:32:16 -0300 Subject: [PATCH 04/17] bump spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5e17dc6f7d..f6843c50ee 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 345, + spec_version: 346, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From d3a662e28508f9d745e711e40bf074bbfc825f61 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 08:15:26 -0300 Subject: [PATCH 05/17] fix evm test --- evm-tests/test/staking.precompile.reward.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evm-tests/test/staking.precompile.reward.test.ts b/evm-tests/test/staking.precompile.reward.test.ts index 1b47239e1d..d04620c91b 100644 --- a/evm-tests/test/staking.precompile.reward.test.ts +++ b/evm-tests/test/staking.precompile.reward.test.ts @@ -74,7 +74,7 @@ describe("Test neuron precompile reward", () => { let index = 0; while (index < 60) { - const pending = await api.query.SubtensorModule.ValidatorEmission.getValue(netuid); + const pending = await api.query.SubtensorModule.PendingValidatorEmission.getValue(netuid); if (pending > 0) { console.log("pending amount is ", pending); break; From 800cddd591838be1eb98d85f4301e85ec41313ae Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 10:52:26 -0300 Subject: [PATCH 06/17] debug github action --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 540238d6d5..5617019c64 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -130,6 +130,12 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Setup tmate session + id: setup-tmate-session + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + - name: Build Docker Image run: docker build -f Dockerfile-localnet -t localnet . @@ -181,7 +187,7 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v5 with: - enable-cache: 'false' + enable-cache: "false" - name: Create Python virtual environment working-directory: ${{ github.workspace }} @@ -275,7 +281,7 @@ jobs: - name: Install uv uses: astral-sh/setup-uv@v5 with: - enable-cache: 'false' + enable-cache: "false" - name: Create Python virtual environment working-directory: ${{ github.workspace }} From e30e8b550e5c48577fd1acda243144d18ee11d56 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:16:58 -0300 Subject: [PATCH 07/17] combine build directly as tar --- .../workflows/check-bittensor-e2e-tests.yml.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 5617019c64..f60edbb178 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -130,23 +130,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Setup tmate session - id: setup-tmate-session - uses: mxschmitt/action-tmate@v3 - with: - limit-access-to-actor: true - - - name: Build Docker Image - run: docker build -f Dockerfile-localnet -t localnet . - - - name: Save Docker Image as Tar - run: docker save -o subtensor-localnet.tar localnet + - name: Build Docker Image (direct tar output) + run: docker build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/subtensor-localnet.tar . - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 with: name: subtensor-localnet - path: subtensor-localnet.tar + path: /mnt/subtensor-localnet.tar # main btcli job run-btcli-e2e-tests: From d8c42d4a8bc0446783acd1e41075bdbe6a7c5ed8 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:18:53 -0300 Subject: [PATCH 08/17] reset debug --- .../workflows/check-bittensor-e2e-tests.yml.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index f60edbb178..5617019c64 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -130,14 +130,23 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build Docker Image (direct tar output) - run: docker build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/subtensor-localnet.tar . + - name: Setup tmate session + id: setup-tmate-session + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + + - name: Build Docker Image + run: docker build -f Dockerfile-localnet -t localnet . + + - name: Save Docker Image as Tar + run: docker save -o subtensor-localnet.tar localnet - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 with: name: subtensor-localnet - path: /mnt/subtensor-localnet.tar + path: subtensor-localnet.tar # main btcli job run-btcli-e2e-tests: From ce25ddc03fce53a3de45537e240e1f580aeb0e91 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:25:40 -0300 Subject: [PATCH 09/17] try fix 2 --- .../check-bittensor-e2e-tests.yml.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 5617019c64..778f38ae94 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -129,24 +129,18 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + + - name: Create directory + run: mkdir -p /mnt/data && chown -R runner:runner /mnt/data - - name: Setup tmate session - id: setup-tmate-session - uses: mxschmitt/action-tmate@v3 - with: - limit-access-to-actor: true - - - name: Build Docker Image - run: docker build -f Dockerfile-localnet -t localnet . - - - name: Save Docker Image as Tar - run: docker save -o subtensor-localnet.tar localnet + - name: Build Docker Image (direct tar output) + run: docker build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/data/subtensor-localnet.tar . - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 with: name: subtensor-localnet - path: subtensor-localnet.tar + path: /mnt/data/subtensor-localnet.tar # main btcli job run-btcli-e2e-tests: From 2020da52151096e665a23fd72468c3790e0ae329 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:25:59 -0300 Subject: [PATCH 10/17] missing sudo --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 778f38ae94..a00ed874c2 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -131,7 +131,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Create directory - run: mkdir -p /mnt/data && chown -R runner:runner /mnt/data + run: sudo mkdir -p /mnt/data && sudo chown -R runner:runner /mnt/data - name: Build Docker Image (direct tar output) run: docker build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/data/subtensor-localnet.tar . From 2d93e2e3e1ed7612e8a6beefb69c66b2ad080d5f Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:27:59 -0300 Subject: [PATCH 11/17] exporter fix --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index a00ed874c2..0f43542618 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -134,7 +134,7 @@ jobs: run: sudo mkdir -p /mnt/data && sudo chown -R runner:runner /mnt/data - name: Build Docker Image (direct tar output) - run: docker build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/data/subtensor-localnet.tar . + run: DOCKER_BUILDKIT=1 docker buildx build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/data/subtensor-localnet.tar . - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 From 391397d3b87deadd61352df8b39cf0f9cf6ce873 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 12:29:46 -0300 Subject: [PATCH 12/17] trigger ci? From ca14a10cc40fc04d4afab9e5b420ca7a14135ab7 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 13:57:24 -0300 Subject: [PATCH 13/17] try with cache to /mnt --- .../workflows/check-bittensor-e2e-tests.yml.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 0f43542618..b06e8d7953 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -129,18 +129,24 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Create directory - run: sudo mkdir -p /mnt/data && sudo chown -R runner:runner /mnt/data + run: sudo mkdir -p /mnt/build-cache && sudo chown -R runner:runner /mnt/build-cache - name: Build Docker Image (direct tar output) - run: DOCKER_BUILDKIT=1 docker buildx build -f Dockerfile-localnet -t localnet --output type=docker,dest=/mnt/data/subtensor-localnet.tar . + run: | + docker buildx build \ + -f Dockerfile-localnet \ + -t localnet \ + --cache-to type=local,dest=/mnt/build-cache \ + --cache-from type=local,src=/mnt/build-cache \ + --output type=docker,dest=subtensor-localnet.tar . - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 with: name: subtensor-localnet - path: /mnt/data/subtensor-localnet.tar + path: subtensor-localnet.tar # main btcli job run-btcli-e2e-tests: From 827b81b46e54b91b2c4457cd7ff7cf1b57f32775 Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 15:12:17 -0300 Subject: [PATCH 14/17] build on root but save on mnt --- .../check-bittensor-e2e-tests.yml.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index b06e8d7953..d3c74f4694 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -129,24 +129,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - + - name: Create directory - run: sudo mkdir -p /mnt/build-cache && sudo chown -R runner:runner /mnt/build-cache + run: mkdir -p /mnt/data && chown -R runner:runner /mnt/data - - name: Build Docker Image (direct tar output) - run: | - docker buildx build \ - -f Dockerfile-localnet \ - -t localnet \ - --cache-to type=local,dest=/mnt/build-cache \ - --cache-from type=local,src=/mnt/build-cache \ - --output type=docker,dest=subtensor-localnet.tar . + - name: Build Docker Image + run: docker build -f Dockerfile-localnet -t localnet . + + - name: Save Docker Image as Tar + run: docker save -o /mnt/data/subtensor-localnet.tar localnet - name: Upload Docker Image as Artifact uses: actions/upload-artifact@v4 with: name: subtensor-localnet - path: subtensor-localnet.tar + path: /mnt/data/subtensor-localnet.tar # main btcli job run-btcli-e2e-tests: From a791e754b193cae3c10bcc22af546cdd0cf355bd Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 15:27:27 -0300 Subject: [PATCH 15/17] missing sudo 2 --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index d3c74f4694..2352b77228 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -131,7 +131,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Create directory - run: mkdir -p /mnt/data && chown -R runner:runner /mnt/data + run: sudo mkdir -p /mnt/data && sudo chown -R runner:runner /mnt/data - name: Build Docker Image run: docker build -f Dockerfile-localnet -t localnet . From f713dfd22a8001e130044f962285e991454d82bb Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 16:36:10 -0300 Subject: [PATCH 16/17] try to docker root to /mnt --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 2352b77228..8c0f6defab 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -129,9 +129,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Create directory - run: sudo mkdir -p /mnt/data && sudo chown -R runner:runner /mnt/data + + - name: Move Docker data-root to /mnt/data + run: | + sudo systemctl stop docker + sudo mkdir -p /mnt/data/docker + echo '{"data-root": "/mnt/data/docker"}' | sudo tee /etc/docker/daemon.json + sudo systemctl start docker + docker info | grep "Docker Root Dir" - name: Build Docker Image run: docker build -f Dockerfile-localnet -t localnet . From 2ed1e7705db303f2e5ad670fb3fe29dc7f402c0e Mon Sep 17 00:00:00 2001 From: Loris Moulin Date: Thu, 13 Nov 2025 17:47:31 -0300 Subject: [PATCH 17/17] fix perms --- .github/workflows/check-bittensor-e2e-tests.yml.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-bittensor-e2e-tests.yml.yml b/.github/workflows/check-bittensor-e2e-tests.yml.yml index 8c0f6defab..c133efab22 100644 --- a/.github/workflows/check-bittensor-e2e-tests.yml.yml +++ b/.github/workflows/check-bittensor-e2e-tests.yml.yml @@ -134,6 +134,8 @@ jobs: run: | sudo systemctl stop docker sudo mkdir -p /mnt/data/docker + sudo chown -R runner:runner /mnt/data + sudo chmod -R 777 /mnt/data echo '{"data-root": "/mnt/data/docker"}' | sudo tee /etc/docker/daemon.json sudo systemctl start docker docker info | grep "Docker Root Dir"