Skip to content

Commit 6669225

Browse files
authored
Merge pull request #30 from opentensor/release/0.5.0
Release/0.5.0
2 parents 34798ea + e61eec1 commit 6669225

File tree

15 files changed

+1220
-89
lines changed

15 files changed

+1220
-89
lines changed

.github/workflows/check-sdk-tests.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Bittensor SDK Test
22

33
permissions:
44
pull-requests: write
5+
issues: write
56
contents: read
67

78
concurrency:
@@ -188,17 +189,17 @@ jobs:
188189
working-directory: ${{ github.workspace }}
189190
run: uv sync --all-extras --dev
190191

191-
- name: Clone bittensor-commit-reveal repo
192-
run: git clone https://github.com/opentensor/bittensor-commit-reveal.git
192+
- name: Clone bittensor-drand repo
193+
run: git clone https://github.com/opentensor/bittensor-drand.git
193194

194-
- name: Checkout PR branch in bittensor-commit-reveal repo
195-
working-directory: ${{ github.workspace }}/bittensor-commit-reveal
195+
- name: Checkout PR branch in bittensor-drand repo
196+
working-directory: ${{ github.workspace }}/bittensor-drand
196197
run: |
197198
git fetch origin ${{ github.event.pull_request.head.ref }}
198199
git checkout ${{ github.event.pull_request.head.ref }}
199200
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
200201
201-
- name: Build and install bittensor-commit-reveal repo package
202+
- name: Build and install bittensor-drand repo package
202203
working-directory: ${{ github.workspace }}
203204
run: |
204205
source ${{ github.workspace }}/venv/bin/activate
@@ -212,8 +213,30 @@ jobs:
212213
- name: Load Docker Image
213214
run: docker load -i subtensor-localnet.tar
214215

215-
- name: Run tests
216-
working-directory: ${{ github.workspace }}
216+
# - name: Run tests
217+
# working-directory: ${{ github.workspace }}
218+
# run: |
219+
# source ${{ github.workspace }}/venv/bin/activate
220+
# pytest ${{ matrix.test-file }} -s
221+
222+
- name: Run tests with retry
217223
run: |
218224
source ${{ github.workspace }}/venv/bin/activate
219-
pytest ${{ matrix.test-file }} -s
225+
set +e
226+
for i in 1 2; do
227+
echo "🔁 Attempt $i: Running tests"
228+
pytest ${{ matrix.test-file }} -s
229+
status=$?
230+
if [ $status -eq 0 ]; then
231+
echo "✅ Tests passed on attempt $i"
232+
break
233+
else
234+
echo "❌ Tests failed on attempt $i"
235+
if [ $i -eq 2 ]; then
236+
echo "Tests failed after 2 attempts"
237+
exit 1
238+
fi
239+
echo "Retrying..."
240+
sleep 5
241+
fi
242+
done

CHANGELOG.MD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v0.5.0 /2025-04-28
4+
5+
## What's Changed
6+
* Rename package to `bittensor-drand` by @basfroman in https://github.com/opentensor/bittensor-drand/pull/25
7+
* update imports in README.md by @basfroman in https://github.com/opentensor/bittensor-drand/pull/26
8+
* feat: implement ffi , generate C headers by @distributedstatemachine in https://github.com/opentensor/bittensor-drand/pull/27
9+
* Add permissions by @basfroman in https://github.com/opentensor/bittensor-drand/pull/28
10+
11+
## New Contributors
12+
* @distributedstatemachine made their first contribution in https://github.com/opentensor/bittensor-drand/pull/27
13+
314
## v0.4.0 /2025-04-14
415

516
## What's Changed

Cargo.lock

Lines changed: 49 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
2-
name = "bittensor-commit-reveal"
3-
version = "0.4.0"
2+
name = "bittensor-drand"
3+
version = "0.5.0"
44
edition = "2021"
55

66
[lib]
7-
name = "bittensor_commit_reveal"
7+
name = "bittensor_drand"
88
crate-type = ["cdylib"]
99

1010
[dependencies]
@@ -19,6 +19,8 @@ sha2 = "0.10.8"
1919
w3f-bls = { version = "=0.1.3", default-features = false }
2020
serde = { version = "1.0.215", features = ["derive"] }
2121
reqwest = { version = "0.12.15", features = ["json"] }
22+
libc = "0.2.172"
23+
rand = "0.9.1"
2224

