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
19 changes: 9 additions & 10 deletions p2p/src/channels/snark/p2p_channels_snark_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,24 @@ impl P2pChannelsSnarkState {
.peer_id()
.and_then(|peer_id| p2p_state.get_ready_peer_mut(peer_id))
.map(|peer_state| &mut peer_state.channels.snark)
.ok_or_else(|| format!("Invalid state for: {action:?}"))
.inspect_err(|error| bug_condition!("{}", error));
.ok_or_else(|| format!("Invalid state for: {action:?}"));

match action {
P2pChannelsSnarkAction::Init { peer_id } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Init { time: meta.time() };

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pChannelsSnarkEffectfulAction::Init { peer_id: *peer_id });
Ok(())
}
P2pChannelsSnarkAction::Pending { .. } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Pending { time: meta.time() };
Ok(())
}
P2pChannelsSnarkAction::Ready { .. } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Ready {
time: meta.time(),
local: SnarkPropagationState::WaitingForRequest { time: meta.time() },
Expand All @@ -52,7 +51,7 @@ impl P2pChannelsSnarkState {
Ok(())
}
P2pChannelsSnarkAction::RequestSend { limit, peer_id } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsSnarkAction::RequestSend`, state: {:?}",
Expand All @@ -73,7 +72,7 @@ impl P2pChannelsSnarkState {
Ok(())
}
P2pChannelsSnarkAction::PromiseReceived { promised_count, .. } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsSnarkAction::PromiseReceived`, state: {:?}",
Expand All @@ -96,7 +95,7 @@ impl P2pChannelsSnarkState {
Ok(())
}
P2pChannelsSnarkAction::Received { .. } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsSnarkAction::Received`, state: {:?}",
Expand Down Expand Up @@ -128,7 +127,7 @@ impl P2pChannelsSnarkState {
Ok(())
}
P2pChannelsSnarkAction::RequestReceived { limit, .. } => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { remote, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsSnarkAction::RequestReceived`, state: {:?}",
Expand All @@ -148,7 +147,7 @@ impl P2pChannelsSnarkState {
peer_id,
..
} => {
let state = state?;
let state = state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready {
remote,
next_send_index,
Expand Down
19 changes: 9 additions & 10 deletions p2p/src/channels/transaction/p2p_channels_transaction_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ impl P2pChannelsTransactionState {
.peer_id()
.and_then(|peer_id| p2p_state.get_ready_peer_mut(peer_id))
.map(|peer_state| &mut peer_state.channels.transaction)
.ok_or_else(|| format!("Invalid state for: {action:?}"))
.inspect_err(|error| bug_condition!("{}", error));
.ok_or_else(|| format!("Invalid state for: {action:?}"));

match action {
P2pChannelsTransactionAction::Init { peer_id } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Init { time: meta.time() };

let dispatcher = state_context.into_dispatcher();
dispatcher.push(P2pChannelsTransactionEffectfulAction::Init { peer_id: *peer_id });
Ok(())
}
P2pChannelsTransactionAction::Pending { .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Pending { time: meta.time() };
Ok(())
}
P2pChannelsTransactionAction::Ready { .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
*state = Self::Ready {
time: meta.time(),
local: TransactionPropagationState::WaitingForRequest { time: meta.time() },
Expand All @@ -53,7 +52,7 @@ impl P2pChannelsTransactionState {
Ok(())
}
P2pChannelsTransactionAction::RequestSend { limit, peer_id, .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsTransactionAction::RequestSend `, state: {:?}",
Expand All @@ -74,7 +73,7 @@ impl P2pChannelsTransactionState {
Ok(())
}
P2pChannelsTransactionAction::PromiseReceived { promised_count, .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsTransactionAction::PromiseReceived `, state: {:?}",
Expand All @@ -101,7 +100,7 @@ impl P2pChannelsTransactionState {
Ok(())
}
P2pChannelsTransactionAction::Received { .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { local, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsTransactionAction::Received `, state: {:?}",
Expand Down Expand Up @@ -129,7 +128,7 @@ impl P2pChannelsTransactionState {
Ok(())
}
P2pChannelsTransactionAction::RequestReceived { limit, .. } => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready { remote, .. } = state else {
bug_condition!(
"Invalid state for `P2pChannelsTransactionAction::RequestReceived `, state: {:?}",
Expand All @@ -149,7 +148,7 @@ impl P2pChannelsTransactionState {
peer_id,
..
} => {
let state = transaction_state?;
let state = transaction_state.inspect_err(|error| bug_condition!("{}", error))?;
let Self::Ready {
remote,
next_send_index,
Expand Down
Loading