Skip to content
Snippets Groups Projects

Introduce smiths command

Closed Éloïs requested to merge smiths_command into main

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
29 29 network_info,
30 30 argos_info,
31 31 list_blocks,
32 smiths,
  • I am trying to have one command or at least a small amount of related commands in the same file to avoid long files like this commands.py file which I started with. I suggest to move this command to a new file. i.e. smiths.py, or a common file for diffi and smiths commands: i.e. pow.py.

  • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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's information.
      • versions percentages
      • number of blocks
      • I prefer to use diffi term over diff, 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 use diffi.

      In the end, I suggest following help message:

      • Smiths monitor in current frame: versions percentages, number of blocks, difficulties
    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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(
    • You can get rid of the format tool in print("{0}".format(X)) since there is just one argument. You can directly print things with print(X)

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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(
    • I suggest to go with one print() call instead of three currently. This in order to have one system call to write on stdout.

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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(
    • I suggest to have the main function to get and generate the data. This main function would call a sub-function to display the generated content. This in order to reduce the size of the function and to make easier to tests each parts separately.

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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
  • Moul
    Moul @moul started a thread on the diff
  • 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 simple dict()? 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 a dict().

      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).

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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(
  • Moul
    Moul @moul started a thread on the diff
  • 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)
    • What about displaying a chart with tabulate for more readability?

      version smiths percent
      1.8.0 30 70
      1.7.21 15 30
    • Please register or sign in to reply
  • Moul changed title from [enh] add smiths command to Introduce smiths command

    changed title from [enh] add smiths command to Introduce smiths command

  • Moul
    Moul @moul started a thread on the diff
  • 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.

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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
    • Do we need this information? It duplicates blocks command.

    • Mon besoin c'était d'avoir toutes ces informations en une seule vue, et j'en ajouterai peut-être même d'autres. Il me semble utile d'avoir une commande qui donne un maximum d'informations sur chaque membre forgeron en une seule vue.

    • Please register or sign in to reply
  • Moul
    Moul @moul started a thread on the diff
  • 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"]]
  • Moul changed milestone to %0.10.0

    changed milestone to %0.10.0

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading