Skip to content

Commit 3eca45f

Browse files
committed
Format
1 parent 30475f1 commit 3eca45f

File tree

2 files changed

+69
-56
lines changed

2 files changed

+69
-56
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl<T: Config> Pallet<T> {
4848
let mut total_moving_prices: I96F32 = I96F32::from_num(0.0);
4949
for netuid_i in subnets.iter() {
5050
// Get and update the moving price of each subnet adding the total together.
51-
total_moving_prices = total_moving_prices.saturating_add( Self::get_moving_alpha_price( *netuid_i ) );
51+
total_moving_prices =
52+
total_moving_prices.saturating_add(Self::get_moving_alpha_price(*netuid_i));
5253
}
5354
log::debug!("total_moving_prices: {:?}", total_moving_prices);
5455

@@ -189,7 +190,7 @@ impl<T: Config> Pallet<T> {
189190
// --- 7 Update moving prices after using them in the emission calculation.
190191
for netuid_i in subnets.iter() {
191192
// Update moving prices after using them above.
192-
Self::update_moving_price( *netuid_i );
193+
Self::update_moving_price(*netuid_i);
193194
}
194195

195196
// --- 7. Drain pending emission through the subnet based on tempo.

pallets/subtensor/src/tests/coinbase.rs

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ fn test_dynamic_function_various_values() {
4949
});
5050
}
5151

52-
5352
// Test the base case of running coinbase with zero emission.
5453
// This test verifies that the coinbase mechanism can handle the edge case
5554
// of zero emission without errors or unexpected behavior.
5655
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::coinbase::test_coinbase_basecase --exact --show-output --nocapture
5756
#[test]
5857
fn test_coinbase_basecase() {
5958
new_test_ext(1).execute_with(|| {
60-
SubtensorModule::run_coinbase( I96F32::from_num(0.0) );
59+
SubtensorModule::run_coinbase(I96F32::from_num(0.0));
6160
});
6261
}
6362

@@ -73,11 +72,11 @@ fn test_coinbase_tao_issuance_base() {
7372
let netuid: u16 = 1;
7473
let emission: u64 = 1_234_567;
7574
add_network(netuid, 1, 0);
76-
assert_eq!( SubnetTAO::<Test>::get( netuid ), 0);
77-
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
78-
assert_eq!( SubnetTAO::<Test>::get( netuid ), emission);
79-
assert_eq!( TotalIssuance::<Test>::get(), emission);
80-
assert_eq!( TotalStake::<Test>::get(), emission);
75+
assert_eq!(SubnetTAO::<Test>::get(netuid), 0);
76+
SubtensorModule::run_coinbase(I96F32::from_num(emission));
77+
assert_eq!(SubnetTAO::<Test>::get(netuid), emission);
78+
assert_eq!(TotalIssuance::<Test>::get(), emission);
79+
assert_eq!(TotalStake::<Test>::get(), emission);
8180
});
8281
}
8382

@@ -98,15 +97,15 @@ fn test_coinbase_tao_issuance_multiple() {
9897
add_network(netuid1, 1, 0);
9998
add_network(netuid2, 1, 0);
10099
add_network(netuid3, 1, 0);
101-
assert_eq!( SubnetTAO::<Test>::get( netuid1 ), 0);
102-
assert_eq!( SubnetTAO::<Test>::get( netuid2 ), 0);
103-
assert_eq!( SubnetTAO::<Test>::get( netuid3 ), 0);
104-
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
105-
assert_eq!( SubnetTAO::<Test>::get( netuid1 ), emission/3);
106-
assert_eq!( SubnetTAO::<Test>::get( netuid2 ), emission/3);
107-
assert_eq!( SubnetTAO::<Test>::get( netuid3 ), emission/3);
108-
assert_eq!( TotalIssuance::<Test>::get(), emission);
109-
assert_eq!( TotalStake::<Test>::get(), emission);
100+
assert_eq!(SubnetTAO::<Test>::get(netuid1), 0);
101+
assert_eq!(SubnetTAO::<Test>::get(netuid2), 0);
102+
assert_eq!(SubnetTAO::<Test>::get(netuid3), 0);
103+
SubtensorModule::run_coinbase(I96F32::from_num(emission));
104+
assert_eq!(SubnetTAO::<Test>::get(netuid1), emission / 3);
105+
assert_eq!(SubnetTAO::<Test>::get(netuid2), emission / 3);
106+
assert_eq!(SubnetTAO::<Test>::get(netuid3), emission / 3);
107+
assert_eq!(TotalIssuance::<Test>::get(), emission);
108+
assert_eq!(TotalStake::<Test>::get(), emission);
110109
});
111110
}
112111

