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

Improve Dissolve Subnet Docs #453

Open
MichaelTrestman opened this issue Jan 5, 2025 · 0 comments
Open

Improve Dissolve Subnet Docs #453

MichaelTrestman opened this issue Jan 5, 2025 · 0 comments

Comments

@MichaelTrestman
Copy link
Collaborator

include SubstrateInterface to submit the extrinsic, a la https://discord.com/channels/799672011265015819/917906456261578792/1324886501171138600

from substrateinterface import SubstrateInterface
import bittensor as bt

node = SubstrateInterface(url="wss://entrypoint-finney.opentensor.ai:443")
wallet = bt.wallet(name="praj")

def print_extrinsic_receipt(receipt):
    success_event = False
    batch_interrupted_event = None
    error_message = None
    for event in receipt.triggered_events:
        event_details = event.value['event']
        module_id = event_details['module_id']
        event_id = event_details['event_id']

        if module_id == 'System' and event_id == 'ExtrinsicSuccess':
            success_event = True
        elif module_id == 'Utility' and event_id == 'BatchInterrupted':
            batch_interrupted_event = event
            error_message = int(event_details['attributes']['error']['Module']['error'], 16) >> 24

    print(f"Extrinsic included in block: {receipt.block_hash}")
    print(f"Extrinsic hash: {receipt.extrinsic_hash}")
    print(f"Block number: {receipt.block_number}")
    print(f"Events: {receipt.triggered_events}")

    if batch_interrupted_event:
        print("Extrinsic failed due to a batch interruption")
        if error_message:
            print(f"Error message: {error_message}")
    elif success_event:
        print("Extrinsic succeeded")
    else:
        print("Extrinsic failed")
        if receipt.error_message:
            print(f"Error message: {receipt.error_message}")

def dissolve_network(node, wallet, netuid):
    call = node.compose_call(
        call_module="SubtensorModule",
        call_function="schedule_dissolve_network",
        call_params={
            "netuid": netuid,
            "coldkey": wallet.coldkey,
        }
    )
    return call

def submit_extrinsic(node, wallet, call):
    extrinsic = node.create_signed_extrinsic(
        call=call,
        keypair=wallet.coldkey,
    )
    print("Submitting extrinsic")

    wait_for_inclusion = True
    response = node.submit_extrinsic(extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=True)

    if wait_for_inclusion:
        print_extrinsic_receipt(response)


netuid_to_dissolve = 36
call = dissolve_network(node, wallet, netuid_to_dissolve)
submit_extrinsic(node, wallet, call)```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant