Skip to content

Commit 748afab

Browse files
committed
add missing docstring and change manager settings to private
1 parent a008e7e commit 748afab

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

hathor/manager.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def __init__(self,
123123
'Either enable it, or use the reset-event-queue CLI command to remove all event-related data'
124124
)
125125

126-
self.settings = settings
126+
self._settings = settings
127127
self._cmd_path: Optional[str] = None
128128

129129
self.log = logger.new()
@@ -228,10 +228,11 @@ def __init__(self,
228228
self.lc_check_sync_state_interval = self.CHECK_SYNC_STATE_INTERVAL
229229

230230
def get_default_capabilities(self) -> list[str]:
231+
"""Return the default capabilities for this manager."""
231232
return [
232-
self.settings.CAPABILITY_WHITELIST,
233-
self.settings.CAPABILITY_SYNC_VERSION,
234-
self.settings.CAPABILITY_GET_BEST_BLOCKCHAIN
233+
self._settings.CAPABILITY_WHITELIST,
234+
self._settings.CAPABILITY_SYNC_VERSION,
235+
self._settings.CAPABILITY_GET_BEST_BLOCKCHAIN
235236
]
236237

237238
def start(self) -> None:
@@ -444,7 +445,7 @@ def _initialize_components_full_verification(self) -> None:
444445
# It's safe to skip block weight verification during initialization because
445446
# we trust the difficulty stored in metadata
446447
skip_block_weight_verification = True
447-
if block_count % self.settings.VERIFY_WEIGHT_EVERY_N_BLOCKS == 0:
448+
if block_count % self._settings.VERIFY_WEIGHT_EVERY_N_BLOCKS == 0:
448449
skip_block_weight_verification = False
449450

450451
try:
@@ -629,14 +630,14 @@ def _verify_soft_voided_txs(self) -> None:
629630
soft_voided_meta = soft_voided_tx.get_metadata()
630631
voided_set = soft_voided_meta.voided_by or set()
631632
# If the tx is not marked as soft voided, then we can't continue the initialization
632-
if self.settings.SOFT_VOIDED_ID not in voided_set:
633+
if self._settings.SOFT_VOIDED_ID not in voided_set:
633634
self.log.error(
634635
'Error initializing node. Your database is not compatible with the current version of the'
635636
' full node. You must use the latest available snapshot or sync from the beginning.'
636637
)
637638
sys.exit(-1)
638639

639-
assert {soft_voided_id, self.settings.SOFT_VOIDED_ID}.issubset(voided_set)
640+
assert {soft_voided_id, self._settings.SOFT_VOIDED_ID}.issubset(voided_set)
640641

641642
def _verify_checkpoints(self) -> None:
642643
""" Method to verify if all checkpoints that exist in the database have the correct hash and are winners.
@@ -775,7 +776,7 @@ def make_block_template(self, parent_block_hash: VertexId, timestamp: Optional[i
775776
"""
776777
parent_block = self.tx_storage.get_transaction(parent_block_hash)
777778
assert isinstance(parent_block, Block)
778-
parent_txs = self.generate_parent_txs(parent_block.timestamp + self.settings.MAX_DISTANCE_BETWEEN_BLOCKS)
779+
parent_txs = self.generate_parent_txs(parent_block.timestamp + self._settings.MAX_DISTANCE_BETWEEN_BLOCKS)
779780
if timestamp is None:
780781
current_timestamp = int(max(self.tx_storage.latest_timestamp, self.reactor.seconds()))
781782
else:
@@ -811,7 +812,7 @@ def _make_block_template(self, parent_block: Block, parent_txs: 'ParentTxs', cur
811812
timestamp_abs_min = parent_block.timestamp + 1
812813
# and absolute maximum limited by max time between blocks
813814
if not parent_block.is_genesis:
814-
timestamp_abs_max = parent_block.timestamp + self.settings.MAX_DISTANCE_BETWEEN_BLOCKS - 1
815+
timestamp_abs_max = parent_block.timestamp + self._settings.MAX_DISTANCE_BETWEEN_BLOCKS - 1
815816
else:
816817
timestamp_abs_max = 0xffffffff
817818
assert timestamp_abs_max > timestamp_abs_min
@@ -820,12 +821,12 @@ def _make_block_template(self, parent_block: Block, parent_txs: 'ParentTxs', cur
820821
timestamp_min = max(timestamp_abs_min, parent_txs.max_timestamp + 1)
821822
assert timestamp_min <= timestamp_abs_max
822823
# when we have weight decay, the max timestamp will be when the next decay happens
823-
if with_weight_decay and self.settings.WEIGHT_DECAY_ENABLED:
824+
if with_weight_decay and self._settings.WEIGHT_DECAY_ENABLED:
824825
# we either have passed the first decay or not, the range will vary depending on that
825-
if timestamp_min > timestamp_abs_min + self.settings.WEIGHT_DECAY_ACTIVATE_DISTANCE:
826-
timestamp_max_decay = timestamp_min + self.settings.WEIGHT_DECAY_WINDOW_SIZE
826+
if timestamp_min > timestamp_abs_min + self._settings.WEIGHT_DECAY_ACTIVATE_DISTANCE:
827+
timestamp_max_decay = timestamp_min + self._settings.WEIGHT_DECAY_WINDOW_SIZE
827828
else:
828-
timestamp_max_decay = timestamp_abs_min + self.settings.WEIGHT_DECAY_ACTIVATE_DISTANCE
829+
timestamp_max_decay = timestamp_abs_min + self._settings.WEIGHT_DECAY_ACTIVATE_DISTANCE
829830
timestamp_max = min(timestamp_abs_max, timestamp_max_decay)
830831
else:
831832
timestamp_max = timestamp_abs_max
@@ -836,7 +837,7 @@ def _make_block_template(self, parent_block: Block, parent_txs: 'ParentTxs', cur
836837
# protect agains a weight that is too small but using WEIGHT_TOL instead of 2*WEIGHT_TOL)
837838
min_significant_weight = calculate_min_significant_weight(
838839
parent_block_metadata.score,
839-
2 * self.settings.WEIGHT_TOL
840+
2 * self._settings.WEIGHT_TOL
840841
)
841842
weight = max(daa.calculate_next_weight(parent_block, timestamp), min_significant_weight)
842843
height = parent_block.get_height() + 1
@@ -904,7 +905,7 @@ def submit_block(self, blk: Block, fails_silently: bool = True) -> bool:
904905
# this is the smallest weight that won't cause the score to increase, anything equal or smaller is bad
905906
min_insignificant_weight = calculate_min_significant_weight(
906907
parent_block_metadata.score,
907-
self.settings.WEIGHT_TOL
908+
self._settings.WEIGHT_TOL
908909
)
909910
if blk.weight <= min_insignificant_weight:
910911
self.log.warn('submit_block(): insignificant weight? accepted anyway', blk=blk.hash_hex, weight=blk.weight)
@@ -915,7 +916,7 @@ def push_tx(self, tx: Transaction, allow_non_standard_script: bool = False,
915916
"""Used by all APIs that accept a new transaction (like push_tx)
916917
"""
917918
if max_output_script_size is None:
918-
max_output_script_size = self.settings.PUSHTX_MAX_OUTPUT_SCRIPT_SIZE
919+
max_output_script_size = self._settings.PUSHTX_MAX_OUTPUT_SCRIPT_SIZE
919920

920921
is_double_spending = tx.is_double_spending()
921922
if is_double_spending:
@@ -978,7 +979,7 @@ def on_new_tx(self, tx: BaseTransaction, *, conn: Optional[HathorProtocol] = Non
978979
self.tx_storage.compare_bytes_with_local_tx(tx)
979980
already_exists = True
980981

981-
if tx.timestamp - self.reactor.seconds() > self.settings.MAX_FUTURE_TIMESTAMP_ALLOWED:
982+
if tx.timestamp - self.reactor.seconds() > self._settings.MAX_FUTURE_TIMESTAMP_ALLOWED:
982983
if not fails_silently:
983984
raise InvalidNewTransaction('Ignoring transaction in the future {} (timestamp={})'.format(
984985
tx.hash_hex, tx.timestamp))
@@ -1127,7 +1128,7 @@ def tx_fully_validated(self, tx: BaseTransaction, *, quiet: bool) -> None:
11271128

11281129
def _log_feature_states(self, vertex: BaseTransaction) -> None:
11291130
"""Log features states for a block. Used as part of the Feature Activation Phased Testing."""
1130-
if not self.settings.FEATURE_ACTIVATION.enable_usage or not isinstance(vertex, Block):
1131+
if not self._settings.FEATURE_ACTIVATION.enable_usage or not isinstance(vertex, Block):
11311132
return
11321133

11331134
feature_descriptions = self._feature_service.get_bits_description(block=vertex)
@@ -1163,10 +1164,10 @@ def listen(self, description: str, use_ssl: Optional[bool] = None) -> None:
11631164
self.my_peer.entrypoints.append(address)
11641165

11651166
def has_sync_version_capability(self) -> bool:
1166-
return self.settings.CAPABILITY_SYNC_VERSION in self.capabilities
1167+
return self._settings.CAPABILITY_SYNC_VERSION in self.capabilities
11671168

11681169
def add_peer_to_whitelist(self, peer_id):
1169-
if not self.settings.ENABLE_PEER_WHITELIST:
1170+
if not self._settings.ENABLE_PEER_WHITELIST:
11701171
return
11711172

11721173
if peer_id in self.peers_whitelist:
@@ -1175,7 +1176,7 @@ def add_peer_to_whitelist(self, peer_id):
11751176
self.peers_whitelist.append(peer_id)
11761177

11771178
def remove_peer_from_whitelist_and_disconnect(self, peer_id: str) -> None:
1178-
if not self.settings.ENABLE_PEER_WHITELIST:
1179+
if not self._settings.ENABLE_PEER_WHITELIST:
11791180
return
11801181

11811182
if peer_id in self.peers_whitelist:
@@ -1190,7 +1191,7 @@ def has_recent_activity(self) -> bool:
11901191
# We use the avg time between blocks as a basis to know how much time we should use to consider the fullnode
11911192
# as not synced.
11921193
maximum_timestamp_delta = (
1193-
self.settings.P2P_RECENT_ACTIVITY_THRESHOLD_MULTIPLIER * self.settings.AVG_TIME_BETWEEN_BLOCKS
1194+
self._settings.P2P_RECENT_ACTIVITY_THRESHOLD_MULTIPLIER * self._settings.AVG_TIME_BETWEEN_BLOCKS
11941195
)
11951196

11961197
if current_timestamp - latest_blockchain_timestamp > maximum_timestamp_delta:

0 commit comments

Comments
 (0)