Skip to content

Commit b2a995b

Browse files
authored
Merge pull request #1980 from coldint/feat/mvds00-run-coinbase-refactoring
Feat/mvds00 run coinbase refactoring
2 parents bc0f55d + 2c6e9cc commit b2a995b

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ impl<T: Config> Pallet<T> {
3939
log::debug!("Subnets to emit to: {subnets_to_emit_to:?}");
4040

4141
// --- 2. Get sum of tao reserves ( in a later version we will switch to prices. )
42-
let mut total_moving_prices = U96F32::saturating_from_num(0.0);
42+
let mut acc_total_moving_prices = U96F32::saturating_from_num(0.0);
4343
// Only get price EMA for subnets that we emit to.
4444
for netuid_i in subnets_to_emit_to.iter() {
4545
// Get and update the moving price of each subnet adding the total together.
46-
total_moving_prices =
47-
total_moving_prices.saturating_add(Self::get_moving_alpha_price(*netuid_i));
46+
acc_total_moving_prices =
47+
acc_total_moving_prices.saturating_add(Self::get_moving_alpha_price(*netuid_i));
4848
}
49+
let total_moving_prices = acc_total_moving_prices;
4950
log::debug!("total_moving_prices: {total_moving_prices:?}");
5051

5152
// --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
@@ -183,21 +184,22 @@ impl<T: Config> Pallet<T> {
183184
});
184185
}
185186

187+
// Get total TAO on root.
188+
let root_tao: U96F32 = asfloat!(SubnetTAO::<T>::get(NetUid::ROOT));
189+
log::debug!("root_tao: {root_tao:?}");
190+
// Get tao_weight
191+
let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight());
192+
log::debug!("tao_weight: {tao_weight:?}");
193+
186194
// --- 6. Seperate out root dividends in alpha and sell them into tao.
187195
// Then accumulate those dividends for later.
188196
for netuid_i in subnets_to_emit_to.iter() {
189197
// Get remaining alpha out.
190198
let alpha_out_i: U96F32 = *alpha_out.get(netuid_i).unwrap_or(&asfloat!(0.0));
191199
log::debug!("alpha_out_i: {alpha_out_i:?}");
192-
// Get total TAO on root.
193-
let root_tao: U96F32 = asfloat!(SubnetTAO::<T>::get(NetUid::ROOT));
194-
log::debug!("root_tao: {root_tao:?}");
195200
// Get total ALPHA on subnet.
196201
let alpha_issuance: U96F32 = asfloat!(Self::get_alpha_issuance(*netuid_i));
197202
log::debug!("alpha_issuance: {alpha_issuance:?}");
198-
// Get tao_weight
199-
let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight());
200-
log::debug!("tao_weight: {tao_weight:?}");
201203
// Get root proportional dividends.
202204
let root_proportion: U96F32 = tao_weight
203205
.checked_div(tao_weight.saturating_add(alpha_issuance))
@@ -239,14 +241,14 @@ impl<T: Config> Pallet<T> {
239241
});
240242
}
241243

242-
// --- 7 Update moving prices after using them in the emission calculation.
244+
// --- 7. Update moving prices after using them in the emission calculation.
243245
// Only update price EMA for subnets that we emit to.
244246
for netuid_i in subnets_to_emit_to.iter() {
245247
// Update moving prices after using them above.
246248
Self::update_moving_price(*netuid_i);
247249
}
248250

249-
// --- 7. Drain pending emission through the subnet based on tempo.
251+
// --- 8. Drain pending emission through the subnet based on tempo.
250252
// Run the epoch for *all* subnets, even if we don't emit anything.
251253
for &netuid in subnets.iter() {
252254
// Reveal matured weights.

pallets/subtensor/src/subnets/registration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<T: Config> Pallet<T> {
369369

370370
// --- 5. Add Balance via faucet.
371371
let balance_to_add: u64 = 1_000_000_000_000;
372-
Self::coinbase(100_000_000_000.into()); // We are creating tokens here from the coinbase.
372+
Self::increase_issuance(100_000_000_000.into()); // We are creating tokens here from the coinbase.
373373

374374
Self::add_balance_to_coldkey_account(&coldkey, balance_to_add);
375375

pallets/subtensor/src/utils/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<T: Config> Pallet<T> {
273273
pub fn burn_tokens(amount: TaoCurrency) {
274274
TotalIssuance::<T>::put(TotalIssuance::<T>::get().saturating_sub(amount));
275275
}
276-
pub fn coinbase(amount: TaoCurrency) {
276+
pub fn increase_issuance(amount: TaoCurrency) {
277277
TotalIssuance::<T>::put(TotalIssuance::<T>::get().saturating_add(amount));
278278
}
279279

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
220220
// `spec_version`, and `authoring_version` are the same between Wasm and native.
221221
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
222222
// the compatible custom types.
223-
spec_version: 306,
223+
spec_version: 307,
224224
impl_version: 1,
225225
apis: RUNTIME_API_VERSIONS,
226226
transaction_version: 1,

0 commit comments

Comments
 (0)