|
| 1 | +/* |
| 2 | +SIMPLE BITENSOR RATE LIMITS CHECKER |
| 3 | +=================================== |
| 4 | +Queries the specific rate limit state variables mentioned in the documentation. |
| 5 | +
|
| 6 | +Usage: node simple-rate-limits.js |
| 7 | +*/ |
| 8 | + |
| 9 | +const { ApiPromise, WsProvider } = require("@polkadot/api"); |
| 10 | + |
| 11 | +async function checkRateLimits() { |
| 12 | + try { |
| 13 | + console.log("Connecting to Bittensor network..."); |
| 14 | + const wsProvider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443"); |
| 15 | + const api = await ApiPromise.create({ provider: wsProvider }); |
| 16 | + |
| 17 | + console.log("✓ Connected successfully!\n"); |
| 18 | + |
| 19 | + const blockTimeSeconds = 12; // Bittensor blocks are ~12 seconds |
| 20 | + |
| 21 | + // Global rate limits |
| 22 | + console.log("GLOBAL RATE LIMITS:"); |
| 23 | + console.log("=================="); |
| 24 | + |
| 25 | + try { |
| 26 | + const txRateLimit = await api.query.subtensorModule.txRateLimit(); |
| 27 | + console.log(`TxRateLimit: ${txRateLimit.toNumber()} blocks (~${Math.round(txRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 28 | + } catch (e) { |
| 29 | + console.log("TxRateLimit: Unable to query"); |
| 30 | + } |
| 31 | + |
| 32 | + try { |
| 33 | + const txDelegateTakeRateLimit = await api.query.subtensorModule.txDelegateTakeRateLimit(); |
| 34 | + console.log(`TxDelegateTakeRateLimit: ${txDelegateTakeRateLimit.toNumber()} blocks (~${Math.round(txDelegateTakeRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 35 | + } catch (e) { |
| 36 | + console.log("TxDelegateTakeRateLimit: Unable to query"); |
| 37 | + } |
| 38 | + |
| 39 | + try { |
| 40 | + const txChildkeyTakeRateLimit = await api.query.subtensorModule.txChildkeyTakeRateLimit(); |
| 41 | + console.log(`TxChildkeyTakeRateLimit: ${txChildkeyTakeRateLimit.toNumber()} blocks (~${Math.round(txChildkeyTakeRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 42 | + } catch (e) { |
| 43 | + console.log("TxChildkeyTakeRateLimit: Unable to query"); |
| 44 | + } |
| 45 | + |
| 46 | + try { |
| 47 | + const networkRateLimit = await api.query.subtensorModule.networkRateLimit(); |
| 48 | + console.log(`NetworkRateLimit: ${networkRateLimit.toNumber()} blocks (~${Math.round(networkRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 49 | + } catch (e) { |
| 50 | + console.log("NetworkRateLimit: Unable to query"); |
| 51 | + } |
| 52 | + |
| 53 | + try { |
| 54 | + const ownerHyperparamRateLimit = await api.query.subtensorModule.ownerHyperparamRateLimit(); |
| 55 | + console.log(`OwnerHyperparamRateLimit: ${ownerHyperparamRateLimit.toNumber()} tempos`); |
| 56 | + } catch (e) { |
| 57 | + console.log("OwnerHyperparamRateLimit: Unable to query"); |
| 58 | + } |
| 59 | + |
| 60 | + try { |
| 61 | + const weightsVersionKeyRateLimit = await api.query.subtensorModule.weightsVersionKeyRateLimit(); |
| 62 | + console.log(`WeightsVersionKeyRateLimit: ${weightsVersionKeyRateLimit.toNumber()} blocks (~${Math.round(weightsVersionKeyRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 63 | + } catch (e) { |
| 64 | + console.log("WeightsVersionKeyRateLimit: Unable to query"); |
| 65 | + } |
| 66 | + |
| 67 | + try { |
| 68 | + const adminFreezeWindow = await api.query.subtensorModule.adminFreezeWindow(); |
| 69 | + console.log(`AdminFreezeWindow: ${adminFreezeWindow.toNumber()} blocks (~${Math.round(adminFreezeWindow.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 70 | + } catch (e) { |
| 71 | + console.log("AdminFreezeWindow: Unable to query"); |
| 72 | + } |
| 73 | + |
| 74 | + // Subnet-specific rate limits (check subnet 1 as example) |
| 75 | + console.log("\nSUBNET-SPECIFIC RATE LIMITS (Subnet 1):"); |
| 76 | + console.log("======================================="); |
| 77 | + |
| 78 | + try { |
| 79 | + const servingRateLimit = await api.query.subtensorModule.servingRateLimit(1); |
| 80 | + console.log(`ServingRateLimit: ${servingRateLimit.toNumber()} blocks (~${Math.round(servingRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 81 | + } catch (e) { |
| 82 | + console.log("ServingRateLimit: Unable to query"); |
| 83 | + } |
| 84 | + |
| 85 | + try { |
| 86 | + const adjustmentInterval = await api.query.subtensorModule.adjustmentInterval(1); |
| 87 | + console.log(`AdjustmentInterval: ${adjustmentInterval.toNumber()} blocks (~${Math.round(adjustmentInterval.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 88 | + } catch (e) { |
| 89 | + console.log("AdjustmentInterval: Unable to query"); |
| 90 | + } |
| 91 | + |
| 92 | + try { |
| 93 | + const immunityPeriod = await api.query.subtensorModule.immunityPeriod(1); |
| 94 | + console.log(`ImmunityPeriod: ${immunityPeriod.toNumber()} blocks (~${Math.round(immunityPeriod.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 95 | + } catch (e) { |
| 96 | + console.log("ImmunityPeriod: Unable to query"); |
| 97 | + } |
| 98 | + |
| 99 | + try { |
| 100 | + const weightsSetRateLimit = await api.query.subtensorModule.weightsSetRateLimit(1); |
| 101 | + console.log(`WeightsSetRateLimit: ${weightsSetRateLimit.toNumber()} blocks (~${Math.round(weightsSetRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`); |
| 102 | + } catch (e) { |
| 103 | + console.log("WeightsSetRateLimit: Unable to query"); |
| 104 | + } |
| 105 | + |
| 106 | + try { |
| 107 | + const maxRegistrationsPerBlock = await api.query.subtensorModule.maxRegistrationsPerBlock(1); |
| 108 | + console.log(`MaxRegistrationsPerBlock: ${maxRegistrationsPerBlock.toNumber()} registrations`); |
| 109 | + } catch (e) { |
| 110 | + console.log("MaxRegistrationsPerBlock: Unable to query"); |
| 111 | + } |
| 112 | + |
| 113 | + try { |
| 114 | + const targetRegistrationsPerInterval = await api.query.subtensorModule.targetRegistrationsPerInterval(1); |
| 115 | + console.log(`TargetRegistrationsPerInterval: ${targetRegistrationsPerInterval.toNumber()} registrations`); |
| 116 | + } catch (e) { |
| 117 | + console.log("TargetRegistrationsPerInterval: Unable to query"); |
| 118 | + } |
| 119 | + |
| 120 | + console.log("\n✓ Complete"); |
| 121 | + |
| 122 | + } catch (error) { |
| 123 | + console.error("Error:", error.message); |
| 124 | + process.exit(1); |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +// Run the script |
| 129 | +checkRateLimits().catch(console.error); |
| 130 | + |
| 131 | +// Suppress warning messages |
| 132 | +console.warn = () => {}; |
0 commit comments