Skip to content

Commit e8a0d18

Browse files
committed
Added log if initial peers are invalid
1 parent 9d1e71a commit e8a0d18

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
Dashboard, documenting all endpoints and specific data fields used by the
2222
frontend ([#1566](https://github.com/o1-labs/mina-rust/issues/1566))
2323

24+
- **FEATURE**: Add logging if initial peers are invalid
25+
([#1703](https://github.com/o1-labs/mina-rust/pull/1703))
26+
2427
### Fixed
2528

2629
- **Docker Compose**: Fix frontend black screen issue by changing environment

node/src/action.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub enum Action {
5757
RpcEffectful(RpcEffectfulAction),
5858

5959
WatchedAccounts(WatchedAccountsAction),
60+
Exit(ExitAction),
6061
}
6162

6263
impl Action {
@@ -71,7 +72,11 @@ impl Action {
7172
#[derive(Serialize, Deserialize, Debug, Clone)]
7273
pub struct CheckTimeoutsAction {}
7374

75+
#[derive(Serialize, Deserialize, Debug, Clone)]
76+
pub struct ExitAction {}
77+
7478
impl redux::EnablingCondition<crate::State> for CheckTimeoutsAction {}
79+
impl redux::EnablingCondition<crate::State> for ExitAction {}
7580

7681
impl redux::EnablingCondition<crate::State> for Action {
7782
fn is_enabled(&self, state: &crate::State, time: redux::Timestamp) -> bool {
@@ -105,6 +110,7 @@ impl redux::EnablingCondition<crate::State> for Action {
105110
Action::TransactionPoolEffect(a) => a.is_enabled(state, time),
106111
Action::P2pCallbacks(a) => a.is_enabled(state, time),
107112
Action::RpcEffectful(a) => a.is_enabled(state, time),
113+
Action::Exit(a) => a.is_enabled(state, time),
108114
}
109115
}
110116
}

node/src/action_kind.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use crate::{
107107
TransitionFrontierAction,
108108
},
109109
watched_accounts::WatchedAccountsAction,
110-
Action, ActionKindGet, CheckTimeoutsAction,
110+
Action, ActionKindGet, CheckTimeoutsAction, ExitAction,
111111
};
112112

113113
/// Unified kind enum for all action types
@@ -177,6 +177,7 @@ pub enum ActionKind {
177177
EventSourceProcessEvents,
178178
EventSourceWaitForEvents,
179179
EventSourceWaitTimeout,
180+
Exit,
180181
ExternalSnarkWorkerCancelWork,
181182
ExternalSnarkWorkerError,
182183
ExternalSnarkWorkerKill,
@@ -757,7 +758,7 @@ pub enum ActionKind {
757758
}
758759

759760
impl ActionKind {
760-
pub const COUNT: u16 = 628;
761+
pub const COUNT: u16 = 629;
761762
}
762763

763764
impl std::fmt::Display for ActionKind {
@@ -789,6 +790,7 @@ impl ActionKindGet for Action {
789790
Self::Rpc(a) => a.kind(),
790791
Self::RpcEffectful(a) => a.kind(),
791792
Self::WatchedAccounts(a) => a.kind(),
793+
Self::Exit(a) => a.kind(),
792794
}
793795
}
794796
}
@@ -1260,6 +1262,12 @@ impl ActionKindGet for WatchedAccountsAction {
12601262
}
12611263
}
12621264

1265+
impl ActionKindGet for ExitAction {
1266+
fn kind(&self) -> ActionKind {
1267+
ActionKind::Exit
1268+
}
1269+
}
1270+
12631271
impl ActionKindGet for P2pInitializeAction {
12641272
fn kind(&self) -> ActionKind {
12651273
match self {

node/src/effects.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ pub fn effects<S: Service>(store: &mut Store<S>, action: ActionWithMeta) {
102102
| Action::Rpc(_)
103103
| Action::WatchedAccounts(_)
104104
| Action::P2pCallbacks(_)
105-
| Action::P2p(_) => {
105+
| Action::P2p(_)
106+
| Action::Exit(_) => {
106107
// Handled by reducer
107108
}
108109
}

node/src/reducer.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
rpc::RpcState,
77
state::{BlockProducerState, LedgerState},
88
transition_frontier::candidate::TransitionFrontierCandidateAction,
9-
Action, ActionWithMeta, EventSourceAction, P2p, State,
9+
Action, ActionWithMeta, EventSourceAction, ExitAction, P2p, State,
1010
};
1111

1212
pub fn reducer(
@@ -17,7 +17,18 @@ pub fn reducer(
1717
let meta = action.meta().clone();
1818
match action.action() {
1919
Action::CheckTimeouts(_) => {
20-
if state.p2p.ready().is_some() {
20+
if let Some(p2p) = state.p2p.ready() {
21+
if let Some(kad_state) = &p2p.network.scheduler.discovery_state {
22+
if p2p.ready_peers().is_empty() && kad_state.has_bootstraped {
23+
if let Some(tip) = &state.transition_frontier.best_tip_breadcrumb() {
24+
// TODO: this might need to change in future
25+
if tip.height() == 296372 {
26+
dispatcher.push(ExitAction {});
27+
}
28+
}
29+
}
30+
}
31+
2132
if let Err(error) =
2233
P2pState::p2p_timeout_dispatch(Substate::new(state, dispatcher), &meta)
2334
{
@@ -108,6 +119,13 @@ pub fn reducer(
108119
Action::P2pCallbacks(action) => {
109120
State::p2p_callback_reducer(Substate::new(state, dispatcher), meta.with_action(action))
110121
}
122+
Action::Exit(_) => {
123+
crate::core::error!(
124+
crate::core::log::system_time();
125+
summary = "Exiting",
126+
error = "Invalid initial peers"
127+
);
128+
}
111129
}
112130

113131
// must be the last.

p2p/src/network/kad/p2p_network_kad_reducer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl super::P2pNetworkKadState {
133133
time: meta.time(),
134134
stats: bootstrap_state.stats.clone(),
135135
};
136+
state.has_bootstraped = true;
136137
Ok(())
137138
}
138139
(_, P2pNetworkKademliaAction::UpdateRoutingTable { peer_id, addrs }) => {

p2p/src/network/kad/p2p_network_kad_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct P2pNetworkKadState {
6060
pub streams: StreamState<P2pNetworkKadStreamState>,
6161
pub status: P2pNetworkKadStatus,
6262
pub filter_addrs: bool,
63+
pub has_bootstraped: bool,
6364
}
6465

6566
impl Default for P2pNetworkKadState {
@@ -74,6 +75,7 @@ impl Default for P2pNetworkKadState {
7475
.ok()
7576
.and_then(|s| s.parse().ok())
7677
.unwrap_or(true),
78+
has_bootstraped: false,
7779
}
7880
}
7981
}

0 commit comments

Comments
 (0)