Skip to content

Commit 4710464

Browse files
authored
Merge pull request #776 from openmina/fix/node-id-logging
Remove node_id logging from non-test runs
2 parents e3e18e5 + faced3f commit 4710464

File tree

8 files changed

+36
-5
lines changed

8 files changed

+36
-5
lines changed

core/src/log.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,20 @@ pub const ACTION_TRACE_TARGET: &str = "openmina_core::log::action";
7878
#[macro_export]
7979
macro_rules! action_event {
8080
($level:expr, $context:expr, $($tts:tt)*) => {
81-
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time(), node_id = $context.node_id(), $($tts)*)
81+
if $context.log_node_id() {
82+
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time(), node_id = $context.node_id(), $($tts)*)
83+
} else {
84+
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time(), $($tts)*)
85+
}
8286
};
8387
($level:expr, $context:expr) => {
84-
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time(), node_id = $context.node_id())
88+
if $context.log_node_id() {
89+
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time(), node_id = $context.node_id())
90+
} else {
91+
$crate::log::inner::event!(target: { $crate::log::ACTION_TRACE_TARGET }, $level, time = $context.time())
92+
}
8593
};
86-
}
94+
}
8795

8896
#[macro_export]
8997
macro_rules! action_error {
@@ -139,6 +147,7 @@ pub trait EventContext {
139147
fn timestamp(&self) -> redux::Timestamp;
140148
fn time(&self) -> &'_ dyn Value;
141149
fn node_id(&self) -> &'_ dyn Value;
150+
fn log_node_id(&self) -> bool;
142151
}
143152

144153
pub trait ActionEvent {

node/native/src/node/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl NodeBuilder {
293293
build: node::BuildEnv::get().into(),
294294
snarker: self.snarker,
295295
consensus_constants: consensus_consts.clone(),
296+
testing_run: false,
296297
},
297298
p2p: P2pConfig {
298299
libp2p_port: self.p2p_libp2p_port,

node/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct GlobalConfig {
3333
pub build: Box<BuildEnv>,
3434
pub snarker: Option<SnarkerConfig>,
3535
pub consensus_constants: ConsensusConstants,
36+
pub testing_run: bool,
3637
}
3738

3839
#[derive(Serialize, Deserialize, Debug, Clone)]

node/src/logger/logger_effects.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ struct ActionLoggerContext {
1818
time: redux::Timestamp,
1919
time_str: String,
2020
node_id: DisplayValue<PeerId>,
21+
log_node_id: bool,
2122
}
2223

2324
impl ActionLoggerContext {
24-
fn new(time: redux::Timestamp, node_id: PeerId) -> Self {
25+
fn new(time: redux::Timestamp, node_id: PeerId, log_node_id: bool) -> Self {
2526
ActionLoggerContext {
2627
time,
2728
time_str: time_to_str(time),
2829
node_id: display(node_id),
30+
log_node_id,
2931
}
3032
}
3133
}
@@ -39,14 +41,22 @@ impl EventContext for ActionLoggerContext {
3941
&self.time_str
4042
}
4143

44+
fn log_node_id(&self) -> bool {
45+
self.log_node_id
46+
}
47+
4248
fn node_id(&self) -> &'_ dyn Value {
4349
&self.node_id
4450
}
4551
}
4652

4753
pub fn logger_effects<S: Service>(store: &Store<S>, action: ActionWithMetaRef<'_>) {
4854
let (action, meta) = action.split();
49-
let context = ActionLoggerContext::new(meta.time(), store.state().p2p.my_id());
55+
let context = ActionLoggerContext::new(
56+
meta.time(),
57+
store.state().p2p.my_id(),
58+
store.state().should_log_node_id(),
59+
);
5060

5161
match action {
5262
Action::P2p(action) => match action {

node/src/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ impl State {
273273
self.current_epoch() <= Some(epoch)
274274
})
275275
}
276+
277+
pub fn should_log_node_id(&self) -> bool {
278+
self.config.testing_run
279+
}
276280
}
277281

278282
#[serde_with::serde_as]

node/testing/src/cluster/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ impl Cluster {
274274
build: BuildEnv::get().into(),
275275
snarker: testing_config.snark_worker,
276276
consensus_constants: consensus_consts.clone(),
277+
testing_run: true,
277278
},
278279
p2p: P2pConfig {
279280
libp2p_port: Some(libp2p_port),

node/web/src/node/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl NodeBuilder {
223223
build: node::BuildEnv::get().into(),
224224
snarker: self.snarker,
225225
consensus_constants: consensus_consts.clone(),
226+
testing_run: false,
226227
},
227228
p2p: P2pConfig {
228229
libp2p_port: None,

p2p/testing/src/redux.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ impl EventContext for ActionLoggerContext {
172172
fn node_id(&self) -> &'_ dyn Value {
173173
&self.node_id
174174
}
175+
176+
fn log_node_id(&self) -> bool {
177+
true
178+
}
175179
}
176180

177181
pub(super) fn log_action(action: &Action, meta: &ActionMeta, node_id: PeerId) {

0 commit comments

Comments
 (0)