Skip to content

Commit cd0e45c

Browse files
committed
fix: increased median table timeout to 180 seconds + logging for ora sync
1 parent 5dcf5ea commit cd0e45c

4 files changed

Lines changed: 81 additions & 9 deletions

File tree

extensions/business/oracle_sync/sync_mixins/ora_sync_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SIGNATURES_EXCHANGE_MULTIPLIER = 2
1010
REQUEST_AGREEMENT_TABLE_MULTIPLIER = 5 if DEBUG_MODE else 2
1111
LOCAL_TABLE_SEND_MULTIPLIER = 3 if DEBUG_MODE else 2
12+
MEDIAN_TABLE_SEND_MULTIPLIER = 3 if DEBUG_MODE else 2
1213

1314
if DEBUG_MODE:
1415
SUPERVISOR_MIN_AVAIL_PRC = 0.4

extensions/business/oracle_sync/sync_mixins/ora_sync_states_mixin.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ORACLE_SYNC_ACCEPTED_MEDIAN_ERROR_MARGIN,
1010

1111
LOCAL_TABLE_SEND_MULTIPLIER,
12+
MEDIAN_TABLE_SEND_MULTIPLIER,
1213
REQUEST_AGREEMENT_TABLE_MULTIPLIER,
1314
SIGNATURES_EXCHANGE_MULTIPLIER,
1415
)
@@ -509,6 +510,9 @@ def _receive_local_table_and_maybe_send_local_table(self):
509510
# end for
510511
return
511512

