Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,17 @@ impl<T: Config> Pallet<T> {
log::debug!(
"incentives: hotkey: {hotkey:?} is SN owner hotkey or associated hotkey, skipping {incentive:?}"
);

// Record the miner burn as a TAO outflow. The incentive is
// denominated in alpha, so convert to its TAO equivalent at
// the current spot price (no slippage, since no swap occurs).
let current_price: U96F32 = T::SwapInterface::current_alpha_price(netuid.into());
let tao_equivalent: TaoBalance = current_price
.saturating_mul(asfloat!(incentive))
.saturating_to_num::<u64>()
.min(i64::MAX as u64)
.into();
Comment thread
JohnReedV marked this conversation as resolved.
Self::record_tao_outflow(netuid, tao_equivalent);
Comment on lines +621 to +630
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Avoid per-hotkey SubnetTaoFlow writes in on_initialize

run_coinbase is reached from the pallet on_initialize hook, which returns a fixed weight. This new record_tao_outflow call mutates SubnetTaoFlow once for every owner-associated hotkey skipped by the incentives loop. OwnedHotkeys is stored as an unbounded Vec, and the skip count is only indirectly bounded by registered UIDs, so this adds loop-amplified DB IO without updating the hook weight.

Aggregate the TAO equivalent into a local total and call record_tao_outflow(netuid, total) once after the incentives loop, or update the hook weight to cover the actual worst case. This should also get a targeted coinbase test asserting SubnetTaoFlow decreases by the expected spot-price TAO equivalent for skipped owner hotkey incentives.

// Check if we should recycle or burn the incentive
match RecycleOrBurn::<T>::try_get(netuid) {
Ok(RecycleOrBurnEnum::Recycle) => {
Expand Down
Loading