Skip to content

Commit

Permalink
CR3 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
namoray authored Dec 22, 2024
1 parent 40ef465 commit edd328c
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 112 deletions.
17 changes: 9 additions & 8 deletions dev_utils/chain/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ async def metagraph_example():
logger.info(f"Found nodes: {nodes}")


async def set_weights_example():
async def set_weights_example(netuid: int = 267):
substrate = interface.get_substrate(subtensor_network="test")
nodes = get_nodes_for_netuid(substrate=substrate, netuid=176)
nodes = get_nodes_for_netuid(substrate=substrate, netuid=netuid)
keypair = chain_utils.load_hotkey_keypair(wallet_name="default", hotkey_name="default")
validator_node_id = substrate.query("SubtensorModule", "Uids", [176, keypair.ss58_address]).value
version_key = substrate.query("SubtensorModule", "WeightsVersionKey", [176]).value
validator_node_id = substrate.query("SubtensorModule", "Uids", [netuid, keypair.ss58_address]).value
version_key = substrate.query("SubtensorModule", "WeightsVersionKey", [netuid]).value
weights.set_node_weights(
substrate=substrate,
keypair=keypair,
node_ids=[node.node_id for node in nodes],
node_weights=[node.incentive for node in nodes],
netuid=176,
node_weights=[node.incentive + 1 for node in nodes],
netuid=netuid,
validator_node_id=validator_node_id,
version_key=version_key,
wait_for_inclusion=True,
wait_for_finalization=True,
)
wait_for_finalization=True )


# NOTE this is also a script in /scropts/post_ip_to_chain and you can use it on the cli with fiber-post-ip
async def post_ip_to_chain_example():
Expand Down Expand Up @@ -68,5 +68,6 @@ async def main():
await set_weights_example()
await post_ip_to_chain_example()


if __name__ == "__main__":
asyncio.run(main())
16 changes: 11 additions & 5 deletions fiber/chain/chain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,28 @@ def sign_message(keypair: Keypair, message: str | None) -> str | None:
return f"0x{keypair.sign(message).hex()}"



def query_substrate(
substrate: SubstrateInterface, module: str, method: str, params: list[Any], return_value: bool = True
substrate: SubstrateInterface,
module: str,
method: str,
params: list[Any],
return_value: bool = True,
block: int | None = None,
) -> tuple[SubstrateInterface, Any]:
try:
query_result = substrate.query(module, method, params)
block_hash = substrate.get_block_hash(block) if block is not None else None
query_result = substrate.query(module, method, params, block_hash=block_hash)

return_val = query_result.value if return_value else query_result

return substrate, return_val
except Exception as e:
logger.error(f"Query failed with error: {e}. Reconnecting and retrying.")
logger.debug(f"Substrate query failed with error: {e}. Reconnecting and retrying.")

substrate = SubstrateInterface(url=substrate.url)

query_result = substrate.query(module, method, params)
block_hash = substrate.get_block_hash(block) if block is not None else None
query_result = substrate.query(module, method, params, block_hash=block_hash)

return_val = query_result.value if return_value else query_result

Expand Down
Loading

0 comments on commit edd328c

Please sign in to comment.