Skip to content

Commit

Permalink
Merge remote-tracking branch 'namada/tomas/fix-pred-epoch-height' (#594)
Browse files Browse the repository at this point in the history
* namada/tomas/fix-pred-epoch-height:
  changelog: add #594
  shared/storage: fix the height recorded for a new epoch
  • Loading branch information
juped committed Oct 14, 2022
2 parents 6993966 + 2fa19cd commit c5be5ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/594-fix-pred-epoch-height.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix the value recorded for epoch start block height.
([#594](https://github.com/anoma/namada/pull/594))
18 changes: 13 additions & 5 deletions shared/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ where
let evidence_max_age_num_blocks: u64 = 100000;
self.block
.pred_epochs
.new_epoch(height + 1, evidence_max_age_num_blocks);
.new_epoch(height, evidence_max_age_num_blocks);
tracing::info!("Began a new epoch {}", self.block.epoch);
}
self.update_epoch_in_merkle_tree()?;
Expand Down Expand Up @@ -992,12 +992,20 @@ 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));
assert_eq!(storage.block.pred_epochs.get_epoch(block_height + 1), Some(epoch_before.next()));
assert_eq!(
storage.block.pred_epochs.get_epoch(BlockHeight(block_height.0 - 1)),
Some(epoch_before));
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.block.pred_epochs.get_epoch(block_height), Some(epoch_before));
assert_eq!(storage.block.pred_epochs.get_epoch(block_height + 1), Some(epoch_before));
assert_eq!(
storage.block.pred_epochs.get_epoch(BlockHeight(block_height.0 - 1)),
Some(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);
Expand Down

0 comments on commit c5be5ca

Please sign in to comment.