Skip to content

Commit 65e9d2d

Browse files
authored
Feat/rao changes (#9)
* update lib and pyi for NeuronInfo fields * bump ver * change ver to pre-release * chore: ruff * chore: ruff * use tuple instead * use older version of bittensor for testing * add more logging to test and attr fix
1 parent 817d79d commit 65e9d2d

12 files changed

+100
-79
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bt_decode"
3-
version = "0.4.0"
3+
version = "0.5.0-a0"
44
edition = "2021"
55

66
[lib]

bt_decode.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class NeuronInfo:
6060
stake: List[
6161
Tuple[bytes, int]
6262
] # map of coldkey to stake on this neuron/hotkey (includes delegations)
63+
total_stake: int
64+
alpha_stake: int
65+
tao_stake: int
6366
rank: int
6467
emission: int
6568
incentive: int
@@ -94,6 +97,9 @@ class NeuronInfoLite:
9497
stake: List[
9598
Tuple[bytes, int]
9699
] # map of coldkey to stake on this neuron/hotkey (includes delegations)
100+
total_stake: int
101+
alpha_stake: int
102+
tao_stake: int
97103
rank: int
98104
emission: int
99105
incentive: int

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bt-decode"
3-
version = "0.4.0"
3+
version = "0.5.0-a0"
44
description = "A wrapper around the scale-codec crate for fast scale-decoding of Bittensor data structures."
55
readme = "README.md"
66
license = {file = "LICENSE"}
@@ -41,7 +41,7 @@ build-backend = "maturin"
4141
[project.optional-dependencies]
4242
dev = ["black==23.7.0","maturin", "ruff==0.4.7"]
4343
test = [
44-
"bittensor==8.2.0",
44+
"bittensor==7.3.1",
4545
"pytest==7.2.0",
4646
"pytest-asyncio==0.23.7",
4747
"pytest-mock==3.12.0",

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ mod bt_decode {
9898
axon_info: AxonInfo,
9999
prometheus_info: PrometheusInfo,
100100
stake: Vec<(AccountId, Compact<u64>)>, // map of coldkey to stake on this neuron/hotkey (includes delegations)
101+
total_stake: Compact<u64>,
102+
alpha_stake: Compact<u64>,
103+
tao_stake: Compact<u64>,
101104
rank: Compact<u16>,
102105
emission: Compact<u64>,
103106
incentive: Compact<u16>,
@@ -127,6 +130,9 @@ mod bt_decode {
127130
axon_info: AxonInfo,
128131
prometheus_info: PrometheusInfo,
129132
stake: Vec<(AccountId, Compact<u64>)>, // map of coldkey to stake on this neuron/hotkey (includes delegations)
133+
total_stake: Compact<u64>,
134+
alpha_stake: Compact<u64>,
135+
tao_stake: Compact<u64>,
130136
rank: Compact<u16>,
131137
emission: Compact<u64>,
132138
incentive: Compact<u16>,

tests/test_decode_by_type_string.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
from typing import Any, Callable, Dict, Tuple
1+
from typing import Any, Dict, Tuple
22

3-
import dataclasses
4-
import unittest
53
import pytest
64

75
import bt_decode
8-
import substrateinterface, scalecodec
9-
import bittensor
10-
11-
from . import (
12-
get_file_bytes,
13-
fix_field as fix_field_fixes,
14-
py_getattr as py_getattr_fixes,
15-
)
166

177

188
TEST_TYPE_STRING_SCALE_INFO_DECODING: Dict[str, Tuple[str, Any]] = {

tests/test_decode_delegate_info.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525
"take": lambda x: bittensor.U16_NORMALIZED_FLOAT(x),
2626
"nominators": lambda x: [(bittensor.u8_key_to_ss58(e[0]), e[1]) for e in x],
2727
}
28-
fix_field = lambda key, value, parent_key=None: fix_field_fixes(
29-
FIELD_FIXES, key, value, parent_key
30-
)
28+
29+
30+
def fix_field(key, value, parent_key=None):
31+
return fix_field_fixes(FIELD_FIXES, key, value, parent_key)
32+
3133

3234
ATTR_NAME_FIXES: Dict[str, str] = {
3335
# None
3436
"delegate_ss58": "hotkey_ss58",
3537
}
3638

37-
py_getattr = lambda obj, attr, parent_name=None: py_getattr_fixes(
38-
ATTR_NAME_FIXES, obj, attr, parent_name
39-
)
39+
40+
def py_getattr(obj, attr, parent_name=None):
41+
return py_getattr_fixes(ATTR_NAME_FIXES, obj, attr, parent_name)
4042

4143

4244
class TestDecodeDelegateInfo(unittest.TestCase):

tests/test_decode_neurons.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, Dict, List, Optional
1+
from typing import Callable, Dict, List
22

33
import dataclasses
44
import netaddr
@@ -44,18 +44,18 @@
4444
"weights": lambda x: [[e[0], e[1]] for e in x],
4545
}
4646

47-
fix_field = lambda key, value, parent_key=None: fix_field_fixes(
48-
FIELD_FIXES, key, value, parent_key
49-
)
47+
48+
def fix_field(key, value, parent_key=None):
49+
return fix_field_fixes(FIELD_FIXES, key, value, parent_key)
5050

5151

5252
ATTR_NAME_FIXES: Dict[str, str] = {
5353
# None
5454
}
5555

56-
py_getattr = lambda obj, attr, parent_name=None: py_getattr_fixes(
57-
ATTR_NAME_FIXES, obj, attr, parent_name
58-
)
56+
57+
def py_getattr(obj, attr, parent_name=None):
58+
return py_getattr_fixes(ATTR_NAME_FIXES, obj, attr, parent_name)
5959

6060

6161
class TestDecodeNeuronInfoLite(unittest.TestCase):

tests/test_decode_stake_info.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import bittensor
88

99
from . import (
10-
get_file_bytes,
1110
fix_field as fix_field_fixes,
1211
py_getattr as py_getattr_fixes,
1312
)
@@ -22,19 +21,21 @@
2221
"coldkey": lambda x: bittensor.u8_key_to_ss58(x),
2322
"hotkey": lambda x: bittensor.u8_key_to_ss58(x),
2423
}
25-
fix_field = lambda key, value, parent_key=None: fix_field_fixes(
26-
FIELD_FIXES, key, value, parent_key
27-
)
24+
25+
26+
def fix_field(key, value, parent_key=None):
27+
return fix_field_fixes(FIELD_FIXES, key, value, parent_key)
28+
2829

2930
ATTR_NAME_FIXES: Dict[str, str] = {
3031
# None
3132
"coldkey": "coldkey_ss58",
3233
"hotkey": "hotkey_ss58",
3334
}
3435

35-
py_getattr = lambda obj, attr, parent_name=None: py_getattr_fixes(
36-
ATTR_NAME_FIXES, obj, attr, parent_name
37-
)
36+
37+
def py_getattr(obj, attr, parent_name=None):
38+
return py_getattr_fixes(ATTR_NAME_FIXES, obj, attr, parent_name)
3839

3940

4041
class TestDecodeStakeInfo(unittest.TestCase):

tests/test_decode_subnet_hyp.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import bittensor
88

99
from . import (
10-
get_file_bytes,
1110
fix_field as fix_field_fixes,
1211
py_getattr as py_getattr_fixes,
1312
)
@@ -21,15 +20,17 @@
2120
FIELD_FIXES: Dict[str, Callable] = {
2221
# None
2322
}
24-
fix_field = lambda key, value, parent_key=None: fix_field_fixes(
25-
FIELD_FIXES, key, value, parent_key
26-
)
23+
24+
25+
def fix_field(key, value, parent_key=None):
26+
return fix_field_fixes(FIELD_FIXES, key, value, parent_key)
27+
2728

2829
ATTR_NAME_FIXES: Dict[str, str] = {"max_weights_limit": "max_weight_limit"}
2930

30-
py_getattr = lambda obj, attr, parent_name=None: py_getattr_fixes(
31-
ATTR_NAME_FIXES, obj, attr, parent_name
32-
)
31+
32+
def py_getattr(obj, attr, parent_name=None):
33+
return py_getattr_fixes(ATTR_NAME_FIXES, obj, attr, parent_name)
3334

3435

3536
class TestDecodeSubnetHyperparameters(unittest.TestCase):

0 commit comments

Comments
 (0)