Skip to content

Commit 30c1f3f

Browse files
committed
useless matches removal
1 parent e897684 commit 30c1f3f

File tree

1 file changed

+30
-143
lines changed
  • protocols/v2/roles-logic-sv2/src/handlers

1 file changed

+30
-143
lines changed

protocols/v2/roles-logic-sv2/src/handlers/mining.rs

+30-143
Original file line numberDiff line numberDiff line change
@@ -170,32 +170,12 @@ pub trait ParseMiningMessagesFromDownstream<
170170
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
171171
}
172172
}
173-
Ok(Mining::UpdateChannel(m)) => match channel_type {
174-
SupportedChannelTypes::Standard => {
175-
info!("Received UpdateChannel->Standard message");
176-
self_mutex
177-
.safe_lock(|self_| self_.handle_update_channel(m))
178-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
179-
}
180-
SupportedChannelTypes::Extended => {
181-
info!("Received UpdateChannel->Extended message");
182-
self_mutex
183-
.safe_lock(|self_| self_.handle_update_channel(m))
184-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
185-
}
186-
SupportedChannelTypes::Group => {
187-
info!("Received UpdateChannel->Group message");
188-
self_mutex
189-
.safe_lock(|self_| self_.handle_update_channel(m))
190-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
191-
}
192-
SupportedChannelTypes::GroupAndExtended => {
193-
info!("Received UpdateChannel->GroupAndExtended message");
194-
self_mutex
195-
.safe_lock(|self_| self_.handle_update_channel(m))
196-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
197-
}
198-
},
173+
Ok(Mining::UpdateChannel(m)) => {
174+
info!("Received UpdateChannel->Standard message");
175+
self_mutex
176+
.safe_lock(|self_| self_.handle_update_channel(m))
177+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
178+
}
199179
Ok(Mining::SubmitSharesStandard(m)) => match channel_type {
200180
SupportedChannelTypes::Standard => {
201181
debug!("Received SubmitSharesStandard->Standard message");
@@ -385,65 +365,29 @@ pub trait ParseMiningMessagesFromUpstream<
385365
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
386366
}
387367
}
388-
389368
Ok(Mining::OpenMiningChannelError(m)) => {
390369
error!(
391370
"Received OpenExtendedMiningChannelError with error code {}",
392371
std::str::from_utf8(m.error_code.as_ref()).unwrap_or("unknown error code")
393372
);
394-
match channel_type {
395-
SupportedChannelTypes::Standard => self_mutex
396-
.safe_lock(|x| x.handle_open_mining_channel_error(m))
397-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
398-
SupportedChannelTypes::Extended => self_mutex
399-
.safe_lock(|x| x.handle_open_mining_channel_error(m))
400-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
401-
SupportedChannelTypes::Group => self_mutex
402-
.safe_lock(|x| x.handle_open_mining_channel_error(m))
403-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
404-
SupportedChannelTypes::GroupAndExtended => self_mutex
405-
.safe_lock(|x| x.handle_open_mining_channel_error(m))
406-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
407-
}
373+
self_mutex
374+
.safe_lock(|x| x.handle_open_mining_channel_error(m))
375+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
408376
}
409-
410377
Ok(Mining::UpdateChannelError(m)) => {
411378
error!(
412379
"Received UpdateChannelError with error code {}",
413380
std::str::from_utf8(m.error_code.as_ref()).unwrap_or("unknown error code")
414381
);
415-
match channel_type {
416-
SupportedChannelTypes::Standard => self_mutex
417-
.safe_lock(|x| x.handle_update_channel_error(m))
418-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
419-
SupportedChannelTypes::Extended => self_mutex
420-
.safe_lock(|x| x.handle_update_channel_error(m))
421-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
422-
SupportedChannelTypes::Group => self_mutex
423-
.safe_lock(|x| x.handle_update_channel_error(m))
424-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
425-
SupportedChannelTypes::GroupAndExtended => self_mutex
426-
.safe_lock(|x| x.handle_update_channel_error(m))
427-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
428-
}
382+
self_mutex
383+
.safe_lock(|x| x.handle_update_channel_error(m))
384+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
429385
}
430-
431386
Ok(Mining::CloseChannel(m)) => {
432387
info!("Received CloseChannel for channel id: {}", m.channel_id);
433-
match channel_type {
434-
SupportedChannelTypes::Standard => self_mutex
435-
.safe_lock(|x| x.handle_close_channel(m))
436-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
437-
SupportedChannelTypes::Extended => self_mutex
438-
.safe_lock(|x| x.handle_close_channel(m))
439-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
440-
SupportedChannelTypes::Group => self_mutex
441-
.safe_lock(|x| x.handle_close_channel(m))
442-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
443-
SupportedChannelTypes::GroupAndExtended => self_mutex
444-
.safe_lock(|x| x.handle_close_channel(m))
445-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
446-
}
388+
self_mutex
389+
.safe_lock(|x| x.handle_close_channel(m))
390+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
447391
}
448392

