Skip to content

Commit dcbbdcc

Browse files
Rate limits work smarter (#117)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * edit rate limit script --------- Co-authored-by: michael trestman <m@latent.to>
1 parent 946d3e4 commit dcbbdcc

File tree

4 files changed

+874
-27
lines changed

4 files changed

+874
-27
lines changed

docs/scripts/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Rate Limits Checker
2+
3+
A simple script to query and display rate limit values from the Bittensor network.
4+
5+
## What it does
6+
7+
Connects to the Bittensor Finney network and queries:
8+
9+
- **Global rate limits**: Transaction limits, delegate take limits, network limits, etc.
10+
- **Subnet-specific limits**: Serving rates, adjustment intervals, immunity periods, etc.
11+
12+
## Prerequisites
13+
14+
- Node.js 18.0 or higher
15+
- Dependencies installed (run `yarn install` if needed)
16+
17+
## How to run
18+
19+
```bash
20+
yarn node docs/scripts/check-rate-limits.js
21+
```
22+
23+
> **Note**: This project uses Yarn PnP, so you must run the script with `yarn node` instead of just `node`.
24+
25+
## Expected output
26+
27+
```
28+
Connecting to Bittensor network...
29+
✓ Connected successfully!
30+
31+
GLOBAL RATE LIMITS:
32+
==================
33+
TxRateLimit: 1 blocks (~0h)
34+
TxDelegateTakeRateLimit: 216000 blocks (~720h)
35+
TxChildkeyTakeRateLimit: 216000 blocks (~720h)
36+
NetworkRateLimit: 28800 blocks (~96h)
37+
OwnerHyperparamRateLimit: 2 tempos
38+
WeightsVersionKeyRateLimit: 5 blocks (~0h)
39+
AdminFreezeWindow: 10 blocks (~0h)
40+
41+
SUBNET-SPECIFIC RATE LIMITS (Subnet 1):
42+
=======================================
43+
ServingRateLimit: 10 blocks (~0h)
44+
AdjustmentInterval: 112 blocks (~0.4h)
45+
ImmunityPeriod: 7200 blocks (~24h)
46+
WeightsSetRateLimit: 100 blocks (~0.3h)
47+
MaxRegistrationsPerBlock: 1 registrations
48+
TargetRegistrationsPerInterval: 2 registrations
49+
50+
✓ Complete
51+
```
52+
53+
## Troubleshooting
54+
55+
**Error: Cannot find module '@polkadot/api'**
56+
57+
- Make sure you've run `yarn install` first
58+
- Use `yarn node` instead of `node` to run the script
59+
60+
**Connection timeout**
61+
62+
- Check your internet connection
63+
- The script connects to `wss://entrypoint-finney.opentensor.ai:443`

docs/scripts/check-rate-limits.js

Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const { ApiPromise, WsProvider } = require("@polkadot/api");
1111
async function checkRateLimits() {
1212
try {
1313
console.log("Connecting to Bittensor network...");
14-
const wsProvider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
14+
const wsProvider = new WsProvider(
15+
"wss://entrypoint-finney.opentensor.ai:443"
16+
);
1517
const api = await ApiPromise.create({ provider: wsProvider });
1618

1719
console.log("✓ Connected successfully!\n");
@@ -21,52 +23,100 @@ async function checkRateLimits() {
2123
// Global rate limits
2224
console.log("GLOBAL RATE LIMITS:");
2325
console.log("==================");
24-
26+
2527
try {
2628
const txRateLimit = await api.query.subtensorModule.txRateLimit();
27-
console.log(`TxRateLimit: ${txRateLimit.toNumber()} blocks (~${Math.round(txRateLimit.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`);
29+
console.log(
30+
`TxRateLimit: ${txRateLimit.toNumber()} blocks (~${
31+
Math.round(
32+
((txRateLimit.toNumber() * blockTimeSeconds) / 3600) * 10
33+
) / 10
34+
}h)`
35+
);
2836
} catch (e) {
2937
console.log("TxRateLimit: Unable to query");
3038
}
3139

3240
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)`);
41+
const txDelegateTakeRateLimit =
42+
await api.query.subtensorModule.txDelegateTakeRateLimit();
43+
console.log(
44+
`TxDelegateTakeRateLimit: ${txDelegateTakeRateLimit.toNumber()} blocks (~${
45+
Math.round(
46+
((txDelegateTakeRateLimit.toNumber() * blockTimeSeconds) / 3600) *
47+
10
48+
) / 10
49+
}h)`
50+
);
3551
} catch (e) {
3652
console.log("TxDelegateTakeRateLimit: Unable to query");
3753
}
3854

3955
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)`);
56+
const txChildkeyTakeRateLimit =
57+
await api.query.subtensorModule.txChildkeyTakeRateLimit();
58+
console.log(
59+
`TxChildkeyTakeRateLimit: ${txChildkeyTakeRateLimit.toNumber()} blocks (~${
60+
Math.round(
61+
((txChildkeyTakeRateLimit.toNumber() * blockTimeSeconds) / 3600) *
62+
10
63+
) / 10
64+
}h)`
65+
);
4266
} catch (e) {
4367
console.log("TxChildkeyTakeRateLimit: Unable to query");
4468
}
4569

4670
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)`);
71+
const networkRateLimit =
72+
await api.query.subtensorModule.networkRateLimit();
73+
console.log(
74+
`NetworkRateLimit: ${networkRateLimit.toNumber()} blocks (~${
75+
Math.round(
76+
((networkRateLimit.toNumber() * blockTimeSeconds) / 3600) * 10
77+
) / 10
78+
}h)`
79+
);
4980
} catch (e) {
5081
console.log("NetworkRateLimit: Unable to query");
5182
}
5283

5384
try {
54-
const ownerHyperparamRateLimit = await api.query.subtensorModule.ownerHyperparamRateLimit();
55-
console.log(`OwnerHyperparamRateLimit: ${ownerHyperparamRateLimit.toNumber()} tempos`);
85+
const ownerHyperparamRateLimit =
86+
await api.query.subtensorModule.ownerHyperparamRateLimit();
87+
console.log(
88+
`OwnerHyperparamRateLimit: ${ownerHyperparamRateLimit.toNumber()} tempos`
89+
);
5690
} catch (e) {
5791
console.log("OwnerHyperparamRateLimit: Unable to query");
5892
}
5993

6094
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)`);
95+
const weightsVersionKeyRateLimit =
96+
await api.query.subtensorModule.weightsVersionKeyRateLimit();
97+
console.log(
98+
`WeightsVersionKeyRateLimit: ${weightsVersionKeyRateLimit.toNumber()} blocks (~${
99+
Math.round(
100+
((weightsVersionKeyRateLimit.toNumber() * blockTimeSeconds) /
101+
3600) *
102+
10
103+
) / 10
104+
}h)`
105+
);
63106
} catch (e) {
64107
console.log("WeightsVersionKeyRateLimit: Unable to query");
65108
}
66109

