Skip to content

Commit cdbdd26

Browse files
paulhaunerWoodpile37
authored andcommitted
Add a flag for storing invalid blocks (sigp#4194)
NA Adds a flag to store invalid blocks on disk for teh debugz. Only *some* invalid blocks are stored, those which: - Were received via gossip (rather than RPC, for instance) - This keeps things simple to start with and should capture most blocks. - Passed gossip verification - This reduces the ability for random people to fill up our disk. A proposer signature is required to write something to disk. It's possible that we'll store blocks that aren't necessarily invalid, but we had an internal error during verification. Those blocks seem like they might be useful sometimes.
1 parent cf9d780 commit cdbdd26

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

beacon_node/lighthouse_network/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ pub struct Config {
145145

146146
/// Configuration for the outbound rate limiter (requests made by this node).
147147
pub outbound_rate_limiter_config: Option<OutboundRateLimiterConfig>,
148+
149+
/// Configures if/where invalid blocks should be stored.
150+
pub invalid_block_storage: Option<PathBuf>,
148151
}
149152

150153
impl Config {
@@ -329,6 +332,7 @@ impl Default for Config {
329332
metrics_enabled: false,
330333
enable_light_client_server: false,
331334
outbound_rate_limiter_config: None,
335+
invalid_block_storage: None,
332336
}
333337
}
334338
}

beacon_node/network/src/beacon_processor/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl TestRig {
203203
max_workers: cmp::max(1, num_cpus::get()),
204204
current_workers: 0,
205205
importing_blocks: duplicate_cache.clone(),
206+
invalid_block_storage: InvalidBlockStorage::Disabled,
206207
log: log.clone(),
207208
}
208209
.spawn_manager(beacon_processor_rx, Some(work_journal_tx));

beacon_node/network/src/router.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![allow(clippy::unit_arg)]
77

88
use crate::beacon_processor::{
9-
BeaconProcessor, WorkEvent as BeaconWorkEvent, MAX_WORK_EVENT_QUEUE_LEN,
9+
BeaconProcessor, InvalidBlockStorage, WorkEvent as BeaconWorkEvent, MAX_WORK_EVENT_QUEUE_LEN,
1010
};
1111
use crate::error;
1212
use crate::service::{NetworkMessage, RequestId};
@@ -80,6 +80,7 @@ impl<T: BeaconChainTypes> Router<T> {
8080
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
8181
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
8282
executor: task_executor::TaskExecutor,
83+
invalid_block_storage: InvalidBlockStorage,
8384
log: slog::Logger,
8485
) -> error::Result<mpsc::UnboundedSender<RouterMessage<T::EthSpec>>> {
8586
let message_handler_log = log.new(o!("service"=> "router"));
@@ -111,6 +112,7 @@ impl<T: BeaconChainTypes> Router<T> {
111112
max_workers: cmp::max(1, num_cpus::get()),
112113
current_workers: 0,
113114
importing_blocks: Default::default(),
115+
invalid_block_storage,
114116
log: log.clone(),
115117
}
116118
.spawn_manager(beacon_processor_receive, None);

beacon_node/network/src/service.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::sync::manager::RequestId as SyncId;
2+
use crate::beacon_processor::InvalidBlockStorage;
23
use crate::persisted_dht::{clear_dht, load_dht, persist_dht};
34
use crate::router::{Router, RouterMessage};
45
use crate::subnet_service::SyncCommitteeService;
@@ -295,6 +296,12 @@ impl<T: BeaconChainTypes> NetworkService<T> {
295296
}
296297
}
297298

299+
let invalid_block_storage = config
300+
.invalid_block_storage
301+
.clone()
302+
.map(InvalidBlockStorage::Enabled)
303+
.unwrap_or(InvalidBlockStorage::Disabled);
304+
298305
// launch derived network services
299306

300307
// router task
@@ -303,6 +310,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
303310
network_globals.clone(),
304311
network_senders.network_send(),
305312
executor.clone(),
313+
invalid_block_storage,
306314
network_log.clone(),
307315
)?;
308316

beacon_node/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,4 +1135,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
11351135
// always using the builder.
11361136
.conflicts_with("builder-profit-threshold")
11371137
)
1138+
.arg(
1139+
Arg::with_name("invalid-gossip-verified-blocks-path")
1140+
.long("invalid-gossip-verified-blocks-path")
1141+
.value_name("PATH")
1142+
.help("If a block succeeds gossip validation whilst failing full validation, store \
1143+
the block SSZ as a file at this path. This feature is only recommended for \
1144+
developers. This directory is not pruned, users should be careful to avoid \
1145+
filling up their disks.")
1146+
)
11381147
}

beacon_node/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ pub fn get_config<E: EthSpec>(
830830
client_config.chain.enable_backfill_rate_limiting =
831831
!cli_args.is_present("disable-backfill-rate-limiting");
832832

833+
if let Some(path) = clap_utils::parse_optional(cli_args, "invalid-gossip-verified-blocks-path")?
834+
{
835+
client_config.network.invalid_block_storage = Some(path);
836+
}
837+
833838
Ok(client_config)
834839
}
835840

lighthouse/tests/beacon_node.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,3 +2238,24 @@ fn disable_optimistic_finalized_sync() {
22382238
assert!(!config.chain.optimistic_finalized_sync);
22392239
});
22402240
}
2241+
2242+
#[test]
2243+
fn invalid_gossip_verified_blocks_path_default() {
2244+
CommandLineTest::new()
2245+
.run_with_zero_port()
2246+
.with_config(|config| assert_eq!(config.network.invalid_block_storage, None));
2247+
}
2248+
2249+
#[test]
2250+
fn invalid_gossip_verified_blocks_path() {
2251+
let path = "/home/karlm/naughty-blocks";
2252+
CommandLineTest::new()
2253+
.flag("invalid-gossip-verified-blocks-path", Some(path))
2254+
.run_with_zero_port()
2255+
.with_config(|config| {
2256+
assert_eq!(
2257+
config.network.invalid_block_storage,
2258+
Some(PathBuf::from(path))
2259+
)
2260+
});
2261+
}

0 commit comments

Comments
 (0)