From e4ff05f71753717ce8893dab72b0a908d36d2d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 26 Jul 2022 11:52:30 +0200 Subject: [PATCH 1/5] ledger: fix last_epoch to only change when committing block --- shared/src/ledger/storage/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shared/src/ledger/storage/mod.rs b/shared/src/ledger/storage/mod.rs index 0b3d19a742..d9e1fb548c 100644 --- a/shared/src/ledger/storage/mod.rs +++ b/shared/src/ledger/storage/mod.rs @@ -358,6 +358,7 @@ where }; self.db.write_block(state)?; self.last_height = self.block.height; + self.last_epoch = self.block.epoch; self.header = None; Ok(()) } @@ -597,8 +598,6 @@ where if new_epoch { // Begin a new epoch self.block.epoch = self.block.epoch.next(); - self.last_epoch = self.last_epoch.next(); - debug_assert_eq!(self.block.epoch, self.last_epoch); let EpochDuration { min_num_of_blocks, min_duration, From 91d038e1b998aa781054c657ce8db3cebae11834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 26 Jul 2022 12:23:42 +0200 Subject: [PATCH 2/5] test/ledger: update last_epoch assertion --- shared/src/ledger/storage/mod.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/shared/src/ledger/storage/mod.rs b/shared/src/ledger/storage/mod.rs index d9e1fb548c..124ee61d57 100644 --- a/shared/src/ledger/storage/mod.rs +++ b/shared/src/ledger/storage/mod.rs @@ -824,7 +824,6 @@ mod tests { ) { assert_eq!(storage.block.epoch, epoch_before.next()); - assert_eq!(storage.last_epoch, epoch_before.next()); assert_eq!(storage.next_epoch_min_start_height, block_height + epoch_duration.min_num_of_blocks); assert_eq!(storage.next_epoch_min_start_time, @@ -832,9 +831,10 @@ mod tests { assert_eq!(storage.block.pred_epochs.get_epoch(block_height), Some(epoch_before.next())); } else { assert_eq!(storage.block.epoch, epoch_before); - assert_eq!(storage.last_epoch, epoch_before); assert_eq!(storage.block.pred_epochs.get_epoch(block_height), Some(epoch_before)); } + // Last epoch should only change when the block is committed + assert_eq!(storage.last_epoch, epoch_before); // Update the epoch duration parameters parameters.epoch_duration.min_num_of_blocks = @@ -848,7 +848,7 @@ mod tests { parameters::update_epoch_parameter(&mut storage, ¶meters.epoch_duration).unwrap(); // Test for 2. - let epoch_before = storage.last_epoch; + let epoch_before = storage.block.epoch; let height_of_update = storage.next_epoch_min_start_height.0 ; let time_of_update = storage.next_epoch_min_start_time; let height_before_update = BlockHeight(height_of_update - 1); @@ -859,18 +859,14 @@ mod tests { // satisfied storage.update_epoch(height_before_update, time_before_update).unwrap(); assert_eq!(storage.block.epoch, epoch_before); - assert_eq!(storage.last_epoch, epoch_before); storage.update_epoch(height_of_update, time_before_update).unwrap(); assert_eq!(storage.block.epoch, epoch_before); - assert_eq!(storage.last_epoch, epoch_before); storage.update_epoch(height_before_update, time_of_update).unwrap(); assert_eq!(storage.block.epoch, epoch_before); - assert_eq!(storage.last_epoch, epoch_before); // Update should happen at this or after this height and time storage.update_epoch(height_of_update, time_of_update).unwrap(); assert_eq!(storage.block.epoch, epoch_before.next()); - assert_eq!(storage.last_epoch, epoch_before.next()); // The next epoch's minimum duration should change assert_eq!(storage.next_epoch_min_start_height, height_of_update + parameters.epoch_duration.min_num_of_blocks); From 096b45a4d9f9fdee7b08c3b0ed76df602bdff0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 26 Jul 2022 12:31:04 +0200 Subject: [PATCH 3/5] changelog: add #1249 --- .changelog/unreleased/bug-fixes/1249-fix-shell-last-epoch.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/1249-fix-shell-last-epoch.md diff --git a/.changelog/unreleased/bug-fixes/1249-fix-shell-last-epoch.md b/.changelog/unreleased/bug-fixes/1249-fix-shell-last-epoch.md new file mode 100644 index 0000000000..d4419e52a5 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1249-fix-shell-last-epoch.md @@ -0,0 +1,2 @@ +- Fix the `last_epoch` field in the shell to only be updated when the block is + committed. ([#1249](https://github.com/anoma/anoma/pull/1249)) \ No newline at end of file From c9e16e726b5aa5f97f03db5fc5c30a6febcd8860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 25 Aug 2022 12:30:47 +0200 Subject: [PATCH 4/5] shared/storage: fix the height recorded for a new epoch --- shared/src/ledger/storage/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/src/ledger/storage/mod.rs b/shared/src/ledger/storage/mod.rs index 124ee61d57..f3e561616c 100644 --- a/shared/src/ledger/storage/mod.rs +++ b/shared/src/ledger/storage/mod.rs @@ -609,7 +609,7 @@ where let evidence_max_age_num_blocks: u64 = 100000; self.block .pred_epochs - .new_epoch(height, evidence_max_age_num_blocks); + .new_epoch(height + 1, evidence_max_age_num_blocks); tracing::info!("Began a new epoch {}", self.block.epoch); } self.update_epoch_in_merkle_tree()?; @@ -828,10 +828,12 @@ mod tests { block_height + epoch_duration.min_num_of_blocks); assert_eq!(storage.next_epoch_min_start_time, block_time + epoch_duration.min_duration); - assert_eq!(storage.block.pred_epochs.get_epoch(block_height), Some(epoch_before.next())); + assert_eq!(storage.block.pred_epochs.get_epoch(block_height), Some(epoch_before)); + assert_eq!(storage.block.pred_epochs.get_epoch(block_height + 1), Some(epoch_before.next())); } else { assert_eq!(storage.block.epoch, epoch_before); assert_eq!(storage.block.pred_epochs.get_epoch(block_height), Some(epoch_before)); + assert_eq!(storage.block.pred_epochs.get_epoch(block_height + 1), Some(epoch_before)); } // Last epoch should only change when the block is committed assert_eq!(storage.last_epoch, epoch_before); From 388a69d6ef4410a11e2e5ca354c704b179649f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 25 Aug 2022 12:54:30 +0200 Subject: [PATCH 5/5] changelog: add #384 --- .../unreleased/bug-fixes/384-fix-new-epoch-start-height.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/384-fix-new-epoch-start-height.md diff --git a/.changelog/unreleased/bug-fixes/384-fix-new-epoch-start-height.md b/.changelog/unreleased/bug-fixes/384-fix-new-epoch-start-height.md new file mode 100644 index 0000000000..cf2bb8f399 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/384-fix-new-epoch-start-height.md @@ -0,0 +1,2 @@ +- Fix the value recorded for epoch start block height. + ([#384](https://github.com/anoma/namada/issues/384)) \ No newline at end of file