-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_txindex.py
More file actions
179 lines (154 loc) Β· 7.28 KB
/
test_txindex.py
File metadata and controls
179 lines (154 loc) Β· 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
"""
Test script to check which DeSo nodes have TxIndex enabled.
This helps identify nodes suitable for monitoring with wait_for_commitment.
"""
import time
import requests
import json
from dotenv import load_dotenv
import os
load_dotenv()
# Test nodes - remove port 17000 (protocol port) and use standard HTTP
TEST_NODES = [
"https://node.deso.org", # Main DeSo node - known to work
"https://lazynina.org",
"https://desocialworld.desovalidator.net",
"https://staketomeorelse.com",
"https://revolutionarystaking.com",
"https://notanagi.com"
]
def test_node_accessibility(node_url):
"""Test basic node accessibility and API responses"""
print(f"\nπ Testing node: {node_url}")
# Test 1: Basic API accessibility using get-app-state with empty body
try:
response = requests.post(f"{node_url}/api/v0/get-app-state",
json={},
timeout=10)
if response.status_code == 200:
data = response.json()
print(f" β
API accessible: {response.status_code}")
# Check if TxIndex info is available in app state
if 'IsPortfolio' in data or 'IsTxIndex' in data:
print(f" π App state includes indexing info")
return True
else:
print(f" β API error: {response.status_code}")
return False
except Exception as e:
print(f" β Connection failed: {e}")
return False
def test_txindex_capability(node_url):
"""
Test if node has TxIndex enabled by checking if we can query transactions.
We'll try to get a known transaction - if TxIndex is disabled, this should fail.
"""
print(f" π Testing TxIndex capability...")
# Test: Try to get a recent transaction to see if TxIndex is working
try:
# First, try to get recent posts to find a transaction hash
response = requests.post(f"{node_url}/api/v0/get-posts-stateless",
json={
"NumToFetch": 5,
"PostContent": "",
"PostHashHex": "",
"PublicKeyBase58Check": ""
},
timeout=10)
if response.status_code == 200:
data = response.json()
if data.get("PostsFound"):
# Try to get transaction info for one of these posts
post_hash = data["PostsFound"][0]["PostHashHex"]
print(f" π Testing transaction lookup with PostHash: {post_hash[:8]}...")
# Try to get single post (this uses TxIndex)
tx_response = requests.post(f"{node_url}/api/v0/get-single-post",
json={
"PostHashHex": post_hash,
"FetchParents": False,
"CommentLimit": 0,
"AddGlobalFeedBool": False
},
timeout=10)
if tx_response.status_code == 200:
tx_data = tx_response.json()
if tx_data.get("PostFound"):
print(f" β
TxIndex appears functional - can query transactions")
return True
else:
print(f" β οΈ TxIndex might be limited - post not found in lookup")
return False
else:
print(f" β TxIndex lookup failed: {tx_response.status_code}")
return False
else:
print(f" β οΈ No posts found to test TxIndex")
return None
else:
print(f" β Failed to get posts for TxIndex test: {response.status_code}")
return None
except Exception as e:
print(f" β TxIndex test failed: {e}")
return None
def test_mempool_info(node_url):
"""Test if we can get mempool information which might indicate full node capabilities"""
print(f" π Testing mempool access...")
try:
# Try to get mempool stats
response = requests.post(f"{node_url}/api/v0/get-txn",
json={
"TxnHashHex": "0000000000000000000000000000000000000000000000000000000000000000" # dummy hash
},
timeout=5)
# Even if transaction doesn't exist, a 400 "transaction not found" is better than 404 "endpoint not found"
if response.status_code in [200, 400]:
print(f" β
Transaction query endpoint accessible")
return True
elif response.status_code == 404:
print(f" β Transaction query endpoint not found (TxIndex likely disabled)")
return False
else:
print(f" β οΈ Unclear transaction query status: {response.status_code}")
return None
except Exception as e:
print(f" β οΈ Mempool test inconclusive: {e}")
return None
def main():
print("π DeSo Node TxIndex Detection Tool")
print("=" * 50)
working_nodes = []
txindex_nodes = []
for node in TEST_NODES:
# Test basic accessibility
if test_node_accessibility(node):
working_nodes.append(node)
# Test TxIndex capability
txindex_result = test_txindex_capability(node)
mempool_result = test_mempool_info(node)
# Determine TxIndex status
if txindex_result is True and mempool_result is not False:
print(f" π’ TxIndex Status: ENABLED - Good for monitoring")
txindex_nodes.append(node)
elif txindex_result is False or mempool_result is False:
print(f" π΄ TxIndex Status: DISABLED - Not suitable for wait_for_commitment")
else:
print(f" π‘ TxIndex Status: UNCLEAR - May need manual testing")
time.sleep(1) # Be nice to the nodes
print("\n" + "=" * 50)
print("π SUMMARY")
print("=" * 50)
print(f"β
Working nodes: {len(working_nodes)}/{len(TEST_NODES)}")
print(f"π’ TxIndex enabled nodes: {len(txindex_nodes)}")
if txindex_nodes:
print("\nπ― RECOMMENDED NODES FOR DESOMONITOR:")
for node in txindex_nodes:
print(f" - {node}")
print(f"\nπ Update your deso_monitor.py NODES list with these {len(txindex_nodes)} nodes")
else:
print("\nβ οΈ No nodes with confirmed TxIndex found. You may need to:")
print(" 1. Test with smaller timeouts")
print(" 2. Use nodes without wait_for_commitment")
print(" 3. Contact node operators about TxIndex status")
if __name__ == "__main__":
main()