Skip to content

Commit 173d8c1

Browse files
committed
refactor(misc): minor maintenance changes
1 parent 8b02ba5 commit 173d8c1

14 files changed

+12
-73
lines changed

docs/event-queue-feature.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@ When the Event Queue feature is enabled, the full node will generate specific ev
1515

1616
## Enabling the Event Queue
1717

18-
To enable the Event Queue feature, you must add two CLI options when running the full node:
19-
20-
1. Add `--unsafe-mode [network_name]`
21-
2. Add `--x-enable-event-queue`
18+
To enable the Event Queue feature, you must add this CLI option when running the full node: `--enable-event-queue`.
2219

2320
For example:
2421

2522
```bash
26-
poetry run hathor-cli run_node --memory-storage --status 8080 --testnet --unsafe-mode testnet-golf --x-enable-event-queue
23+
poetry run hathor-cli run_node --memory-storage --status 8080 --testnet --enable-event-queue
2724
```
2825

29-
**ATTENTION**: While the Event Queue is in beta, it's considered unsafe. You must not use it in production environments.
30-
3126
### First run
3227

3328
If this is the first time your full node is running with the event queue enabled, there are 3 possibilities:
@@ -45,7 +40,7 @@ For case 2.2, an extra loading step will be performed during full node initializ
4540

4641
After running the full node with the Event Queue enabled, if you restart your full node (that is, stop it and then run it again), there are 2 possibilities:
4742

48-
1. You run the full node with the `--x-enable-event-queue` CLI option, that is, you keep the Event Queue enabled, or
43+
1. You run the full node with the `--enable-event-queue` CLI option, that is, you keep the Event Queue enabled, or
4944
2. You run the full node without the CLI option, that is, you don't enable it, but you **have to clear the event data in the database**.
5045

5146
For case 1, the full node will start normally, and continue to generate new events for synced vertices from where it stopped in the previous run.

hathor/p2p/states/peer_id.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ async def handle_peer_id(self, payload: str) -> None:
102102

103103
data = json_loads(payload)
104104

105-
peer = PublicPeer.create_from_json(data)
105+
try:
106+
peer = PublicPeer.create_from_json(data)
107+
except ValueError as e:
108+
protocol.send_error_and_close_connection(f'Unable to parse peer id. Reason: {str(e)}')
109+
return
110+
106111
assert peer.id is not None
107112

108113
# If the connection URL had a peer-id parameter we need to check it's the same

tests/cli/test_shell.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import tempfile
22

3-
import pytest
4-
53
from hathor.cli.shell import Shell
64
from tests import unittest
7-
from tests.utils import HAS_ROCKSDB
85

96

107
class ShellTest(unittest.TestCase):
@@ -14,7 +11,6 @@ def test_shell_execution_memory_storage(self):
1411
shell = Shell(argv=['--memory-storage', '--', '--extra-arg'])
1512
self.assertTrue(shell is not None)
1613

17-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
1814
def test_shell_execution_default_storage(self):
1915
temp_data = tempfile.TemporaryDirectory()
2016
shell = Shell(argv=['--data', temp_data.name])

tests/event/event_simulation_tester.py

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from typing import Any, Iterable
1717
from unittest.mock import Mock
1818

19-
import pytest
2019
from twisted.internet.testing import StringTransport
2120

2221
from hathor.builder import Builder
@@ -27,7 +26,6 @@
2726
from hathor.transaction.util import unpack, unpack_len
2827
from hathor.util import json_loadb
2928
from tests.simulation.base import SimulatorTestCase
30-
from tests.utils import HAS_ROCKSDB
3129

3230

3331
class BaseEventSimulationTester(SimulatorTestCase):
@@ -101,7 +99,6 @@ def setUp(self) -> None:
10199
self._create_artifacts()
102100

103101

104-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
105102
class RocksDBEventSimulationTester(BaseEventSimulationTester):
106103
def setUp(self) -> None:
107104
super().setUp()

tests/event/test_event_storage.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import tempfile
22

3-
import pytest
4-
53
from hathor.event.model.base_event import BaseEvent
64
from hathor.event.model.node_state import NodeState
75
from hathor.event.storage import EventStorage
86
from hathor.event.storage.memory_storage import EventMemoryStorage
97
from hathor.event.storage.rocksdb_storage import EventRocksDBStorage
108
from hathor.storage.rocksdb_storage import RocksDBStorage
119
from tests import unittest
12-
from tests.utils import HAS_ROCKSDB, EventMocker
10+
from tests.utils import EventMocker
1311

1412

1513
class EventStorageBaseTest(unittest.TestCase):
@@ -237,7 +235,6 @@ def test_reset_all_full_database(self) -> None:
237235
assert event_queue_state is False
238236

239237

240-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
241238
class EventStorageRocksDBTest(EventStorageBaseTest):
242239
__test__ = True
243240

tests/feature_activation/test_feature_simulation.py

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from hathor.util import not_none
3232
from tests.resources.base_resource import StubSite
3333
from tests.simulation.base import SimulatorTestCase
34-
from tests.utils import HAS_ROCKSDB
3534

3635

3736
class BaseFeatureSimulationTest(SimulatorTestCase):
@@ -671,7 +670,6 @@ def get_simulator_builder(self) -> Builder:
671670
return self.simulator.get_default_builder()
672671

673672

674-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
675673
class RocksDBStorageFeatureSimulationTest(BaseFeatureSimulationTest):
676674
__test__ = True
677675

tests/others/test_cli_builder.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from unittest.mock import Mock
22

3-
import pytest
4-
53
from hathor.builder import CliBuilder, ResourcesBuilder
64
from hathor.cli.run_node_args import RunNodeArgs
75
from hathor.event import EventManager
@@ -14,7 +12,6 @@
1412
from hathor.transaction.storage import TransactionCacheStorage, TransactionMemoryStorage, TransactionRocksDBStorage
1513
from hathor.wallet import HDWallet, Wallet
1614
from tests import unittest
17-
from tests.utils import HAS_ROCKSDB
1815

1916

2017
class BuilderTestCase(unittest.TestCase):
@@ -49,7 +46,6 @@ def _build(self, cmd_args: list[str]) -> HathorManager:
4946
def test_empty(self):
5047
self._build_with_error([], '--data is expected')
5148

52-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
5349
def test_all_default(self):
5450
data_dir = self.mkdtemp()
5551
manager = self._build(['--data', data_dir])
@@ -64,30 +60,26 @@ def test_all_default(self):
6460
self.assertFalse(self.resources_builder._built_status)
6561
self.assertFalse(manager._enable_event_queue)
6662

67-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
6863
def test_disable_cache_storage(self):
6964
data_dir = self.mkdtemp()
7065
manager = self._build(['--disable-cache', '--data', data_dir])
7166
self.assertIsInstance(manager.tx_storage, TransactionRocksDBStorage)
7267
self.assertIsInstance(manager.tx_storage.indexes, RocksDBIndexesManager)
7368

74-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
7569
def test_default_storage_memory_indexes(self):
7670
data_dir = self.mkdtemp()
7771
manager = self._build(['--memory-indexes', '--data', data_dir])
7872
self.assertIsInstance(manager.tx_storage, TransactionCacheStorage)
7973
self.assertIsInstance(manager.tx_storage.store, TransactionRocksDBStorage)
8074
self.assertIsInstance(manager.tx_storage.indexes, MemoryIndexesManager)
8175

82-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
8376
def test_default_storage_with_rocksdb_indexes(self):
8477
data_dir = self.mkdtemp()
8578
manager = self._build(['--x-rocksdb-indexes', '--data', data_dir])
8679
self.assertIsInstance(manager.tx_storage, TransactionCacheStorage)
8780
self.assertIsInstance(manager.tx_storage.store, TransactionRocksDBStorage)
8881
self.assertIsInstance(manager.tx_storage.indexes, RocksDBIndexesManager)
8982

90-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
9183
def test_rocksdb_storage(self):
9284
data_dir = self.mkdtemp()
9385
manager = self._build(['--rocksdb-storage', '--data', data_dir])
@@ -153,20 +145,17 @@ def test_prometheus_no_data(self):
153145
args = ['--memory-storage', '--prometheus']
154146
self._build_with_error(args, 'To run prometheus exporter you must have a data path')
155147

