Skip to content

Commit

Permalink
Less log getter setup calls (Chia-Network#6123)
Browse files Browse the repository at this point in the history
* init

* remove whitespace

* docs

* rem double colon

* more type annotation

* retrigger timed out test

Co-authored-by: wjblanke
  • Loading branch information
Nikolaj-K authored Jun 14, 2021
1 parent dc78116 commit 07f64d2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 54 deletions.
6 changes: 3 additions & 3 deletions chia/cmds/units.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict

# The rest of the codebase uses mojos everywhere. Only uses these units
# for user facing interfaces
# The rest of the codebase uses mojos everywhere.
# Only use these units for user facing interfaces.
units: Dict[str, int] = {
"chia": 10 ** 12, # 1 chia (XCH) is 1,000,000,000,000 mojo (1 Trillion)
"chia": 10 ** 12, # 1 chia (XCH) is 1,000,000,000,000 mojo (1 trillion)
"mojo:": 1,
"colouredcoin": 10 ** 3, # 1 coloured coin is 1000 colouredcoin mojos
}
8 changes: 4 additions & 4 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ async def get_wallet(wallet_client: WalletRpcClient, fingerprint: int = None) ->
if "backup_path" not in log_in_response or use_cloud is False:
if use_cloud is True:
val = input(
"No online backup file found, \n Press S to skip restore from backup"
" \n Press F to use your own backup file: "
"No online backup file found,\n Press S to skip restore from backup"
"\n Press F to use your own backup file: "
)
else:
val = input(
"Cloud backup declined, \n Press S to skip restore from backup"
" \n Press F to use your own backup file: "
"Cloud backup declined,\n Press S to skip restore from backup"
"\n Press F to use your own backup file: "
)

if val.lower() == "s":
Expand Down
10 changes: 4 additions & 6 deletions chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ def __init__(
self.sync_store = None
self.signage_point_times = [time.time() for _ in range(self.constants.NUM_SPS_SUB_SLOT)]
self.full_node_store = FullNodeStore(self.constants)
self._ui_tasks = set()

if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)

self._ui_tasks = set()

db_path_replaced: str = config["database_path"].replace("CHALLENGE", config["selected_network"])
self.db_path = path_from_root(root_path, db_path_replaced)
Expand Down Expand Up @@ -731,7 +729,7 @@ async def sync_from_fork_point(
if len(ses_heigths) > 2 and our_peak_height is not None:
ses_heigths.sort()
max_fork_ses_height = ses_heigths[-3]
# This is fork point in SES in case where fork was not detected
# This is the fork point in SES in the case where no fork was detected
if self.blockchain.get_peak_height() is not None and fork_point_height == max_fork_ses_height:
for peer in peers_with_peak:
# Grab a block at peak + 1 and check if fork point is actually our current height
Expand Down
5 changes: 1 addition & 4 deletions chia/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ def __init__(
# Task list to keep references to tasks, so they don't get GCd
self._tasks: List[asyncio.Task] = []

if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)

# Our unique random node id that we will send to other peers, regenerated on launch
self.api = api
Expand Down
19 changes: 4 additions & 15 deletions chia/wallet/did_wallet/did_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ async def create_new_did_wallet(
self.base_puzzle_program = None
self.base_inner_puzzle_hash = None
self.standard_wallet = wallet
if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)

if amount & 1 == 0:
raise ValueError("DID amount must be odd number")
self.wallet_state_manager = wallet_state_manager
Expand Down Expand Up @@ -137,11 +135,7 @@ async def create_new_did_wallet_from_recovery(
self.base_puzzle_program = None
self.base_inner_puzzle_hash = None
self.standard_wallet = wallet
if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)

self.log = logging.getLogger(name if name else __name__)
self.wallet_state_manager = wallet_state_manager
self.did_info = DIDInfo(None, [], uint64(0), [], None, None, None, None)
info_as_string = json.dumps(self.did_info.to_json_dict())
Expand All @@ -165,12 +159,7 @@ async def create(
name: str = None,
):
self = DIDWallet()

if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)

self.log = logging.getLogger(name if name else __name__)
self.wallet_state_manager = wallet_state_manager
self.wallet_info = wallet_info
self.wallet_id = wallet_info.id
Expand Down
5 changes: 1 addition & 4 deletions chia/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ async def create(
name: str = None,
):
self = Wallet()
if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)
self.wallet_state_manager = wallet_state_manager
self.wallet_id = info.id
self.secret_key_store = SecretKeyStore()
Expand Down
20 changes: 8 additions & 12 deletions chia/wallet/wallet_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ def __init__(
self.config = config
self.constants = consensus_constants
self.root_path = root_path
if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)
# Normal operation data
self.cached_blocks: Dict = {}
self.future_block_hashes: Dict = {}
Expand All @@ -115,7 +112,7 @@ def __init__(
self.wallet_peers_initialized = False
self.last_new_peak_messages = LRUCache(5)

def get_key_for_fingerprint(self, fingerprint: Optional[int]):
def get_key_for_fingerprint(self, fingerprint: Optional[int]) -> Optional[PrivateKey]:
private_keys = self.keychain.get_all_private_keys()
if len(private_keys) == 0:
self.log.warning("No keys present. Create keys with the UI, or with the 'chia keys' program.")
Expand All @@ -128,7 +125,7 @@ def get_key_for_fingerprint(self, fingerprint: Optional[int]):
private_key = sk
break
else:
private_key = private_keys[0][0]
private_key = private_keys[0][0] # If no fingerprint, take the first private key
return private_key

async def _start(
Expand Down Expand Up @@ -320,14 +317,15 @@ async def _messages_to_resend(self) -> List[Tuple[Message, Set[bytes32]]]:

def set_server(self, server: ChiaServer):
self.server = server
# TODO: perhaps use a different set of DNS seeders for wallets, to split the traffic.
DNS_SERVERS_EMPTY: list = []
# TODO: Perhaps use a different set of DNS seeders for wallets, to split the traffic.
self.wallet_peers = WalletPeers(
self.server,
self.root_path,
self.config["target_peer_count"],
self.config["wallet_peers_path"],
self.config["introducer_peer"],
[],
DNS_SERVERS_EMPTY,
self.config["peer_connect_interval"],
self.config["selected_network"],
None,
Expand Down Expand Up @@ -588,7 +586,7 @@ async def _sync(self) -> None:
if len(ses_heigths) > 2 and our_peak_height is not None:
ses_heigths.sort()
max_fork_ses_height = ses_heigths[-3]
# This is fork point in SES in case where fork was not detected
# This is the fork point in SES in the case where no fork was detected
if (
self.wallet_state_manager.blockchain.get_peak_height() is not None
and fork_height == max_fork_ses_height
Expand Down Expand Up @@ -652,7 +650,6 @@ async def fetch_blocks_and_validate(
) -> Tuple[bool, bool]:
"""
Returns whether the blocks validated, and whether the peak was advanced
"""
if self.wallet_state_manager is None:
return False, False
Expand Down Expand Up @@ -864,8 +861,7 @@ async def get_additions(self, peer: WSChiaConnection, block_i, additions) -> Opt
return None
return None
else:
added_coins = []
return added_coins
return [] # No added coins

async def get_removals(self, peer: WSChiaConnection, block_i, additions, removals) -> Optional[List[Coin]]:
assert self.wallet_state_manager is not None
Expand Down
7 changes: 1 addition & 6 deletions chia/wallet/wallet_state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ async def create(
self.config = config
self.constants = constants
self.server = server

if name:
self.log = logging.getLogger(name)
else:
self.log = logging.getLogger(__name__)
self.log = logging.getLogger(name if name else __name__)
self.lock = asyncio.Lock()

self.log.debug(f"Starting in db path: {db_path}")
self.db_connection = await aiosqlite.connect(db_path)
self.db_wrapper = DBWrapper(self.db_connection)
Expand Down

0 comments on commit 07f64d2

Please sign in to comment.