775d222299
## Proposed Changes With proposer boosting implemented (#2822) we have an opportunity to re-org out late blocks. This PR adds three flags to the BN to control this behaviour: * `--disable-proposer-reorgs`: turn aggressive re-orging off (it's on by default). * `--proposer-reorg-threshold N`: attempt to orphan blocks with less than N% of the committee vote. If this parameter isn't set then N defaults to 20% when the feature is enabled. * `--proposer-reorg-epochs-since-finalization N`: only attempt to re-org late blocks when the number of epochs since finalization is less than or equal to N. The default is 2 epochs, meaning re-orgs will only be attempted when the chain is finalizing optimally. For safety Lighthouse will only attempt a re-org under very specific conditions: 1. The block being proposed is 1 slot after the canonical head, and the canonical head is 1 slot after its parent. i.e. at slot `n + 1` rather than building on the block from slot `n` we build on the block from slot `n - 1`. 2. The current canonical head received less than N% of the committee vote. N should be set depending on the proposer boost fraction itself, the fraction of the network that is believed to be applying it, and the size of the largest entity that could be hoarding votes. 3. The current canonical head arrived after the attestation deadline from our perspective. This condition was only added to support suppression of forkchoiceUpdated messages, but makes intuitive sense. 4. The block is being proposed in the first 2 seconds of the slot. This gives it time to propagate and receive the proposer boost. ## Additional Info For the initial idea and background, see: https://github.com/ethereum/consensus-specs/pull/2353#issuecomment-950238004 There is also a specification for this feature here: https://github.com/ethereum/consensus-specs/pull/3034 Co-authored-by: Michael Sproul <micsproul@gmail.com> Co-authored-by: pawan <pawandhananjay@gmail.com>
76 lines
2.2 KiB
Rust
76 lines
2.2 KiB
Rust
use crate::TaskExecutor;
|
|
use slog::Logger;
|
|
use sloggers::{null::NullLoggerBuilder, Build};
|
|
use std::sync::Arc;
|
|
use tokio::runtime;
|
|
|
|
/// Whilst the `TestRuntime` is not necessarily useful in itself, it provides the necessary
|
|
/// components for creating a `TaskExecutor` during tests.
|
|
///
|
|
/// May create its own runtime or use an existing one.
|
|
///
|
|
/// ## Warning
|
|
///
|
|
/// This struct should never be used in production, only testing.
|
|
pub struct TestRuntime {
|
|
runtime: Option<Arc<tokio::runtime::Runtime>>,
|
|
_runtime_shutdown: exit_future::Signal,
|
|
pub task_executor: TaskExecutor,
|
|
pub log: Logger,
|
|
}
|
|
|
|
impl Default for TestRuntime {
|
|
/// If called *inside* an existing runtime, instantiates `Self` using a handle to that runtime. If
|
|
/// called *outside* any existing runtime, create a new `Runtime` and keep it alive until the
|
|
/// `Self` is dropped.
|
|
fn default() -> Self {
|
|
let (runtime_shutdown, exit) = exit_future::signal();
|
|
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
|
|
let log = null_logger().unwrap();
|
|
|
|
let (runtime, handle) = if let Ok(handle) = runtime::Handle::try_current() {
|
|
(None, handle)
|
|
} else {
|
|
let runtime = Arc::new(
|
|
runtime::Builder::new_multi_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap(),
|
|
);
|
|
let handle = runtime.handle().clone();
|
|
(Some(runtime), handle)
|
|
};
|
|
|
|
let task_executor = TaskExecutor::new(handle, exit, log.clone(), shutdown_tx);
|
|
|
|
Self {
|
|
runtime,
|
|
_runtime_shutdown: runtime_shutdown,
|
|
task_executor,
|
|
log,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Drop for TestRuntime {
|
|
fn drop(&mut self) {
|
|
if let Some(runtime) = self.runtime.take() {
|
|
Arc::try_unwrap(runtime).unwrap().shutdown_background()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TestRuntime {
|
|
pub fn set_logger(&mut self, log: Logger) {
|
|
self.log = log.clone();
|
|
self.task_executor.log = log;
|
|
}
|
|
}
|
|
|
|
pub fn null_logger() -> Result<Logger, String> {
|
|
let log_builder = NullLoggerBuilder;
|
|
log_builder
|
|
.build()
|
|
.map_err(|e| format!("Failed to start null logger: {:?}", e))
|
|
}
|