156-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
157148
def test_prometheus(self):
158149
data_dir = self.mkdtemp()
159150
self._build(['--prometheus', '--data', data_dir])
160151
self.assertTrue(self.resources_builder._built_prometheus)
161152
self.clean_pending(required_to_quiesce=False)
162153

163-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
164154
def test_memory_and_rocksdb_indexes(self):
165155
data_dir = self.mkdtemp()
166156
args = ['--memory-indexes', '--x-rocksdb-indexes', '--data', data_dir]
167157
self._build_with_error(args, 'You cannot use --memory-indexes and --x-rocksdb-indexes.')
168158

169-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
170159
def test_event_queue_with_rocksdb_storage(self):
171160
data_dir = self.mkdtemp()
172161
manager = self._build(['--x-enable-event-queue', '--rocksdb-storage', '--data', data_dir])

tests/others/test_metrics.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import tempfile
22
from unittest.mock import Mock
33

4-
import pytest
5-
64
from hathor.p2p.manager import PeerConnectionsMetrics
75
from hathor.p2p.peer import PrivatePeer
86
from hathor.p2p.peer_endpoint import PeerEndpoint
@@ -12,7 +10,6 @@
1210
from hathor.transaction.storage import TransactionCacheStorage, TransactionMemoryStorage
1311
from hathor.wallet import Wallet
1412
from tests import unittest
15-
from tests.utils import HAS_ROCKSDB
1613

1714

1815
class MetricsTest(unittest.TestCase):
@@ -82,7 +79,6 @@ def test_connections_manager_integration(self):
8279

8380
manager.metrics.stop()
8481

85-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
8682
def test_tx_storage_data_collection_with_rocksdb_storage_and_no_cache(self):
8783
"""Tests storage data collection when using RocksDB Storage
8884
with cache disabled.
@@ -134,7 +130,6 @@ def _init_manager():
134130
self.assertGreater(manager.metrics.rocksdb_cfs_sizes[b'tx'], 500)
135131
self.assertGreater(manager.metrics.rocksdb_cfs_sizes[b'meta'], 1000)
136132

137-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
138133
def test_tx_storage_data_collection_with_rocksdb_storage_and_cache(self):
139134
"""Tests storage data collection when using RocksDB Storage
140135
with cache enabled.

tests/p2p/test_sync_v2.py

-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
from unittest.mock import patch
44

5-
import pytest
65
from twisted.internet.defer import Deferred, succeed
76
from twisted.python.failure import Failure
87

@@ -24,7 +23,6 @@
2423
from hathor.types import VertexId
2524
from hathor.util import not_none
2625
from tests.simulation.base import SimulatorTestCase
27-
from tests.utils import HAS_ROCKSDB
2826

2927

3028
class BaseRandomSimulatorTestCase(SimulatorTestCase):
@@ -148,19 +146,15 @@ def _run_restart_test(self, *, full_verification: bool, use_tx_storage_cache: bo
148146
self.assertEqual(manager1.tx_storage.get_vertices_count(), manager3.tx_storage.get_vertices_count())
149147
self.assertConsensusEqualSyncV2(manager1, manager3)
150148

151-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
152149
def test_restart_fullnode_full_verification(self) -> None:
153150
self._run_restart_test(full_verification=True, use_tx_storage_cache=False)
154151

155-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
156152
def test_restart_fullnode_quick(self) -> None:
157153
self._run_restart_test(full_verification=False, use_tx_storage_cache=False)
158154

159-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
160155
def test_restart_fullnode_quick_with_cache(self) -> None:
161156
self._run_restart_test(full_verification=False, use_tx_storage_cache=True)
162157

163-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
164158
def test_restart_fullnode_full_verification_with_cache(self) -> None:
165159
self._run_restart_test(full_verification=True, use_tx_storage_cache=True)
166160

tests/poa/test_poa_simulation.py

-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import Iterator
1818

1919
import base58
20-
import pytest
2120
from cryptography.hazmat.primitives import hashes
2221
from cryptography.hazmat.primitives.asymmetric import ec
2322
from twisted.python.failure import Failure
@@ -39,7 +38,6 @@
3938
from hathor.util import not_none
4039
from tests.poa.utils import get_settings, get_signer
4140
from tests.simulation.base import SimulatorTestCase
42-
from tests.utils import HAS_ROCKSDB
4341

4442

4543
def _get_blocks_by_height(manager: HathorManager) -> defaultdict[int, list[PoaBlock]]:
@@ -325,7 +323,6 @@ def test_producer_leave_and_comeback(self) -> None:
325323
expected,
326324
)
327325

