Skip to content

Introduce a max delay bound of 1s for the column reconstruction #7702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::time::Duration;
use strum::AsRefStr;
use task_executor::TaskExecutor;
use tokio::sync::mpsc::{self, Receiver, Sender};
use tokio::time::Instant;
use tokio_util::time::delay_queue::{DelayQueue, Key as DelayKey};
use tracing::{debug, error, trace, warn};
use types::{EthSpec, Hash256, Slot};
Expand Down Expand Up @@ -58,6 +59,9 @@ pub const QUEUED_SAMPLING_REQUESTS_DELAY: Duration = Duration::from_secs(12);
/// For how long to queue delayed column reconstruction.
pub const QUEUED_RECONSTRUCTION_DELAY: Duration = Duration::from_millis(150);

/// The maximum delay for a column reconstruction to be processed.
pub const MAX_RECONSTRUCTION_DELAY: Duration = Duration::from_secs(1);

/// Set an arbitrary upper-bound on the number of queued blocks to avoid DoS attacks. The fact that
/// we signature-verify blocks before putting them in the queue *should* protect against this, but
/// it's nice to have extra protection.
Expand Down Expand Up @@ -86,6 +90,14 @@ pub const BACKFILL_SCHEDULE_IN_SLOT: [(u32, u32); 3] = [
(4, 5),
];

/// Column reconstruction bound
pub struct ReconstructionBound {
/// The first time this reconstruction was requested.
pub first: Instant,
/// The delay key
pub key: DelayKey,
}

/// Messages that the scheduler can receive.
#[derive(AsRefStr)]
pub enum ReprocessQueueMessage {
Expand Down Expand Up @@ -269,7 +281,7 @@ struct ReprocessQueue<S> {
/// Sampling requests per block root.
awaiting_sampling_requests_per_block_root: HashMap<Hash256, Vec<QueuedSamplingRequestId>>,
/// Column reconstruction per block root.
queued_column_reconstructions: HashMap<Hash256, DelayKey>,
queued_column_reconstructions: HashMap<Hash256, ReconstructionBound>,
/// Queued backfill batches
queued_backfill_batches: Vec<QueuedBackfillBatch>,

Expand Down Expand Up @@ -847,17 +859,24 @@ impl<S: SlotClock> ReprocessQueue<S> {
}
}
InboundEvent::Msg(DelayColumnReconstruction(request)) => {
let current: Instant = Instant::now();
match self.queued_column_reconstructions.entry(request.block_root) {
Entry::Occupied(key) => {
Entry::Occupied(mut key) => {
let bound = key.get_mut();
// Push back the reattempted reconstruction
self.column_reconstructions_delay_queue
.reset(key.get(), QUEUED_RECONSTRUCTION_DELAY)
if current.duration_since(bound.first) < MAX_RECONSTRUCTION_DELAY {
self.column_reconstructions_delay_queue
.reset(&bound.key, QUEUED_RECONSTRUCTION_DELAY)
}
}
Entry::Vacant(vacant) => {
let delay_key = self
.column_reconstructions_delay_queue
.insert(request, QUEUED_RECONSTRUCTION_DELAY);
vacant.insert(delay_key);
vacant.insert(ReconstructionBound {
first: current,
key: delay_key,
});
}
}
}
Expand Down