From 09a8ce479afd5b14c8817a9eff6bd0d571b6c931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 4 Sep 2024 12:43:13 +0100 Subject: [PATCH 01/11] asd --- crates/tests/src/integration/ledger_tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 65c0862061..650a4edfba 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -1157,6 +1157,7 @@ fn pgf_governance_proposal() -> Result<()> { assert!(captured.contains("Pgf fundings: no fundings are currently set.")); // 7.1 Query total NAM supply and PGF balance + node.finalize_and_commit(); let query_balance_args = vec![ "balance", "--owner", From 9b090e3c146cb658ec9e8199a29bd0b57c0e1c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 10:48:38 +0100 Subject: [PATCH 02/11] fixup! asd --- crates/tests/src/integration/ledger_tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 650a4edfba..65c0862061 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -1157,7 +1157,6 @@ fn pgf_governance_proposal() -> Result<()> { assert!(captured.contains("Pgf fundings: no fundings are currently set.")); // 7.1 Query total NAM supply and PGF balance - node.finalize_and_commit(); let query_balance_args = vec![ "balance", "--owner", From faf78bbc11607e79d667079b72a43e5cc7e47b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 10:49:06 +0100 Subject: [PATCH 03/11] try to get logs for it --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5b069e7e4f..604dfaa653 100644 --- a/Makefile +++ b/Makefile @@ -177,8 +177,8 @@ test-e2e: # Run integration tests test-integration: - RUST_BACKTRACE=$(RUST_BACKTRACE) \ - $(cargo) +$(nightly) test --lib $(jobs) integration::$(TEST_FILTER) \ + RUST_LOG=info RUST_BACKTRACE=$(RUST_BACKTRACE) \ + $(cargo) +$(nightly) test --lib $(jobs) integration::pgf_governance_proposal \ -Z unstable-options \ -- \ --test-threads=1 \ From 49dd609f68ce127247ab2d737ba9086472b68ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 11:19:24 +0100 Subject: [PATCH 04/11] fixup! try to get logs for it --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 604dfaa653..790258d542 100644 --- a/Makefile +++ b/Makefile @@ -177,8 +177,8 @@ test-e2e: # Run integration tests test-integration: - RUST_LOG=info RUST_BACKTRACE=$(RUST_BACKTRACE) \ - $(cargo) +$(nightly) test --lib $(jobs) integration::pgf_governance_proposal \ + RUST_BACKTRACE=$(RUST_BACKTRACE) \ + $(cargo) +$(nightly) test --lib $(jobs) integration::$(TEST_FILTER) \ -Z unstable-options \ -- \ --test-threads=1 \ @@ -206,9 +206,9 @@ test-unit-with-coverage: -Z unstable-options --report-time test-integration-with-coverage: - $(cargo) +$(nightly) llvm-cov --lib --output-path lcov.info \ + RUST_LOG=info $(cargo) +$(nightly) llvm-cov --lib --output-path lcov.info \ --lcov \ - -- integration \ + -- integration::ledger_tests::pgf_governance_proposal \ --test-threads=1 \ -Z unstable-options --report-time From e0f6d652f915f7b18adcae3c5f226122f0c6b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 11:34:03 +0100 Subject: [PATCH 05/11] deliberatly empty From e6963205565ad0dc0f58da80a5fe9f50889d3c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 12:35:53 +0100 Subject: [PATCH 06/11] use same timestamp for `next_epoch_min_start_time` and block header --- crates/node/src/shell/testing/node.rs | 23 ++++++++++---------- crates/tests/src/integration/ledger_tests.rs | 8 +++---- crates/tests/src/integration/masp.rs | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index a6e67d3987..5b92d3184d 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -363,6 +363,8 @@ 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(); @@ -370,22 +372,19 @@ impl MockNode { 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 = { - #[allow(clippy::disallowed_methods)] - DateTimeUtc::now() - }; - let next_epoch_min_start_height = - locked.state.in_mem().next_epoch_min_start_height; + locked.state.in_mem_mut().next_epoch_min_start_time = header_time; if let Some(LastBlock { height, .. }) = locked.state.in_mem_mut().last_block.as_mut() { - *height = next_epoch_min_start_height; + *height = next_epoch_height; } } - self.finalize_and_commit(); + // 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)); for _ in 0..EPOCH_SWITCH_BLOCKS_DELAY { - self.finalize_and_commit(); + self.finalize_and_commit(None); } self.shell .lock() @@ -459,7 +458,7 @@ impl MockNode { /// Simultaneously call the `FinalizeBlock` and /// `Commit` handlers. - pub fn finalize_and_commit(&self) { + pub fn finalize_and_commit(&self, header_time: Option) { let (proposer_address, votes) = self.prepare_request(); let mut locked = self.shell.lock().unwrap(); @@ -490,7 +489,7 @@ impl MockNode { header: BlockHeader { hash: Hash([0; 32]), #[allow(clippy::disallowed_methods)] - time: DateTimeUtc::now(), + time: header_time.unwrap_or_else(DateTimeUtc::now), next_validators_hash: Hash([0; 32]), }, block_hash: Hash([0; 32]), @@ -570,7 +569,7 @@ impl MockNode { /// Send a tx through Process Proposal and Finalize Block /// and register the results. pub fn submit_txs(&self, txs: Vec>) { - self.finalize_and_commit(); + self.finalize_and_commit(None); let (proposer_address, votes) = self.prepare_request(); #[allow(clippy::disallowed_methods)] diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 65c0862061..9e0e0a6777 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -389,7 +389,7 @@ fn invalid_transactions() -> Result<()> { assert_matches!(captured.result, Ok(_)); assert!(captured.contains(TX_REJECTED)); - node.finalize_and_commit(); + node.finalize_and_commit(None); // There should be state now { let locked = node.shell.lock().unwrap(); @@ -1719,7 +1719,7 @@ fn enforce_fee_payment() -> Result<()> { } // Finalize the next block to execute the txs node.clear_results(); - node.finalize_and_commit(); + node.finalize_and_commit(None); { let results = node.results.lock().unwrap(); for result in results.iter() { @@ -2028,7 +2028,7 @@ fn scheduled_migration() -> Result<()> { } while node.block_height().0 != 4 { - node.finalize_and_commit() + node.finalize_and_commit(None) } // check that the key doesn't exist before the scheduled block let rt = tokio::runtime::Runtime::new().unwrap(); @@ -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(); + node.finalize_and_commit(None); let rt = tokio::runtime::Runtime::new().unwrap(); let bytes = rt .block_on(RPC.shell().storage_value( diff --git a/crates/tests/src/integration/masp.rs b/crates/tests/src/integration/masp.rs index e2f6d66848..19d092dbb3 100644 --- a/crates/tests/src/integration/masp.rs +++ b/crates/tests/src/integration/masp.rs @@ -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(); + node.finalize_and_commit(None); { let results = node.results.lock().unwrap(); for result in results.iter() { From 7caebb1595ece8d157b07842d0ab18d6b2da6f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 12:38:44 +0100 Subject: [PATCH 07/11] fixup! use same timestamp for `next_epoch_min_start_time` and block header --- crates/node/src/shell/testing/node.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index 5b92d3184d..c3420fc8d9 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -363,8 +363,8 @@ impl MockNode { } pub fn next_epoch(&mut self) -> Epoch { - let header_time = #[allow(clippy::disallowed_methods)] - DateTimeUtc::now(); + #[allow(clippy::disallowed_methods)] + let header_time = DateTimeUtc::now(); { let mut locked = self.shell.lock().unwrap(); From 80f9a6e2758a4d27508f4c8451a80f6f274440e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 13:59:31 +0100 Subject: [PATCH 08/11] deliberatly empty From 39f1bc2451f732be8b61037f02eaefcae31b936a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 14:54:07 +0100 Subject: [PATCH 09/11] Revert "fixup! use same timestamp for `next_epoch_min_start_time` and block header" This reverts commit 7caebb1595ece8d157b07842d0ab18d6b2da6f26. --- crates/node/src/shell/testing/node.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index c3420fc8d9..5b92d3184d 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -363,8 +363,8 @@ impl MockNode { } pub fn next_epoch(&mut self) -> Epoch { - #[allow(clippy::disallowed_methods)] - let header_time = DateTimeUtc::now(); + let header_time = #[allow(clippy::disallowed_methods)] + DateTimeUtc::now(); { let mut locked = self.shell.lock().unwrap(); From 1461b794f9d74c785d84f21ede3bd81d7c1c3310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 14:54:13 +0100 Subject: [PATCH 10/11] Revert "use same timestamp for `next_epoch_min_start_time` and block header" This reverts commit e6963205565ad0dc0f58da80a5fe9f50889d3c9d. --- crates/node/src/shell/testing/node.rs | 23 ++++++++++---------- crates/tests/src/integration/ledger_tests.rs | 8 +++---- crates/tests/src/integration/masp.rs | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index 5b92d3184d..a6e67d3987 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -363,8 +363,6 @@ 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(); @@ -372,19 +370,22 @@ impl MockNode { 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() @@ -458,7 +459,7 @@ impl MockNode { /// Simultaneously call the `FinalizeBlock` and /// `Commit` handlers. - pub fn finalize_and_commit(&self, header_time: Option) { + pub fn finalize_and_commit(&self) { let (proposer_address, votes) = self.prepare_request(); let mut locked = self.shell.lock().unwrap(); @@ -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]), @@ -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>) { - self.finalize_and_commit(None); + self.finalize_and_commit(); let (proposer_address, votes) = self.prepare_request(); #[allow(clippy::disallowed_methods)] diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 9e0e0a6777..65c0862061 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -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(); @@ -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() { @@ -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(); @@ -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( diff --git a/crates/tests/src/integration/masp.rs b/crates/tests/src/integration/masp.rs index 19d092dbb3..e2f6d66848 100644 --- a/crates/tests/src/integration/masp.rs +++ b/crates/tests/src/integration/masp.rs @@ -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() { From fa3ea9cd5d59879ba4911b51ea60b22d64d8d544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 5 Sep 2024 14:56:14 +0100 Subject: [PATCH 11/11] dbg --- crates/node/src/shell/testing/node.rs | 25 ++++++++++++++++++++++--- crates/state/src/wl_state.rs | 10 +++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/node/src/shell/testing/node.rs b/crates/node/src/shell/testing/node.rs index a6e67d3987..5cae8e4a05 100644 --- a/crates/node/src/shell/testing/node.rs +++ b/crates/node/src/shell/testing/node.rs @@ -363,7 +363,16 @@ impl MockNode { } pub fn next_epoch(&mut self) -> Epoch { - { + println!("next_epoch"); + let before = self + .shell + .lock() + .unwrap() + .state + .in_mem() + .get_current_epoch() + .0; + let is_already_switching = { let mut locked = self.shell.lock().unwrap(); let next_epoch_height = @@ -381,10 +390,20 @@ impl MockNode { { *height = next_epoch_min_start_height; } - } + dbg!(locked.state.in_mem().update_epoch_blocks_delay.is_some()) + }; + println!("1. finalize_and_commit"); self.finalize_and_commit(); + if !is_already_switching { + let locked = self.shell.lock().unwrap(); + assert_eq!( + locked.state.in_mem().update_epoch_blocks_delay, + Some(EPOCH_SWITCH_BLOCKS_DELAY) + ) + }; - for _ in 0..EPOCH_SWITCH_BLOCKS_DELAY { + for i in 0..EPOCH_SWITCH_BLOCKS_DELAY { + println!("{}. finalize_and_commit", i + 2); self.finalize_and_commit(); } self.shell diff --git a/crates/state/src/wl_state.rs b/crates/state/src/wl_state.rs index a252f2bd81..1269865fcf 100644 --- a/crates/state/src/wl_state.rs +++ b/crates/state/src/wl_state.rs @@ -155,7 +155,7 @@ where time: DateTimeUtc, parameters: &Parameters, ) -> Result { - match self.in_mem.update_epoch_blocks_delay.as_mut() { + match dbg!(self.in_mem.update_epoch_blocks_delay.as_mut()) { None => { // Check if the new epoch minimum start height and start time // have been fulfilled. If so, queue the next @@ -163,10 +163,10 @@ where // as to align validator set updates + etc with // tendermint. This is because tendermint has a two block delay // to validator changes. - let current_epoch_duration_satisfied = height - >= self.in_mem.next_epoch_min_start_height - && time >= self.in_mem.next_epoch_min_start_time; - if current_epoch_duration_satisfied { + let current_epoch_duration_satisfied = + dbg!(height >= self.in_mem.next_epoch_min_start_height) + && dbg!(time >= self.in_mem.next_epoch_min_start_time); + if dbg!(current_epoch_duration_satisfied) { self.in_mem.update_epoch_blocks_delay = Some(EPOCH_SWITCH_BLOCKS_DELAY); }