Skip to content

Adds ability to log raw websockets for debugging. #133

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

Merged
merged 4 commits into from
Jun 11, 2025

Conversation

thewhaleking
Copy link
Collaborator

@thewhaleking thewhaleking commented Jun 10, 2025

Works something like this:

from async_substrate_interface import SubstrateInterface
from async_substrate_interface.substrate_addons import RetrySyncSubstrate
from async_substrate_interface.errors import StateDiscardedError
import logging

logger = logging.getLogger("raw_websocket")
logger.setLevel(logging.DEBUG)
log_handler = logging.StreamHandler()
logger.addHandler(log_handler)


def main():
    with SubstrateInterface("wss://lite.sub.latent.to:443", _log_raw_websockets=True) as substrate:
        current_block = substrate.get_block_number()
        old_block = current_block - 1000
        try:
            substrate.get_block(block_number=old_block)
        except StateDiscardedError:
            pass
    with RetrySyncSubstrate(
            "wss://lite.sub.latent.to:443", archive_nodes=["ws://178.156.172.75:9944"], _log_raw_websockets=True
    ) as substrate:
        assert isinstance((substrate.get_block(block_number=old_block)), dict)


main()

First half of opentensor/bittensor#2916

@thewhaleking thewhaleking requested a review from a team June 10, 2025 22:25
@github-actions github-actions bot added run-bittensor-sdk-tests Runs Bittensor SDK tests. run-bittensor-cli-tests Runs BTCLI tests. labels Jun 10, 2025
@thewhaleking thewhaleking added run-bittensor-sdk-tests Runs Bittensor SDK tests. run-bittensor-cli-tests Runs BTCLI tests. and removed run-bittensor-sdk-tests Runs Bittensor SDK tests. run-bittensor-cli-tests Runs BTCLI tests. labels Jun 11, 2025
@thewhaleking thewhaleking merged commit 922fc72 into staging Jun 11, 2025
49 of 52 checks passed
@thewhaleking thewhaleking deleted the feat/thewhaleking/add-websocket-logging branch June 11, 2025 16:29
@thewhaleking thewhaleking mentioned this pull request Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-bittensor-cli-tests Runs BTCLI tests. run-bittensor-sdk-tests Runs Bittensor SDK tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants