From 4b886c97ab46be8c21dd02fd4f8db94778eaef5d Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 7 Nov 2023 01:51:09 +0200 Subject: [PATCH 1/2] Fix sending duplicate PoT proofs --- crates/sc-proof-of-time/src/source.rs | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/crates/sc-proof-of-time/src/source.rs b/crates/sc-proof-of-time/src/source.rs index cf50000345..9a3f1557ec 100644 --- a/crates/sc-proof-of-time/src/source.rs +++ b/crates/sc-proof-of-time/src/source.rs @@ -60,6 +60,7 @@ pub struct PotSourceWorker { timekeeper_proofs_receiver: mpsc::Receiver, to_gossip_sender: mpsc::Sender, from_gossip_receiver: mpsc::Receiver<(PeerId, GossipProof)>, + last_slot_sent: Slot, slot_sender: mpsc::Sender, state: Arc, _block: PhantomData, @@ -176,6 +177,7 @@ where timekeeper_proofs_receiver, to_gossip_sender, from_gossip_receiver, + last_slot_sent: Slot::from(0), slot_sender, state, _block: PhantomData, @@ -268,9 +270,13 @@ where ); } - // We don't care if block production is too slow or block production is not enabled on this - // node at all - let _ = self.slot_sender.try_send(PotSlotInfo { slot, checkpoints }); + if slot > self.last_slot_sent { + self.last_slot_sent = slot; + + // We don't care if block production is too slow or block production is not enabled on this + // node at all + let _ = self.slot_sender.try_send(PotSlotInfo { slot, checkpoints }); + } } // TODO: Follow both verified and unverified checkpoints to start secondary timekeeper ASAP in @@ -288,12 +294,16 @@ where proof.checkpoints.output(), None, ) { - // We don't care if block production is too slow or block production is not enabled on - // this node at all - let _ = self.slot_sender.try_send(PotSlotInfo { - slot: proof.slot, - checkpoints: proof.checkpoints, - }); + if proof.slot > self.last_slot_sent { + self.last_slot_sent = proof.slot; + + // We don't care if block production is too slow or block production is not enabled on + // this node at all + let _ = self.slot_sender.try_send(PotSlotInfo { + slot: proof.slot, + checkpoints: proof.checkpoints, + }); + } if self .to_gossip_sender From bcb5604cae80f2608a18030dc04721c2d843afa3 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 7 Nov 2023 01:51:23 +0200 Subject: [PATCH 2/2] Small cleanups --- crates/sc-consensus-subspace-rpc/src/lib.rs | 3 +-- crates/sc-proof-of-time/src/lib.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/sc-consensus-subspace-rpc/src/lib.rs b/crates/sc-consensus-subspace-rpc/src/lib.rs index 552a8e5783..84bbc4a0e0 100644 --- a/crates/sc-consensus-subspace-rpc/src/lib.rs +++ b/crates/sc-consensus-subspace-rpc/src/lib.rs @@ -405,8 +405,7 @@ where slot = %slot_number, %sector_index, %public_key, - "Solution receiver is closed, likely because farmer was too \ - slow" + "Solution receiver is closed, likely because farmer was too slow" ); } } diff --git a/crates/sc-proof-of-time/src/lib.rs b/crates/sc-proof-of-time/src/lib.rs index 46698e6972..82c4ffd29e 100644 --- a/crates/sc-proof-of-time/src/lib.rs +++ b/crates/sc-proof-of-time/src/lib.rs @@ -70,9 +70,17 @@ pub async fn start_slot_worker( let mut worker = SimpleSlotWorkerToSlotWorker(worker); - let mut maybe_last_claimed_slot = None; + let mut maybe_last_proven_slot = None; while let Some(PotSlotInfo { slot, checkpoints }) = slot_info_stream.next().await { + if let Some(last_proven_slot) = maybe_last_proven_slot { + if last_proven_slot >= slot { + // Already processed + continue; + } + } + maybe_last_proven_slot.replace(slot); + worker.0.on_proof(slot, checkpoints); if sync_oracle.is_major_syncing() { @@ -86,14 +94,6 @@ pub async fn start_slot_worker( continue; }; - if let Some(last_claimed_slot) = maybe_last_claimed_slot { - if last_claimed_slot >= slot_to_claim { - // Already processed - continue; - } - } - maybe_last_claimed_slot.replace(slot_to_claim); - if let Some(slot_info) = slot_info_producer.produce_slot_info(slot_to_claim).await { let _ = worker.on_slot(slot_info).await; }