Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/src/reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn reducer(
let time = meta.time();
let result = p2p::P2pState::reducer(
Substate::new(state, dispatcher),
meta.with_action(action),
meta.with_action(action.clone()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking that In general, for the remaining of the code, being that we still need to clone the action I would wait until much later to take care of these kind of changes, because I don't think they offer any immediate benefit.

);

if let Err(error) = result {
Expand Down
6 changes: 3 additions & 3 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ pub mod discovery {
}

Ok(RpcDiscoveryRoutingTable {
this_key: value.this_key.clone(),
this_key: value.this_key,
buckets,
})
}
Expand Down Expand Up @@ -643,8 +643,8 @@ pub mod discovery {
Ok(RpcEntry {
peer_id: value.peer_id,
libp2p: value.peer_id.try_into()?,
key: value.key.clone(),
dist: this_key - &value.key,
key: value.key,
dist: this_key - value.key,
addrs: value.addresses().clone(),
connection: value.connection,
})
Expand Down
11 changes: 4 additions & 7 deletions p2p/src/channels/best_tip/p2p_channels_best_tip_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl P2pChannelsBestTipState {
/// Substate is accessed
pub fn reducer<Action, State>(
mut state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsBestTipAction>,
action: ActionWithMeta<P2pChannelsBestTipAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand Down Expand Up @@ -90,10 +90,7 @@ impl P2pChannelsBestTipState {
*last_received = Some(best_tip.clone());

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pPeerAction::BestTipUpdate {
peer_id,
best_tip: best_tip.clone(),
});
dispatcher.push(P2pPeerAction::BestTipUpdate { peer_id, best_tip });
dispatcher.push(P2pChannelsBestTipAction::RequestSend { peer_id });
Ok(())
}
Expand All @@ -115,7 +112,7 @@ impl P2pChannelsBestTipState {
.callbacks
.on_p2p_channels_best_tip_request_received
{
dispatcher.push_callback(callback.clone(), *peer_id);
dispatcher.push_callback(callback.clone(), peer_id);
}
Ok(())
}
Expand All @@ -141,7 +138,7 @@ impl P2pChannelsBestTipState {
if !is_libp2p {
dispatcher.push(P2pChannelsBestTipEffectfulAction::ResponseSend {
peer_id,
best_tip: best_tip.clone(),
best_tip,
});
return Ok(());
}
Expand Down
6 changes: 3 additions & 3 deletions p2p/src/channels/p2p_channels_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use redux::{ActionWithMeta, Dispatcher};
impl P2pChannelsState {
pub fn reducer<Action, State>(
state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsAction>,
action: ActionWithMeta<P2pChannelsAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl P2pChannelsState {
}

fn dispatch_message<Action, State>(
action: ActionWithMeta<&P2pChannelsMessageReceivedAction>,
action: ActionWithMeta<P2pChannelsMessageReceivedAction>,
dispatcher: &mut Dispatcher<Action, State>,
state: &State,
) -> Result<(), String>
Expand All @@ -91,7 +91,7 @@ impl P2pChannelsState {

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

let was_expected = match *action.message.clone() {
let was_expected = match *action.message {
ChannelMsg::SignalingDiscovery(msg) => match msg {
SignalingDiscoveryChannelMsg::GetNext => is_enabled(
P2pChannelsSignalingDiscoveryAction::RequestReceived { peer_id }.into(),
Expand Down
35 changes: 17 additions & 18 deletions p2p/src/channels/rpc/p2p_channels_rpc_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl P2pChannelsRpcState {
/// Substate is accessed
pub fn reducer<Action, State>(
mut state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsRpcAction>,
action: ActionWithMeta<P2pChannelsRpcAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl P2pChannelsRpcState {
*next_local_rpc_id += 1;
*local = P2pRpcLocalState::Requested {
time: meta.time(),
id: *id,
id,
request: request.clone(),
};

Expand All @@ -92,7 +92,7 @@ impl P2pChannelsRpcState {
#[cfg(feature = "p2p-libp2p")]
if is_libp2p {
if let Some((query, data)) =
super::libp2p::internal_request_into_libp2p(*request.clone(), *id)
super::libp2p::internal_request_into_libp2p(*request.clone(), id)
{
dispatcher.push(P2pNetworkRpcAction::OutgoingQuery {
peer_id,
Expand All @@ -101,17 +101,17 @@ impl P2pChannelsRpcState {
});
}
if let Some(on_init) = on_init {
dispatcher.push_callback(on_init.clone(), (peer_id, *id, *request.clone()));
dispatcher.push_callback(on_init, (peer_id, id, *request));
}

return Ok(());
}

dispatcher.push(P2pChannelsRpcEffectfulAction::RequestSend {
peer_id,
id: *id,
request: request.clone(),
on_init: on_init.clone(),
id,
request,
on_init,
});
Ok(())
}
Expand All @@ -120,7 +120,7 @@ impl P2pChannelsRpcState {
let p2p_state: &P2pState = state.substate()?;

if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_timeout {
dispatcher.push_callback(callback.clone(), (peer_id, *id));
dispatcher.push_callback(callback.clone(), (peer_id, id));
}

Ok(())
Expand Down Expand Up @@ -163,8 +163,7 @@ impl P2pChannelsRpcState {
}

if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_response_received {
dispatcher
.push_callback(callback.clone(), (peer_id, *rpc_id, response.clone()));
dispatcher.push_callback(callback.clone(), (peer_id, rpc_id, response));
}
Ok(())
}
Expand All @@ -180,16 +179,16 @@ impl P2pChannelsRpcState {
.pending_requests
.push_back(P2pRpcRemotePendingRequestState {
time: meta.time(),
id: *id,
request: (**request).clone(),
id,
request: *request.clone(),
is_pending: false,
});

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

if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_rpc_request_received {
dispatcher.push_callback(callback.clone(), (peer_id, *id, request.clone()));
dispatcher.push_callback(callback.clone(), (peer_id, id, request));
}
Ok(())
}
Expand All @@ -201,7 +200,7 @@ impl P2pChannelsRpcState {
);
return Ok(());
};
if let Some(req) = remote.pending_requests.iter_mut().find(|r| r.id == *id) {
if let Some(req) = remote.pending_requests.iter_mut().find(|r| r.id == id) {
req.is_pending = true;
}
Ok(())
Expand All @@ -215,7 +214,7 @@ impl P2pChannelsRpcState {
return Ok(());
};

if let Some(pos) = remote.pending_requests.iter().position(|r| r.id == *id) {
if let Some(pos) = remote.pending_requests.iter().position(|r| r.id == id) {
remote.pending_requests.remove(pos);
remote.last_responded = meta.time();
}
Expand All @@ -226,7 +225,7 @@ impl P2pChannelsRpcState {
if is_libp2p {
if let Some(response) = response {
if let Some((response, data)) =
super::libp2p::internal_response_into_libp2p(*response.clone(), *id)
super::libp2p::internal_response_into_libp2p(*response, id)
{
dispatcher.push(P2pNetworkRpcAction::OutgoingResponse {
peer_id,
Expand All @@ -241,8 +240,8 @@ impl P2pChannelsRpcState {

dispatcher.push(P2pChannelsRpcEffectfulAction::ResponseSend {
peer_id,
id: *id,
response: response.clone(),
id,
response,
});
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl P2pChannelsSignalingDiscoveryState {
/// Substate is accessed
pub fn reducer<Action, State>(
mut state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsSignalingDiscoveryAction>,
action: ActionWithMeta<P2pChannelsSignalingDiscoveryAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand Down Expand Up @@ -405,7 +405,7 @@ impl P2pChannelsSignalingDiscoveryState {
P2pConnectionResponse::Rejected(reason) => {
dispatcher.push(P2pConnectionOutgoingAction::AnswerRecvError {
peer_id: target_public_key.peer_id(),
error: P2pConnectionErrorResponse::Rejected(*reason),
error: P2pConnectionErrorResponse::Rejected(reason),
})
}
P2pConnectionResponse::SignalDecryptionFailed => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl P2pChannelsSignalingExchangeState {
/// Substate is accessed
pub fn reducer<Action, State>(
mut state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsSignalingExchangeAction>,
action: ActionWithMeta<P2pChannelsSignalingExchangeAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand Down
26 changes: 10 additions & 16 deletions p2p/src/channels/snark/p2p_channels_snark_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mina_p2p_messages::{gossip::GossipNetMessageV2, v2};
impl P2pChannelsSnarkState {
pub fn reducer<Action, State>(
mut state_context: Substate<Action, State, P2pState>,
action: ActionWithMeta<&P2pChannelsSnarkAction>,
action: ActionWithMeta<P2pChannelsSnarkAction>,
) -> Result<(), String>
where
State: crate::P2pStateTrait,
Expand All @@ -32,7 +32,7 @@ impl P2pChannelsSnarkState {
*state = Self::Init { time: meta.time() };

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pChannelsSnarkEffectfulAction::Init { peer_id: *peer_id });
dispatcher.push(P2pChannelsSnarkEffectfulAction::Init { peer_id });
Ok(())
}
P2pChannelsSnarkAction::Pending { .. } => {
Expand Down Expand Up @@ -61,14 +61,11 @@ impl P2pChannelsSnarkState {
};
*local = SnarkPropagationState::Requested {
time: meta.time(),
requested_limit: *limit,
requested_limit: limit,
};

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pChannelsSnarkEffectfulAction::RequestSend {
peer_id: *peer_id,
limit: *limit,
});
dispatcher.push(P2pChannelsSnarkEffectfulAction::RequestSend { peer_id, limit });
Ok(())
}
P2pChannelsSnarkAction::PromiseReceived { promised_count, .. } => {
Expand All @@ -89,7 +86,7 @@ impl P2pChannelsSnarkState {
*local = SnarkPropagationState::Responding {
time: meta.time(),
requested_limit: *requested_limit,
promised_count: *promised_count,
promised_count,
current_count: 0,
};
Ok(())
Expand Down Expand Up @@ -129,7 +126,7 @@ impl P2pChannelsSnarkState {
let p2p_state: &P2pState = state.substate()?;

if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_snark_received {
dispatcher.push_callback(callback.clone(), (*peer_id, snark.clone()));
dispatcher.push_callback(callback.clone(), (peer_id, snark));
}

Ok(())
Expand All @@ -145,7 +142,7 @@ impl P2pChannelsSnarkState {
};
*remote = SnarkPropagationState::Requested {
time: meta.time(),
requested_limit: *limit,
requested_limit: limit,
};
Ok(())
}
Expand Down Expand Up @@ -181,16 +178,13 @@ impl P2pChannelsSnarkState {
};

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pChannelsSnarkEffectfulAction::ResponseSend {
peer_id: *peer_id,
snarks: snarks.clone(),
});
dispatcher.push(P2pChannelsSnarkEffectfulAction::ResponseSend { peer_id, snarks });
Ok(())
}
#[cfg(feature = "p2p-libp2p")]
P2pChannelsSnarkAction::Libp2pBroadcast { snark, nonce } => {
let dispatcher = state_context.into_dispatcher();
let message = Box::new((snark.statement(), (snark).into()));
let message = Box::new((snark.statement(), (&snark).into()));
let message = v2::NetworkPoolSnarkPoolDiffVersionedStableV2::AddSolvedWork(message);
let nonce = nonce.into();
let message = Box::new(GossipNetMessageV2::SnarkPoolDiff { message, nonce });
Expand All @@ -204,7 +198,7 @@ impl P2pChannelsSnarkState {
let p2p_state: &P2pState = state.substate()?;

if let Some(callback) = &p2p_state.callbacks.on_p2p_channels_snark_libp2p_received {
dispatcher.push_callback(callback.clone(), (*peer_id, snark.clone()));
dispatcher.push_callback(callback.clone(), (peer_id, snark));
}

Ok(())
Expand Down
Loading
Loading