Skip to content

Commit ea699b0

Browse files
committed
Updated reducer to accept action instead of & action
1 parent bb40137 commit ea699b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+658
-737
lines changed

node/src/reducer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn reducer(
3636
let time = meta.time();
3737
let result = p2p::P2pState::reducer(
3838
Substate::new(state, dispatcher),
39-
meta.with_action(action),
39+
meta.with_action(action.clone()),
4040
);
4141

4242
if let Err(error) = result {

node/src/rpc/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub mod discovery {
587587
}
588588

589589
Ok(RpcDiscoveryRoutingTable {
590-
this_key: value.this_key.clone(),
590+
this_key: value.this_key,
591591
buckets,
592592
})
593593
}
@@ -643,8 +643,8 @@ pub mod discovery {
643643
Ok(RpcEntry {
644644
peer_id: value.peer_id,
645645
libp2p: value.peer_id.try_into()?,
646-
key: value.key.clone(),
647-
dist: this_key - &value.key,
646+
key: value.key,
647+
dist: this_key - value.key,
648648
addrs: value.addresses().clone(),
649649
connection: value.connection,
650650
})

p2p/src/channels/best_tip/p2p_channels_best_tip_reducer.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl P2pChannelsBestTipState {
1212
/// Substate is accessed
1313
pub fn reducer<Action, State>(
1414
mut state_context: Substate<Action, State, P2pState>,
15-
action: ActionWithMeta<&P2pChannelsBestTipAction>,
15+
action: ActionWithMeta<P2pChannelsBestTipAction>,
1616
) -> Result<(), String>
1717
where
1818
State: crate::P2pStateTrait,
@@ -90,10 +90,7 @@ impl P2pChannelsBestTipState {
9090
*last_received = Some(best_tip.clone());
9191

9292
let dispatcher = state_context.into_dispatcher();
93-
dispatcher.push(P2pPeerAction::BestTipUpdate {
94-
peer_id,
95-
best_tip: best_tip.clone(),
96-
});
93+
dispatcher.push(P2pPeerAction::BestTipUpdate { peer_id, best_tip });
9794
dispatcher.push(P2pChannelsBestTipAction::RequestSend { peer_id });
9895
Ok(())
9996
}
@@ -115,7 +112,7 @@ impl P2pChannelsBestTipState {
115112
.callbacks
116113
.on_p2p_channels_best_tip_request_received
117114
{
118-
dispatcher.push_callback(callback.clone(), *peer_id);
115+
dispatcher.push_callback(callback.clone(), peer_id);
119116
}
120117
Ok(())
121118
}
@@ -141,7 +138,7 @@ impl P2pChannelsBestTipState {
141138
if !is_libp2p {
142139
dispatcher.push(P2pChannelsBestTipEffectfulAction::ResponseSend {
143140
peer_id,
144-
best_tip: best_tip.clone(),
141+
best_tip,
145142
});
146143
return Ok(());
147144
}

p2p/src/channels/p2p_channels_reducer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use redux::{ActionWithMeta, Dispatcher};
3434
impl P2pChannelsState {
3535
pub fn reducer<Action, State>(
3636
state_context: Substate<Action, State, P2pState>,
37-
action: ActionWithMeta<&P2pChannelsAction>,
37+
action: ActionWithMeta<P2pChannelsAction>,
3838
) -> Result<(), String>
3939
where
4040
State: crate::P2pStateTrait,
@@ -75,7 +75,7 @@ impl P2pChannelsState {
7575
}
7676

7777
fn dispatch_message<Action, State>(
78-
action: ActionWithMeta<&P2pChannelsMessageReceivedAction>,
78+
action: ActionWithMeta<P2pChannelsMessageReceivedAction>,
7979
dispatcher: &mut Dispatcher<Action, State>,
8080
state: &State,
8181
) -> Result<(), String>
@@ -91,7 +91,7 @@ impl P2pChannelsState {
9191

9292
let mut is_enabled = |action: Action| dispatcher.push_if_enabled(action, state, time);
9393

94-
let was_expected = match *action.message.clone() {
94+
let was_expected = match *action.message {
9595
ChannelMsg::SignalingDiscovery(msg) => match msg {
9696
SignalingDiscoveryChannelMsg::GetNext => is_enabled(
9797
P2pChannelsSignalingDiscoveryAction::RequestReceived { peer_id }.into(),

p2p/src/channels/rpc/p2p_channels_rpc_reducer.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl P2pChannelsRpcState {
1717
/// Substate is accessed
1818
pub fn reducer<Action, State>(
1919
mut state_context: Substate<Action, State, P2pState>,
20-
action: ActionWithMeta<&P2pChannelsRpcAction>,
20+
action: ActionWithMeta<P2pChannelsRpcAction>,
2121
) -> Result<(), String>
2222
where
2323
State: crate::P2pStateTrait,
@@ -83,7 +83,7 @@ impl P2pChannelsRpcState {
8383
*next_local_rpc_id += 1;
8484
*local = P2pRpcLocalState::Requested {
8585
time: meta.time(),
86-
id: *id,
86+
id,
8787
request: request.clone(),
8888
};
8989

@@ -92,7 +92,7 @@ impl P2pChannelsRpcState {
9292
#[cfg(feature = "p2p-libp2p")]
9393
if is_libp2p {
9494
if let Some((query, data)) =
95-
super::libp2p::internal_request_into_libp2p(*request.clone(), *id)
95+
super::libp2p::internal_request_into_libp2p(*request.clone(), id)
9696
{
9797
dispatcher.push(P2pNetworkRpcAction::OutgoingQuery {
9898
peer_id,
@@ -101,17 +101,17 @@ impl P2pChannelsRpcState {
101101
});
102102
}
103103
if let Some(on_init) = on_init {
104-
dispatcher.push_callback(on_init.clone(), (peer_id, *id, *request.clone()));
104+
dispatcher.push_callback(on_init, (peer_id, id, *request));
105105
}
106106

107107
return Ok(());
108108
}
109109

110110
dispatcher.push(P2pChannelsRpcEffectfulAction::RequestSend {
111111
peer_id,
112-
id: *id,
113-
request: request.clone(),
114-
on_init: on_init.clone(),
112+
id,
113+
request,
114+
on_init,
115115
});
116116
Ok(())
117117
}
@@ -120,7 +120,7 @@ impl P2pChannelsRpcState {
120120
let p2p_state: &P2pState = state.substate()?;
121121

122122
if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_timeout {
123-
dispatcher.push_callback(callback.clone(), (peer_id, *id));
123+
dispatcher.push_callback(callback.clone(), (peer_id, id));
124124
}
125125

126126
Ok(())
@@ -163,8 +163,7 @@ impl P2pChannelsRpcState {
163163
}
164164

165165
if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_response_received {
166-
dispatcher
167-
.push_callback(callback.clone(), (peer_id, *rpc_id, response.clone()));
166+
dispatcher.push_callback(callback.clone(), (peer_id, rpc_id, response));
168167
}
169168
Ok(())
170169
}
@@ -180,16 +179,16 @@ impl P2pChannelsRpcState {
180179
.pending_requests
181180
.push_back(P2pRpcRemotePendingRequestState {
182181
time: meta.time(),
183-
id: *id,
184-
request: (**request).clone(),
182+
id,
183+
request: *request.clone(),
185184
is_pending: false,
186185
});
187186

188187
let (dispatcher, state) = state_context.into_dispatcher_and_state();
189188
let p2p_state: &P2pState = state.substate()?;
190189

191190
if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_request_received {
192-
dispatcher.push_callback(callback.clone(), (peer_id, *id, request.clone()));
191+
dispatcher.push_callback(callback.clone(), (peer_id, id, request));
193192
}
194193
Ok(())
195194
}
@@ -201,7 +200,7 @@ impl P2pChannelsRpcState {
201200
);
202201
return Ok(());
203202
};
204-
if let Some(req) = remote.pending_requests.iter_mut().find(|r| r.id == *id) {
203+
if let Some(req) = remote.pending_requests.iter_mut().find(|r| r.id == id) {
205204
req.is_pending = true;
206205
}
207206
Ok(())
@@ -215,7 +214,7 @@ impl P2pChannelsRpcState {
215214
return Ok(());
216215
};
217216

218-
if let Some(pos) = remote.pending_requests.iter().position(|r| r.id == *id) {
217+
if let Some(pos) = remote.pending_requests.iter().position(|r| r.id == id) {
219218
remote.pending_requests.remove(pos);
220219
remote.last_responded = meta.time();
221220
}
@@ -226,7 +225,7 @@ impl P2pChannelsRpcState {
226225
if is_libp2p {
227226
if let Some(response) = response {
228227
if let Some((response, data)) =
229-
super::libp2p::internal_response_into_libp2p(*response.clone(), *id)
228+
super::libp2p::internal_response_into_libp2p(*response, id)
230229
{
231230
dispatcher.push(P2pNetworkRpcAction::OutgoingResponse {
232231
peer_id,
@@ -241,8 +240,8 @@ impl P2pChannelsRpcState {
241240

242241
dispatcher.push(P2pChannelsRpcEffectfulAction::ResponseSend {
243242
peer_id,
244-
id: *id,
245-
response: response.clone(),
243+
id,
244+
response,
246245
});
247246
Ok(())
248247
}

p2p/src/channels/signaling/discovery/p2p_channels_signaling_discovery_reducer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl P2pChannelsSignalingDiscoveryState {
2323
/// Substate is accessed
2424
pub fn reducer<Action, State>(
2525
mut state_context: Substate<Action, State, P2pState>,
26-
action: ActionWithMeta<&P2pChannelsSignalingDiscoveryAction>,
26+
action: ActionWithMeta<P2pChannelsSignalingDiscoveryAction>,
2727
) -> Result<(), String>
2828
where
2929
State: crate::P2pStateTrait,
@@ -405,7 +405,7 @@ impl P2pChannelsSignalingDiscoveryState {
405405
P2pConnectionResponse::Rejected(reason) => {
406406
dispatcher.push(P2pConnectionOutgoingAction::AnswerRecvError {
407407
peer_id: target_public_key.peer_id(),
408-
error: P2pConnectionErrorResponse::Rejected(*reason),
408+
error: P2pConnectionErrorResponse::Rejected(reason),
409409
})
410410
}
411411
P2pConnectionResponse::SignalDecryptionFailed => {

p2p/src/channels/signaling/exchange/p2p_channels_signaling_exchange_reducer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl P2pChannelsSignalingExchangeState {
2424
/// Substate is accessed
2525
pub fn reducer<Action, State>(
2626
mut state_context: Substate<Action, State, P2pState>,
27-
action: ActionWithMeta<&P2pChannelsSignalingExchangeAction>,
27+
action: ActionWithMeta<P2pChannelsSignalingExchangeAction>,
2828
) -> Result<(), String>
2929
where
3030
State: crate::P2pStateTrait,

p2p/src/channels/snark/p2p_channels_snark_reducer.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use mina_p2p_messages::{gossip::GossipNetMessageV2, v2};
1111
impl P2pChannelsSnarkState {
1212
pub fn reducer<Action, State>(
1313
mut state_context: Substate<Action, State, P2pState>,
14-
action: ActionWithMeta<&P2pChannelsSnarkAction>,
14+
action: ActionWithMeta<P2pChannelsSnarkAction>,
1515
) -> Result<(), String>
1616
where
1717
State: crate::P2pStateTrait,
@@ -32,7 +32,7 @@ impl P2pChannelsSnarkState {
3232
*state = Self::Init { time: meta.time() };
3333

3434
let dispatcher = state_context.into_dispatcher();
35-
dispatcher.push(P2pChannelsSnarkEffectfulAction::Init { peer_id: *peer_id });
35+
dispatcher.push(P2pChannelsSnarkEffectfulAction::Init { peer_id });
3636
Ok(())
3737
}
3838
P2pChannelsSnarkAction::Pending { .. } => {
@@ -61,14 +61,11 @@ impl P2pChannelsSnarkState {
6161
};
6262
*local = SnarkPropagationState::Requested {
6363
time: meta.time(),
64-
requested_limit: *limit,
64+
requested_limit: limit,
6565
};
6666

6767
let dispatcher = state_context.into_dispatcher();
68-
dispatcher.push(P2pChannelsSnarkEffectfulAction::RequestSend {
69-
peer_id: *peer_id,
70-
limit: *limit,
71-
});
68+
dispatcher.push(P2pChannelsSnarkEffectfulAction::RequestSend { peer_id, limit });
7269
Ok(())
7370
}
7471
P2pChannelsSnarkAction::PromiseReceived { promised_count, .. } => {
@@ -89,7 +86,7 @@ impl P2pChannelsSnarkState {
8986
*local = SnarkPropagationState::Responding {
9087
time: meta.time(),
9188
requested_limit: *requested_limit,
92-
promised_count: *promised_count,
89+
promised_count,
9390
current_count: 0,
9491
};
9592
Ok(())
@@ -129,7 +126,7 @@ impl P2pChannelsSnarkState {
129126
let p2p_state: &P2pState = state.substate()?;
130127

131128
if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_snark_received {
132-
dispatcher.push_callback(callback.clone(), (*peer_id, snark.clone()));
129+
dispatcher.push_callback(callback.clone(), (peer_id, snark));
133130
}
134131

135132
Ok(())
@@ -145,7 +142,7 @@ impl P2pChannelsSnarkState {
145142
};
146143
*remote = SnarkPropagationState::Requested {
147144
time: meta.time(),
148-
requested_limit: *limit,
145+
requested_limit: limit,
149146
};
150147
Ok(())
151148
}
@@ -181,16 +178,13 @@ impl P2pChannelsSnarkState {
181178
};
182179

183180
let dispatcher = state_context.into_dispatcher();
184-
dispatcher.push(P2pChannelsSnarkEffectfulAction::ResponseSend {
185-
peer_id: *peer_id,
186-
snarks: snarks.clone(),
187-
});
181+
dispatcher.push(P2pChannelsSnarkEffectfulAction::ResponseSend { peer_id, snarks });
188182
Ok(())
189183
}
190184
#[cfg(feature = "p2p-libp2p")]
191185
P2pChannelsSnarkAction::Libp2pBroadcast { snark, nonce } => {
192186
let dispatcher = state_context.into_dispatcher();
193-
let message = Box::new((snark.statement(), (snark).into()));
187+
let message = Box::new((snark.statement(), (&snark).into()));
194188
let message = v2::NetworkPoolSnarkPoolDiffVersionedStableV2::AddSolvedWork(message);
195189
let nonce = nonce.into();
196190
let message = Box::new(GossipNetMessageV2::SnarkPoolDiff { message, nonce });
@@ -204,7 +198,7 @@ impl P2pChannelsSnarkState {
204198
let p2p_state: &P2pState = state.substate()?;
205199

206200
if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_snark_libp2p_received {
207-
dispatcher.push_callback(callback.clone(), (*peer_id, snark.clone()));
201+
dispatcher.push_callback(callback.clone(), (peer_id, snark));
208202
}
209203

210204
Ok(())

0 commit comments

Comments
 (0)