Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delegate info type #36

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions bittensor_cli/src/bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def get_null_neuron() -> "NeuronInfo":
def from_vec_u8(cls, vec_u8: bytes) -> "NeuronInfo":
n = bt_decode.NeuronInfo.decode(vec_u8)
stake_dict = process_stake_data(n.stake)
total_stake = sum(stake_dict.values())
total_stake = sum(stake_dict.values()) if stake_dict else Balance(0)
axon_info = n.axon_info
coldkey = decode_account_id(n.coldkey)
hotkey = decode_account_id(n.hotkey)
Expand Down Expand Up @@ -368,7 +368,7 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["NeuronInfoLite"]:
pruning_score = item.pruning_score
rank = item.rank
stake_dict = process_stake_data(item.stake)
stake = sum(stake_dict.values())
stake = sum(stake_dict.values()) if stake_dict else Balance(0)
trust = item.trust
uid = item.uid
validator_permit = item.validator_permit
Expand Down Expand Up @@ -452,8 +452,10 @@ def from_vec_u8(cls, vec_u8: bytes) -> Optional["DelegateInfo"]:
decoded = bt_decode.DelegateInfo.decode(vec_u8)
hotkey = decode_account_id(decoded.delegate_ss58)
owner = decode_account_id(decoded.owner_ss58)
nominators = process_stake_data(decoded.nominators)
total_stake = sum(nominators.values())
nominators = [
(decode_account_id(x), Balance.from_rao(y)) for x, y in decoded.nominators
]
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
return DelegateInfo(
hotkey_ss58=hotkey,
total_stake=total_stake,
Expand All @@ -473,8 +475,10 @@ def list_from_vec_u8(cls, vec_u8: bytes) -> list["DelegateInfo"]:
for d in decoded:
hotkey = decode_account_id(d.delegate_ss58)
owner = decode_account_id(d.owner_ss58)
nominators = process_stake_data(d.nominators)
total_stake = sum(nominators.values())
nominators = [
(decode_account_id(x), Balance.from_rao(y)) for x, y in d.nominators
]
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
results.append(
DelegateInfo(
hotkey_ss58=hotkey,
Expand All @@ -497,10 +501,13 @@ def delegated_list_from_vec_u8(
decoded = bt_decode.DelegateInfo.decode_delegated(vec_u8)
results = []
for d, b in decoded:
nominators = process_stake_data(d.nominators)
nominators = [
(decode_account_id(x), Balance.from_rao(y)) for x, y in d.nominators
]
total_stake = sum((x[1] for x in nominators)) if nominators else Balance(0)
delegate = DelegateInfo(
hotkey_ss58=decode_account_id(d.delegate_ss58),
total_stake=sum(nominators.values()),
total_stake=total_stake,
nominators=nominators,
owner_ss58=decode_account_id(d.owner_ss58),
take=d.take,
Expand Down
12 changes: 3 additions & 9 deletions bittensor_cli/src/bittensor/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,11 @@ async def get_total_subnets():
return getattr(_result, "value", 0)

async def get_subnets():
_result = await self.subtensor.substrate.query_map(
_result = await self.subtensor.substrate.query(
module="SubtensorModule",
storage_function="NetworksAdded",
params=[],
reuse_block_hash=True,
)
return (
[network[0].value for network in _result.records]
if _result and hasattr(_result, "records")
else []
storage_function="TotalNetworks",
)
return [i for i in range(_result)]

data_array = []
n_subnets, subnets = await asyncio.gather(get_total_subnets(), get_subnets())
Expand Down
13 changes: 5 additions & 8 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,13 +1474,11 @@ async def list_delegates(subtensor: SubtensorInterface):
block_hash=block_hash
)

try:
prev_block_hash = await subtensor.substrate.get_block_hash(
max(0, block_number - 1200)
)
prev_delegates = await subtensor.get_delegates(block_hash=prev_block_hash)
except SubstrateRequestException:
prev_delegates = None
# TODO keep an eye on this, was not working at one point
prev_block_hash = await subtensor.substrate.get_block_hash(
max(0, block_number - 1200)
)
prev_delegates = await subtensor.get_delegates(block_hash=prev_block_hash)

if prev_delegates is None:
err_console.print(
Expand Down Expand Up @@ -1592,7 +1590,6 @@ async def list_delegates(subtensor: SubtensorInterface):
rate_change_in_stake_str = "[grey0]0%[/grey0]"
else:
rate_change_in_stake_str = "[grey0]NA[/grey0]"

table.add_row(
# INDEX
str(i),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ substrate-interface~=1.7.9
typer~=0.12
websockets>=12.0
git+ssh://git@github.com/opentensor/btwallet.git@main#egg=bittensor-wallet
# bt_decode # TODO get this from github
bt-decode
Loading