@@ -128,18 +127,18 @@ fn test_coinbase_tao_issuance_different_prices() {
128127
SubnetMechanism::<Test>::insert(netuid1, 1);
129128
SubnetMechanism::<Test>::insert(netuid2, 1);
130129
// Set subnet prices.
131-
SubnetMovingPrice::<Test>::insert( netuid1, I96F32::from_num(1) );
132-
SubnetMovingPrice::<Test>::insert( netuid2, I96F32::from_num(2) );
130+
SubnetMovingPrice::<Test>::insert(netuid1, I96F32::from_num(1));
131+
SubnetMovingPrice::<Test>::insert(netuid2, I96F32::from_num(2));
133132
// Assert initial TAO reserves.
134-
assert_eq!( SubnetTAO::<Test>::get( netuid1 ), 0);
135-
assert_eq!( SubnetTAO::<Test>::get( netuid2 ), 0);
133+
assert_eq!(SubnetTAO::<Test>::get(netuid1), 0);
134+
assert_eq!(SubnetTAO::<Test>::get(netuid2), 0);
136135
// Run the coinbase with the emission amount.
137-
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
136+
SubtensorModule::run_coinbase(I96F32::from_num(emission));
138137
// Assert tao emission is split evenly.
139-
assert_eq!( SubnetTAO::<Test>::get( netuid1 ), emission/3 );
140-
assert_eq!( SubnetTAO::<Test>::get( netuid2 ), emission/3 + emission/3);
141-
close( TotalIssuance::<Test>::get(), emission, 2);
142-
close( TotalStake::<Test>::get(), emission, 2);
138+
assert_eq!(SubnetTAO::<Test>::get(netuid1), emission / 3);
139+
assert_eq!(SubnetTAO::<Test>::get(netuid2), emission / 3 + emission / 3);
140+
close(TotalIssuance::<Test>::get(), emission, 2);
141+
close(TotalStake::<Test>::get(), emission, 2);
143142
});
144143
}
145144

@@ -158,31 +157,43 @@ fn test_coinbase_moving_prices() {
158157
SubnetTAO::<Test>::insert(netuid, 1_000_000);
159158
SubnetAlphaIn::<Test>::insert(netuid, 1_000_000);
160159
SubnetMechanism::<Test>::insert(netuid, 1);
161-
SubnetMovingPrice::<Test>::insert( netuid, I96F32::from_num(1) );
160+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(1));
162161
// Updating the moving price keeps it the same.
163-
assert_eq!( SubtensorModule::get_moving_alpha_price(netuid), I96F32::from_num(1) );
164-
SubtensorModule::update_moving_price( netuid );
165-
assert_eq!( SubtensorModule::get_moving_alpha_price(netuid), I96F32::from_num(1) );
162+
assert_eq!(
163+
SubtensorModule::get_moving_alpha_price(netuid),
164+
I96F32::from_num(1)
165+
);
166+
SubtensorModule::update_moving_price(netuid);
167+
assert_eq!(
168+
SubtensorModule::get_moving_alpha_price(netuid),
169+
I96F32::from_num(1)
170+
);
166171
// Check alpha of 1.
167172
// Set price to zero.
168-
SubnetMovingPrice::<Test>::insert( netuid, I96F32::from_num(0) );
169-
SubnetMovingAlpha::<Test>::set( I96F32::from_num(1.0) );
173+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(0));
174+
SubnetMovingAlpha::<Test>::set(I96F32::from_num(1.0));
170175
// Run moving 1 times.
171-
SubtensorModule::update_moving_price( netuid );
176+
SubtensorModule::update_moving_price(netuid);
172177
// Assert price is == 100% of the real price.
173-
assert_eq!( SubtensorModule::get_moving_alpha_price(netuid), I96F32::from_num(1.0) );
178+
assert_eq!(
179+
SubtensorModule::get_moving_alpha_price(netuid),
180+
I96F32::from_num(1.0)
181+
);
174182
// Set price to zero.
175-
SubnetMovingPrice::<Test>::insert( netuid, I96F32::from_num(0) );
176-
SubnetMovingAlpha::<Test>::set( I96F32::from_num(0.1) );
183+
SubnetMovingPrice::<Test>::insert(netuid, I96F32::from_num(0));
184+
SubnetMovingAlpha::<Test>::set(I96F32::from_num(0.1));
177185
// Run moving 6 times.
178-
SubtensorModule::update_moving_price( netuid );
179-
SubtensorModule::update_moving_price( netuid );
180-
SubtensorModule::update_moving_price( netuid );
181-
SubtensorModule::update_moving_price( netuid );
182-
SubtensorModule::update_moving_price( netuid );
183-
SubtensorModule::update_moving_price( netuid );
186+
SubtensorModule::update_moving_price(netuid);
187+
SubtensorModule::update_moving_price(netuid);
188+
SubtensorModule::update_moving_price(netuid);
189+
SubtensorModule::update_moving_price(netuid);
190+
SubtensorModule::update_moving_price(netuid);
191+
SubtensorModule::update_moving_price(netuid);
184192
// Assert price is > 50% of the real price.
185-
assert_eq!( SubtensorModule::get_moving_alpha_price(netuid), I96F32::from_num(0.468559) );
193+
assert_eq!(
194+
SubtensorModule::get_moving_alpha_price(netuid),
195+
I96F32::from_num(0.468559)
196+
);
186197
});
187198
}
188199

