diff --git a/hathor/builder/builder.py b/hathor/builder/builder.py index d8ee85522..815ed352f 100644 --- a/hathor/builder/builder.py +++ b/hathor/builder/builder.py @@ -18,7 +18,7 @@ from structlog import get_logger from hathor.checkpoint import Checkpoint -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.conf.settings import HathorSettings as HathorSettingsType from hathor.consensus import ConsensusAlgorithm from hathor.daa import DifficultyAdjustmentAlgorithm @@ -285,7 +285,7 @@ def set_peer_id(self, peer_id: PeerId) -> 'Builder': def _get_or_create_settings(self) -> HathorSettingsType: """Return the HathorSettings instance set on this builder, or a new one if not set.""" if self._settings is None: - self._settings = get_settings() + self._settings = get_global_settings() return self._settings def _get_reactor(self) -> Reactor: diff --git a/hathor/builder/cli_builder.py b/hathor/builder/cli_builder.py index 368846ce7..9d0cc2da1 100644 --- a/hathor/builder/cli_builder.py +++ b/hathor/builder/cli_builder.py @@ -61,7 +61,7 @@ def check_or_raise(self, condition: bool, message: str) -> None: def create_manager(self, reactor: Reactor) -> HathorManager: import hathor - from hathor.conf.get_settings import get_settings, get_settings_source + from hathor.conf.get_settings import get_global_settings, get_settings_source from hathor.daa import TestMode from hathor.event.storage import EventMemoryStorage, EventRocksDBStorage, EventStorage from hathor.event.websocket.factory import EventWebsocketFactory @@ -79,7 +79,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager: ) from hathor.util import get_environment_info - settings = get_settings() + settings = get_global_settings() # only used for logging its location settings_source = get_settings_source() diff --git a/hathor/builder/resources_builder.py b/hathor/builder/resources_builder.py index ce92ccaa1..0e89448ab 100644 --- a/hathor/builder/resources_builder.py +++ b/hathor/builder/resources_builder.py @@ -77,7 +77,7 @@ def create_prometheus(self) -> PrometheusMetricsExporter: return prometheus def create_resources(self) -> server.Site: - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings from hathor.debug_resources import ( DebugCrashResource, DebugLogResource, @@ -142,7 +142,7 @@ def create_resources(self) -> server.Site: ) from hathor.websocket import HathorAdminWebsocketFactory, WebsocketStatsResource - settings = get_settings() + settings = get_global_settings() cpu = get_cpu_profiler() # TODO get this from a file. How should we do with the factory? diff --git a/hathor/cli/db_export.py b/hathor/cli/db_export.py index 1a13afd9e..62187e021 100644 --- a/hathor/cli/db_export.py +++ b/hathor/cli/db_export.py @@ -34,8 +34,8 @@ def register_signal_handlers(self) -> None: @classmethod def create_parser(cls) -> ArgumentParser: - from hathor.conf.get_settings import get_settings - settings = get_settings() + from hathor.conf.get_settings import get_global_settings + settings = get_global_settings() def max_height(arg: str) -> Optional[int]: if arg.lower() == 'checkpoint': @@ -80,8 +80,8 @@ def prepare(self, *, register_resources: bool = True) -> None: self.skip_voided = self._args.export_skip_voided def iter_tx(self) -> Iterator['BaseTransaction']: - from hathor.conf.get_settings import get_settings - settings = get_settings() + from hathor.conf.get_settings import get_global_settings + settings = get_global_settings() soft_voided_ids = set(settings.SOFT_VOIDED_TX_IDS) for tx in self._iter_tx: diff --git a/hathor/cli/events_simulator/scenario.py b/hathor/cli/events_simulator/scenario.py index 7c08a72bc..25723697a 100644 --- a/hathor/cli/events_simulator/scenario.py +++ b/hathor/cli/events_simulator/scenario.py @@ -52,10 +52,10 @@ def simulate_single_chain_one_block(simulator: 'Simulator', manager: 'HathorMana def simulate_single_chain_blocks_and_transactions(simulator: 'Simulator', manager: 'HathorManager') -> None: - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings from hathor.simulator.utils import add_new_blocks, gen_new_tx - settings = get_settings() + settings = get_global_settings() assert manager.wallet is not None address = manager.wallet.get_unused_address(mark_as_used=False) @@ -97,11 +97,11 @@ def simulate_reorg(simulator: 'Simulator', manager: 'HathorManager') -> None: def simulate_unvoided_transaction(simulator: 'Simulator', manager: 'HathorManager') -> None: - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings from hathor.simulator.utils import add_new_block, add_new_blocks, gen_new_tx from hathor.util import not_none - settings = get_settings() + settings = get_global_settings() assert manager.wallet is not None address = manager.wallet.get_unused_address(mark_as_used=False) diff --git a/hathor/cli/mining.py b/hathor/cli/mining.py index 1fbd8a927..35a131640 100644 --- a/hathor/cli/mining.py +++ b/hathor/cli/mining.py @@ -135,10 +135,10 @@ def execute(args: Namespace) -> None: block.nonce, block.weight)) try: - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings from hathor.daa import DifficultyAdjustmentAlgorithm from hathor.verification.verification_service import VerificationService, VertexVerifiers - settings = get_settings() + settings = get_global_settings() daa = DifficultyAdjustmentAlgorithm(settings=settings) verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa) verification_service = VerificationService(verifiers=verifiers) diff --git a/hathor/cli/nginx_config.py b/hathor/cli/nginx_config.py index 974d0f74c..5c6f2a874 100644 --- a/hathor/cli/nginx_config.py +++ b/hathor/cli/nginx_config.py @@ -114,9 +114,9 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k: """ from datetime import datetime - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings - settings = get_settings() + settings = get_global_settings() api_prefix = settings.API_VERSION_PREFIX locations: dict[str, dict[str, Any]] = {} diff --git a/hathor/cli/run_node.py b/hathor/cli/run_node.py index 30bab7fb2..7b5ac15ed 100644 --- a/hathor/cli/run_node.py +++ b/hathor/cli/run_node.py @@ -166,8 +166,8 @@ def prepare(self, *, register_resources: bool = True) -> None: assert self.manager.stratum_factory is not None self.reactor.listenTCP(self._args.stratum, self.manager.stratum_factory) - from hathor.conf.get_settings import get_settings - settings = get_settings() + from hathor.conf.get_settings import get_global_settings + settings = get_global_settings() if register_resources: resources_builder = ResourcesBuilder( @@ -212,8 +212,8 @@ def start_sentry_if_possible(self) -> None: sys.exit(-3) import hathor - from hathor.conf.get_settings import get_settings - settings = get_settings() + from hathor.conf.get_settings import get_global_settings + settings = get_global_settings() sentry_sdk.init( dsn=self._args.sentry_dsn, release=hathor.__version__, @@ -274,8 +274,8 @@ def check_unsafe_arguments(self) -> None: '', ] - from hathor.conf.get_settings import get_settings - settings = get_settings() + from hathor.conf.get_settings import get_global_settings + settings = get_global_settings() if self._args.unsafe_mode != settings.NETWORK_NAME: message.extend([ @@ -355,7 +355,7 @@ def check_python_version(self) -> None: def __init__(self, *, argv=None): from hathor.cli.run_node_args import RunNodeArgs from hathor.conf import TESTNET_SETTINGS_FILEPATH - from hathor.conf.get_settings import get_settings + from hathor.conf.get_settings import get_global_settings self.log = logger.new() if argv is None: @@ -373,7 +373,7 @@ def __init__(self, *, argv=None): os.environ['HATHOR_CONFIG_YAML'] = TESTNET_SETTINGS_FILEPATH try: - get_settings() + get_global_settings() except (TypeError, ValidationError) as e: from hathor.exception import PreInitializationError raise PreInitializationError( diff --git a/hathor/conf/get_settings.py b/hathor/conf/get_settings.py index c330ca795..6bdbd88b6 100644 --- a/hathor/conf/get_settings.py +++ b/hathor/conf/get_settings.py @@ -33,7 +33,7 @@ class _SettingsMetadata(NamedTuple): _settings_singleton: Optional[_SettingsMetadata] = None -def get_settings() -> Settings: +def get_global_settings() -> Settings: return HathorSettings() diff --git a/hathor/consensus/block_consensus.py b/hathor/consensus/block_consensus.py index 9c8c0d83a..515b96a07 100644 --- a/hathor/consensus/block_consensus.py +++ b/hathor/consensus/block_consensus.py @@ -17,7 +17,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.profiler import get_cpu_profiler from hathor.transaction import BaseTransaction, Block, Transaction, sum_weights from hathor.util import classproperty, not_none @@ -35,7 +35,7 @@ class BlockConsensusAlgorithm: """Implement the consensus algorithm for blocks.""" def __init__(self, context: 'ConsensusAlgorithmContext') -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.context = context @classproperty diff --git a/hathor/consensus/consensus.py b/hathor/consensus/consensus.py index e0a1ad5b5..34167d973 100644 --- a/hathor/consensus/consensus.py +++ b/hathor/consensus/consensus.py @@ -14,7 +14,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.consensus.block_consensus import BlockConsensusAlgorithmFactory from hathor.consensus.context import ConsensusAlgorithmContext from hathor.consensus.transaction_consensus import TransactionConsensusAlgorithmFactory @@ -56,7 +56,7 @@ class ConsensusAlgorithm: """ def __init__(self, soft_voided_tx_ids: set[bytes], pubsub: PubSubManager) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() self._pubsub = pubsub self.soft_voided_tx_ids = frozenset(soft_voided_tx_ids) diff --git a/hathor/consensus/transaction_consensus.py b/hathor/consensus/transaction_consensus.py index 0747c1753..1cb250679 100644 --- a/hathor/consensus/transaction_consensus.py +++ b/hathor/consensus/transaction_consensus.py @@ -16,7 +16,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.profiler import get_cpu_profiler from hathor.transaction import BaseTransaction, Block, Transaction, TxInput, sum_weights from hathor.util import classproperty @@ -34,7 +34,7 @@ class TransactionConsensusAlgorithm: """Implement the consensus algorithm for transactions.""" def __init__(self, context: 'ConsensusAlgorithmContext') -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.context = context @classproperty diff --git a/hathor/crypto/util.py b/hathor/crypto/util.py index 9bf4bad89..dbb36783b 100644 --- a/hathor/crypto/util.py +++ b/hathor/crypto/util.py @@ -27,7 +27,7 @@ load_der_private_key, ) -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import not_none _BACKEND = default_backend() @@ -129,7 +129,7 @@ def get_address_from_public_key_hash(public_key_hash: bytes, version_byte: Optio :return: address in bytes :rtype: bytes """ - settings = get_settings() + settings = get_global_settings() address = b'' actual_version_byte: bytes = version_byte if version_byte is not None else settings.P2PKH_VERSION_BYTE # Version byte @@ -208,7 +208,7 @@ def get_address_b58_from_redeem_script_hash(redeem_script_hash: bytes, version_b :return: address in base 58 :rtype: string """ - settings = get_settings() + settings = get_global_settings() actual_version_byte: bytes = version_byte if version_byte is not None else settings.MULTISIG_VERSION_BYTE address = get_address_from_redeem_script_hash(redeem_script_hash, actual_version_byte) return base58.b58encode(address).decode('utf-8') @@ -226,7 +226,7 @@ def get_address_from_redeem_script_hash(redeem_script_hash: bytes, version_byte: :return: address in bytes :rtype: bytes """ - settings = get_settings() + settings = get_global_settings() actual_version_byte: bytes = version_byte if version_byte is not None else settings.MULTISIG_VERSION_BYTE address = b'' # Version byte diff --git a/hathor/graphviz.py b/hathor/graphviz.py index 3e06bed8b..c75074576 100644 --- a/hathor/graphviz.py +++ b/hathor/graphviz.py @@ -18,7 +18,7 @@ from graphviz import Digraph -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction import BaseTransaction from hathor.transaction.storage import TransactionStorage @@ -26,7 +26,7 @@ class GraphvizVisualizer: def __init__(self, storage: TransactionStorage, include_funds: bool = False, include_verifications: bool = False, only_blocks: bool = False): - self._settings = get_settings() + self._settings = get_global_settings() self.storage = storage # Indicate whether it should show fund edges diff --git a/hathor/indexes/base_index.py b/hathor/indexes/base_index.py index 22a782313..bc9195009 100644 --- a/hathor/indexes/base_index.py +++ b/hathor/indexes/base_index.py @@ -17,7 +17,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes.scope import Scope from hathor.transaction.base_transaction import BaseTransaction @@ -34,7 +34,7 @@ class BaseIndex(ABC): created to generalize how we initialize indexes and keep track of which ones are up-to-date. """ def __init__(self) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() def init_start(self, indexes_manager: 'IndexesManager') -> None: diff --git a/hathor/indexes/rocksdb_tokens_index.py b/hathor/indexes/rocksdb_tokens_index.py index 575b44f37..b978d9c38 100644 --- a/hathor/indexes/rocksdb_tokens_index.py +++ b/hathor/indexes/rocksdb_tokens_index.py @@ -18,7 +18,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes.rocksdb_utils import ( InternalUid, RocksDBIndexUtils, @@ -85,7 +85,7 @@ class RocksDBTokensIndex(TokensIndex, RocksDBIndexUtils): """ def __init__(self, db: 'rocksdb.DB', *, cf_name: Optional[bytes] = None) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() RocksDBIndexUtils.__init__(self, db, cf_name or _CF_NAME_TOKENS_INDEX) diff --git a/hathor/indexes/rocksdb_utils.py b/hathor/indexes/rocksdb_utils.py index 8ce19ba39..431bfc2f6 100644 --- a/hathor/indexes/rocksdb_utils.py +++ b/hathor/indexes/rocksdb_utils.py @@ -15,7 +15,7 @@ from collections.abc import Collection from typing import TYPE_CHECKING, Iterable, Iterator, NewType -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings if TYPE_CHECKING: # pragma: no cover import rocksdb @@ -30,7 +30,7 @@ def to_internal_token_uid(token_uid: bytes) -> InternalUid: """Normalizes a token_uid so that the native token (\x00) will have the same length as custom tokens.""" - settings = get_settings() + settings = get_global_settings() if token_uid == settings.HATHOR_TOKEN_UID: return _INTERNAL_HATHOR_TOKEN_UID assert len(token_uid) == 32 @@ -40,7 +40,7 @@ def to_internal_token_uid(token_uid: bytes) -> InternalUid: def from_internal_token_uid(token_uid: InternalUid) -> bytes: """De-normalizes the token_uid so that the native token is b'\x00' as expected""" assert len(token_uid) == 32 - settings = get_settings() + settings = get_global_settings() if token_uid == _INTERNAL_HATHOR_TOKEN_UID: return settings.HATHOR_TOKEN_UID return token_uid diff --git a/hathor/indexes/utxo_index.py b/hathor/indexes/utxo_index.py index 5b1cf34ee..5ccbf07e4 100644 --- a/hathor/indexes/utxo_index.py +++ b/hathor/indexes/utxo_index.py @@ -18,7 +18,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes.base_index import BaseIndex from hathor.indexes.scope import Scope from hathor.transaction import BaseTransaction, Block, TxOutput @@ -60,7 +60,7 @@ def __repr__(self): @classmethod def from_tx_output(cls, tx: BaseTransaction, index: int, tx_output: TxOutput) -> 'UtxoIndexItem': assert tx.hash is not None - settings = get_settings() + settings = get_global_settings() if tx_output.is_token_authority(): raise ValueError('UtxoIndexItem cannot be used with a token authority output') @@ -206,7 +206,7 @@ def iter_utxos(self, *, address: str, target_amount: int, token_uid: Optional[by target_height: Optional[int] = None) -> Iterator[UtxoIndexItem]: """ Search UTXOs for a given token_uid+address+target_value, if no token_uid is given, HTR is assumed. """ - settings = get_settings() + settings = get_global_settings() actual_token_uid = token_uid if token_uid is not None else settings.HATHOR_TOKEN_UID iter_nolock = self._iter_utxos_nolock(token_uid=actual_token_uid, address=address, target_amount=target_amount) diff --git a/hathor/p2p/peer_id.py b/hathor/p2p/peer_id.py index f3122c34f..678111f1c 100644 --- a/hathor/p2p/peer_id.py +++ b/hathor/p2p/peer_id.py @@ -27,7 +27,7 @@ from twisted.internet.interfaces import ISSLTransport from twisted.internet.ssl import Certificate, CertificateOptions, TLSVersion, trustRootFromCertificates -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.daa import DifficultyAdjustmentAlgorithm from hathor.p2p.utils import connection_string_to_host, discover_dns, generate_certificate from hathor.util import not_none @@ -66,7 +66,7 @@ class PeerId: flags: set[str] def __init__(self, auto_generate_keys: bool = True) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.id = None self.private_key = None self.public_key = None diff --git a/hathor/p2p/protocol.py b/hathor/p2p/protocol.py index 696ba3c07..e4cff0d5a 100644 --- a/hathor/p2p/protocol.py +++ b/hathor/p2p/protocol.py @@ -23,7 +23,7 @@ from twisted.protocols.basic import LineReceiver from twisted.python.failure import Failure -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.p2p.messages import ProtocolMessages from hathor.p2p.peer_id import PeerId from hathor.p2p.rate_limiter import RateLimiter @@ -93,7 +93,7 @@ class WarningFlags(str, Enum): def __init__(self, network: str, my_peer: PeerId, p2p_manager: 'ConnectionsManager', *, use_ssl: bool, inbound: bool) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.network = network self.my_peer = my_peer self.connections = p2p_manager diff --git a/hathor/p2p/resources/mining_info.py b/hathor/p2p/resources/mining_info.py index 8263ee273..180e3876e 100644 --- a/hathor/p2p/resources/mining_info.py +++ b/hathor/p2p/resources/mining_info.py @@ -16,7 +16,7 @@ from hathor.api_util import Resource, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.difficulty import Weight from hathor.util import json_dumpb @@ -30,7 +30,7 @@ class MiningInfoResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request): diff --git a/hathor/p2p/resources/status.py b/hathor/p2p/resources/status.py index 09be830ca..544484f46 100644 --- a/hathor/p2p/resources/status.py +++ b/hathor/p2p/resources/status.py @@ -15,7 +15,7 @@ import hathor from hathor.api_util import Resource, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.p2p.utils import to_serializable_best_blockchain from hathor.util import json_dumpb @@ -30,7 +30,7 @@ class StatusResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager self.reactor = manager.reactor diff --git a/hathor/p2p/states/hello.py b/hathor/p2p/states/hello.py index 56f514dd7..9472f140c 100644 --- a/hathor/p2p/states/hello.py +++ b/hathor/p2p/states/hello.py @@ -17,7 +17,7 @@ from structlog import get_logger import hathor -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.exception import HathorError from hathor.p2p.messages import ProtocolMessages from hathor.p2p.states.base import BaseState @@ -34,7 +34,7 @@ class HelloState(BaseState): def __init__(self, protocol: 'HathorProtocol') -> None: super().__init__(protocol) - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new(**protocol.get_logger_context()) self.cmd_map.update({ ProtocolMessages.HELLO: self.handle_hello, @@ -172,7 +172,7 @@ def handle_hello(self, payload: str) -> None: def _parse_sync_versions(hello_data: dict[str, Any]) -> set[SyncVersion]: """Versions that are not recognized will not be included.""" - settings = get_settings() + settings = get_global_settings() if settings.CAPABILITY_SYNC_VERSION in hello_data['capabilities']: if 'sync_versions' not in hello_data: raise HathorError('protocol error, expected sync_versions field') diff --git a/hathor/p2p/states/ready.py b/hathor/p2p/states/ready.py index 3f945ff02..f500aadf1 100644 --- a/hathor/p2p/states/ready.py +++ b/hathor/p2p/states/ready.py @@ -18,7 +18,7 @@ from structlog import get_logger from twisted.internet.task import LoopingCall -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes.height_index import HeightInfo from hathor.p2p.messages import ProtocolMessages from hathor.p2p.peer_id import PeerId @@ -37,7 +37,7 @@ class ReadyState(BaseState): def __init__(self, protocol: 'HathorProtocol') -> None: super().__init__(protocol) - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new(**self.protocol.get_logger_context()) diff --git a/hathor/p2p/sync_v1/agent.py b/hathor/p2p/sync_v1/agent.py index cb300907c..110514a83 100644 --- a/hathor/p2p/sync_v1/agent.py +++ b/hathor/p2p/sync_v1/agent.py @@ -22,7 +22,7 @@ from twisted.internet.defer import Deferred, inlineCallbacks from twisted.internet.interfaces import IDelayedCall -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.p2p.messages import GetNextPayload, GetTipsPayload, NextPayload, ProtocolMessages, TipsPayload from hathor.p2p.sync_agent import SyncAgent from hathor.p2p.sync_v1.downloader import Downloader @@ -68,7 +68,7 @@ def __init__(self, protocol: 'HathorProtocol', downloader: Downloader, reactor: :param reactor: Reactor to schedule later calls. (default=twisted.internet.reactor) :type reactor: Reactor """ - self._settings = get_settings() + self._settings = get_global_settings() self.protocol = protocol self.manager = protocol.node self.downloader = downloader diff --git a/hathor/p2p/sync_v1/downloader.py b/hathor/p2p/sync_v1/downloader.py index c28863abb..670b1133a 100644 --- a/hathor/p2p/sync_v1/downloader.py +++ b/hathor/p2p/sync_v1/downloader.py @@ -20,7 +20,7 @@ from twisted.internet import defer from twisted.internet.defer import Deferred -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction.storage.exceptions import TransactionDoesNotExist if TYPE_CHECKING: @@ -51,7 +51,7 @@ class TxDetails: requested_index: int def __init__(self, tx_id: bytes, deferred: Deferred, connections: list['NodeSyncTimestamp']): - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() self.tx_id = tx_id self.deferred = deferred @@ -145,7 +145,7 @@ class Downloader: window_size: int def __init__(self, manager: 'HathorManager', window_size: int = 100): - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() self.manager = manager diff --git a/hathor/p2p/sync_v2/agent.py b/hathor/p2p/sync_v2/agent.py index c93ee57eb..7fb763498 100644 --- a/hathor/p2p/sync_v2/agent.py +++ b/hathor/p2p/sync_v2/agent.py @@ -24,7 +24,7 @@ from twisted.internet.defer import Deferred, inlineCallbacks from twisted.internet.task import LoopingCall, deferLater -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.p2p.messages import ProtocolMessages from hathor.p2p.sync_agent import SyncAgent from hathor.p2p.sync_v2.blockchain_streaming_client import BlockchainStreamingClient, StreamingError @@ -91,7 +91,7 @@ def __init__(self, protocol: 'HathorProtocol', reactor: Reactor) -> None: :param reactor: Reactor to schedule later calls. (default=twisted.internet.reactor) :type reactor: Reactor """ - self._settings = get_settings() + self._settings = get_global_settings() self.protocol = protocol self.manager = protocol.node self.tx_storage: 'TransactionStorage' = protocol.node.tx_storage diff --git a/hathor/p2p/utils.py b/hathor/p2p/utils.py index 12509ffc4..66f1bda37 100644 --- a/hathor/p2p/utils.py +++ b/hathor/p2p/utils.py @@ -27,7 +27,7 @@ from cryptography.x509.oid import NameOID from twisted.internet.interfaces import IAddress -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes.height_index import HeightInfo from hathor.p2p.peer_discovery import DNSPeerDiscovery from hathor.transaction.genesis import get_representation_for_all_genesis @@ -74,14 +74,14 @@ def description_to_connection_string(description: str) -> tuple[str, Optional[st def get_genesis_short_hash() -> str: """ Return the first 7 chars of the GENESIS_HASH used for validation that the genesis are the same """ - settings = get_settings() + settings = get_global_settings() return get_representation_for_all_genesis(settings).hex()[:7] def get_settings_hello_dict() -> dict[str, Any]: """ Return a dict of settings values that must be validated in the hello state """ - settings = get_settings() + settings = get_global_settings() settings_dict = {} for key in settings.P2P_SETTINGS_HASH_FIELDS: value = getattr(settings, key) diff --git a/hathor/prometheus.py b/hathor/prometheus.py index 63c1a7727..ac5ed653f 100644 --- a/hathor/prometheus.py +++ b/hathor/prometheus.py @@ -18,7 +18,7 @@ from prometheus_client import CollectorRegistry, Gauge, write_to_textfile from twisted.internet.task import LoopingCall -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.reactor import get_global_reactor if TYPE_CHECKING: @@ -77,7 +77,7 @@ def __init__(self, metrics: 'Metrics', path: str, filename: str = 'hathor.prom', :param filename: Name of the prometheus file (must end in .prom) :type filename: str """ - self._settings = get_settings() + self._settings = get_global_settings() self.metrics = metrics self.metrics_prefix = metrics_prefix diff --git a/hathor/simulator/miner/geometric_miner.py b/hathor/simulator/miner/geometric_miner.py index 2dc8209d6..a7828e015 100644 --- a/hathor/simulator/miner/geometric_miner.py +++ b/hathor/simulator/miner/geometric_miner.py @@ -15,7 +15,7 @@ import math from typing import TYPE_CHECKING, Optional -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.exception import BlockTemplateTimestampError from hathor.manager import HathorEvents from hathor.simulator.miner.abstract_miner import AbstractMiner @@ -45,7 +45,7 @@ def __init__( blocks than values provided, 0 is used. """ super().__init__(manager, rng) - self._settings = get_settings() + self._settings = get_global_settings() self._hashpower = hashpower self._signal_bits = signal_bits or [] diff --git a/hathor/simulator/simulator.py b/hathor/simulator/simulator.py index b6c546a3f..6155df3b8 100644 --- a/hathor/simulator/simulator.py +++ b/hathor/simulator/simulator.py @@ -21,7 +21,7 @@ from structlog import get_logger from hathor.builder import BuildArtifacts, Builder -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.conf.settings import HathorSettings from hathor.daa import DifficultyAdjustmentAlgorithm from hathor.feature_activation.feature_service import FeatureService @@ -54,7 +54,7 @@ def __init__(self, seed: Optional[int] = None): seed = secrets.randbits(64) self.seed = seed self.rng = Random(self.seed) - self.settings = get_settings()._replace(AVG_TIME_BETWEEN_BLOCKS=SIMULATOR_AVG_TIME_BETWEEN_BLOCKS) + self.settings = get_global_settings()._replace(AVG_TIME_BETWEEN_BLOCKS=SIMULATOR_AVG_TIME_BETWEEN_BLOCKS) self._network = 'testnet' self._clock = MemoryReactorHeapClock() self._peers: OrderedDict[str, HathorManager] = OrderedDict() diff --git a/hathor/simulator/tx_generator.py b/hathor/simulator/tx_generator.py index 347721d5b..8c977c870 100644 --- a/hathor/simulator/tx_generator.py +++ b/hathor/simulator/tx_generator.py @@ -17,7 +17,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.simulator.utils import NoCandidatesError, gen_new_double_spending, gen_new_tx from hathor.transaction.exceptions import RewardLocked from hathor.util import Random @@ -43,7 +43,7 @@ def __init__(self, manager: 'HathorManager', rng: Random, *, :param: rate: Number of transactions per second :param: hashpower: Number of hashes per second """ - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager # List of addresses to send tokens. If this list is empty, tokens will be sent to an address diff --git a/hathor/stratum/stratum.py b/hathor/stratum/stratum.py index 5d4085569..2b9dd8322 100644 --- a/hathor/stratum/stratum.py +++ b/hathor/stratum/stratum.py @@ -33,7 +33,7 @@ from twisted.protocols.basic import LineReceiver from twisted.python.failure import Failure -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.exception import InvalidNewTransaction from hathor.p2p.utils import format_address @@ -365,7 +365,7 @@ class StratumProtocol(JSONRPC): def __init__(self, factory: 'StratumFactory', manager: 'HathorManager', address: IAddress, id_generator: Optional[Callable[[], Iterator[Union[str, int]]]] = lambda: count()): - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new(address=address) self.factory = factory self.manager = manager diff --git a/hathor/transaction/base_transaction.py b/hathor/transaction/base_transaction.py index ae65a5000..532538969 100644 --- a/hathor/transaction/base_transaction.py +++ b/hathor/transaction/base_transaction.py @@ -27,7 +27,7 @@ from structlog import get_logger from hathor.checkpoint import Checkpoint -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction.exceptions import InvalidOutputValue, WeightError from hathor.transaction.transaction_metadata import TransactionMetadata from hathor.transaction.util import VerboseCallback, int_to_bytes, unpack, unpack_len @@ -158,7 +158,7 @@ def __init__(self, assert signal_bits <= _ONE_BYTE, f'signal_bits {hex(signal_bits)} must not be larger than one byte' assert version <= _ONE_BYTE, f'version {hex(version)} must not be larger than one byte' - self._settings = get_settings() + self._settings = get_global_settings() self.nonce = nonce self.timestamp = timestamp or int(time.time()) self.signal_bits = signal_bits diff --git a/hathor/transaction/resources/dashboard.py b/hathor/transaction/resources/dashboard.py index c181e210a..47f366a8e 100644 --- a/hathor/transaction/resources/dashboard.py +++ b/hathor/transaction/resources/dashboard.py @@ -14,7 +14,7 @@ from hathor.api_util import Resource, get_args, get_missing_params_msg, parse_args, parse_int, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import json_dumpb ARGS = ['block', 'tx'] @@ -31,7 +31,7 @@ class DashboardTransactionResource(Resource): def __init__(self, manager): # Important to have the manager so we can know the tx_storage - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request): diff --git a/hathor/transaction/resources/mempool.py b/hathor/transaction/resources/mempool.py index 08340b074..90ce29010 100644 --- a/hathor/transaction/resources/mempool.py +++ b/hathor/transaction/resources/mempool.py @@ -18,7 +18,7 @@ from hathor.api_util import Resource, get_args, parse_args, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction import Transaction from hathor.util import json_dumpb @@ -44,7 +44,7 @@ class MempoolResource(Resource): def __init__(self, manager: 'HathorManager'): # Important to have the manager so we can know the tx_storage - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request: 'Request') -> bytes: diff --git a/hathor/transaction/resources/push_tx.py b/hathor/transaction/resources/push_tx.py index 8db827edf..c550231f2 100644 --- a/hathor/transaction/resources/push_tx.py +++ b/hathor/transaction/resources/push_tx.py @@ -21,7 +21,7 @@ from hathor.api_util import Resource, get_args, parse_args, render_options, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.exception import InvalidNewTransaction from hathor.transaction import Transaction from hathor.transaction.base_transaction import tx_or_block_from_bytes @@ -46,7 +46,7 @@ class PushTxResource(Resource): def __init__(self, manager: 'HathorManager', max_output_script_size: Optional[int] = None, allow_non_standard_script: bool = False) -> None: - self._settings = get_settings() + self._settings = get_global_settings() self.log = logger.new() # Important to have the manager so we can know the tx_storage self.manager = manager diff --git a/hathor/transaction/resources/transaction.py b/hathor/transaction/resources/transaction.py index 1646e06e5..8b755ae02 100644 --- a/hathor/transaction/resources/transaction.py +++ b/hathor/transaction/resources/transaction.py @@ -24,7 +24,7 @@ validate_tx_hash, ) from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction.base_transaction import BaseTransaction, TxVersion from hathor.transaction.token_creation_tx import TokenCreationTransaction from hathor.util import json_dumpb @@ -49,7 +49,7 @@ def get_tx_extra_data(tx: BaseTransaction, *, detail_tokens: bool = True) -> dic assert tx.storage is not None assert tx.storage.indexes is not None - settings = get_settings() + settings = get_global_settings() serialized = tx.to_json(decode_script=True) serialized['raw'] = tx.get_struct().hex() serialized['nonce'] = str(tx.nonce) @@ -205,7 +205,7 @@ def get_list_tx(self, request): 'timestamp': int, the timestamp reference we are in the pagination 'page': 'previous' or 'next', to indicate if the user wants after or before the hash reference """ - settings = get_settings() + settings = get_global_settings() raw_args = get_args(request) parsed = parse_args(raw_args, GET_LIST_ARGS) if not parsed['success']: diff --git a/hathor/transaction/resources/utxo_search.py b/hathor/transaction/resources/utxo_search.py index 93f67e561..a7c46382a 100644 --- a/hathor/transaction/resources/utxo_search.py +++ b/hathor/transaction/resources/utxo_search.py @@ -24,7 +24,7 @@ set_cors, ) from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.util import json_dumpb from hathor.wallet.exceptions import InvalidAddress @@ -45,7 +45,7 @@ class UtxoSearchResource(Resource): def __init__(self, manager: 'HathorManager'): # Important to have the manager so we can know the tx_storage - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request: 'Request') -> bytes: diff --git a/hathor/transaction/scripts/construct.py b/hathor/transaction/scripts/construct.py index 8508b5270..94eee27b7 100644 --- a/hathor/transaction/scripts/construct.py +++ b/hathor/transaction/scripts/construct.py @@ -15,7 +15,7 @@ import re from typing import TYPE_CHECKING, Any, Generator, NamedTuple, Optional, Pattern, Union -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.transaction.exceptions import ScriptError from hathor.transaction.scripts.base_script import BaseScript @@ -84,7 +84,7 @@ def create_base_script(address: str, timelock: Optional[Any] = None) -> BaseScri """ Verifies if address is P2PKH or Multisig and return the corresponding BaseScript implementation. """ from hathor.transaction.scripts.execute import binary_to_int - settings = get_settings() + settings = get_global_settings() baddress = decode_address(address) if baddress[0] == binary_to_int(settings.P2PKH_VERSION_BYTE): from hathor.transaction.scripts import P2PKH @@ -110,7 +110,7 @@ def create_output_script(address: bytes, timelock: Optional[Any] = None) -> byte :rtype: bytes """ from hathor.transaction.scripts.execute import binary_to_int - settings = get_settings() + settings = get_global_settings() # XXX: if the address class can somehow be simplified create_base_script could be used here if address[0] == binary_to_int(settings.P2PKH_VERSION_BYTE): from hathor.transaction.scripts import P2PKH @@ -193,7 +193,7 @@ def count_sigops(data: bytes) -> int: """ from hathor.transaction.scripts import Opcode from hathor.transaction.scripts.execute import decode_opn, get_script_op - settings = get_settings() + settings = get_global_settings() n_ops: int = 0 data_len: int = len(data) pos: int = 0 diff --git a/hathor/transaction/scripts/opcode.py b/hathor/transaction/scripts/opcode.py index 3c185f5a5..460c66821 100644 --- a/hathor/transaction/scripts/opcode.py +++ b/hathor/transaction/scripts/opcode.py @@ -20,7 +20,7 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import ec -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import ( get_address_b58_from_bytes, get_hash160, @@ -523,7 +523,7 @@ def op_checkmultisig(context: ScriptContext) -> None: :raises MissingStackItems: if stack is empty or it has less signatures than the minimum required :raises VerifyFailed: verification failed """ - settings = get_settings() + settings = get_global_settings() if not len(context.stack): raise MissingStackItems('OP_CHECKMULTISIG: empty stack') diff --git a/hathor/transaction/storage/migrations/remove_first_nop_features.py b/hathor/transaction/storage/migrations/remove_first_nop_features.py index c245e8d22..555bcf741 100644 --- a/hathor/transaction/storage/migrations/remove_first_nop_features.py +++ b/hathor/transaction/storage/migrations/remove_first_nop_features.py @@ -16,7 +16,7 @@ from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.transaction.storage.migrations import BaseMigration from hathor.util import progress @@ -37,7 +37,7 @@ def run(self, storage: 'TransactionStorage') -> None: """ This migration clears the Feature Activation metadata related to the first Phased Testing on testnet. """ - settings = get_settings() + settings = get_global_settings() log = logger.new() if settings.NETWORK_NAME != 'testnet-golf': diff --git a/hathor/transaction/storage/transaction_storage.py b/hathor/transaction/storage/transaction_storage.py index a4358c6c4..8b4d5a195 100644 --- a/hathor/transaction/storage/transaction_storage.py +++ b/hathor/transaction/storage/transaction_storage.py @@ -23,7 +23,7 @@ from intervaltree.interval import Interval from structlog import get_logger -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.indexes import IndexesManager from hathor.indexes.height_index import HeightInfo from hathor.profiler import get_cpu_profiler @@ -94,7 +94,7 @@ class TransactionStorage(ABC): _migrations: list[BaseMigration] def __init__(self) -> None: - self._settings = get_settings() + self._settings = get_global_settings() # Weakref is used to guarantee that there is only one instance of each transaction in memory. self._tx_weakref: WeakValueDictionary[bytes, BaseTransaction] = WeakValueDictionary() self._tx_weakref_disabled: bool = False diff --git a/hathor/transaction/transaction_metadata.py b/hathor/transaction/transaction_metadata.py index c223d928f..17ed326a1 100644 --- a/hathor/transaction/transaction_metadata.py +++ b/hathor/transaction/transaction_metadata.py @@ -15,7 +15,7 @@ from collections import defaultdict from typing import TYPE_CHECKING, Any, Optional -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.feature_activation.feature import Feature from hathor.feature_activation.model.feature_state import FeatureState from hathor.transaction.validation_state import ValidationState @@ -129,7 +129,7 @@ def __init__( self.feature_activation_bit_counts = feature_activation_bit_counts - settings = get_settings() + settings = get_global_settings() # Genesis specific: if hash is not None and is_genesis(hash, settings=settings): diff --git a/hathor/transaction/util.py b/hathor/transaction/util.py index d476daeda..a7970359a 100644 --- a/hathor/transaction/util.py +++ b/hathor/transaction/util.py @@ -17,7 +17,7 @@ from math import ceil, floor from typing import Any, Callable, Optional -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings VerboseCallback = Optional[Callable[[str, Any], None]] @@ -49,12 +49,12 @@ def unpack_len(n: int, buf: bytes) -> tuple[bytes, bytes]: def get_deposit_amount(mint_amount: int) -> int: - settings = get_settings() + settings = get_global_settings() return ceil(abs(settings.TOKEN_DEPOSIT_PERCENTAGE * mint_amount)) def get_withdraw_amount(melt_amount: int) -> int: - settings = get_settings() + settings = get_global_settings() return floor(abs(settings.TOKEN_DEPOSIT_PERCENTAGE * melt_amount)) diff --git a/hathor/util.py b/hathor/util.py index bd674f128..1f409d0f1 100644 --- a/hathor/util.py +++ b/hathor/util.py @@ -29,7 +29,7 @@ from structlog import get_logger import hathor -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.types import TokenUid if TYPE_CHECKING: @@ -760,7 +760,7 @@ def is_token_uid_valid(token_uid: TokenUid) -> bool: >>> is_token_uid_valid(bytes.fromhex('000003a3b261e142d3dfd84970d3a50a93b5bc3a66a3b6ba973956148a3eb82400')) False """ - settings = get_settings() + settings = get_global_settings() if token_uid == settings.HATHOR_TOKEN_UID: return True elif len(token_uid) == 32: @@ -784,7 +784,7 @@ def as_dict(self): def get_environment_info(args: str, peer_id: Optional[str]) -> EnvironmentInfo: - settings = get_settings() + settings = get_global_settings() environment_info = EnvironmentInfo( python_implementation=str(sys.implementation), hathor_core_args=args, diff --git a/hathor/version_resource.py b/hathor/version_resource.py index fa7f96ccb..ec64c3114 100644 --- a/hathor/version_resource.py +++ b/hathor/version_resource.py @@ -15,7 +15,7 @@ import hathor from hathor.api_util import Resource, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import json_dumpb @@ -29,7 +29,7 @@ class VersionResource(Resource): def __init__(self, manager): # Important to have the manager so we can have access to min_tx_weight_coefficient - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request): diff --git a/hathor/wallet/resources/balance.py b/hathor/wallet/resources/balance.py index 43122f5dd..b91adafd1 100644 --- a/hathor/wallet/resources/balance.py +++ b/hathor/wallet/resources/balance.py @@ -14,7 +14,7 @@ from hathor.api_util import Resource, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import json_dumpb @@ -28,7 +28,7 @@ class BalanceResource(Resource): def __init__(self, manager): # Important to have the manager so we can know the tx_storage - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request): diff --git a/hathor/wallet/resources/thin_wallet/address_balance.py b/hathor/wallet/resources/thin_wallet/address_balance.py index a80ec6355..6e12568be 100644 --- a/hathor/wallet/resources/thin_wallet/address_balance.py +++ b/hathor/wallet/resources/thin_wallet/address_balance.py @@ -19,7 +19,7 @@ from hathor.api_util import Resource, get_args, get_missing_params_msg, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.transaction.scripts import parse_address_script from hathor.util import json_dumpb @@ -53,7 +53,7 @@ class AddressBalanceResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def has_address(self, output: 'TxOutput', requested_address: str) -> bool: diff --git a/hathor/wallet/resources/thin_wallet/address_history.py b/hathor/wallet/resources/thin_wallet/address_history.py index ef4dc323b..8e0ffc0ca 100644 --- a/hathor/wallet/resources/thin_wallet/address_history.py +++ b/hathor/wallet/resources/thin_wallet/address_history.py @@ -19,7 +19,7 @@ from hathor.api_util import Resource, get_args, get_missing_params_msg, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.util import json_dumpb, json_loadb from hathor.wallet.exceptions import InvalidAddress @@ -34,7 +34,7 @@ class AddressHistoryResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager # TODO add openapi docs for this API diff --git a/hathor/wallet/resources/thin_wallet/address_search.py b/hathor/wallet/resources/thin_wallet/address_search.py index ef63bc50f..124fb4732 100644 --- a/hathor/wallet/resources/thin_wallet/address_search.py +++ b/hathor/wallet/resources/thin_wallet/address_search.py @@ -18,7 +18,7 @@ from hathor.api_util import Resource, get_args, get_missing_params_msg, parse_int, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import decode_address from hathor.transaction.scripts import parse_address_script from hathor.util import json_dumpb @@ -37,7 +37,7 @@ class AddressSearchResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def has_token_and_address(self, tx: 'BaseTransaction', address: str, token: bytes) -> bool: diff --git a/hathor/wallet/resources/thin_wallet/send_tokens.py b/hathor/wallet/resources/thin_wallet/send_tokens.py index c9bbf10ce..6cd6badaf 100644 --- a/hathor/wallet/resources/thin_wallet/send_tokens.py +++ b/hathor/wallet/resources/thin_wallet/send_tokens.py @@ -25,7 +25,7 @@ from hathor.api_util import Resource, render_options, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.exception import InvalidNewTransaction from hathor.reactor import get_global_reactor from hathor.transaction import Transaction @@ -56,7 +56,7 @@ class SendTokensResource(Resource): def __init__(self, manager): # Important to have the manager so we can know the tx_storage - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager self.sleep_seconds = 0 self.log = logger.new() diff --git a/hathor/wallet/resources/thin_wallet/token_history.py b/hathor/wallet/resources/thin_wallet/token_history.py index 698aa94cd..a68cf4077 100644 --- a/hathor/wallet/resources/thin_wallet/token_history.py +++ b/hathor/wallet/resources/thin_wallet/token_history.py @@ -16,7 +16,7 @@ from hathor.api_util import Resource, get_args, get_missing_params_msg, parse_args, parse_int, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import json_dumpb ARGS = ['id', 'count'] @@ -31,7 +31,7 @@ class TokenHistoryResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def render_GET(self, request: Request) -> bytes: diff --git a/hathor/wallet/resources/thin_wallet/tokens.py b/hathor/wallet/resources/thin_wallet/tokens.py index 3190aaa5b..fcd29d476 100644 --- a/hathor/wallet/resources/thin_wallet/tokens.py +++ b/hathor/wallet/resources/thin_wallet/tokens.py @@ -18,7 +18,7 @@ from hathor.api_util import Resource, get_args, set_cors from hathor.cli.openapi_files.register import register_resource -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.util import is_token_uid_valid, json_dumpb @@ -31,7 +31,7 @@ class TokenResource(Resource): isLeaf = True def __init__(self, manager): - self._settings = get_settings() + self._settings = get_global_settings() self.manager = manager def get_one_token_data(self, token_uid: bytes) -> dict[str, Any]: diff --git a/hathor/wallet/util.py b/hathor/wallet/util.py index 111f07ac0..b8b1aa9b4 100644 --- a/hathor/wallet/util.py +++ b/hathor/wallet/util.py @@ -19,7 +19,7 @@ from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import ec -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.crypto.util import get_hash160, get_private_key_from_bytes from hathor.transaction.scripts import HathorScript, Opcode from hathor.transaction.transaction import Transaction @@ -39,7 +39,7 @@ def generate_multisig_redeem_script(signatures_required: int, public_key_bytes: :return: The redeem script for the multisig wallet :rtype: bytes """ - settings = get_settings() + settings = get_global_settings() if signatures_required > settings.MAX_MULTISIG_SIGNATURES: raise ValueError('Signatures required {} is over the limit'.format(signatures_required)) if len(public_key_bytes) > settings.MAX_MULTISIG_PUBKEYS: @@ -71,7 +71,7 @@ def generate_multisig_address(redeem_script: bytes, version_byte: Optional[bytes :return: The multisig address :rtype: str(base58) """ - settings = get_settings() + settings = get_global_settings() actual_version_byte: bytes = version_byte if version_byte is not None else settings.MULTISIG_VERSION_BYTE address = bytearray() diff --git a/tests/feature_activation/test_feature_simulation.py b/tests/feature_activation/test_feature_simulation.py index 2e7e1f307..1a6665a1e 100644 --- a/tests/feature_activation/test_feature_simulation.py +++ b/tests/feature_activation/test_feature_simulation.py @@ -18,7 +18,7 @@ import pytest from hathor.builder import Builder -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.feature_activation import feature_service as feature_service_module from hathor.feature_activation.feature import Feature from hathor.feature_activation.feature_service import FeatureService @@ -75,7 +75,7 @@ def test_feature(self) -> None: } ) - settings = get_settings()._replace(FEATURE_ACTIVATION=feature_settings) + settings = get_global_settings()._replace(FEATURE_ACTIVATION=feature_settings) builder = self.get_simulator_builder().set_settings(settings) artifacts = self.simulator.create_artifacts(builder) feature_service = artifacts.feature_service @@ -351,7 +351,7 @@ def test_reorg(self) -> None: } ) - settings = get_settings()._replace(FEATURE_ACTIVATION=feature_settings) + settings = get_global_settings()._replace(FEATURE_ACTIVATION=feature_settings) builder = self.get_simulator_builder().set_settings(settings) artifacts = self.simulator.create_artifacts(builder) feature_service = artifacts.feature_service @@ -566,7 +566,7 @@ def test_feature_from_existing_storage(self) -> None: } ) - settings = get_settings()._replace(FEATURE_ACTIVATION=feature_settings) + settings = get_global_settings()._replace(FEATURE_ACTIVATION=feature_settings) rocksdb_dir = self.get_rocksdb_directory() builder1 = self.get_simulator_builder_from_dir(rocksdb_dir).set_settings(settings) artifacts1 = self.simulator.create_artifacts(builder1) diff --git a/tests/tx/test_block.py b/tests/tx/test_block.py index a363cfb78..735351215 100644 --- a/tests/tx/test_block.py +++ b/tests/tx/test_block.py @@ -16,7 +16,7 @@ import pytest -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.conf.settings import HathorSettings from hathor.feature_activation.feature import Feature from hathor.feature_activation.feature_service import BlockIsMissingSignal, BlockIsSignaling, FeatureService @@ -27,7 +27,7 @@ def test_calculate_feature_activation_bit_counts_genesis(): - settings = get_settings() + settings = get_global_settings() storage = TransactionMemoryStorage() genesis_block = storage.get_transaction(settings.GENESIS_BLOCK_HASH) assert isinstance(genesis_block, Block) @@ -38,7 +38,7 @@ def test_calculate_feature_activation_bit_counts_genesis(): @pytest.fixture def block_mocks() -> list[Block]: - settings = get_settings() + settings = get_global_settings() blocks: list[Block] = [] feature_activation_bits = [ 0b0000, # 0: boundary block diff --git a/tests/unittest.py b/tests/unittest.py index 852f27bd8..019437e26 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -11,7 +11,7 @@ from hathor.builder import BuildArtifacts, Builder from hathor.conf import HathorSettings -from hathor.conf.get_settings import get_settings +from hathor.conf.get_settings import get_global_settings from hathor.daa import DifficultyAdjustmentAlgorithm, TestMode from hathor.p2p.peer_id import PeerId from hathor.p2p.sync_version import SyncVersion @@ -114,7 +114,7 @@ def setUp(self): self.log.info('set seed', seed=self.seed) self.rng = Random(self.seed) self._pending_cleanups = [] - self._settings = get_settings() + self._settings = get_global_settings() def tearDown(self): self.clean_tmpdirs()