Skip to content

Commit 57126e4

Browse files
committed
feat(reliable-integration): emit VERTEX_METADATA_CHANGED events in reverse topological order
1 parent 54a1a66 commit 57126e4

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

hathor/consensus/consensus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _unsafe_update(self, base: BaseTransaction) -> None:
136136
reorg_size=reorg_size)
137137

138138
# finally signal an index update for all affected transactions
139-
sorted_txs_affected = sorted(context.txs_affected, key=lambda tx: not_none(tx.hash))
139+
sorted_txs_affected = sorted(context.txs_affected, key=lambda tx: not_none(tx.timestamp), reverse=True)
140140
for tx_affected in sorted_txs_affected:
141141
assert tx_affected.storage is not None
142142
assert tx_affected.storage.indexes is not None

tests/event/test_event_reorg.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
from hathor.conf import HathorSettings
42
from hathor.event.model.event_type import EventType
53
from hathor.event.storage import EventMemoryStorage
@@ -54,11 +52,9 @@ def test_reorg_events(self):
5452
(EventType.NEW_VERTEX_ACCEPTED, {'hash': settings.GENESIS_TX1_HASH.hex()}),
5553
(EventType.NEW_VERTEX_ACCEPTED, {'hash': settings.GENESIS_TX2_HASH.hex()}),
5654
(EventType.LOAD_FINISHED, {}),
57-
*sorted_by_hash(
58-
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[0].hash_hex}),
59-
(EventType.VERTEX_METADATA_CHANGED, {'hash': settings.GENESIS_TX1_HASH.hex()}),
60-
(EventType.VERTEX_METADATA_CHANGED, {'hash': settings.GENESIS_TX2_HASH.hex()}),
61-
),
55+
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[0].hash_hex}),
56+
(EventType.VERTEX_METADATA_CHANGED, {'hash': settings.GENESIS_TX2_HASH.hex()}),
57+
(EventType.VERTEX_METADATA_CHANGED, {'hash': settings.GENESIS_TX1_HASH.hex()}),
6258
(EventType.NEW_VERTEX_ACCEPTED, {'hash': blocks[0].hash_hex}),
6359
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[1].hash_hex}),
6460
(EventType.NEW_VERTEX_ACCEPTED, {'hash': blocks[1].hash_hex}),
@@ -80,11 +76,9 @@ def test_reorg_events(self):
8076
(EventType.NEW_VERTEX_ACCEPTED, {'hash': blocks[9].hash_hex}),
8177
(EventType.REORG_STARTED, {'reorg_size': 2, 'previous_best_block': blocks[9].hash_hex,
8278
'new_best_block': b0.hash_hex}),
83-
*sorted_by_hash(
84-
(EventType.VERTEX_METADATA_CHANGED, {'hash': b0.hash_hex}),
85-
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[9].hash_hex}),
86-
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[8].hash_hex}),
87-
),
79+
(EventType.VERTEX_METADATA_CHANGED, {'hash': b0.hash_hex}),
80+
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[9].hash_hex}),
81+
(EventType.VERTEX_METADATA_CHANGED, {'hash': blocks[8].hash_hex}),
8882
(EventType.REORG_FINISHED, {}),
8983
(EventType.NEW_VERTEX_ACCEPTED, {'hash': b0.hash_hex}),
9084
]
@@ -98,10 +92,6 @@ def test_reorg_events(self):
9892
self.assertEqual(actual_event.data.dict()[expected_data_key], expected_data_value)
9993

10094

101-
def sorted_by_hash(*events: tuple[EventType, dict[str, Any]]) -> list[tuple[EventType, dict[str, Any]]]:
102-
return sorted(events, key=lambda event: event[1]['hash'])
103-
104-
10595
class SyncV1EventReorgTest(unittest.SyncV1Params, BaseEventReorgTest):
10696
__test__ = True
10797

0 commit comments

Comments
 (0)