@@ -71,42 +71,50 @@ def disable_idle_timeout(self):
71
71
self ._proto1 .disable_idle_timeout ()
72
72
self ._proto2 .disable_idle_timeout ()
73
73
74
- def is_both_synced (self ) -> bool :
74
+ def is_both_synced (self , * , errmsgs : Optional [ list [ str ]] = None ) -> bool :
75
75
"""Short-hand check that can be used to make "step loops" without having to guess the number of iterations."""
76
+ if errmsgs is None :
77
+ errmsgs = []
76
78
from hathor .p2p .states .ready import ReadyState
77
79
conn1_aborting = self ._proto1 .aborting
78
80
conn2_aborting = self ._proto2 .aborting
79
81
if conn1_aborting or conn2_aborting :
80
82
self .log .debug ('conn aborting' , conn1_aborting = conn1_aborting , conn2_aborting = conn2_aborting )
83
+ errmsgs .append ('conn aborting' )
81
84
return False
82
85
state1 = self ._proto1 .state
83
86
state2 = self ._proto2 .state
84
87
state1_is_ready = isinstance (state1 , ReadyState )
85
88
state2_is_ready = isinstance (state2 , ReadyState )
86
89
if not state1_is_ready or not state2_is_ready :
87
90
self .log .debug ('peer not ready' , peer1_ready = state1_is_ready , peer2_ready = state2_is_ready )
91
+ errmsgs .append ('peer not ready' )
88
92
return False
89
93
assert isinstance (state1 , ReadyState ) # mypy can't infer this from the above
90
94
assert isinstance (state2 , ReadyState ) # mypy can't infer this from the above
91
95
state1_is_errored = state1 .sync_agent .is_errored ()
92
96
state2_is_errored = state2 .sync_agent .is_errored ()
93
97
if state1_is_errored or state2_is_errored :
94
98
self .log .debug ('peer errored' , peer1_errored = state1_is_errored , peer2_errored = state2_is_errored )
99
+ errmsgs .append ('peer errored' )
95
100
return False
96
101
state1_is_synced = state1 .sync_agent .is_synced ()
97
102
state2_is_synced = state2 .sync_agent .is_synced ()
98
103
if not state1_is_synced or not state2_is_synced :
99
104
self .log .debug ('peer not synced' , peer1_synced = state1_is_synced , peer2_synced = state2_is_synced )
105
+ errmsgs .append ('peer not synced' )
100
106
return False
101
107
[best_block_info1 ] = state1 .protocol .node .tx_storage .get_n_height_tips (1 )
102
108
[best_block_info2 ] = state2 .protocol .node .tx_storage .get_n_height_tips (1 )
103
109
if best_block_info1 .id != best_block_info2 .id :
104
110
self .log .debug ('best block is different' )
111
+ errmsgs .append ('best block is different' )
105
112
return False
106
113
tips1 = {i .data for i in state1 .protocol .node .tx_storage .get_tx_tips ()}
107
114
tips2 = {i .data for i in state2 .protocol .node .tx_storage .get_tx_tips ()}
108
115
if tips1 != tips2 :
109
116
self .log .debug ('tx tips are different' )
117
+ errmsgs .append ('tx tips are different' )
110
118
return False
111
119
return True
112
120
0 commit comments