Skip to content

Commit 81cfb33

Browse files
authored
Merge branch 'staging' into feat--silent-aiohttp.ClientOSError
2 parents 922b9b3 + 0c75b51 commit 81cfb33

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](https://discord.gg/bittensor)
55
[![CodeQL](https://github.com/opentensor/bittensor/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/opentensor/bittensor/actions)
66
[![PyPI version](https://badge.fury.io/py/bittensor.svg)](https://badge.fury.io/py/bittensor)
7+
[![Codecov](https://codecov.io/gh/opentensor/bittensor/graph/badge.svg)](https://app.codecov.io/gh/opentensor/bittensor)
78
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
89

910
---

bittensor/core/timelock.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
"""
2+
This module provides functionality for TimeLock Encryption (TLE), a mechanism that encrypts data such that it can
3+
only be decrypted after a specific amount of time (expressed in the form of Drand rounds). It includes functions
4+
for encryption, decryption, and handling the decryption process by waiting for the reveal round. The logic is based on
5+
Drand QuickNet.
6+
7+
Main Functions:
8+
- encrypt: Encrypts data and returns the encrypted data along with the reveal round.
9+
- decrypt: Decrypts the provided encrypted data when the reveal round is reached.
10+
- wait_reveal_and_decrypt: Waits for the reveal round and decrypts the encrypted data.
11+
12+
Usage Example:
13+
```python
14+
from bittensor import timelock
15+
data = "From Cortex to Bittensor"
16+
encrypted_data, reveal_round = timelock.encrypt(data, n_blocks=5)
17+
decrypted_data = timelock.wait_reveal_and_decrypt(encrypted_data)
18+
```
19+
20+
Usage Example with custom data:
21+
```python
22+
import pickle
23+
from dataclasses import dataclass
24+
25+
from bittensor import timelock
26+
27+
28+
@dataclass
29+
class Person:
30+
name: str
31+
age: int
32+
33+
# get instance of your data
34+
x_person = Person("X Lynch", 123)
35+
36+
# get bytes of your instance
37+
byte_data = pickle.dumps(x_person)
38+
39+
# get TLE encoded bytes
40+
encrypted, reveal_round = timelock.encrypt(byte_data, 1)
41+
42+
# wait when reveal round appears in Drand QuickNet and get decrypted data
43+
decrypted = timelock.wait_reveal_and_decrypt(encrypted_data=encrypted)
44+
45+
# convert bytes into your instance back
46+
x_person_2 = pickle.loads(decrypted)
47+
48+
# make sure initial and decoded instances are the same
49+
assert x_person == x_person_2
50+
```
51+
52+
Note:
53+
For handling fast-block nodes, set the `block_time` parameter to 0.25 seconds during encryption.
54+
"""
55+
156
import struct
257
import time
358
from typing import Optional, Union

contrib/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Here is a high-level summary:
9393

9494
> Review the Bittensor [style guide](./STYLE.md) and [development workflow](./DEVELOPMENT_WORKFLOW.md) before contributing.
9595
96-
If you're looking to contribute to Bittensor but unsure where to start, please join our community [discord](https://discord.gg/bittensor), a developer-friendly Bittensor town square. Start with [#development](https://discord.com/channels/799672011265015819/799678806159392768) and [#bounties](https://discord.com/channels/799672011265015819/1095684873810890883) to see what issues are currently posted. For a greater understanding of Bittensor's usage and development, check the [Bittensor Documentation](https://bittensor.com/docs).
96+
If you're looking to contribute to Bittensor but unsure where to start, please join our community [discord](https://discord.gg/bittensor), a developer-friendly Bittensor town square. Start with [#development](https://discord.com/channels/799672011265015819/799678806159392768) and [#bounties](https://discord.com/channels/799672011265015819/1095684873810890883) to see what issues are currently posted. For a greater understanding of Bittensor's usage and development, check the [Bittensor Documentation](https://docs.bittensor.com).
9797

9898
#### Pull Request Philosophy
9999

tests/helpers/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ def get_mock_neuron(**kwargs) -> NeuronInfo:
105105
"""
106106

107107
mock_neuron_d = dict(
108-
# TODO fix the AxonInfo here — it doesn't work
109108
{
110109
"netuid": -1, # mock netuid
111110
"axon_info": AxonInfo(
112-
block=0,
113111
version=1,
114-
ip=0,
112+
ip="0.0.0.0",
115113
port=0,
116114
ip_type=0,
115+
hotkey=get_mock_hotkey(),
116+
coldkey=get_mock_coldkey(),
117117
protocol=0,
118118
placeholder1=0,
119119
placeholder2=0,

0 commit comments

Comments
 (0)