1+ use std:: process;
2+
13use mina_core:: { bug_condition, error, Substate } ;
24use p2p:: { P2pAction , P2pEffectfulAction , P2pInitializeAction , P2pState } ;
35
@@ -6,7 +8,7 @@ use crate::{
68 rpc:: RpcState ,
79 state:: { BlockProducerState , LedgerState } ,
810 transition_frontier:: candidate:: TransitionFrontierCandidateAction ,
9- Action , ActionWithMeta , EventSourceAction , P2p , State ,
11+ Action , ActionWithMeta , EventSourceAction , ExitAction , P2p , State ,
1012} ;
1113
1214pub fn reducer (
@@ -17,7 +19,18 @@ pub fn reducer(
1719 let meta = action. meta ( ) . clone ( ) ;
1820 match action. action ( ) {
1921 Action :: CheckTimeouts ( _) => {
20- if state. p2p . ready ( ) . is_some ( ) {
22+ if let Some ( p2p) = state. p2p . ready ( ) {
23+ if let Some ( kad_state) = & p2p. network . scheduler . discovery_state {
24+ if p2p. ready_peers ( ) . is_empty ( ) && kad_state. has_bootstraped {
25+ if let Some ( tip) = & state. transition_frontier . best_tip_breadcrumb ( ) {
26+ // TODO: this might need to change in future
27+ if tip. height ( ) == 296372 {
28+ dispatcher. push ( ExitAction { } ) ;
29+ }
30+ }
31+ }
32+ }
33+
2134 if let Err ( error) =
2235 P2pState :: p2p_timeout_dispatch ( Substate :: new ( state, dispatcher) , & meta)
2336 {
@@ -108,6 +121,18 @@ pub fn reducer(
108121 Action :: P2pCallbacks ( action) => {
109122 State :: p2p_callback_reducer ( Substate :: new ( state, dispatcher) , meta. with_action ( action) )
110123 }
124+ Action :: Exit ( _) => {
125+ // In some tests we want the node to fail because we are testing for handling
126+ #[ cfg( not( test) ) ]
127+ {
128+ crate :: core:: error!(
129+ crate :: core:: log:: system_time( ) ;
130+ summary = "Exiting" ,
131+ error = "Invalid initial peers"
132+ ) ;
133+ process:: exit ( 1 ) ;
134+ }
135+ }
111136 }
112137
113138 // must be the last.
0 commit comments