@@ -206,13 +217,13 @@ fn test_coinbase_alpha_issuance_base() {
206217
SubnetTAO::<Test>::insert(netuid2, 1_000_000);
207218
SubnetAlphaIn::<Test>::insert(netuid2, 1_000_000);
208219
// Check initial
209-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid1 ), 0);
210-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid2 ), 0);
211-
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
220+
assert_eq!(SubnetAlphaIn::<Test>::get(netuid1), 0);
221+
assert_eq!(SubnetAlphaIn::<Test>::get(netuid2), 0);
222+
SubtensorModule::run_coinbase(I96F32::from_num(emission));
212223
// tao_in = 500_000
213224
// alpha_in = 500_000/price = 500_000
214-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid1 ), emission/2);
215-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid2 ), emission/2);
225+
assert_eq!(SubnetAlphaIn::<Test>::get(netuid1), emission / 2);
226+
assert_eq!(SubnetAlphaIn::<Test>::get(netuid2), emission / 2);
216227
});
217228
}
218229

@@ -235,17 +246,18 @@ fn test_coinbase_alpha_issuance_different() {
235246
SubnetTAO::<Test>::insert(netuid2, initial);
236247
SubnetAlphaIn::<Test>::insert(netuid2, initial);
237248
// Set subnet prices.
238-
SubnetMovingPrice::<Test>::insert( netuid1, I96F32::from_num(1) );
239-
SubnetMovingPrice::<Test>::insert( netuid2, I96F32::from_num(2) );
249+
SubnetMovingPrice::<Test>::insert(netuid1, I96F32::from_num(1));
250+
SubnetMovingPrice::<Test>::insert(netuid2, I96F32::from_num(2));
240251
// Run coinbase
241-
SubtensorModule::run_coinbase( I96F32::from_num( emission ) );
252+
SubtensorModule::run_coinbase(I96F32::from_num(emission));
242253
// tao_in = 333_333
243254
// alpha_in = 333_333/price = 333_333 + initial
244-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid1 ), initial + emission/3);
255+
assert_eq!(SubnetAlphaIn::<Test>::get(netuid1), initial + emission / 3);
245256
// tao_in = 666_666
246257
// alpha_in = 666_666/price = 666_666 + initial
247-
assert_eq!( SubnetAlphaIn::<Test>::get( netuid2 ), initial + emission/3 + emission/3);
258+
assert_eq!(
259+
SubnetAlphaIn::<Test>::get(netuid2),
260+
initial + emission / 3 + emission / 3
261+
);
248262
});
249263
}
250-
251-

0 commit comments

Comments
 (0)