Skip to content

Commit d0f748a

Browse files
author
Felipe Rosa
authored
chore: Add eligible voters snapshot metric | NPG-0000 (#581)
# Description This PR adds "eligible voters" metric to the snapshot importer logs as being the amount of wallets able to vote. ## How Has This Been Tested? Executed the voting node + snapshot importer locally. ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
1 parent 2a68afe commit d0f748a

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

services/voting-node/voting_node/importer.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,14 @@ def _remaining_intervals_n_seconds_to_next_snapshot(self, current_time: datetime
162162

163163
async def _ideascale_snapshot(self, event_id: int) -> None:
164164
"""Call the 'ideascale-importer ideascale import-all <ARGS..>' command."""
165-
try:
166-
# Initialize external data importer
167-
importer = ExternalDataImporter()
168-
await importer.ideascale_import_all(event_id)
169-
# raise Exception("ideascale import is DISABLED. Skipping...")
170-
except Exception as e:
171-
logger.error(f"snapshot: {e}")
165+
importer = ExternalDataImporter()
166+
await importer.ideascale_import_all(event_id)
167+
# raise Exception("ideascale import is DISABLED. Skipping...")
172168

173169
async def _dbsync_snapshot(self, event_id: int) -> None:
174170
"""Call the 'ideascale-importer snapshot import <ARGS..>' command."""
175-
try:
176-
# Initialize external data importer
177-
importer = ExternalDataImporter()
178-
await importer.snapshot_import(event_id)
179-
except Exception as e:
180-
logger.error(f"snapshot: {e}")
171+
importer = ExternalDataImporter()
172+
await importer.snapshot_import(event_id)
181173

182174
async def take_snapshots(self, event_id: int) -> None:
183175
"""Takes snapshots at regular intervals using ExternalDataImporter.

services/voting-node/voting_node/main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Main entrypoint for executing the voting node service from the shell command-line.
44
"""
55

6+
import json
7+
import logging
68
import click
79
import uvicorn
810
from ideascale_importer.utils import configure_logger
@@ -30,7 +32,7 @@ def voting_node_cli():
3032
"""Deploy a jormungandr node for voting events."""
3133

3234

33-
@click.command()
35+
@click.command(context_settings={"show_default": True})
3436
@click.option(
3537
"--reloadable",
3638
is_flag=True,
@@ -50,15 +52,15 @@ def voting_node_cli():
5052
default="0.0.0.0",
5153
help="""Host for the voting node API.
5254
53-
If left unset it will look for envvar `VOTING_HOST`. If no host is found, the default value is: 0.0.0.0""",
55+
If left unset it will look for envvar `VOTING_HOST`.""",
5456
)
5557
@click.option(
5658
"--api-port",
5759
envvar=VOTING_PORT,
5860
default=8000,
5961
help="""Port for the voting node API.
6062
61-
If left unset it will look for envvar `VOTING_PORT`. If no port is found, the default value is: 8000""",
63+
If left unset it will look for envvar `VOTING_PORT`.""",
6264
)
6365
@click.option(
6466
"--log-level",
@@ -67,16 +69,16 @@ def voting_node_cli():
6769
type=click.Choice(["info", "debug", "warn", "error", "trace"]),
6870
help="""Set the level for logs in the voting node.
6971
70-
If left unset it will look for envvar `VOTING_LOG_LEVEL`. If no level is found, the default value is: info""",
72+
If left unset it will look for envvar `VOTING_LOG_LEVEL`.""",
7173
)
7274
@click.option(
7375
"--log-format",
7476
envvar=VOTING_LOG_FORMAT,
75-
default="text",
77+
default="json",
7678
type=click.Choice(["text", "json"]),
7779
help="""Set the format for logs in the voting node.
7880
79-
If left unset it will look for envvar `VOTING_LOG_FORMAT`. If no format is found, the default value is: text""",
81+
If left unset it will look for envvar `VOTING_LOG_FORMAT`.""",
8082
)
8183
@click.option(
8284
"--database-url",

utilities/ideascale-importer/ideascale_importer/snapshot_importer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class SnapshotReport(BaseModel):
266266
registrations_count: int = 0
267267
registered_voting_power: int = 0
268268
unregistered_voting_power: int = 0
269+
eligible_voters_count: int = 0
269270
processed_voting_power: int = 0
270271
cip_15_registration_count: int = 0
271272
cip_36_single_registration_count: int = 0
@@ -702,6 +703,7 @@ async def _write_db_data(self):
702703
for ctd in network_processed_snapshot:
703704
for snapshot_contribution in ctd.contributions:
704705
network_report.processed_voting_power += snapshot_contribution.value
706+
network_report.eligible_voters_count += 1
705707

706708
voting_key = ctd.hir.voting_key
707709
# This can be removed once it's fixed in catalyst-toolbox
@@ -746,6 +748,7 @@ async def _write_db_data(self):
746748
total_cip_36_multi_registrations=network_report.cip_36_multi_registration_count,
747749
total_registered_voting_power=network_report.registered_voting_power,
748750
total_unregistered_voting_power=network_report.unregistered_voting_power,
751+
total_eligible_voters=network_report.eligible_voters_count,
749752
total_processed_voting_power=network_report.processed_voting_power,
750753
total_rewards_payable=network_report.rewards_payable,
751754
total_rewards_unpayable=network_report.rewards_unpayable,

0 commit comments

Comments
 (0)