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

slots: incrementally backoff claiming slots if finality lags behind #7186

Merged
45 commits merged into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
250fbeb
babe: backoff authoring blocks when finality lags
octol Sep 16, 2020
d531efa
babe: move backoff authoring params to default constructor
octol Sep 22, 2020
b060e9b
babe: deduplicate the test a bit
octol Sep 22, 2020
0f95c44
babe: set backoff constants in service
octol Sep 23, 2020
df1951c
babe: use better names for backoff authoring block parameters
octol Sep 23, 2020
c17ca03
babe: remove last unwrap
octol Sep 23, 2020
2892da0
babe: slight style tweak
octol Sep 23, 2020
01f1ac3
babe: fix comment
octol Sep 23, 2020
9794ffa
slots: move backoff block authorship logic to SimpleSlotWorker
octol Sep 28, 2020
d2ee780
aura: append SlotInfo in on_slot
octol Sep 30, 2020
026a8d0
slots: use the correct types for parameters
octol Sep 30, 2020
f428a35
Merge branch 'master' into jon/incremental-backoff-on-finality
octol Oct 14, 2020
6903837
slots: fix review comments
octol Oct 23, 2020
4a6b8b7
Merge branch 'master' into jon/incremental-backoff-on-finality
octol Oct 23, 2020
92b506a
aura: add missing backoff authoring blocks parameters
octol Oct 23, 2020
cda5150
slots: add comments for default values
octol Oct 27, 2020
62f97dc
slots: add additional checks in test
octol Oct 27, 2020
7fa2084
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Oct 28, 2020
af8d30b
slots: update implementation for new master
octol Oct 28, 2020
76b745a
slots: revert the change to SlotInfo
octol Oct 28, 2020
dafd2e5
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Oct 28, 2020
dc04a1f
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Oct 29, 2020
cb6d24c
Fix review comments
octol Oct 30, 2020
55827c3
slots: rework unit tests for backing off claiming slots
octol Nov 2, 2020
83538f0
slots: add test for asymptotic behaviour for slot claims
octol Nov 3, 2020
c87145d
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Nov 3, 2020
0435142
slots: address review comments
octol Nov 4, 2020
38e61e5
slots: add test for max_interval
octol Nov 4, 2020
1228aef
slots: add assertion for intervals between between claimed slots
octol Nov 4, 2020
f7b8c76
slots: remove rustfmt directive
octol Nov 4, 2020
9790f60
slots: another attempt at explaining authoring_rate
octol Nov 4, 2020
f95225a
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Nov 4, 2020
461d5f9
slots: up unfinalized_slack to 50 by default
octol Nov 6, 2020
796baf7
slots: add tests for time to reach max_interval
octol Nov 6, 2020
0d11df5
slots: fix typo in comments
octol Nov 6, 2020
9a968c6
Apply suggestions from code review
octol Nov 10, 2020
a607bc4
slots: additional tweaks to comments and info calls
octol Nov 10, 2020
bc32a7c
slots: rename to BackoffAuthoringOnFinalizedHeadLagging
octol Nov 10, 2020
eb45ed7
slots: make the backing off strategy generic
octol Nov 10, 2020
5a40da8
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Nov 10, 2020
4f44b62
Apply suggestions from code review
octol Nov 10, 2020
1423649
slots: implement backoff trait for () for simplicity
octol Nov 10, 2020
44de2cf
slots: move logging inside backing off function to make it more specific
octol Nov 11, 2020
90d0ad3
Merge remote-tracking branch 'upstream/master' into jon/incremental-b…
octol Nov 11, 2020
b6435ff
aura: add missing function parameter
octol Nov 11, 2020
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
1 change: 1 addition & 0 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ where
chain_head_slot,
self.client.info().finalized_number,
slot_number,
self.logging_target(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the most elegant maybe, is there a cleaner way @bkchr ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not that nice, but yeah 🤷

@andresilva WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option would be to pass the logging target to the strategy itself when creating it but I think that's as nice as this. The reason we use the same logging target here as block production is to make sure these logging messages don't go unnoticed (i.e. people would forget to add some "slots" target). In this case the message is being logged under info so it should always be printed regardless of the target we provide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're saying might as well drop the logging_target altogether?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either keep the changes you made or drop it altogether. I don't have a strict opinion about this, I guess we can keep it as is.

);
}
}
Expand Down
32 changes: 24 additions & 8 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ pub trait SimpleSlotWorker<B: BlockT> {
};

if self.should_backoff(slot_number, &chain_head) {
info!(
target: self.logging_target(),
"Backing off claiming new slot for block authorship.",
);
return Box::pin(future::ready(None));
}

Expand Down Expand Up @@ -613,6 +609,7 @@ pub trait BackoffAuthoringBlocksStrategy<N> {
chain_head_slot: u64,
finalized_number: N,
slow_now: u64,
logging_target: &str,
) -> bool;
}

Expand Down Expand Up @@ -659,6 +656,7 @@ where
chain_head_slot: u64,
finalized_number: N,
slot_now: u64,
logging_target: &str,
) -> bool {
andresilva marked this conversation as resolved.
Show resolved Hide resolved
// This should not happen, but we want to keep the previous behaviour if it does.
if slot_now <= chain_head_slot {
Expand All @@ -675,7 +673,15 @@ where

// If interval is nonzero we backoff if the current slot isn't far enough ahead of the chain
// head.
slot_now <= chain_head_slot + interval
if slot_now <= chain_head_slot + interval {
info!(
target: logging_target,
"Backing off claiming new slot for block authorship: finality is lagging.",
);
true
} else {
false
}
}
}

Expand All @@ -686,6 +692,7 @@ impl<N> BackoffAuthoringBlocksStrategy<N> for () {
_chain_head_slot: u64,
_finalized_number: N,
_slot_now: u64,
_logging_target: &str,
) -> bool {
false
}
Expand Down Expand Up @@ -791,7 +798,7 @@ mod test {
let slot_now = 2;

let should_backoff: Vec<bool> = (slot_now..1000)
.map(|s| strategy.should_backoff(head_number, head_slot, finalized_number, s))
.map(|s| strategy.should_backoff(head_number, head_slot, finalized_number, s, "slots"))
.collect();

// Should always be false, since the head isn't advancing
Expand All @@ -814,7 +821,13 @@ mod test {

let should_backoff: Vec<bool> = (slot_now..300)
.map(move |s| {
let b = strategy.should_backoff(head_number, head_slot, finalized_number, s);
let b = strategy.should_backoff(
head_number,
head_slot,
finalized_number,
s,
"slots",
);
// Chain is still advancing (by someone else)
head_number += 1;
head_slot = s;
Expand Down Expand Up @@ -849,7 +862,7 @@ mod test {
let max_interval = strategy.max_interval;

let should_backoff: Vec<bool> = (slot_now..200)
.map(|s| strategy.should_backoff(head_number, head_slot, finalized_number, s))
.map(|s| strategy.should_backoff(head_number, head_slot, finalized_number, s, "slots"))
.collect();

// Should backoff (true) until we are `max_interval` number of slots ahead of the chain
Expand Down Expand Up @@ -880,6 +893,7 @@ mod test {
head_state.head_slot,
finalized_number,
head_state.slot_now,
"slots",
)
};

Expand Down Expand Up @@ -951,6 +965,7 @@ mod test {
head_state.head_slot,
finalized_number,
head_state.slot_now,
"slots",
)
};

Expand Down Expand Up @@ -1014,6 +1029,7 @@ mod test {
head_state.head_slot,
finalized_number,
head_state.slot_now,
"slots",
)
};

Expand Down