Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

sc-slots: Cleanup #13590

Merged
merged 1 commit into from
Mar 13, 2023
Merged
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
24 changes: 16 additions & 8 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
proposer: Self::Proposer,
claim: &Self::Claim,
slot_info: SlotInfo<B>,
proposing_remaining: Delay,
end_proposing_at: Instant,
) -> Option<
Proposal<
B,
Expand All @@ -202,9 +202,11 @@ pub trait SimpleSlotWorker<B: BlockT> {
let telemetry = self.telemetry();
let log_target = self.logging_target();

let inherent_data = Self::create_inherent_data(&slot_info, &log_target).await?;
let inherent_data =
Self::create_inherent_data(&slot_info, &log_target, end_proposing_at).await?;

let proposing_remaining_duration = self.proposing_remaining_duration(&slot_info);
let proposing_remaining_duration =
end_proposing_at.saturating_duration_since(Instant::now());
let logs = self.pre_digest_data(slot, claim);

// deadline our production to 98% of the total time left for proposing. As we deadline
Expand All @@ -219,7 +221,12 @@ pub trait SimpleSlotWorker<B: BlockT> {
)
.map_err(|e| sp_consensus::Error::ClientImport(e.to_string()));

let proposal = match futures::future::select(proposing, proposing_remaining).await {
let proposal = match futures::future::select(
proposing,
Delay::new(proposing_remaining_duration),
)
.await
{
Either::Left((Ok(p), _)) => p,
Either::Left((Err(err), _)) => {
warn!(target: log_target, "Proposing failed: {}", err);
Expand Down Expand Up @@ -255,8 +262,9 @@ pub trait SimpleSlotWorker<B: BlockT> {
async fn create_inherent_data(
slot_info: &SlotInfo<B>,
logging_target: &str,
end_proposing_at: Instant,
) -> Option<sp_inherents::InherentData> {
let remaining_duration = slot_info.ends_at.saturating_duration_since(Instant::now());
let remaining_duration = end_proposing_at.saturating_duration_since(Instant::now());
let delay = Delay::new(remaining_duration);
let cid = slot_info.create_inherent_data.create_inherent_data();
let inherent_data = match futures::future::select(delay, cid).await {
Expand Down Expand Up @@ -300,15 +308,15 @@ pub trait SimpleSlotWorker<B: BlockT> {

let proposing_remaining_duration = self.proposing_remaining_duration(&slot_info);

let proposing_remaining = if proposing_remaining_duration == Duration::default() {
let end_proposing_at = if proposing_remaining_duration == Duration::default() {
debug!(
target: logging_target,
"Skipping proposal slot {} since there's no time left to propose", slot,
);

return None
} else {
Delay::new(proposing_remaining_duration)
Instant::now() + proposing_remaining_duration
};

let aux_data = match self.aux_data(&slot_info.chain_head, slot) {
Expand Down Expand Up @@ -379,7 +387,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
},
};

let proposal = self.propose(proposer, &claim, slot_info, proposing_remaining).await?;
let proposal = self.propose(proposer, &claim, slot_info, end_proposing_at).await?;

let (block, storage_proof) = (proposal.block, proposal.proof);
let (header, body) = block.deconstruct();
Expand Down