Skip to content

Commit bcc1c10

Browse files
authored
Merge pull request #2017 from opentensor/feat/hyperparams-set-rate-limit
Rate limit hyperparams setting
2 parents b033d0e + 8089518 commit bcc1c10

17 files changed

+842
-79
lines changed

evm-tests/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ between runtime and precompile contracts.
1313

1414
## polkadot api
1515

16+
You need `polkadot-api` globally installed:
17+
18+
```bash
19+
$ npm i -g polkadot-api
20+
```
21+
1622
To get the metadata, you need start the localnet via run
1723
`./scripts/localnet.sh`. then run following command to get metadata, a folder
1824
name .papi will be created, which include the metadata and type definitions.

evm-tests/test/neuron.precompile.reveal-weights.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as assert from "assert";
2-
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
2+
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
33
import { devnet } from "@polkadot-api/descriptors"
44
import { PolkadotSigner, TypedApi } from "polkadot-api";
55
import { convertPublicKeyToSs58, convertH160ToSS58 } from "../src/address-utils"
@@ -70,6 +70,20 @@ describe("Test neuron precompile reveal weights", () => {
7070
await startCall(api, netuid, coldkey)
7171

7272
console.log("test the case on subnet ", netuid)
73+
// Disable admin freeze window and owner hyperparam rate limiting for tests
74+
{
75+
const alice = getAliceSigner()
76+
77+
// Set AdminFreezeWindow to 0
78+
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
79+
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
80+
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)
81+
82+
// Set OwnerHyperparamRateLimit to 0
83+
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
84+
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
85+
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
86+
}
7387

7488
await setWeightsSetRateLimit(api, netuid, BigInt(0))
7589

@@ -164,4 +178,4 @@ describe("Test neuron precompile reveal weights", () => {
164178
assert.ok(weight[1] !== undefined)
165179
}
166180
})
167-
});
181+
});

evm-tests/test/neuron.precompile.set-weights.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "assert";
22

3-
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
3+
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
44
import { devnet } from "@polkadot-api/descriptors"
55
import { TypedApi } from "polkadot-api";
66
import { convertH160ToSS58, convertPublicKeyToSs58, } from "../src/address-utils"
@@ -38,6 +38,20 @@ describe("Test neuron precompile contract, set weights function", () => {
3838
await burnedRegister(api, netuid, convertH160ToSS58(wallet.address), coldkey)
3939
const uid = await api.query.SubtensorModule.Uids.getValue(netuid, convertH160ToSS58(wallet.address))
4040
assert.notEqual(uid, undefined)
41+
// Disable admin freeze window and owner hyperparam rate limiting for tests
42+
{
43+
const alice = getAliceSigner()
44+
45+
// Set AdminFreezeWindow to 0
46+
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
47+
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
48+
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)
49+
50+
// Set OwnerHyperparamRateLimit to 0
51+
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
52+
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
53+
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
54+
}
4155
// disable reveal and enable direct set weights
4256
await setCommitRevealWeightsEnabled(api, netuid, false)
4357
await setWeightsSetRateLimit(api, netuid, BigInt(0))
@@ -68,4 +82,4 @@ describe("Test neuron precompile contract, set weights function", () => {
6882
});
6983
}
7084
})
71-
});
85+
});

evm-tests/test/staking.precompile.reward.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as assert from "assert";
2-
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
2+
import { getAliceSigner, getDevnetApi, getRandomSubstrateKeypair, waitForTransactionWithRetry } from "../src/substrate"
33
import { devnet } from "@polkadot-api/descriptors"
44
import { TypedApi } from "polkadot-api";
55
import { convertPublicKeyToSs58 } from "../src/address-utils"
@@ -39,6 +39,20 @@ describe("Test neuron precompile reward", () => {
3939
await startCall(api, netuid, coldkey)
4040

4141
console.log("test the case on subnet ", netuid)
42+
// Disable admin freeze window and owner hyperparam rate limiting for tests
43+
{
44+
const alice = getAliceSigner()
45+
46+
// Set AdminFreezeWindow to 0
47+
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
48+
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
49+
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)
50+
51+
// Set OwnerHyperparamRateLimit to 0
52+
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
53+
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
54+
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
55+
}
4256

4357
await setTxRateLimit(api, BigInt(0))
4458
await setTempo(api, root_netuid, root_tempo)

evm-tests/test/staking.precompile.stake-get.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("Test staking precompile get methods", () => {
4545
await contract.getStake(hotkey.publicKey, coldkey.publicKey, netuid)
4646
);
4747

48-
// validator returned as bigint now.
48+
// validator returned as bigint now.
4949
const validators =
5050
await contract.getAlphaStakedValidators(hotkey.publicKey, netuid)
5151

evm-tests/test/subnet.precompile.hyperparameter.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "assert";
22

3-
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
3+
import { getDevnetApi, getRandomSubstrateKeypair, getAliceSigner, waitForTransactionWithRetry } from "../src/substrate"
44
import { devnet } from "@polkadot-api/descriptors"
55
import { TypedApi } from "polkadot-api";
66
import { convertPublicKeyToSs58 } from "../src/address-utils"
@@ -25,6 +25,21 @@ describe("Test the Subnet precompile contract", () => {
2525
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey1.publicKey))
2626
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey2.publicKey))
2727
await forceSetBalanceToEthAddress(api, wallet.address)
28+
29+
// Disable admin freeze window and owner hyperparam rate limiting for tests
30+
{
31+
const alice = getAliceSigner()
32+
33+
// Set AdminFreezeWindow to 0
34+
const setFreezeWindow = api.tx.AdminUtils.sudo_set_admin_freeze_window({ window: 0 })
35+
const sudoFreezeTx = api.tx.Sudo.sudo({ call: setFreezeWindow.decodedCall })
36+
await waitForTransactionWithRetry(api, sudoFreezeTx, alice)
37+
38+
// Set OwnerHyperparamRateLimit to 0
39+
const setOwnerRateLimit = api.tx.AdminUtils.sudo_set_owner_hparam_rate_limit({ limit: BigInt(0) })
40+
const sudoOwnerRateTx = api.tx.Sudo.sudo({ call: setOwnerRateLimit.decodedCall })
41+
await waitForTransactionWithRetry(api, sudoOwnerRateTx, alice)
42+
}
2843
})
2944

3045
it("Can register network without identity info", async () => {

pallets/admin-utils/src/benchmarking.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,18 @@ mod benchmarks {
346346
_(RawOrigin::Root, 5u16/*version*/)/*sudo_set_commit_reveal_version()*/;
347347
}
348348

349+
#[benchmark]
350+
fn sudo_set_admin_freeze_window() {
351+
#[extrinsic_call]
352+
_(RawOrigin::Root, 5u16/*window*/)/*sudo_set_admin_freeze_window*/;
353+
}
354+
355+
#[benchmark]
356+
fn sudo_set_owner_hparam_rate_limit() {
357+
#[extrinsic_call]
358+
_(RawOrigin::Root, 10u64/*limit*/)/*sudo_set_owner_hparam_rate_limit*/;
359+
}
360+
349361
#[benchmark]
350362
fn sudo_set_owner_immune_neuron_limit() {
351363
pallet_subtensor::Pallet::<T>::init_new_network(

0 commit comments

Comments
 (0)