513+
def get_local_table_timeout(self):
514+
return self.cfg_send_period * LOCAL_TABLE_SEND_MULTIPLIER
515+
512516
def _send_local_table_timeout(self):
513517
"""
514518
Check if the exchange phase of the local table has finished.
@@ -517,8 +521,8 @@ def _send_local_table_timeout(self):
517521
-------
518522
bool: True if the exchange phase of the local table has finished, False otherwise
519523
"""
520-
timeout_reached = (self.time() - self.first_time_local_table_sent) > (
521-
self.cfg_send_period * LOCAL_TABLE_SEND_MULTIPLIER)
524+
first_time = self.first_time_local_table_sent
525+
timeout_reached = first_time is not None and (self.time() - first_time) > self.get_local_table_timeout()
522526
early_stopping = self._maybe_early_stop_phase(
523527
data=self.dct_local_tables,
524528
phase=self.STATES.S2_SEND_LOCAL_TABLE,
@@ -713,6 +717,9 @@ def _receive_median_table_and_maybe_send_median_table(self):
713717
# end for
714718
return
715719

720+
def get_median_table_timeout(self):
721+
return self.cfg_send_period * MEDIAN_TABLE_SEND_MULTIPLIER
722+
716723
def _send_median_table_timeout(self):
717724
"""
718725
Check if the exchange phase of the median table has finished.
@@ -721,7 +728,8 @@ def _send_median_table_timeout(self):
721728
-------
722729
bool: True if the exchange phase of the median table has finished, False otherwise
723730
"""
724-
timeout_reached = (self.time() - self.first_time_median_table_sent) > self.cfg_send_period
731+
first_time = self.first_time_median_table_sent
732+
timeout_reached = first_time is not None and (self.time() - first_time) > self.get_median_table_timeout()
725733
early_stopping = self._maybe_early_stop_phase(
726734
data=self.dct_median_tables,
727735
phase=self.STATES.S4_SEND_MEDIAN_TABLE,
@@ -1020,6 +1028,9 @@ def _receive_agreement_signature_and_maybe_send_agreement_signature(self):
10201028
# endfor received messages
10211029
return
10221030

1031+
def get_agreement_signature_timeout(self):
1032+
return self.cfg_send_period
1033+
10231034
def _send_agreement_signature_timeout(self):
10241035
"""
10251036
Check if the exchange phase of the agreed median table has finished.
@@ -1028,7 +1039,8 @@ def _send_agreement_signature_timeout(self):
10281039
-------
10291040
bool: True if the exchange phase of the agreed median table has finished, False otherwise
10301041
"""
1031-
timeout_reached = (self.time() - self.first_time__agreement_signature_sent) > self.cfg_send_period
1042+
first_time = self.first_time__agreement_signature_sent
1043+
timeout_reached = first_time is not None and (self.time() - first_time) > self.get_agreement_signature_timeout()
10321044
early_stopping = self._maybe_early_stop_phase(
10331045
data=self.compiled_agreed_median_table_signatures,
10341046
phase=self.STATES.S6_SEND_AGREED_MEDIAN_TABLE,
@@ -1086,6 +1098,9 @@ def _exchange_agreement_signatures(self):
10861098
# endfor received messages
10871099
return
10881100

1101+
def get_exchange_signatures_timeout(self):
1102+
return self.cfg_send_period * SIGNATURES_EXCHANGE_MULTIPLIER
1103+
10891104
def _exchange_signatures_timeout(self):
10901105
"""
10911106
Check if the exchange phase of the agreement signatures has finished.
@@ -1094,8 +1109,8 @@ def _exchange_signatures_timeout(self):
10941109
-------
10951110
bool: True if the exchange phase of the agreement signatures has finished, False otherwise
10961111
"""
1097-
timeout_reached = (self.time() - self.first_time__agreement_signatures_exchanged) > (
1098-
self.cfg_send_period * SIGNATURES_EXCHANGE_MULTIPLIER)
1112+
first_time = self.first_time__agreement_signatures_exchanged
1113+
timeout_reached = first_time is not None and (self.time() - first_time) > self.get_exchange_signatures_timeout()
10991114
early_stopping = self._maybe_early_stop_phase(
11001115
data=self.compiled_agreed_median_table_signatures,
11011116
phase=self.STATES.S10_EXCHANGE_AGREEMENT_SIGNATURES,

extensions/business/oracle_sync/sync_mixins/ora_sync_utils_mixin.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,14 @@ def update_participant_oracles(
332332
# endfor
333333
total_current_participants = sum(self.is_participating.values())
334334
if state is not None:
335+
elapsed, total = self.get_elapsed_and_total_time_of_stage(stage=state)
336+
elapsed_str = ""
337+
if elapsed_str is not None and total is not None:
338+
elapsed_str = f"[elapsed: {elapsed:.2f}s/{total:.2f}s]"
339+
# endif elapsed and total
335340
log_str = f"Updating participating oracles based on {state = }.\n"
336341
log_str += f"{total_previous_participants} previous participants => "
337-
log_str += f"{total_current_participants} current participants.\n"
342+
log_str += f"{total_current_participants} current participants.{elapsed_str}\n"
338343
if len(disappearing_oracles) > 0:
339344
log_str += f"{len(disappearing_oracles)} oracles disappeared:"
340345
log_str += "".join([
@@ -568,7 +573,52 @@ def get_sender_str(self, sender: str):
568573
-------
569574
str : The string representation of the sender
570575
"""
571-
return f"`{self.netmon.network_node_eeid(sender)}` <{sender}>"
576+
short_sender = self.shorten_address(sender)
577+
return f"`{self.netmon.network_node_eeid(sender)}` <{short_sender}>"
578+
579+
def get_elapsed_and_total_time_of_stage(self, stage: str):
580+
"""
581+
Get the elapsed and total time of a stage.
582+
Parameters
583+
----------
584+
stage : str
585+
The stage to get the elapsed and total time for.
586+
587+
Returns
588+
-------
589+
(elapsed, total) : tuple
590+
The elapsed and total time of the stage.
591+
If the stage is not found or the stage does not have a timeout period, (None, None) is returned.
592+
"""
593+
elapsed = None
594+
total = None
595+
values = {
596+
self.STATES.S2_SEND_LOCAL_TABLE: {
597+
'started': self.first_time_local_table_sent,
598+
'total': self.get_local_table_timeout()
599+
},
600+
self.STATES.S4_SEND_MEDIAN_TABLE: {
601+
'started': self.first_time_median_table_sent,
602+
'total': self.get_median_table_timeout()
603+
},
604+
self.STATES.S6_SEND_AGREED_MEDIAN_TABLE: {
605+
'started': self.first_time__agreement_signature_sent,
606+
'total': self.get_agreement_signature_timeout()
607+
},
608+
self.STATES.S10_EXCHANGE_AGREEMENT_SIGNATURES: {
609+
'started': self.first_time__agreement_signatures_exchanged,
610+
'total': self.get_exchange_signatures_timeout()
611+
}
612+
}
613+
stage_values = values.get(stage)
614+
if stage_values is not None:
615+
started = stage_values.get('started')
616+
total = stage_values.get('total')
617+
if started is not None:
618+
elapsed = self.time() - started
619+
# endif started exists
620+
# endif stage_values is not None
621+
return elapsed, total
572622

573623
def log_received_message(
574624
self,
@@ -584,6 +634,12 @@ def log_received_message(
584634
sender_str = self.get_sender_str(sender)
585635
log_str = f"{progress_str}Received message{duplicated_str} from oracle {sender_str}: {stage = }"
586636

637+
elapsed, total = self.get_elapsed_and_total_time_of_stage(stage)
638+
639+
if elapsed is not None and total is not None:
640+
log_str += f" | elapsed: {elapsed:.2f}s/{total:.2f}s"
641+
# endif elapsed and total
642+
587643
if return_str:
588644
return log_str
589645
self.P(log_str)

ver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__VER__ = '2.9.680'
1+
__VER__ = '2.9.690'
22

0 commit comments

Comments
 (0)