Skip to content

Commit 41fd2f6

Browse files
authored
Merge pull request #722 from opentensor/increment-blocks-since-last-step
Increment blocks since last step in coinbase
2 parents cb35762 + 037b76d commit 41fd2f6

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ impl<T: Config> Pallet<T> {
131131
log::debug!("Accumulated emissions on hotkey {:?} for netuid {:?}: mining {:?}, validator {:?}", hotkey, *netuid, mining_emission, validator_emission);
132132
}
133133
} else {
134+
// No epoch, increase blocks since last step and continue
135+
Self::set_blocks_since_last_step(
136+
*netuid,
137+
Self::get_blocks_since_last_step(*netuid).saturating_add(1),
138+
);
134139
log::debug!("Tempo not reached for subnet: {:?}", *netuid);
135140
}
136141
}

pallets/subtensor/tests/epoch.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,53 @@ fn test_get_set_alpha() {
27032703
});
27042704
}
27052705

2706+
#[test]
2707+
fn test_blocks_since_last_step() {
2708+
new_test_ext(1).execute_with(|| {
2709+
System::set_block_number(0);
2710+
2711+
let netuid: u16 = 1;
2712+
let tempo: u16 = 7200;
2713+
add_network(netuid, tempo, 0);
2714+
2715+
let original_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid);
2716+
2717+
step_block(5);
2718+
2719+
let new_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid);
2720+
2721+
assert!(new_blocks > original_blocks);
2722+
assert_eq!(new_blocks, 5);
2723+
2724+
let blocks_to_step: u16 = SubtensorModule::blocks_until_next_epoch(
2725+
netuid,
2726+
tempo,
2727+
SubtensorModule::get_current_block_as_u64(),
2728+
) as u16
2729+
+ 10;
2730+
step_block(blocks_to_step);
2731+
2732+
let post_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid);
2733+
2734+
assert_eq!(post_blocks, 10);
2735+
2736+
let blocks_to_step: u16 = SubtensorModule::blocks_until_next_epoch(
2737+
netuid,
2738+
tempo,
2739+
SubtensorModule::get_current_block_as_u64(),
2740+
) as u16
2741+
+ 20;
2742+
step_block(blocks_to_step);
2743+
2744+
let new_post_blocks: u64 = SubtensorModule::get_blocks_since_last_step(netuid);
2745+
2746+
assert_eq!(new_post_blocks, 20);
2747+
2748+
step_block(7);
2749+
2750+
assert_eq!(SubtensorModule::get_blocks_since_last_step(netuid), 27);
2751+
});
2752+
}
27062753
// // Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes, of which the first 64 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other.
27072754
// //
27082755
// // ```import torch

0 commit comments

Comments
 (0)