Skip to content

Commit ed32cbb

Browse files
committed
update: find_index
1 parent f626f28 commit ed32cbb

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

primitives/src/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ impl SpecValidators {
232232
}
233233
}
234234

235-
pub fn find_index(&self, validator_id: &ValidatorId) -> i32 {
235+
pub fn find_index(&self, validator_id: &ValidatorId) -> Option<i32> {
236236
if &self.leader().id == validator_id {
237-
0
237+
Some(0)
238238
} else if &self.follower().id == validator_id {
239-
1
239+
Some(1)
240240
} else {
241-
-1
241+
None
242242
}
243243
}
244244

sentry/src/routes/channel.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,15 @@ pub async fn create_validator_messages<A: Adapter + 'static>(
254254
.await?;
255255

256256
if channel_is_exhausted {
257-
// can never be -1
258-
let validator_index = channel.spec.validators.find_index(&session.uid);
259-
update_exhausted_channel(
260-
&app.pool,
261-
&channel,
262-
validator_index
263-
).await?;
257+
if let Some(validator_index) = channel.spec.validators.find_index(&session.uid) {
258+
update_exhausted_channel(
259+
&app.pool,
260+
&channel,
261+
validator_index
262+
).await?;
263+
}
264264
}
265265

266-
267266
Ok(success_response(serde_json::to_string(&SuccessResponse {
268267
success: true,
269268
})?))

0 commit comments

Comments
 (0)