Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light miner: Diagnostics page should NOT display blockchain details #142

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

pritamghanghas
Copy link
Contributor

@pritamghanghas pritamghanghas commented Mar 25, 2022

grpc client for communication with gatewayrs

Issue

  • Link:
  • Summary: Ground work to make the diagnostic change required by this ticket

How
Write a small client for local.proto grpc service.
Try and maintain compatibility with old interface.
Keep it separate from jsonrpc code even if this means a little bit of copied code.

Screenshots

References

Checklist

  • Tests added
  • Cleaned up commit history (rebase!)
  • Documentation added
  • Thought about variable and method names

@pritamghanghas pritamghanghas requested a review from a team as a code owner March 25, 2022 15:23
LOGGER = get_logger(__name__)


def decode_pub_key(encoded_key: bytes) -> str:
Copy link
Contributor Author

@pritamghanghas pritamghanghas Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this functions is as is copy from jsonrpc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the old files be deleted as they will no longer be usable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping that we will be able to merge this into master and not change all requirements.txt to point to a git branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed json_rpc files.

return json.loads(response.decode())


def get_address_from_add_gateway_txn(add_gateway_txn:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this functions is also as is copy from jsonrpc client

Copy link
Contributor Author

@pritamghanghas pritamghanghas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code smells are in grpc generated code. Will have to ignore.

requirements.txt Outdated
protobuf==3.19.3
grpcio==1.44.0
grpcio-tools==1.44.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think grpcio-tools is required for runtime but needed for generating the code, we don't have a dev requirements.txt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to make dev-requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added. Assuming only additional ones have to go in there just like test-requirements

return self.get_validator_info().height

def get_region_enum(self) -> int:
'''
Copy link
Contributor Author

@pritamghanghas pritamghanghas Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Letting possible grpc exceptions pass through for all grpc invocations. Caller might be in a better position.
Catching them here and raising MinerFetchException might be good abstraction but I didn't see any value in that.

@@ -0,0 +1,26 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be mentioned in the README

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

hm_pyhelper/gateway_grpc/client.py Show resolved Hide resolved
LOGGER = get_logger(__name__)


def decode_pub_key(encoded_key: bytes) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the old files be deleted as they will no longer be usable?

for line in output.decode().splitlines():
if line.strip().startswith('Version'):
return line.split(':')[1].strip()
return 'unknown'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return None or raise an exception instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returned None

update_proto https://raw.githubusercontent.com/helium/proto/master/src/service/local.proto local.proto
update_proto https://raw.githubusercontent.com/helium/proto/master/src/region.proto region.proto

# python -m grpc_tools.protoc -I=$SRC_DIR --python_out=$DST_DIR $SRC_DIR/blockchain_txn.proto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid committing unused code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@@ -0,0 +1,26 @@
#!/bin/bash

# NOTE:: It would be better if we just pull in the helium proto repo as a submodule.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird place to make a comment like this. I also don't agree with the statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Copy link
Contributor Author

@pritamghanghas pritamghanghas Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our protos are out of sync because nothing keeps them updated. A submodule will show such variance with simple git commands. If I download the latest blockchain_txn.proto all these files will be missing:

import "blockchain_txn_coinbase_v1.proto";
import "blockchain_txn_security_coinbase_v1.proto";
import "blockchain_txn_oui_v1.proto";
import "blockchain_txn_gen_gateway_v1.proto";
import "blockchain_txn_routing_v1.proto";
import "blockchain_txn_payment_v1.proto";
import "blockchain_txn_security_exchange_v1.proto";
import "blockchain_txn_consensus_group_v1.proto";
import "blockchain_txn_consensus_group_failure_v1.proto";
import "blockchain_txn_add_gateway_v1.proto";
import "blockchain_txn_assert_location_v1.proto";
import "blockchain_txn_create_htlc_v1.proto";
import "blockchain_txn_redeem_htlc_v1.proto";
import "blockchain_txn_poc_request_v1.proto";
import "blockchain_txn_poc_receipts_v1.proto";
import "blockchain_txn_vars_v1.proto";
import "blockchain_txn_rewards_v1.proto";
import "blockchain_txn_token_burn_v1.proto";
import "blockchain_txn_dc_coinbase_v1.proto";
import "blockchain_txn_token_burn_exchange_rate_v1.proto";
import "blockchain_txn_state_channel_open_v1.proto";
import "blockchain_txn_update_gateway_oui_v1.proto";
import "blockchain_txn_state_channel_close_v1.proto";
import "blockchain_txn_payment_v2.proto";
import "blockchain_txn_price_oracle_v1.proto";
import "blockchain_txn_gen_price_oracle_v1.proto";
import "blockchain_txn_transfer_hotspot_v1.proto";
import "blockchain_txn_rewards_v2.proto";

import "blockchain_txn_gen_validator_v1.proto";
import "blockchain_txn_stake_validator_v1.proto";
import "blockchain_txn_transfer_validator_stake_v1.proto";
import "blockchain_txn_unstake_validator_v1.proto";
import "blockchain_txn_validator_heartbeat_v1.proto";

import "blockchain_txn_assert_location_v2.proto";
import "blockchain_txn_transfer_hotspot_v2.proto";

The other options is to evaluated whether we even need this proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved during daily standup. Manual copying continues.


def test_client(self):
with GatewayClient(f'localhost:{TestData.server_port}') as client:
self.assertEqual(client.get_pubkey(), TestData.pubkey_decoded)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to make each of these different tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Lot of repetition though

@pritamghanghas pritamghanghas self-assigned this Mar 29, 2022
@pritamghanghas pritamghanghas force-pushed the gateway-grpc branch 4 times, most recently from 43c8b04 to f578d90 Compare March 29, 2022 13:56
…ails (#321)

grpc client for communication with gatewayrs
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 17 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -182,13 +180,10 @@ def get_ethernet_addresses(diagnostics):
for (path, key) in zip(path_to_files, keys):
try:
diagnostics[key] = get_mac_address(path)
except MinerFailedToFetchMacAddress as e:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemed like dead useless code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@@ -206,8 +201,6 @@ def get_mac_address(path):
The path must be a string value")
try:
file = open(path)
except MinerFailedToFetchMacAddress as e:
Copy link
Contributor Author

@pritamghanghas pritamghanghas Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. why would open throw one of our exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@@ -182,13 +180,10 @@ def get_ethernet_addresses(diagnostics):
for (path, key) in zip(path_to_files, keys):
try:
diagnostics[key] = get_mac_address(path)
except MinerFailedToFetchMacAddress as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@@ -206,8 +201,6 @@ def get_mac_address(path):
The path must be a string value")
try:
file = open(path)
except MinerFailedToFetchMacAddress as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@pritamghanghas pritamghanghas merged commit 228892c into light-hotspot Mar 30, 2022
@shawaj shawaj deleted the gateway-grpc branch August 28, 2022 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants