|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Set 100% weights to burn UID every 360 blocks.""" |
| 3 | + |
| 4 | +import argparse |
| 5 | +import time |
| 6 | + |
| 7 | +import bittensor as bt |
| 8 | + |
| 9 | +import tplr |
| 10 | + |
| 11 | +BURN_UID = 1 # Same as validator.py |
| 12 | +WEIGHT_INTERVAL = 360 # Blocks between weight sets |
| 13 | + |
| 14 | + |
| 15 | +def get_config(): |
| 16 | + parser = argparse.ArgumentParser(description="Burn-only validator script") |
| 17 | + parser.add_argument( |
| 18 | + "--netuid", type=int, default=268, help="Bittensor network UID." |
| 19 | + ) |
| 20 | + bt.subtensor.add_args(parser) |
| 21 | + bt.logging.add_args(parser) |
| 22 | + bt.wallet.add_args(parser) |
| 23 | + return bt.config(parser) |
| 24 | + |
| 25 | + |
| 26 | +def main(): |
| 27 | + config = get_config() |
| 28 | + |
| 29 | + wallet = bt.wallet(config=config) |
| 30 | + subtensor = bt.subtensor(config=config) |
| 31 | + |
| 32 | + metagraph = subtensor.metagraph(config.netuid) |
| 33 | + my_uid = metagraph.hotkeys.index(wallet.hotkey.ss58_address) |
| 34 | + tplr.logger.info(f"Running burn on UID {my_uid}, netuid {config.netuid}") |
| 35 | + tplr.logger.info( |
| 36 | + f"Will set 100% weight to burn UID {BURN_UID} every {WEIGHT_INTERVAL} blocks" |
| 37 | + ) |
| 38 | + |
| 39 | + last_set_block = 0 |
| 40 | + log_interval = 10 # Log status every N iterations (~2 minutes) |
| 41 | + iteration = 0 |
| 42 | + |
| 43 | + while True: |
| 44 | + try: |
| 45 | + current_block = subtensor.block |
| 46 | + blocks_since_last = current_block - last_set_block |
| 47 | + blocks_until_next = max(0, WEIGHT_INTERVAL - blocks_since_last) |
| 48 | + |
| 49 | + if blocks_since_last >= WEIGHT_INTERVAL: |
| 50 | + tplr.logger.info( |
| 51 | + f"Block {current_block}: Setting weights to burn UID {BURN_UID}" |
| 52 | + ) |
| 53 | + |
| 54 | + success, msg = subtensor.set_weights( |
| 55 | + wallet=wallet, |
| 56 | + netuid=config.netuid, |
| 57 | + uids=[BURN_UID], |
| 58 | + weights=[1.0], |
| 59 | + wait_for_inclusion=True, |
| 60 | + ) |
| 61 | + |
| 62 | + if success: |
| 63 | + tplr.logger.info( |
| 64 | + f"Weights set successfully at block {current_block}" |
| 65 | + ) |
| 66 | + last_set_block = current_block |
| 67 | + else: |
| 68 | + tplr.logger.warning(f"Failed to set weights: {msg}") |
| 69 | + else: |
| 70 | + # Periodic status log |
| 71 | + iteration += 1 |
| 72 | + if iteration % log_interval == 0: |
| 73 | + tplr.logger.info( |
| 74 | + f"Block {current_block} | " |
| 75 | + f"Blocks until next weight set: {blocks_until_next} | " |
| 76 | + f"Last set: {last_set_block or 'never'}" |
| 77 | + ) |
| 78 | + |
| 79 | + time.sleep(12) |
| 80 | + |
| 81 | + except KeyboardInterrupt: |
| 82 | + tplr.logger.info("Shutting down...") |
| 83 | + break |
| 84 | + except Exception as e: |
| 85 | + tplr.logger.error(f"Error: {e}") |
| 86 | + time.sleep(12) |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == "__main__": |
| 90 | + main() |
0 commit comments