67110
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)`);
111+
const adminFreezeWindow =
112+
await api.query.subtensorModule.adminFreezeWindow();
113+
console.log(
114+
`AdminFreezeWindow: ${adminFreezeWindow.toNumber()} blocks (~${
115+
Math.round(
116+
((adminFreezeWindow.toNumber() * blockTimeSeconds) / 3600) * 10
117+
) / 10
118+
}h)`
119+
);
70120
} catch (e) {
71121
console.log("AdminFreezeWindow: Unable to query");
72122
}
@@ -76,49 +126,85 @@ async function checkRateLimits() {
76126
console.log("=======================================");
77127

78128
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)`);
129+
const servingRateLimit = await api.query.subtensorModule.servingRateLimit(
130+
1
131+
);
132+
console.log(
133+
`ServingRateLimit: ${servingRateLimit.toNumber()} blocks (~${
134+
Math.round(
135+
((servingRateLimit.toNumber() * blockTimeSeconds) / 3600) * 10
136+
) / 10
137+
}h)`
138+
);
81139
} catch (e) {
82140
console.log("ServingRateLimit: Unable to query");
83141
}
84142

85143
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)`);
144+
const adjustmentInterval =
145+
await api.query.subtensorModule.adjustmentInterval(1);
146+
console.log(
147+
`AdjustmentInterval: ${adjustmentInterval.toNumber()} blocks (~${
148+
Math.round(
149+
((adjustmentInterval.toNumber() * blockTimeSeconds) / 3600) * 10
150+
) / 10
151+
}h)`
152+
);
88153
} catch (e) {
89154
console.log("AdjustmentInterval: Unable to query");
90155
}
91156

92157
try {
93158
const immunityPeriod = await api.query.subtensorModule.immunityPeriod(1);
94-
console.log(`ImmunityPeriod: ${immunityPeriod.toNumber()} blocks (~${Math.round(immunityPeriod.toNumber() * blockTimeSeconds / 3600 * 10) / 10}h)`);
159+
console.log(
160+
`ImmunityPeriod: ${immunityPeriod.toNumber()} blocks (~${
161+
Math.round(
162+
((immunityPeriod.toNumber() * blockTimeSeconds) / 3600) * 10
163+
) / 10
164+
}h)`
165+
);
95166
} catch (e) {
96167
console.log("ImmunityPeriod: Unable to query");
97168
}
98169

99170
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)`);
171+
const weightsSetRateLimit =
172+
await api.query.subtensorModule.weightsSetRateLimit(1);
173+
console.log(
174+
`WeightsSetRateLimit: ${weightsSetRateLimit.toNumber()} blocks (~${
175+
Math.round(
176+
((weightsSetRateLimit.toNumber() * blockTimeSeconds) / 3600) * 10
177+
) / 10
178+
}h)`
179+
);
102180
} catch (e) {
103181
console.log("WeightsSetRateLimit: Unable to query");
104182
}
105183

