Skip to content

Commit

Permalink
Revert "use same timestamp for next_epoch_min_start_time and block …
Browse files Browse the repository at this point in the history
…header"

This reverts commit e696320.
  • Loading branch information
tzemanovic committed Sep 5, 2024
1 parent 39f1bc2 commit 1461b79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
23 changes: 12 additions & 11 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,28 +363,29 @@ impl MockNode {
}

pub fn next_epoch(&mut self) -> Epoch {
let header_time = #[allow(clippy::disallowed_methods)]
DateTimeUtc::now();
{
let mut locked = self.shell.lock().unwrap();

let next_epoch_height =
locked.state.in_mem().get_last_block_height() + 1;
locked.state.in_mem_mut().next_epoch_min_start_height =
next_epoch_height;
locked.state.in_mem_mut().next_epoch_min_start_time = header_time;
locked.state.in_mem_mut().next_epoch_min_start_time = {
#[allow(clippy::disallowed_methods)]
DateTimeUtc::now()
};
let next_epoch_min_start_height =
locked.state.in_mem().next_epoch_min_start_height;
if let Some(LastBlock { height, .. }) =
locked.state.in_mem_mut().last_block.as_mut()
{
*height = next_epoch_height;
*height = next_epoch_min_start_height;
}
}
// Use the same timestamp as `next_epoch_min_start_time` to ensure a new
// epoch is started on this block
self.finalize_and_commit(Some(header_time));
self.finalize_and_commit();

for _ in 0..EPOCH_SWITCH_BLOCKS_DELAY {
self.finalize_and_commit(None);
self.finalize_and_commit();
}
self.shell
.lock()
Expand Down Expand Up @@ -458,7 +459,7 @@ impl MockNode {

/// Simultaneously call the `FinalizeBlock` and
/// `Commit` handlers.
pub fn finalize_and_commit(&self, header_time: Option<DateTimeUtc>) {
pub fn finalize_and_commit(&self) {
let (proposer_address, votes) = self.prepare_request();

let mut locked = self.shell.lock().unwrap();
Expand Down Expand Up @@ -489,7 +490,7 @@ impl MockNode {
header: BlockHeader {
hash: Hash([0; 32]),
#[allow(clippy::disallowed_methods)]
time: header_time.unwrap_or_else(DateTimeUtc::now),
time: DateTimeUtc::now(),
next_validators_hash: Hash([0; 32]),
},
block_hash: Hash([0; 32]),
Expand Down Expand Up @@ -569,7 +570,7 @@ impl MockNode {
/// Send a tx through Process Proposal and Finalize Block
/// and register the results.
pub fn submit_txs(&self, txs: Vec<Vec<u8>>) {
self.finalize_and_commit(None);
self.finalize_and_commit();
let (proposer_address, votes) = self.prepare_request();

#[allow(clippy::disallowed_methods)]
Expand Down
8 changes: 4 additions & 4 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn invalid_transactions() -> Result<()> {
assert_matches!(captured.result, Ok(_));
assert!(captured.contains(TX_REJECTED));

node.finalize_and_commit(None);
node.finalize_and_commit();
// There should be state now
{
let locked = node.shell.lock().unwrap();
Expand Down Expand Up @@ -1719,7 +1719,7 @@ fn enforce_fee_payment() -> Result<()> {
}
// Finalize the next block to execute the txs
node.clear_results();
node.finalize_and_commit(None);
node.finalize_and_commit();
{
let results = node.results.lock().unwrap();
for result in results.iter() {
Expand Down Expand Up @@ -2028,7 +2028,7 @@ fn scheduled_migration() -> Result<()> {
}

while node.block_height().0 != 4 {
node.finalize_and_commit(None)
node.finalize_and_commit()
}
// check that the key doesn't exist before the scheduled block
let rt = tokio::runtime::Runtime::new().unwrap();
Expand All @@ -2045,7 +2045,7 @@ fn scheduled_migration() -> Result<()> {
assert!(bytes.is_empty());

// check that the key now exists and has the expected value
node.finalize_and_commit(None);
node.finalize_and_commit();
let rt = tokio::runtime::Runtime::new().unwrap();
let bytes = rt
.block_on(RPC.shell().storage_value(
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/integration/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ fn multiple_unfetched_txs_same_block() -> Result<()> {
}
// Finalize the next block to actually execute the decrypted txs
node.clear_results();
node.finalize_and_commit(None);
node.finalize_and_commit();
{
let results = node.results.lock().unwrap();
for result in results.iter() {
Expand Down

0 comments on commit 1461b79

Please sign in to comment.