Skip to content

Commit

Permalink
Merge pull request #295 from HathorNetwork/fix/more-robust-status-par…
Browse files Browse the repository at this point in the history
…sing

fix: make node status parsing more robust
  • Loading branch information
jansegre authored Jan 8, 2024
2 parents 799c747 + 6cd4e78 commit a410d07
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions domain/network/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,25 @@ def from_status_dict(cls, status: dict) -> "Node":
synced_block: Optional[BlockInfo] = None
protocol_version = peer["protocol_version"]
if protocol_version in {"sync-v1", "sync-v1.1"}:
latest_timestamp = peer["plugins"]["node-sync-timestamp"][
"latest_timestamp"
]
sync_timestamp = peer["plugins"]["node-sync-timestamp"][
"synced_timestamp"
]
node_sync_timestamp_dict = peer["plugins"].get("node-sync-timestamp")
if node_sync_timestamp_dict is None:
raise ValueError(
"Expected 'node-block-timestamp' property when protocol is sync-v1"
)
latest_timestamp = node_sync_timestamp_dict.get("latest_timestamp")
sync_timestamp = node_sync_timestamp_dict.get("synced_timestamp")
elif protocol_version == "sync-v2":
peer_best_block = BlockInfo.from_status_dict(
peer["plugins"]["node-block-sync"]["peer_best_block"]
)
synced_block = BlockInfo.from_status_dict(
peer["plugins"]["node-block-sync"]["synced_block"]
)
node_block_sync_dict = peer["plugins"].get("node-block-sync")
if node_block_sync_dict is None:
raise ValueError(
"Expected 'node-block-sync' property when protocol is sync-v2"
)
peer_best_block_dict = node_block_sync_dict.get("peer_best_block")
if peer_best_block_dict:
peer_best_block = BlockInfo.from_status_dict(peer_best_block_dict)
synced_block_dict = node_block_sync_dict.get("synced_block")
if synced_block_dict:
synced_block = BlockInfo.from_status_dict(synced_block_dict)
else:
# still try to support, but don't attempt to parse the fields above
# mark version as unsupported
Expand Down

0 comments on commit a410d07

Please sign in to comment.