449393
Ok(Mining::SetExtranoncePrefix(m)) => {
@@ -452,60 +396,26 @@ pub trait ParseMiningMessagesFromUpstream<
452396
m.channel_id
453397
);
454398
debug!("SetExtranoncePrefix: {:?}", m);
455-
match channel_type {
456-
SupportedChannelTypes::Standard => self_mutex
457-
.safe_lock(|x| x.handle_set_extranonce_prefix(m))
458-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
459-
SupportedChannelTypes::Extended => self_mutex
460-
.safe_lock(|x| x.handle_set_extranonce_prefix(m))
461-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
462-
SupportedChannelTypes::Group => self_mutex
463-
.safe_lock(|x| x.handle_set_extranonce_prefix(m))
464-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
465-
SupportedChannelTypes::GroupAndExtended => self_mutex
466-
.safe_lock(|x| x.handle_set_extranonce_prefix(m))
467-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
468-
}
399+
self_mutex
400+
.safe_lock(|x| x.handle_set_extranonce_prefix(m))
401+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
469402
}
470403
Ok(Mining::SubmitSharesSuccess(m)) => {
471404
debug!("Received SubmitSharesSuccess");
472405
trace!("SubmitSharesSuccess: {:?}", m);
473-
match channel_type {
474-
SupportedChannelTypes::Standard => self_mutex
475-
.safe_lock(|x| x.handle_submit_shares_success(m))
476-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
477-
SupportedChannelTypes::Extended => self_mutex
478-
.safe_lock(|x| x.handle_submit_shares_success(m))
479-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
480-
SupportedChannelTypes::Group => self_mutex
481-
.safe_lock(|x| x.handle_submit_shares_success(m))
482-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
483-
SupportedChannelTypes::GroupAndExtended => self_mutex
484-
.safe_lock(|x| x.handle_submit_shares_success(m))
485-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
486-
}
406+
self_mutex
407+
.safe_lock(|x| x.handle_submit_shares_success(m))
408+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
487409
}
488410
Ok(Mining::SubmitSharesError(m)) => {
489411
error!(
490412
"Received SubmitSharesError with error code {}",
491413
std::str::from_utf8(m.error_code.as_ref()).unwrap_or("unknown error code")
492414
);
493-
match channel_type {
494-
SupportedChannelTypes::Standard => self_mutex
495-
.safe_lock(|x| x.handle_submit_shares_error(m))
496-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
497-
SupportedChannelTypes::Extended => self_mutex
498-
.safe_lock(|x| x.handle_submit_shares_error(m))
499-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
500-
SupportedChannelTypes::Group => self_mutex
501-
.safe_lock(|x| x.handle_submit_shares_error(m))
502-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
503-
SupportedChannelTypes::GroupAndExtended => self_mutex
504-
.safe_lock(|x| x.handle_submit_shares_error(m))
505-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
506-
}
415+
self_mutex
416+
.safe_lock(|x| x.handle_submit_shares_error(m))
417+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
507418
}
508-
509419
Ok(Mining::NewMiningJob(m)) => {
510420
info!(
511421
"Received new mining job for channel id: {} with job id: {} is future: {}",
@@ -553,22 +463,10 @@ pub trait ParseMiningMessagesFromUpstream<
553463
m.channel_id, m.job_id
554464
);
555465
debug!("SetNewPrevHash: {:?}", m);
556-
match channel_type {
557-
SupportedChannelTypes::Standard => self_mutex
558-
.safe_lock(|x| x.handle_set_new_prev_hash(m))
559-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
560-
SupportedChannelTypes::Extended => self_mutex
561-
.safe_lock(|x| x.handle_set_new_prev_hash(m))
562-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
563-
SupportedChannelTypes::Group => self_mutex
564-
.safe_lock(|x| x.handle_set_new_prev_hash(m))
565-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
566-
SupportedChannelTypes::GroupAndExtended => self_mutex
567-
.safe_lock(|x| x.handle_set_new_prev_hash(m))
568-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
569-
}
466+
self_mutex
467+
.safe_lock(|x| x.handle_set_new_prev_hash(m))
468+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
570469
}
571-
572470
Ok(Mining::SetCustomMiningJobSuccess(m)) => {
573471
info!(
574472
"Received SetCustomMiningJobSuccess for channel id: {} for job id: {}",
@@ -611,20 +509,9 @@ pub trait ParseMiningMessagesFromUpstream<
611509
Ok(Mining::SetTarget(m)) => {
612510
info!("Received SetTarget for channel id: {}", m.channel_id);
613511
debug!("SetTarget: {:?}", m);
614-
match channel_type {
615-
SupportedChannelTypes::Standard => self_mutex
616-
.safe_lock(|x| x.handle_set_target(m))
617-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
618-
SupportedChannelTypes::Extended => self_mutex
619-
.safe_lock(|x| x.handle_set_target(m))
620-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
621-
SupportedChannelTypes::Group => self_mutex
622-
.safe_lock(|x| x.handle_set_target(m))
623-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
624-
SupportedChannelTypes::GroupAndExtended => self_mutex
625-
.safe_lock(|x| x.handle_set_target(m))
626-
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?,
627-
}
512+
self_mutex
513+
.safe_lock(|x| x.handle_set_target(m))
514+
.map_err(|e| crate::Error::PoisonLock(e.to_string()))?
628515
}
629516
Ok(Mining::SetGroupChannel(m)) => {
630517
info!("Received SetGroupChannel");

0 commit comments

Comments
 (0)