Skip to content

Commit 0b30594

Browse files
committed
review changes 9
1 parent 17f19b6 commit 0b30594

File tree

9 files changed

+32
-34
lines changed

9 files changed

+32
-34
lines changed

hathor/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def _initialize_components(self) -> None:
497497
assert self.tx_storage.indexes is not None
498498
if self.tx_storage.indexes.mempool_tips:
499499
self.tx_storage.indexes.mempool_tips.update(tx)
500+
# XXX: refactor this in the future so the index manager decies whether to update each index
500501
if tx_meta.validation.is_fully_connected():
501502
self.tx_storage.add_to_indexes(tx)
502503
if tx.is_transaction and tx_meta.voided_by:

hathor/p2p/node_sync_v2.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PeerState(Enum):
5050
UNKNOWN = 'unknown'
5151
SYNCING_CHECKPOINTS = 'syncing-checkpoints'
5252
SYNCING_BLOCKS = 'syncing-blocks'
53+
# XXX: maybe use a SYNCING_MEMPOOL and SYNCING_REALTIME too
5354

5455

5556
class StreamEnd(IntFlag):
@@ -785,8 +786,7 @@ def handle_blocks(self, payload: str) -> None:
785786
else:
786787
self.log.debug('block received', blk_id=blk.hash.hex())
787788
self.manager.on_new_tx(blk, propagate_to_peers=False, quiet=True, partial=True,
788-
sync_checkpoints=is_syncing_checkpoints,
789-
reject_locked_reward=not is_syncing_checkpoints)
789+
sync_checkpoints=is_syncing_checkpoints)
790790
except HathorError:
791791
self.handle_invalid_block(exc_info=True)
792792
return
@@ -923,10 +923,6 @@ def handle_transaction(self, payload: str) -> None:
923923
"""Handle a received TRANSACTION message."""
924924
assert self.protocol.connections is not None
925925

926-
# if self.state != PeerState.SYNCING_TXS:
927-
# self.protocol.send_error_and_close_connection('Not expecting to receive transactions')
928-
# return
929-
930926
# tx_bytes = bytes.fromhex(payload)
931927
tx_bytes = base64.b64decode(payload)
932928
tx = tx_or_block_from_bytes(tx_bytes)

hathor/p2p/sync_checkpoints.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, manager: 'HathorManager'):
7272
self.peer_syncing = None
7373

7474
# If set to true next run_sync_transactions will be skipped
75+
# XXX: review how this is implemented
7576
self.should_skip_sync_tx = False
7677

7778
# Create logger with context

hathor/p2p/sync_mempool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, sync_manager: 'NodeBlockSync'):
4545
# Maximum number of items in the DFS.
4646
self.MAX_STACK_LENGTH: int = 1000
4747

48-
# Looping call of the main method
48+
# Whether the mempool algorithm is running
4949
self._is_running = False
5050

5151
def is_running(self) -> bool:

hathor/transaction/storage/transaction_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def pre_save_validation(self, tx: BaseTransaction, tx_meta: TransactionMetadata)
368368
assert tx_meta.hash is not None
369369
assert tx.hash == tx_meta.hash, f'{tx.hash.hex()} != {tx_meta.hash.hex()}'
370370
voided_by = tx_meta.voided_by or set()
371-
# XXX: PARTIALLY_VALIDATED_ID must be included if the tx is fully connected and must not included otherwise
371+
# XXX: PARTIALLY_VALIDATED_ID must be included if the tx is fully connected and must not be included otherwise
372372
has_partially_validated_marker = settings.PARTIALLY_VALIDATED_ID in voided_by
373373
validation_is_fully_connected = tx_meta.validation.is_fully_connected()
374374
assert (not has_partially_validated_marker) == validation_is_fully_connected, \

tests/p2p/test_split_brain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_split_brain_plain(self):
101101
dot2.render('dot2-post')
102102

103103
node_sync = conn.proto1.state.sync_manager
104-
self.assertSynced(node_sync)
104+
self.assertSyncedProgress(node_sync)
105105
self.assertTipsEqual(manager1, manager2)
106106
self.assertConsensusEqual(manager1, manager2)
107107
self.assertConsensusValid(manager1)

tests/p2p/test_split_brain2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_split_brain(self):
6767
dot2 = GraphvizVisualizer(manager2.tx_storage, include_verifications=True).dot()
6868
dot2.render('dot2-post')
6969

