This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Define PohRecorder set_bank related test helper methods #33626
Merged
ryoqun
merged 1 commit into
solana-labs:master
from
ryoqun:pohrecorder-set-bank-test-methods
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -642,6 +642,16 @@ impl PohRecorder { | |
let _ = self.flush_cache(false); | ||
} | ||
|
||
#[cfg(feature = "dev-context-only-utils")] | ||
pub fn set_bank_for_test(&mut self, bank: Arc<Bank>) { | ||
self.set_bank(bank, false) | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn set_bank_with_transaction_index_for_test(&mut self, bank: Arc<Bank>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi, this is only used once.... another justification for hiding the |
||
self.set_bank(bank, true) | ||
} | ||
|
||
// Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height | ||
// On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record | ||
// occurs after the min_tick_height was generated | ||
|
@@ -1219,7 +1229,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank, false); | ||
poh_recorder.set_bank_for_test(bank); | ||
assert!(poh_recorder.working_bank.is_some()); | ||
poh_recorder.clear_bank(); | ||
assert!(poh_recorder.working_bank.is_none()); | ||
|
@@ -1253,7 +1263,7 @@ mod tests { | |
let bank1 = Arc::new(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); | ||
|
||
// Set a working bank | ||
poh_recorder.set_bank(bank1.clone(), false); | ||
poh_recorder.set_bank_for_test(bank1.clone()); | ||
|
||
// Tick until poh_recorder.tick_height == working bank's min_tick_height | ||
let num_new_ticks = bank1.tick_height() - poh_recorder.tick_height(); | ||
|
@@ -1322,7 +1332,7 @@ mod tests { | |
); | ||
assert_eq!(poh_recorder.tick_height, bank.max_tick_height() + 1); | ||
|
||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
poh_recorder.tick(); | ||
|
||
assert_eq!(poh_recorder.tick_height, bank.max_tick_height() + 2); | ||
|
@@ -1363,7 +1373,7 @@ mod tests { | |
|
||
bank0.fill_bank_with_ticks_for_tests(); | ||
let bank1 = Arc::new(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); | ||
poh_recorder.set_bank(bank1.clone(), false); | ||
poh_recorder.set_bank_for_test(bank1.clone()); | ||
// Let poh_recorder tick up to bank1.tick_height() - 1 | ||
for _ in 0..bank1.tick_height() - 1 { | ||
poh_recorder.tick() | ||
|
@@ -1404,7 +1414,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
let tx = test_tx(); | ||
let h1 = hash(b"hello world!"); | ||
|
||
|
@@ -1448,7 +1458,7 @@ mod tests { | |
|
||
bank0.fill_bank_with_ticks_for_tests(); | ||
let bank1 = Arc::new(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); | ||
poh_recorder.set_bank(bank1.clone(), false); | ||
poh_recorder.set_bank_for_test(bank1.clone()); | ||
|
||
// Record up to exactly min tick height | ||
let min_tick_height = poh_recorder.working_bank.as_ref().unwrap().min_tick_height; | ||
|
@@ -1502,7 +1512,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
let num_ticks_to_max = bank.max_tick_height() - poh_recorder.tick_height; | ||
for _ in 0..num_ticks_to_max { | ||
poh_recorder.tick(); | ||
|
@@ -1542,7 +1552,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank.clone(), true); | ||
poh_recorder.set_bank_with_transaction_index_for_test(bank.clone()); | ||
poh_recorder.tick(); | ||
assert_eq!( | ||
poh_recorder | ||
|
@@ -1616,7 +1626,7 @@ mod tests { | |
|
||
bank0.fill_bank_with_ticks_for_tests(); | ||
let bank1 = Arc::new(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); | ||
poh_recorder.set_bank(bank1, false); | ||
poh_recorder.set_bank_for_test(bank1); | ||
|
||
// Check we can make two ticks without hitting min_tick_height | ||
let remaining_ticks_to_min = | ||
|
@@ -1764,7 +1774,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
assert_eq!(bank.slot(), 0); | ||
poh_recorder.reset(bank, Some((4, 4))); | ||
assert!(poh_recorder.working_bank.is_none()); | ||
|
@@ -1796,7 +1806,7 @@ mod tests { | |
None, | ||
Arc::new(AtomicBool::default()), | ||
); | ||
poh_recorder.set_bank(bank, false); | ||
poh_recorder.set_bank_for_test(bank); | ||
poh_recorder.clear_bank(); | ||
assert!(receiver.try_recv().is_ok()); | ||
} | ||
|
@@ -1831,7 +1841,7 @@ mod tests { | |
Arc::new(AtomicBool::default()), | ||
); | ||
|
||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
|
||
// Simulate ticking much further than working_bank.max_tick_height | ||
let max_tick_height = poh_recorder.working_bank.as_ref().unwrap().max_tick_height; | ||
|
@@ -2126,7 +2136,7 @@ mod tests { | |
// Move the bank up a slot (so that max_tick_height > slot 0's tick_height) | ||
let bank = Arc::new(Bank::new_from_parent(bank, &Pubkey::default(), 1)); | ||
// If we set the working bank, the node should be leader within next 2 slots | ||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
assert!(poh_recorder.would_be_leader(2 * bank.ticks_per_slot())); | ||
} | ||
} | ||
|
@@ -2160,7 +2170,7 @@ mod tests { | |
for _ in 0..(bank.ticks_per_slot() * 3) { | ||
poh_recorder.tick(); | ||
} | ||
poh_recorder.set_bank(bank.clone(), false); | ||
poh_recorder.set_bank_for_test(bank.clone()); | ||
assert!(!bank.is_hash_valid_for_age(&genesis_hash, 0)); | ||
assert!(bank.is_hash_valid_for_age(&genesis_hash, 1)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i eliminated these
false
s at all call-sites as a bonus.