2325
[features]
2426
default = ["extension-module"]

README.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,10 @@
11
# Usage
2-
Python package `bittensor_commit_reveal` has one function.
2+
Python package `bittensor_drand` has one function.
33

44
```python
5-
from bittensor_commit_reveal import get_encrypted_commit
5+
from bittensor_drand import get_encrypted_commit
66
```
77

8-
## Function docstring
9-
The function could be considered like this:
10-
```python
11-
def get_encrypted_commit(
12-
uids: Union[NDArray[np.int64], "torch.LongTensor"],
13-
weights: Union[NDArray[np.float32], "torch.FloatTensor"],
14-
version_key: int,
15-
tempo: int,
16-
current_block: int,
17-
netuid: int,
18-
subnet_reveal_period_epochs: int,
19-
block_time: int = 12
20-
) -> tuple[bytes, int]:
21-
"""Returns encrypted commit and target round for `commit_crv3_weights` extrinsic.
22-
23-
Arguments:
24-
uids: The uids to commit.
25-
weights: The weights associated with the uids.
26-
version_key: The version key to use for committing and revealing. Default is `bittensor.core.settings.version_as_int`.
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-
33-
Returns:
34-
commit (bytes): Raw bytes of the encrypted, and compressed uids & weights values for setting weights.
35-
target_round (int): Drand round number when weights have to be revealed. Based on Drand Quicknet network.
36-
"""
37-
# function logic
38-
return commit, target_round
39-
```
40-
41-
428
To test the function in your terminal:
439
1. Spin up a local subtensor branch which includes CR3
4410
2. Create a subnet with netuid 1 (or replace the netuid with the one you create)
@@ -58,7 +24,7 @@ ipython
5824
then copy-past to ipython
5925
```python
6026
import numpy as np
61-
import bittensor_commit_reveal as crv3
27+
import bittensor_drand as crv3
6228
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
6329
import bittensor as bt
6430

bindings.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Generated by cbindgen – DO NOT EDIT */
2+
3+
#include <stdarg.h>
4+
#include <stdbool.h>
5+
#include <stdint.h>
6+
#include <stdlib.h>
7+
8+
#define SUBTENSOR_PULSE_DELAY 24
9+
10+
#define GENESIS_TIME 1692803367
11+
12+
#define DRAND_PERIOD 3
13+
14+
typedef struct CRByteBuffer {
15+
uint8_t *ptr;
16+
uintptr_t len;
17+
uintptr_t cap;
18+
} CRByteBuffer;
19+
20+
const char *drand_public_key_hex(void);
21+
22+
const char *drand_chain_hash(void);
23+
24+
const char *drand_endpoint(uintptr_t idx);
25+
26+
void cr_free(struct CRByteBuffer buf);
27+
28+
void cr_free_str(char *s);
29+
30+
struct CRByteBuffer cr_encrypt(const uint8_t *data_ptr,
31+
uintptr_t data_len,
32+
uint64_t n_blocks,
33+
double block_time,
34+
uint64_t *round_out,
35+
char **err_out);
36+
37+
uint8_t *cr_decrypt(const uint8_t *enc_ptr,
38+
uintptr_t enc_len,
39+
bool no_errors,
40+
uintptr_t *out_len,
41+
char **err_out);
42+
43+
uint64_t cr_get_latest_round(char **err_out);
44+
45+
struct CRByteBuffer cr_encrypt_commitment(const uint8_t *data_ptr,
46+
uintptr_t data_len,
47+
uint64_t blocks_until_reveal,
48+
double block_time,
49+
uint64_t *round_out,
50+
char **err_out);
51+
52+
struct CRByteBuffer cr_generate_commit(const uint16_t *uids_ptr,
53+
uintptr_t uids_len,
54+
const uint16_t *vals_ptr,
55+
uintptr_t vals_len,
56+
uint64_t version_key,
57+
uint64_t tempo,
58+
uint64_t current_block,
59+
uint16_t netuid,
60+
uint64_t subnet_reveal_epochs,
61+
double block_time,
62+
uint64_t *round_out,
63+
char **err_out);

0 commit comments

Comments
 (0)