Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions agent/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ def core(raw):
return out


def app_version(header, node_info):
# The committed header carries the app (protocol) version its block was made under.
# node_info.protocol_version.app is fixed when Tenderdash starts: a protocol upgrade
# activates without a restart, so that field keeps the old number until the next one.
header = header if isinstance(header, dict) else {}
node_info = node_info if isinstance(node_info, dict) else {}
for source in (header.get('version'), node_info.get('protocol_version')):
try:
v = int((source or {}).get('app') or 0)
except (AttributeError, TypeError, ValueError):
continue
if v > 0:
return v
return None


def tenderdash(raw):
c = find(raw, ['dashpay/tenderdash'])
if not c:
Expand Down Expand Up @@ -332,8 +348,10 @@ def fetch(path, port):
raise RuntimeError('rpc unreachable on %s' % ports)
get = lambda p: fetch(p, port)
ni, si, vi = st.get('node_info') or {}, st.get('sync_info') or {}, st.get('validator_info') or {}
block = (attempt('latest block', get, 'block') or {}).get('block') or {}
header = block.get('header') or {}
out = dict(network=ni.get('network'), version=ni.get('version'), nodeId=ni.get('id'),
protocolApp=int((ni.get('protocol_version') or {}).get('app') or 0) or None,
protocolApp=app_version(header, ni),
height=int(si.get('latest_block_height') or 0), blockTime=si.get('latest_block_time'),
catchingUp=si.get('catching_up'), proTxHash=vi.get('pro_tx_hash'),
votingPower=int(vi['voting_power']) if vi.get('voting_power') is not None else None)
Expand All @@ -351,9 +369,6 @@ def fetch(path, port):
rs = consensus.get('round_state', {})
hrs = str(rs.get('height/round/step', '')).split('/')
out['round'] = int(hrs[1]) if len(hrs) > 1 and hrs[1].isdigit() else None
block = attempt('latest commit', get, 'block') or {}
block = block.get('block', {})
header = block.get('header', {})
out['proposer'] = header.get('proposer_pro_tx_hash') or header.get('proposer_address')
out['commitRound'] = (block.get('last_commit') or {}).get('round')
# Tenderdash has a threshold block signature, not individual Tendermint signatures.
Expand Down
33 changes: 33 additions & 0 deletions agent/test_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,39 @@ def test_explorer_selects_live_indexer_over_stopped_same_image(self):
self.assertIsNone(check['indexedHeight'])
self.assertIsNone(check['chainHeight'])

def test_consensus_protocol_comes_from_the_committed_header(self):
# Palmatum, 2026-11-20: protocol 15 activated at height 509 while Tenderdash kept
# reporting the 14 it started with, so every validator warned about a disagreement.
td = container('dashpay/tenderdash:2.0.0-dev.3')
td['State']['Pid'] = 4242
status = {'node_info': {'network': 'dash-devnet-palmatum', 'version': '2.0.0-dev.3', 'id': 'node',
'protocol_version': {'p2p': '11', 'block': '14', 'app': '14'}},
'sync_info': {'latest_block_height': '644', 'latest_block_time': '2026-11-20T15:53:51.5Z', 'catching_up': False},
'validator_info': {'pro_tx_hash': 'AB', 'voting_power': '100'}}
block = {'block': {'header': {'version': {'block': '14', 'app': '15'}, 'proposer_pro_tx_hash': 'CD'},
'last_commit': {'round': 0, 'threshold_block_signature': 'sig'}}}

def rpc(replies):
def run(args, timeout):
self.assertEqual(args[:4], ['nsenter', '-t', '4242', '-n'])
path = args[-1].split('/', 3)[3]
if path not in replies: raise RuntimeError('unavailable')
return json.dumps({'result': replies[path]}).encode()
return run
for role in ['validator', 'fullnode']:
with patch.object(p, 'ROLE', role), patch.object(p, 'run', rpc({'status': status, 'block': block})):
self.assertEqual(p.tenderdash({'td': td})['protocolApp'], 15, role)
with patch.object(p, 'ROLE', 'validator'), patch.object(p, 'run', rpc({'status': status, 'block': block})):
out = p.tenderdash({'td': td})
self.assertEqual((out['proposer'], out['commitRound'], out['thresholdSigned']), ('CD', 0, True))
# A node whose block cannot be read still reports the number it started with.
with patch.object(p, 'ROLE', 'validator'), patch.object(p, 'run', rpc({'status': status})), patch.object(p, 'errors', []):
self.assertEqual(p.tenderdash({'td': td})['protocolApp'], 14)
self.assertEqual(p.app_version({'version': {'app': '15'}}, {'protocol_version': {'app': '14'}}), 15)
self.assertEqual(p.app_version({'version': {'block': '14'}}, {'protocol_version': {'app': '14'}}), 14)
self.assertEqual(p.app_version({'version': 'bad'}, {'protocol_version': {'app': 'x'}}), None)
self.assertEqual(p.app_version(None, None), None)

def test_malformed_protobuf_is_bounded(self):
for data in [b'\x80'*100,b'\x0a\x08a',b'\x09a',b'\x0da']:
with self.assertRaises(ValueError): p.protobuf(data)
Expand Down
Loading