Skip to content

Conversation

thewhaleking
Copy link
Collaborator

For events, the Python is the same speed at decoding as bt-decode (sometimes faster). However, the Python scalecodec offers significantly better decoding, and doesn't rely on us hacking it after the fact.

Compare the following.
bt-decode

{'phase': 'ApplyExtrinsic', 'extrinsic_idx': 1, 'event': {'module_id': 'SubtensorModule', 'event_id': 'CRV3WeightsCommitted', 'attributes': (((174, 102, 210, 111, 237, 83, 159, 197, 1, 180, 52, 15, 170, 239, 101, 226, 15, 235, 13, 191, 56, 134, 88, 153, 124, 3, 75, 171, 173, 6, 191, 67),), 30, ((166, 180, 229, 200, 36, 29, 96, 236, 224, 194, 80, 86, 177, 159, 125, 33, 174, 132, 82, 105, 252, 119, 26, 212, 107, 243, 224, 17, 134, 81, 41, 165),))}, 'topics': []}

scalecodec:

{'phase': 'ApplyExtrinsic', 'extrinsic_idx': 1, 'event': {'event_index': '0759', 'module_id': 'SubtensorModule', 'event_id': 'CRV3WeightsCommitted', 'attributes': ('5G1NjW9YhXLadMWajvTkfcJy6up3yH2q1YzMXDTi6ijanChe', 30, '0xa6b4e5c8241d60ece0c25056b19f7d21ae845269fc771ad46bf3e011865129a5')}, 'event_index': 7, 'module_id': 'SubtensorModule', 'event_id': 'CRV3WeightsCommitted', 'attributes': ('5G1NjW9YhXLadMWajvTkfcJy6up3yH2q1YzMXDTi6ijanChe', 30, '0xa6b4e5c8241d60ece0c25056b19f7d21ae845269fc771ad46bf3e011865129a5'), 'topics': []}

The bt-decode version does not decode the SS58s. In addition, we'd previously had to use various hacks to get inner values to parse correctly:

if isinstance(value, dict):
# Convert nested single-key dictionaries to their keys as strings
for sub_key, sub_value in value.items():
if isinstance(sub_value, dict):
for sub_sub_key, sub_sub_value in sub_value.items():
if sub_sub_value == ():
attributes[key][sub_key] = sub_sub_key

which changes {"pays_fee": {"Yes": ()}} to {"pays_fee": "Yes"}

This rectifies these issues by just using the MetadataV14 decoder.

@thewhaleking thewhaleking requested a review from a team June 30, 2025 18:52
@github-actions github-actions bot added run-bittensor-cli-tests Runs BTCLI tests. run-bittensor-sdk-tests Runs Bittensor SDK tests. labels Jun 30, 2025
@thewhaleking thewhaleking merged commit bd870cf into staging Jun 30, 2025
40 checks passed
@thewhaleking thewhaleking deleted the feat/thewhaleking/only-use-v14-decoding-for-events branch June 30, 2025 19:35
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