328-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
329326
def test_existing_storage(self) -> None:
330327
import tempfile
331328
rocksdb_directory = tempfile.mkdtemp()

tests/tx/test_indexes.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
31
from hathor.crypto.util import decode_address
42
from hathor.graphviz import GraphvizVisualizer
53
from hathor.simulator.utils import add_new_block, add_new_blocks
@@ -9,7 +7,7 @@
97
from hathor.util import iwindows
108
from hathor.wallet import Wallet
119
from tests import unittest
12-
from tests.utils import HAS_ROCKSDB, add_blocks_unlock_reward, add_custom_tx, add_new_tx, get_genesis_key
10+
from tests.utils import add_blocks_unlock_reward, add_custom_tx, add_new_tx, get_genesis_key
1311

1412

1513
class BaseIndexesTest(unittest.TestCase):
@@ -715,7 +713,6 @@ def setUp(self):
715713
self.graphviz = GraphvizVisualizer(self.tx_storage, include_verifications=True, include_funds=True)
716714

717715

718-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
719716
class RocksDBIndexesTest(BaseIndexesTest):
720717
__test__ = True
721718

tests/tx/test_indexes2.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import tempfile
22
from typing import TYPE_CHECKING, NamedTuple
33

4-
import pytest
5-
64
from tests import unittest
7-
from tests.utils import HAS_ROCKSDB
85

96
if TYPE_CHECKING: # pragma: no cover
107
import rocksdb
@@ -36,7 +33,6 @@ def create_tmp_rocksdb_db(self) -> 'rocksdb.DB':
3633
options = rocksdb.Options(create_if_missing=True, error_if_exists=True)
3734
return rocksdb.DB(directory, options)
3835

39-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
4036
def test_timestamp_index(self):
4137
# setup two indexes with different backends
4238
from hathor.indexes.memory_timestamp_index import MemoryTimestampIndex

tests/tx/test_tx_storage.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44
from itertools import chain
55

6-
import pytest
76
from twisted.internet.defer import gatherResults, inlineCallbacks
87
from twisted.internet.threads import deferToThread
98
from twisted.trial import unittest
@@ -15,14 +14,7 @@
1514
from hathor.transaction.storage.exceptions import TransactionDoesNotExist
1615
from hathor.transaction.validation_state import ValidationState
1716
from tests.unittest import TestBuilder
18-
from tests.utils import (
19-
BURN_ADDRESS,
20-
HAS_ROCKSDB,
21-
add_blocks_unlock_reward,
22-
add_new_transactions,
23-
add_new_tx,
24-
create_tokens,
25-
)
17+
from tests.utils import BURN_ADDRESS, add_blocks_unlock_reward, add_new_transactions, add_new_tx, create_tokens
2618

2719

2820
class BaseTransactionStorageTest(unittest.TestCase):
@@ -629,7 +621,6 @@ def _config_builder(self, builder: TestBuilder) -> None:
629621
builder.use_tx_storage_cache(capacity=5)
630622

631623

632-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
633624
class TransactionRocksDBStorageTest(BaseTransactionStorageTest):
634625
__test__ = True
635626

@@ -646,7 +637,6 @@ def test_storage_new_blocks(self):
646637
super().test_storage_new_blocks()
647638

648639

649-
@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
650640
class CacheRocksDBStorageTest(BaseCacheStorageTest):
651641
__test__ = True
652642

tests/utils.py

-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
from hathor.transaction.util import get_deposit_amount
2828
from hathor.util import Random
2929

30-
try:
31-
import rocksdb # noqa: F401
32-
except ImportError:
33-
HAS_ROCKSDB = False
34-
else:
35-
HAS_ROCKSDB = True
36-
3730
settings = HathorSettings()
3831

3932
# useful for adding blocks to a different wallet

0 commit comments

Comments
 (0)