9
9
import substrateinterface
10
10
11
11
from async_substrate_interface .async_substrate import AsyncSubstrateInterface
12
+ from async_substrate_interface .sync_substrate import SubstrateInterface
12
13
13
14
try :
14
15
n = int (os .getenv ("NUMBER_RUNS" ))
15
16
except TypeError :
16
17
n = 3
17
18
18
-
19
+ FINNEY_ENTRYPOINT = "wss://entrypoint-finney.opentensor.ai:443"
19
20
coldkey = "5HHHHHzgLnYRvnKkHd45cRUDMHXTSwx7MjUzxBrKbY4JfZWn"
20
21
21
22
# dtao epoch is 4920350
@@ -70,7 +71,7 @@ async def exhaust(qmr):
70
71
71
72
start = time .time ()
72
73
async with AsyncSubstrateInterface (
73
- "wss://entrypoint-finney.opentensor.ai:443" , ss58_format = SS58_FORMAT
74
+ FINNEY_ENTRYPOINT , ss58_format = SS58_FORMAT
74
75
) as substrate :
75
76
block_hash = await substrate .get_chain_head ()
76
77
tasks = [
@@ -92,16 +93,37 @@ async def exhaust(qmr):
92
93
)
93
94
94
95
elapsed = time .time () - start
95
- print (f"time elapsed : { elapsed } " )
96
+ print (f"Async Time : { elapsed } " )
96
97
97
98
print ("Async Results" , len (results_dicts_list ))
98
99
return results_dicts_list , block_hash
99
100
101
+ def sync_new_method (block_hash ):
102
+ result_dicts_list = []
103
+ start = time .time ()
104
+ with SubstrateInterface (
105
+ FINNEY_ENTRYPOINT , ss58_format = SS58_FORMAT
106
+ ) as substrate :
107
+ for netuid in range (1 , 51 ):
108
+ tao_divs = list (
109
+ substrate .query_map (
110
+ "SubtensorModule" ,
111
+ "TaoDividendsPerSubnet" ,
112
+ [netuid ],
113
+ block_hash = block_hash ,
114
+ )
115
+ )
116
+ tao_divs = [(decode_account_id (k ), v .value ) for k , v in tao_divs ]
117
+ result_dicts_list .extend (tao_divs )
118
+ print ("New Sync Time:" , time .time () - start )
119
+ print ("New Sync Results" , len (result_dicts_list ))
120
+ return result_dicts_list
121
+
100
122
def sync_old_method (block_hash ):
101
123
results_dicts_list = []
102
124
start = time .time ()
103
125
substrate = substrateinterface .SubstrateInterface (
104
- "wss://entrypoint-finney.opentensor.ai:443"
126
+ FINNEY_ENTRYPOINT , ss58_format = SS58_FORMAT
105
127
)
106
128
for netuid in range (1 , 51 ):
107
129
tao_divs = list (
@@ -114,11 +136,15 @@ def sync_old_method(block_hash):
114
136
)
115
137
tao_divs = [(k .value , v .value ) for k , v in tao_divs ]
116
138
results_dicts_list .extend (tao_divs )
117
- print (time .time () - start )
118
- print ("Sync Results" , len (results_dicts_list ))
139
+ substrate .close ()
140
+ print ("Legacy Sync Time:" , time .time () - start )
141
+ print ("Legacy Sync Results" , len (results_dicts_list ))
119
142
return results_dicts_list
120
143
121
144
async_ , block_hash_ = await async_gathering ()
122
- sync_ = sync_old_method (block_hash_ )
145
+ new_sync_ = sync_new_method (block_hash_ )
146
+ legacy_sync = sync_old_method (block_hash_ )
123
147
for k_v in async_ :
124
- assert k_v in sync_
148
+ assert k_v in legacy_sync
149
+ for k_v in new_sync_ :
150
+ assert k_v in legacy_sync
0 commit comments