mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 04:45:42 +00:00
Drop timers for new requests of active participations (#6974)
* First pass adding logs * fmt * Adjustments * Get rid of extra timers for running participations * fmt * Handling timer discards more elegantly
This commit is contained in:
@@ -160,10 +160,11 @@ impl Participation {
|
|||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut Context,
|
ctx: &mut Context,
|
||||||
priority: ParticipationPriority,
|
priority: ParticipationPriority,
|
||||||
req: ParticipationRequest,
|
mut req: ParticipationRequest,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Participation already running - we can ignore that request:
|
// Participation already running - we can ignore that request, discarding its timer:
|
||||||
if self.running_participations.contains(req.candidate_hash()) {
|
if self.running_participations.contains(req.candidate_hash()) {
|
||||||
|
req.discard_timer();
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
// Available capacity - participate right away (if we already have a recent block):
|
// Available capacity - participate right away (if we already have a recent block):
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ impl ParticipationRequest {
|
|||||||
pub fn session(&self) -> SessionIndex {
|
pub fn session(&self) -> SessionIndex {
|
||||||
self.session
|
self.session
|
||||||
}
|
}
|
||||||
|
pub fn discard_timer(&mut self) {
|
||||||
|
if let Some(timer) = self.request_timer.take() {
|
||||||
|
timer.stop_and_discard();
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn into_candidate_info(self) -> (CandidateHash, CandidateReceipt) {
|
pub fn into_candidate_info(self) -> (CandidateHash, CandidateReceipt) {
|
||||||
let Self { candidate_hash, candidate_receipt, .. } = self;
|
let Self { candidate_hash, candidate_receipt, .. } = self;
|
||||||
(candidate_hash, candidate_receipt)
|
(candidate_hash, candidate_receipt)
|
||||||
@@ -246,17 +251,12 @@ impl Queues {
|
|||||||
// Remove any best effort entry, using it to replace our new
|
// Remove any best effort entry, using it to replace our new
|
||||||
// request.
|
// request.
|
||||||
if let Some(older_request) = self.best_effort.remove(&comparator) {
|
if let Some(older_request) = self.best_effort.remove(&comparator) {
|
||||||
if let Some(timer) = req.request_timer {
|
req.discard_timer();
|
||||||
timer.stop_and_discard();
|
|
||||||
}
|
|
||||||
req = older_request;
|
req = older_request;
|
||||||
}
|
}
|
||||||
// Keeping old request if any.
|
// Keeping old request if any.
|
||||||
match self.priority.entry(comparator) {
|
match self.priority.entry(comparator) {
|
||||||
Entry::Occupied(_) =>
|
Entry::Occupied(_) => req.discard_timer(),
|
||||||
if let Some(timer) = req.request_timer {
|
|
||||||
timer.stop_and_discard();
|
|
||||||
},
|
|
||||||
Entry::Vacant(vac) => {
|
Entry::Vacant(vac) => {
|
||||||
vac.insert(req);
|
vac.insert(req);
|
||||||
},
|
},
|
||||||
@@ -274,10 +274,7 @@ impl Queues {
|
|||||||
}
|
}
|
||||||
// Keeping old request if any.
|
// Keeping old request if any.
|
||||||
match self.best_effort.entry(comparator) {
|
match self.best_effort.entry(comparator) {
|
||||||
Entry::Occupied(_) =>
|
Entry::Occupied(_) => req.discard_timer(),
|
||||||
if let Some(timer) = req.request_timer {
|
|
||||||
timer.stop_and_discard();
|
|
||||||
},
|
|
||||||
Entry::Vacant(vac) => {
|
Entry::Vacant(vac) => {
|
||||||
vac.insert(req);
|
vac.insert(req);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user