106184
try {
107-
const maxRegistrationsPerBlock = await api.query.subtensorModule.maxRegistrationsPerBlock(1);
108-
console.log(`MaxRegistrationsPerBlock: ${maxRegistrationsPerBlock.toNumber()} registrations`);
185+
const maxRegistrationsPerBlock =
186+
await api.query.subtensorModule.maxRegistrationsPerBlock(1);
187+
console.log(
188+
`MaxRegistrationsPerBlock: ${maxRegistrationsPerBlock.toNumber()} registrations`
189+
);
109190
} catch (e) {
110191
console.log("MaxRegistrationsPerBlock: Unable to query");
111192
}
112193

113194
try {
114-
const targetRegistrationsPerInterval = await api.query.subtensorModule.targetRegistrationsPerInterval(1);
115-
console.log(`TargetRegistrationsPerInterval: ${targetRegistrationsPerInterval.toNumber()} registrations`);
195+
const targetRegistrationsPerInterval =
196+
await api.query.subtensorModule.targetRegistrationsPerInterval(1);
197+
console.log(
198+
`TargetRegistrationsPerInterval: ${targetRegistrationsPerInterval.toNumber()} registrations`
199+
);
116200
} catch (e) {
117201
console.log("TargetRegistrationsPerInterval: Unable to query");
118202
}
119203

120204
console.log("\n✓ Complete");
121205

206+
await api.disconnect();
207+
process.exit(0);
122208
} catch (error) {
123209
console.error("Error:", error.message);
124210
process.exit(1);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@docusaurus/theme-search-algolia": "^3.7.0",
2525
"@gracefullight/docusaurus-plugin-vercel-analytics": "^1.0.0",
2626
"@mdx-js/react": "^3.0.0",
27+
"@polkadot/api": "^16.4.8",
2728
"@vercel/analytics": "^1.1.2",
2829
"clsx": "^1.2.1",
2930
"hast-util-is-element": "1.1.0",

0 commit comments

Comments
 (0)