Skip to content

Commit 9f29af1

Browse files
Merge pull request #5 from opentensor/update-readme-file
Updates the readme file
2 parents 941a492 + 946e863 commit 9f29af1

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

README.md

+28-12
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,36 @@ def get_encrypted_commit(
1212
uids: Union[NDArray[np.int64], "torch.LongTensor"],
1313
weights: Union[NDArray[np.float32], "torch.FloatTensor"],
1414
version_key: int,
15-
subnet_reveal_period_epochs: int = 1,
16-
block_time: int = 12,
17-
tempo: int = 360
15+
tempo: int,
16+
current_block: int,
17+
netuid: int,
18+
subnet_reveal_period_epochs: int,
19+
block_time: int = 12
1820
) -> tuple[bytes, int]:
1921
"""Returns encrypted commit and target round for `commit_crv3_weights` extrinsic.
2022
2123
Arguments:
2224
uids: The uids to commit.
2325
weights: The weights associated with the uids.
2426
version_key: The version key to use for committing and revealing. Default is `bittensor.core.settings.version_as_int`.
25-
subnet_reveal_period_epochs: Number of epochs after which the revive will be performed. Corresponds to hyperparameter 'commit_reveal_weights_interval' of the subnet. In epochs.
26-
block_time: Amount if seconds in one block. In seconds.
27-
tempo: Amount of blocks in one Epoch.
28-
27+
tempo: Number of blocks in one epoch.
28+
current_block: The current block number in the network.
29+
netuid: The network unique identifier (NetUID) for the subnet.
30+
subnet_reveal_period_epochs: Number of epochs after which the reveal will be performed. Corresponds to the hyperparameter `commit_reveal_weights_interval` of the subnet. In epochs.
31+
block_time: Amount of time in seconds for one block. Defaults to 12 seconds.
32+
2933
Returns:
30-
commit (bites): hex value of encrypted and compressed uids and weights values for setting weights.
34+
commit (bytes): Raw bytes of the encrypted, and compressed uids & weights values for setting weights.
3135
target_round (int): Drand round number when weights have to be revealed. Based on Drand Quicknet network.
32-
"""
36+
"""
3337
# function logic
3438
return commit, target_round
3539
```
3640

3741

3842
To test the function run in terminal:
43+
1. Spin up a local subtensor branch which includes CR3
44+
2. Create a subnet with netuid 1 (or replace the netuid with the one you create)
3945
```bash
4046
mkdir test
4147
cd test
@@ -54,10 +60,20 @@ then copy-past to ipython
5460
import numpy as np
5561
import bittensor_commit_reveal as crv3
5662
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
63+
import bittensor as bt
5764

5865
uids = [1, 3]
5966
weights = [0.3, 0.7]
6067
version_key = 843000
68+
netuid = 1
69+
70+
subtensor = bt.Subtensor("local")
71+
72+
subnet_reveal_period_epochs = subtensor.get_subnet_reveal_period_epochs(
73+
netuid=netuid
74+
)
75+
tempo = subtensor.get_subnet_hyperparameters(netuid).tempo
76+
current_block = subtensor.get_current_block()
6177

6278
if isinstance(uids, list):
6379
uids = np.array(uids, dtype=np.int64)
@@ -66,15 +82,15 @@ if isinstance(weights, list):
6682

6783
uids, weights = convert_weights_and_uids_for_emit(uids, weights)
6884

69-
print(crv3.get_encrypted_commit(uids, weights, version_key))
85+
print(crv3.get_encrypted_commit(uids, weights, version_key, tempo, current_block, netuid, subnet_reveal_period_epochs))
7086
```
7187
expected result
7288
```python
7389
(b'\xb9\x96\xe4\xd1\xfd\xabm\x8cc\xeb\xe3W\r\xc7J\xb4\xea\xa9\xd5u}OG~\xae\xcc\x9a@\xdf\xee\x16\xa9\x0c\x8d7\xd6\xea_c\xc2<\xcb\xa6\xbe^K\x97|\x16\xc6|;\xb5Z\x97\xc9\xb4\x8em\xf1hv\x16\xcf\xea\x1e7\xbe-Z\xe7e\x1f$\n\xf8\x08\xcb\x18.\x94V\xa3\xd7\xcd\xc9\x04F::\t)Z\xc6\xbey \x00\x00\x00\x00\x00\x00\x00\xaaN\xe8\xe97\x8f\x99\xbb"\xdf\xad\xf6\\#%\xca:\xc2\xce\xf9\x96\x9d\x8f\x9d\xa2\xad\xfd\xc73j\x16\xda \x00\x00\x00\x00\x00\x00\x00\x84*\xb0\rw\xad\xdc\x02o\xf7i)\xbb^\x99e\xe2\\\xee\x02NR+-Q\xcd \xf7\x02\x83\xffV>\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00*\x13wXb\x93\xc5"F\x17F\x05\xcd\x15\xb0=\xe2d\xfco3\x16\xfd\xe9\xc6\xbc\xd1\xb3Y\x97\xf9\xb9!\x01\x0c\x00\x00\x00\x00\x00\x00\x00X\xa2\x8c\x18Wkq\xe5\xe6\x1c2\x86\x08\x00\x00\x00\x00\x00\x00\x00AES_GCM_', 13300875)
7490
```
7591

7692
To test this in local subnet you need:
77-
1. Spinup local node based on the subtensor branch `spiigot/add-pallet-drand` using command `./scripts/localnet.sh "False"`
93+
1. Spinup local node based on the subtensor branch `spiigot/add-pallet-drand` using command `./scripts/localnet.sh False`
7894
2. Create subnet
7995
3. Change the next hyperparameters:
8096
- `commit_reveal_weights_enabled` -> `True`
@@ -159,7 +175,7 @@ import bittensor as bt
159175

160176
sub = bt.Subtensor(network="local")
161177

162-
netuid = 1 # your created subnets netuid
178+
netuid = 1 # your created subnet's netuid
163179

164180
print(sub.weights(netuid=netuid))
165181
```

0 commit comments

Comments
 (0)