Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hathor/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hathor/builder/cli_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions hathor/builder/resources_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions hathor/cli/db_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions hathor/cli/events_simulator/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions hathor/cli/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions hathor/cli/nginx_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {}
Expand Down
16 changes: 8 additions & 8 deletions hathor/cli/run_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion hathor/conf/get_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _SettingsMetadata(NamedTuple):
_settings_singleton: Optional[_SettingsMetadata] = None


def get_settings() -> Settings:
def get_global_settings() -> Settings:
return HathorSettings()


Expand Down
4 changes: 2 additions & 2 deletions hathor/consensus/block_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hathor/consensus/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions hathor/consensus/transaction_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions hathor/crypto/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hathor/graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

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


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
Expand Down
4 changes: 2 additions & 2 deletions hathor/indexes/base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions hathor/indexes/rocksdb_tokens_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions hathor/indexes/rocksdb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions hathor/indexes/utxo_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
Loading