Introduce smiths command
Merge request reports
Activity
added API: BMA CLI Feature Network enhancement labels
@moul si tu veut l'intégrer n'hésite pas. on peut bien sur changer le nom de la commande si tu a un nom plus pertinent :)
removed API: BMA CLI Network enhancement labels
changed milestone to %0.9.0
Thanks for your contribution
smiths
as a command name looks fine.I planned this MR to enter next release %0.9.0, since the planning for %0.8.0 is now closed and close to be released.
d090367c is not formatted. To be sure your commits are always formatted, you can automate Black formatting check at every commit with
pre-commit
.I will start with a first quick review on what's obvious to me and can be improved.
Then, I will ask some tests to ensure the feature is working on the long-term. Silkaj project is new to testing and is still experimenting. There is not much tests and the test environment is not perfect. For your inspiration, the best examples I can provide is test_verify_blocks.py and !130 (merged).
Then, I will continue with a deeper review, which might come after %0.8.0 is released.
29 29 network_info, 30 30 argos_info, 31 31 list_blocks, 32 smiths, 249 249 print(tabulate(infos, headers="keys", tablefmt="orgtbl", stralign="center")) 250 250 251 251 252 @command("smiths", help="Display smiths informations (version, blocks on frame, diff)") -
informations
does not exists in English. It'sinformation
. - versions percentages
- number of blocks
- I prefer to use
diffi
term overdiff
, as diff means a difference. I do not see any issue, I just want to avoid misunderstanding. For consistency with the rest of the project, I suggest to usediffi
.
In the end, I suggest following help message:
Smiths monitor in current frame: versions percentages, number of blocks, difficulties
-
311 print( 312 "Current frame: {0} issuers [{1} blocks (#{2} to #{3})]\n".format( 313 len(issuers_dict), frame_size, current_nbr - frame_size + 1, current_nbr 314 ) 315 ) 316 for version, count in versions_dict.items(): 317 print( 318 "{0}: {1} smith{2} [{3} %]".format( 319 version, count, "s" if count > 1 else "", round(count / len(issuers_dict) * 100, 2) 320 ) 321 ) 322 sorted_list = sorted( 323 issuers_dict.values(), key=itemgetter("blocks_on_frame"), reverse=True 324 ) 325 print( 326 "{0}".format( 310 # print datas 311 print( 312 "Current frame: {0} issuers [{1} blocks (#{2} to #{3})]\n".format( 313 len(issuers_dict), frame_size, current_nbr - frame_size + 1, current_nbr 314 ) 315 ) 316 for version, count in versions_dict.items(): 317 print( 318 "{0}: {1} smith{2} [{3} %]".format( 319 version, count, "s" if count > 1 else "", round(count / len(issuers_dict) * 100, 2) 320 ) 321 ) 322 sorted_list = sorted( 323 issuers_dict.values(), key=itemgetter("blocks_on_frame"), reverse=True 324 ) 325 print( 296 297 # Fill issuer infos 298 issuer["uid"] = "" 299 issuer["version"] = version 300 issuer["blocks_on_frame"] = 1 301 issuer["diff"] = 0 302 issuers_dict[block["issuer"]] = issuer 303 # Get username of each issuer (and fill their difficulty) 304 for pubkey, issuer in issuers_dict.items(): 305 idty = await identity_of(pubkey) 306 issuer["uid"] = idty["uid"] 307 issuer["diff"] = difficulties_dict[issuer["uid"]] 308 await sleep(ASYNC_SLEEP) 309 await client.close() 310 # print datas 311 print( 285 issuer = OrderedDict() 286 287 # get issuer version 288 version = "unknown" 289 if block["issuer"] in heads_dict: 290 version = heads_dict[block["issuer"]][7] 291 # Counting version occurrences 292 if version in versions_dict: 293 versions_dict[version] += 1 294 else: 295 versions_dict[version] = 1 296 297 # Fill issuer infos 298 issuer["uid"] = "" 299 issuer["version"] = version 300 issuer["blocks_on_frame"] = 1 270 heads_dict = dict() 271 for entry in heads_obj["heads"]: 272 head_v2 = entry["messageV2"].split(":") 273 heads_dict[head_v2[3]] = head_v2 274 275 # Collect issuers and count number of forged blocks for each 276 issuers_dict = dict() 277 versions_dict = dict() 278 for block in blocks: 279 if block["issuer"] in issuers_dict: 280 # Update issuer 281 issuer = issuers_dict[block["issuer"]] 282 issuer["blocks_on_frame"] += 1 283 else: 284 # Create issuer 285 issuer = OrderedDict() Any reason why you choose to use
OrderedDict()
over a simpledict()
? Is it just by mimicking the other commands? Or is it required by the sorting bellow? I am not sure, but I remember, it was required to have it to sorted, but, the sorting seems to work with adict()
.We had an issue back then with the columns of the table changing position. If I remember correctly, this have been fixed since Python v3.6. Writing tests checking the display content would allow to check that the columns are not changing position with Python 3.5.
For further details See #124 (closed).
303 # Get username of each issuer (and fill their difficulty) 304 for pubkey, issuer in issuers_dict.items(): 305 idty = await identity_of(pubkey) 306 issuer["uid"] = idty["uid"] 307 issuer["diff"] = difficulties_dict[issuer["uid"]] 308 await sleep(ASYNC_SLEEP) 309 await client.close() 310 # print datas 311 print( 312 "Current frame: {0} issuers [{1} blocks (#{2} to #{3})]\n".format( 313 len(issuers_dict), frame_size, current_nbr - frame_size + 1, current_nbr 314 ) 315 ) 316 for version, count in versions_dict.items(): 317 print( 318 "{0}: {1} smith{2} [{3} %]".format( 304 for pubkey, issuer in issuers_dict.items(): 305 idty = await identity_of(pubkey) 306 issuer["uid"] = idty["uid"] 307 issuer["diff"] = difficulties_dict[issuer["uid"]] 308 await sleep(ASYNC_SLEEP) 309 await client.close() 310 # print datas 311 print( 312 "Current frame: {0} issuers [{1} blocks (#{2} to #{3})]\n".format( 313 len(issuers_dict), frame_size, current_nbr - frame_size + 1, current_nbr 314 ) 315 ) 316 for version, count in versions_dict.items(): 317 print( 318 "{0}: {1} smith{2} [{3} %]".format( 319 version, count, "s" if count > 1 else "", round(count / len(issuers_dict) * 100, 2) 275 # Collect issuers and count number of forged blocks for each 276 issuers_dict = dict() 277 versions_dict = dict() 278 for block in blocks: 279 if block["issuer"] in issuers_dict: 280 # Update issuer 281 issuer = issuers_dict[block["issuer"]] 282 issuer["blocks_on_frame"] += 1 283 else: 284 # Create issuer 285 issuer = OrderedDict() 286 287 # get issuer version 288 version = "unknown" 289 if block["issuer"] in heads_dict: 290 version = heads_dict[block["issuer"]][7] What if the issuer have multiple nodes with different versions?
curl -s https://g1.duniter.org/network/ws2p/heads | grep "messageV2\": \"WS2POCAIC:HEAD:2:GfKERH" "messageV2": "WS2POCAIC:HEAD:2:GfKERHnJTYzKhKUma5h1uWhetbA8yHKymhVH2raf2aCP:331852-0000001FB2C1A5C4F5767B0D696EFF811E25BF846E5D9346838DC2D5A60082D0:2ed4fa74:duniter:1.8.0:42:20:20", "messageV2": "WS2POCAIC:HEAD:2:GfKERHnJTYzKhKUma5h1uWhetbA8yHKymhVH2raf2aCP:331852-0000001FB2C1A5C4F5767B0D696EFF811E25BF846E5D9346838DC2D5A60082D0:4eabaa9c:duniter:1.8.1:21:20:20",
In the main table, we just get the first version found.
@moul oui je n'ai volontairement pas géré ce cas. Car je part de l’hypothèse que si un membre forgeron a plusieurs noeuds il les met a jours en même temps.
Idéalement il fraudais un tableau de versions pour chaque membre, tu peut le faire si tu veut, comme je l'ai dit sur le forum mon but était de répondre a mon besoin le plus rapidement possible, je ne souhaite pas y passer du temps.
267 difficulties_dict[entry["uid"]] = entry["level"] 268 # Get ws2p heads 269 heads_obj = await client(bma.network.ws2p_heads) 270 heads_dict = dict() 271 for entry in heads_obj["heads"]: 272 head_v2 = entry["messageV2"].split(":") 273 heads_dict[head_v2[3]] = head_v2 274 275 # Collect issuers and count number of forged blocks for each 276 issuers_dict = dict() 277 versions_dict = dict() 278 for block in blocks: 279 if block["issuer"] in issuers_dict: 280 # Update issuer 281 issuer = issuers_dict[block["issuer"]] 282 issuer["blocks_on_frame"] += 1 292 if version in versions_dict: 293 versions_dict[version] += 1 294 else: 295 versions_dict[version] = 1 296 297 # Fill issuer infos 298 issuer["uid"] = "" 299 issuer["version"] = version 300 issuer["blocks_on_frame"] = 1 301 issuer["diff"] = 0 302 issuers_dict[block["issuer"]] = issuer 303 # Get username of each issuer (and fill their difficulty) 304 for pubkey, issuer in issuers_dict.items(): 305 idty = await identity_of(pubkey) 306 issuer["uid"] = idty["uid"] 307 issuer["diff"] = difficulties_dict[issuer["uid"]] changed milestone to %0.10.0