70-
self.assertSynced(conn12.proto1.state.sync_manager)
71-
self.assertSynced(conn12.proto2.state.sync_manager)
70+
self.assertSyncedProgress(conn12.proto1.state.sync_manager)
71+
self.assertSyncedProgress(conn12.proto2.state.sync_manager)
7272
self.assertTipsEqual(manager1, manager2)
7373
self.assertConsensusEqual(manager1, manager2)
7474
self.assertConsensusValid(manager1)

tests/tx/test_indexes3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,20 @@ class SyncV1SimulatorIndexesTestCase(unittest.SyncV1Params, BaseSimulatorIndexes
118118
class SyncV2SimulatorIndexesTestCase(unittest.SyncV2Params, BaseSimulatorIndexesTestCase):
119119
__test__ = True
120120

121+
@pytest.mark.flaky(max_runs=5, min_passes=1)
122+
def test_topological_iterators(self):
123+
super().test_topological_iterators()
124+
125+
# XXX: disable this on sync-v2 because it's flaky and it won't make sense when tips indexes are removed
126+
def test_tips_index_initialization(self):
127+
pass
128+
121129

122130
# sync-bridge should behave like sync-v2
123131
class SyncBridgeSimulatorIndexesTestCase(unittest.SyncBridgeParams, SyncV2SimulatorIndexesTestCase):
124132
__test__ = True
133+
134+
# XXX: re-enable this on sync-bridge with higher flakiness, sync-bridge has tips indexes so it makes sense
135+
@pytest.mark.flaky(max_runs=5, min_passes=1)
136+
def test_tips_index_initialization(self):
137+
SyncV1SimulatorIndexesTestCase.test_tips_index_initialization(self)

tests/unittest.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -272,28 +272,15 @@ def assertTipsNotEqual(self, manager1, manager2):
272272
self.assertNotEqual(s1, s2)
273273

274274
def assertTipsEqualSyncV1(self, manager1, manager2):
275-
# tx tips
276-
tips1 = {tx.hash for tx in manager1.tx_storage.iter_mempool_tips_from_tx_tips()}
277-
tips2 = {tx.hash for tx in manager2.tx_storage.iter_mempool_tips_from_tx_tips()}
278-
self.log.debug('tx tips1', len=len(tips1), list=shorten_hash(tips1))
279-
self.log.debug('tx tips2', len=len(tips2), list=shorten_hash(tips2))
280-
self.assertEqual(tips1, tips2)
281-
282-
# best block
283-
s1 = set(manager1.tx_storage.get_best_block_tips())
284-
s2 = set(manager2.tx_storage.get_best_block_tips())
285-
self.assertEqual(s1, s2)
286-
287-
# best block (from height index)
288-
b1 = manager1.tx_storage.indexes.height.get_tip()
289-
b2 = manager2.tx_storage.indexes.height.get_tip()
290-
self.assertEqual(b1, b2)
291-
292-
# all tips must be equal (this check should be removed together with the index)
275+
# XXX: this is the original implementation of assertTipsEqual
293276
s1 = set(manager1.tx_storage.get_all_tips())
294277
s2 = set(manager2.tx_storage.get_all_tips())
295278
self.assertEqual(s1, s2)
296279

280+
s1 = set(manager1.tx_storage.get_tx_tips())
281+
s2 = set(manager2.tx_storage.get_tx_tips())
282+
self.assertEqual(s1, s2)
283+
297284
def assertTipsEqualSyncV2(self, manager1, manager2, *, strict_sync_v2_indexes=True):
298285
# tx tips
299286
if strict_sync_v2_indexes:
@@ -433,18 +420,18 @@ def assertTransactionConsensusValid(self, tx):
433420
self.assertTrue(meta.voided_by)
434421
self.assertTrue(parent_meta.voided_by.issubset(meta.voided_by))
435422

436-
def assertSynced(self, node_sync):
423+
def assertSyncedProgress(self, node_sync):
437424
"""Check "synced" status of p2p-manager, uses self._enable_sync_vX to choose which check to run."""
438425
enable_sync_v1, enable_sync_v2 = self._syncVersionFlags()
439426
if enable_sync_v2:
440-
self.assertV2Synced(node_sync)
427+
self.assertV2SyncedProgress(node_sync)
441428
elif enable_sync_v1:
442-
self.assertV1Synced(node_sync)
429+
self.assertV1SyncedProgress(node_sync)
443430

444-
def assertV1Synced(self, node_sync):
431+
def assertV1SyncedProgress(self, node_sync):
445432
self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp)
446433

447-
def assertV2Synced(self, node_sync):
434+
def assertV2SyncedProgress(self, node_sync):
448435
self.assertEqual(node_sync.synced_height, node_sync.peer_height)
449436

450437
def clean_tmpdirs(self):

0 commit comments

Comments
 (0)