Skip to content

Commit ec1bccb

Browse files
committed
Merge remote-tracking branch 'origin/main' into devnet-ready
2 parents 064a074 + 8834a7c commit ec1bccb

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ impl<T: Config> Pallet<T> {
124124
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
125125
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
126126
let mut excess_tao: BTreeMap<NetUid, U96F32> = BTreeMap::new();
127+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
128+
Self::get_block_emission()
129+
.unwrap_or(TaoCurrency::ZERO)
130+
.to_u64(),
131+
);
127132

128133
// Only calculate for subnets that we are emitting to.
129134
for (&netuid_i, &tao_emission_i) in subnet_emissions.iter() {
@@ -142,8 +147,9 @@ impl<T: Config> Pallet<T> {
142147
let alpha_out_i: U96F32 = alpha_emission_i;
143148
let mut alpha_in_i: U96F32 = tao_emission_i.safe_div_or(price_i, U96F32::from_num(0.0));
144149

145-
if alpha_in_i > alpha_emission_i {
146-
alpha_in_i = alpha_emission_i;
150+
let alpha_injection_cap: U96F32 = alpha_emission_i.min(tao_block_emission);
151+
if alpha_in_i > alpha_injection_cap {
152+
alpha_in_i = alpha_injection_cap;
147153
tao_in_i = alpha_in_i.saturating_mul(price_i);
148154
}
149155

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,3 +3980,39 @@ fn test_root_proportion() {
39803980
assert_eq!(actual_root_proportion, expected_root_prop);
39813981
});
39823982
}
3983+
3984+
#[test]
3985+
fn test_get_subnet_terms_alpha_emissions_cap() {
3986+
new_test_ext(1).execute_with(|| {
3987+
let owner_hotkey = U256::from(10);
3988+
let owner_coldkey = U256::from(11);
3989+
let netuid = add_dynamic_network(&owner_hotkey, &owner_coldkey);
3990+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
3991+
SubtensorModule::get_block_emission()
3992+
.unwrap_or(TaoCurrency::ZERO)
3993+
.to_u64(),
3994+
);
3995+
3996+
// price = 1.0
3997+
// tao_block_emission = 1000000000
3998+
// tao_block_emission == alpha_emission_i
3999+
// alpha_in_i <= alpha_injection_cap
4000+
let emissions1 = U96F32::from_num(100_000_000);
4001+
4002+
let subnet_emissions1 = BTreeMap::from([(netuid, emissions1)]);
4003+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions1);
4004+
4005+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), emissions1);
4006+
4007+
// price = 1.0
4008+
// tao_block_emission = 1000000000
4009+
// tao_block_emission == alpha_emission_i
4010+
// alpha_in_i > alpha_injection_cap
4011+
let emissions2 = U96F32::from_num(10_000_000_000u64);
4012+
4013+
let subnet_emissions2 = BTreeMap::from([(netuid, emissions2)]);
4014+
let (_, alpha_in, _, _) = SubtensorModule::get_subnet_terms(&subnet_emissions2);
4015+
4016+
assert_eq!(alpha_in.get(&netuid).copied().unwrap(), tao_block_emission);
4017+
});
4018+
}

runtime/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ extern crate alloc;
1919
use codec::{Compact, Decode, Encode};
2020
use ethereum::AuthorizationList;
2121
use frame_support::{
22-
PalletId,
2322
dispatch::DispatchResult,
2423
genesis_builder_helper::{build_state, get_preset},
2524
pallet_prelude::Get,
26-
traits::{Contains, InsideBoth, LinearStoragePrice, fungible::HoldConsideration},
25+
traits::{fungible::HoldConsideration, Contains, InsideBoth, LinearStoragePrice},
26+
PalletId,
2727
};
2828
use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned};
2929
use pallet_commitments::{CanCommit, OnMetadataCommitment};
30-
use pallet_grandpa::{AuthorityId as GrandpaId, fg_primitives};
30+
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
3131
use pallet_registry::CanRegisterIdentity;
3232
pub use pallet_shield;
3333
use pallet_subtensor::rpc_info::{
@@ -49,42 +49,44 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
4949
use sp_consensus_babe::BabeConfiguration;
5050
use sp_consensus_babe::BabeEpochConfiguration;
5151
use sp_core::{
52-
H160, H256, OpaqueMetadata, U256,
5352
crypto::{ByteArray, KeyTypeId},
53+
OpaqueMetadata, H160, H256, U256,
5454
};
55-
use sp_runtime::Cow;
5655
use sp_runtime::generic::Era;
56+
use sp_runtime::Cow;
5757
use sp_runtime::{
58-
AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, generic, impl_opaque_keys,
58+
generic, impl_opaque_keys,
5959
traits::{
6060
AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, One,
6161
PostDispatchInfoOf, UniqueSaturatedInto, Verify,
6262
},
6363
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
64+
AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent,
6465
};
6566
use sp_std::cmp::Ordering;
6667
use sp_std::prelude::*;
6768
#[cfg(feature = "std")]
6869
use sp_version::NativeVersion;
6970
use sp_version::RuntimeVersion;
7071
use subtensor_precompiles::Precompiles;
71-
use subtensor_runtime_common::{AlphaCurrency, TaoCurrency, time::*, *};
72+
use subtensor_runtime_common::{time::*, AlphaCurrency, TaoCurrency, *};
7273
use subtensor_swap_interface::{Order, SwapHandler};
7374

7475
// A few exports that help ease life for downstream crates.
7576
pub use frame_support::{
76-
StorageValue, construct_runtime, parameter_types,
77+
construct_runtime, parameter_types,
7778
traits::{
78-
ConstBool, ConstU8, ConstU32, ConstU64, ConstU128, FindAuthor, InstanceFilter,
79+
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, FindAuthor, InstanceFilter,
7980
KeyOwnerProofSystem, OnFinalize, OnTimestampSet, PrivilegeCmp, Randomness, StorageInfo,
8081
},
8182
weights::{
82-
IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
83-
WeightToFeePolynomial,
8483
constants::{
8584
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
8685
},
86+
IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
87+
WeightToFeePolynomial,
8788
},
89+
StorageValue,
8890
};
8991
pub use frame_system::Call as SystemCall;
9092
pub use pallet_balances::Call as BalancesCall;

0 commit comments

Comments
 (0)