Skip to content

Commit 2df861a

Browse files
committed
feat(cli): Add feature flag and CLI parameters for Nano Contracts
1 parent 0f5ff70 commit 2df861a

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

hathor/builder/cli_builder.py

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
103103
reactor_type=type(reactor).__name__,
104104
)
105105

106+
if not self._args.nano_testnet:
107+
# Add protection to prevent enabling Nano Contracts due to misconfigurations.
108+
self.check_or_raise(not settings.ENABLE_NANO_CONTRACTS,
109+
'configuration error: NanoContracts can only be enabled on localnets for now')
110+
106111
tx_storage: TransactionStorage
107112
event_storage: EventStorage
108113
indexes: IndexesManager

hathor/cli/run_node.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def create_parser(cls) -> ArgumentParser:
5252
parser.add_argument('--auto-hostname', action='store_true', help='Try to discover the hostname automatically')
5353
parser.add_argument('--unsafe-mode',
5454
help='Enable unsafe parameters. **NEVER USE IT IN PRODUCTION ENVIRONMENT**')
55+
parser.add_argument('--nano-testnet', action='store_true', help='Connect to Hathor nano-testnet')
5556
parser.add_argument('--testnet', action='store_true', help='Connect to Hathor testnet')
5657
parser.add_argument('--test-mode-tx-weight', action='store_true',
5758
help='Reduces tx weight to 1 for testing purposes')
@@ -359,7 +360,7 @@ def check_python_version(self) -> None:
359360

360361
def __init__(self, *, argv=None):
361362
from hathor.cli.run_node_args import RunNodeArgs
362-
from hathor.conf import TESTNET_SETTINGS_FILEPATH
363+
from hathor.conf import NANO_TESTNET_SETTINGS_FILEPATH, TESTNET_SETTINGS_FILEPATH
363364
from hathor.conf.get_settings import get_global_settings
364365
self.log = logger.new()
365366

@@ -376,6 +377,8 @@ def __init__(self, *, argv=None):
376377
os.environ['HATHOR_CONFIG_YAML'] = self._args.config_yaml
377378
elif self._args.testnet:
378379
os.environ['HATHOR_CONFIG_YAML'] = TESTNET_SETTINGS_FILEPATH
380+
elif self._args.nano_testnet:
381+
os.environ['HATHOR_CONFIG_YAML'] = NANO_TESTNET_SETTINGS_FILEPATH
379382

380383
try:
381384
get_global_settings()

hathor/conf/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
MAINNET_SETTINGS_FILEPATH = str(parent_dir / 'mainnet.yml')
2222
TESTNET_SETTINGS_FILEPATH = str(parent_dir / 'testnet.yml')
23+
NANO_TESTNET_SETTINGS_FILEPATH = str(parent_dir / 'nano_testnet.yml')
2324
UNITTESTS_SETTINGS_FILEPATH = str(parent_dir / 'unittests.yml')
2425

2526
__all__ = [
2627
'MAINNET_SETTINGS_FILEPATH',
2728
'TESTNET_SETTINGS_FILEPATH',
29+
'NANO_TESTNET_SETTINGS_FILEPATH',
2830
'UNITTESTS_SETTINGS_FILEPATH',
2931
'HathorSettings',
3032
]

hathor/conf/nano_testnet.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
P2PKH_VERSION_BYTE: x49
2+
MULTISIG_VERSION_BYTE: x87
3+
NETWORK_NAME: nano-testnet-alpha
4+
BOOTSTRAP_DNS: []
5+
6+
# Genesis stuff
7+
GENESIS_OUTPUT_SCRIPT: 76a914a584cf48b161e4a49223ed220df30037ab740e0088ac
8+
GENESIS_BLOCK_TIMESTAMP: 1677601898
9+
GENESIS_BLOCK_NONCE: 717217
10+
GENESIS_BLOCK_HASH: 000006417e5ad864ce7e7c97090f6794e86058f99b7baf2b65acda21159dfa12
11+
GENESIS_TX1_NONCE: 190
12+
GENESIS_TX1_HASH: 00e161a6b0bee1781ea9300680913fb76fd0fac4acab527cd9626cc1514abdc9
13+
GENESIS_TX2_NONCE: 115
14+
GENESIS_TX2_HASH: 00975897028ceb037307327c953f5e7ad4d3f42402d71bd3d11ecb63ac39f01a
15+
16+
# tx weight parameters. With these settings tx weight is always 8
17+
MIN_TX_WEIGHT_K: 0
18+
MIN_TX_WEIGHT_COEFFICIENT: 0
19+
MIN_TX_WEIGHT: 8
20+
CHECKPOINTS:
21+
ENABLE_NANO_CONTRACTS: true
22+
BLUEPRINTS:

hathor/conf/settings.py

+9
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ def GENESIS_TX2_TIMESTAMP(self) -> int:
423423
OLD_MAX_MERKLE_PATH_LENGTH: int = 12
424424
NEW_MAX_MERKLE_PATH_LENGTH: int = 20
425425

426+
# Used to enable nano contracts.
427+
#
428+
# This should NEVER be enabled for mainnet and testnet, since both networks will
429+
# activate Nano Contracts through the Feature Activation.
430+
ENABLE_NANO_CONTRACTS: bool = False
431+
432+
# List of enabled blueprints.
433+
BLUEPRINTS: list['str'] = []
434+
426435
@classmethod
427436
def from_yaml(cls, *, filepath: str) -> 'HathorSettings':
428437
"""Takes a filepath to a yaml file and returns a validated HathorSettings instance."""

hathor/conf/unittests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
evaluation_interval=4,
4040
max_signal_bits=4,
4141
default_threshold=3
42-
)
42+
),
43+
ENABLE_NANO_CONTRACTS=True,
4344
)

0 commit comments

Comments
 (0)