Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4509: Speculative config changes to help reactor rewards tests pass r=AlexanderLimonov a=AlexanderLimonov

See casper-network#4433 and casper-network#4446

Ticket casper-network#4401

Co-authored-by: Félix <[email protected]>
Co-authored-by: Fraser Hutchison <[email protected]>
Co-authored-by: Alexander Limonov <[email protected]>
  • Loading branch information
4 people authored Feb 22, 2024
2 parents 210208c + 18b4c19 commit 0e5c843
Show file tree
Hide file tree
Showing 10 changed files with 788 additions and 38 deletions.
2 changes: 1 addition & 1 deletion node/src/components/block_accumulator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Reactor for MockReactor {
_event_queue: EventQueueHandle<Self::Event>,
_rng: &mut NodeRng,
) -> Result<(Self, Effects<Self::Event>), Self::Error> {
let (storage_config, storage_tempdir) = storage::Config::default_for_tests();
let (storage_config, storage_tempdir) = storage::Config::new_for_tests(1);
let storage_withdir = WithDir::new(storage_tempdir.path(), storage_config);
let validator_matrix = ValidatorMatrix::new_with_validator(ALICE_SECRET_KEY.clone());
let block_accumulator_config = Config::default();
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/contract_runtime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl reactor::Reactor for Reactor {
_event_queue: EventQueueHandle<Self::Event>,
_rng: &mut NodeRng,
) -> Result<(Self, Effects<Self::Event>), Self::Error> {
let (storage_config, storage_tempdir) = storage::Config::default_for_tests();
let (storage_config, storage_tempdir) = storage::Config::new_for_tests(1);
let storage_withdir = WithDir::new(storage_tempdir.path(), storage_config);
let storage = Storage::new(
&storage_withdir,
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/fetcher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct FetcherTestConfig {

impl Default for FetcherTestConfig {
fn default() -> Self {
let (storage_config, temp_dir) = storage::Config::default_for_tests();
let (storage_config, temp_dir) = storage::Config::new_for_tests(1);
FetcherTestConfig {
fetcher_config: Default::default(),
storage_config,
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/gossiper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl reactor::Reactor for Reactor {
event_queue: EventQueueHandle<Self::Event>,
rng: &mut NodeRng,
) -> Result<(Self, Effects<Self::Event>), Self::Error> {
let (storage_config, storage_tempdir) = storage::Config::default_for_tests();
let (storage_config, storage_tempdir) = storage::Config::new_for_tests(1);
let storage_withdir = WithDir::new(storage_tempdir.path(), storage_config);
let storage = Storage::new(
&storage_withdir,
Expand Down
15 changes: 12 additions & 3 deletions node/src/components/storage/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,24 @@ impl Default for Config {
}

impl Config {
/// Returns a default `Config` suitable for tests, along with a `TempDir` which must be kept
/// alive for the duration of the test since its destructor removes the dir from the filesystem.
/// Returns a `Config` suitable for tests, along with a `TempDir` which must be kept alive for
/// the duration of the test since its destructor removes the dir from the filesystem.
///
/// `size_multiplier` is used to multiply the default DB sizes.
#[cfg(test)]
pub(crate) fn default_for_tests() -> (Self, TempDir) {
pub(crate) fn new_for_tests(size_multiplier: u8) -> (Self, TempDir) {
if size_multiplier == 0 {
panic!("size_multiplier cannot be zero");
}
let tempdir = tempfile::tempdir().expect("should get tempdir");
let path = tempdir.path().join("lmdb");

let config = Config {
path,
max_block_store_size: 1024 * 1024 * size_multiplier as usize,
max_deploy_store_size: 1024 * 1024 * size_multiplier as usize,
max_deploy_metadata_store_size: 1024 * 1024 * size_multiplier as usize,
max_state_store_size: 12 * 1024 * size_multiplier as usize,
..Default::default()
};
(config, tempdir)
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/transaction_acceptor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl reactor::Reactor for Reactor {
_event_queue: EventQueueHandle<Self::Event>,
_rng: &mut NodeRng,
) -> Result<(Self, Effects<Self::Event>), Self::Error> {
let (storage_config, storage_tempdir) = storage::Config::default_for_tests();
let (storage_config, storage_tempdir) = storage::Config::new_for_tests(1);
let storage_withdir = WithDir::new(storage_tempdir.path(), storage_config);

let transaction_acceptor =
Expand Down
5 changes: 5 additions & 0 deletions node/src/failpoints_disabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ impl<T> Failpoint<T> {
pub(crate) struct FailpointActivation;

impl FailpointActivation {
#[allow(dead_code)]
pub(crate) fn new<S: ToString>(_key: S) -> FailpointActivation {
FailpointActivation
}

pub(crate) fn key(&self) -> &str {
""
}
Expand Down
18 changes: 15 additions & 3 deletions node/src/reactor/main_reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ pub(crate) struct MainReactor {
upgrade_timeout: TimeDiff,
sync_handling: SyncHandling,
signature_gossip_tracker: SignatureGossipTracker,

finality_signature_creation: bool,
}

impl reactor::Reactor for MainReactor {
Expand Down Expand Up @@ -242,9 +244,13 @@ impl reactor::Reactor for MainReactor {
MainEvent::MainReactorRequest(req) => {
req.0.respond((self.state, self.last_progress)).ignore()
}
MainEvent::MetaBlockAnnouncement(MetaBlockAnnouncement(meta_block)) => {
self.handle_meta_block(effect_builder, rng, meta_block)
}
MainEvent::MetaBlockAnnouncement(MetaBlockAnnouncement(meta_block)) => self
.handle_meta_block(
effect_builder,
rng,
self.finality_signature_creation,
meta_block,
),
MainEvent::UnexecutedBlockAnnouncement(UnexecutedBlockAnnouncement(block_height)) => {
let only_from_available_block_range = true;
if let Ok(Some(block_header)) = self
Expand Down Expand Up @@ -1209,6 +1215,7 @@ impl reactor::Reactor for MainReactor {
shutdown_for_upgrade_timeout: config.node.shutdown_for_upgrade_timeout,
switched_to_shutdown_for_upgrade: Timestamp::from(0),
upgrade_timeout: config.node.upgrade_timeout,
finality_signature_creation: true,
};
info!("MainReactor: instantiated");
let effects = effect_builder
Expand All @@ -1230,6 +1237,9 @@ impl reactor::Reactor for MainReactor {
activation,
);
}
if activation.key().starts_with("finality_signature_creation") {
self.finality_signature_creation = false;
}
}
}

Expand Down Expand Up @@ -1262,6 +1272,7 @@ impl MainReactor {
&mut self,
effect_builder: EffectBuilder<MainEvent>,
rng: &mut NodeRng,
create_finality_signatures: bool,
mut meta_block: MetaBlock,
) -> Effects<MainEvent> {
debug!(
Expand Down Expand Up @@ -1378,6 +1389,7 @@ impl MainReactor {
.mut_state()
.register_we_have_tried_to_sign()
.was_updated()
&& create_finality_signatures
{
// When this node is a validator in this era, sign and announce.
if let Some(finality_signature) = self
Expand Down
Loading

0 comments on commit 0e5c843

Please sign in to comment.