Skip to content

Commit

Permalink
core/storage/epochs: Change pred Epochs default to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Oct 18, 2023
1 parent 6a046bb commit 6fb1984
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ mod tests {
.expect("write failed");

storage.block.epoch = storage.block.epoch.next();
storage.block.pred_epochs.new_epoch(new_epoch_start);
let batch = PersistentStorage::batch();
storage.commit_block(batch).expect("commit failed");

Expand Down
8 changes: 6 additions & 2 deletions core/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,6 @@ where
} = parameters.epoch_duration;
self.next_epoch_min_start_height = initial_height + min_num_of_blocks;
self.next_epoch_min_start_time = genesis_time + min_duration;
// The default start height in `Epochs` is set to 1, we override it
// here in case it differs at genesis
self.block.pred_epochs = Epochs {
first_block_heights: vec![initial_height],
};
Expand Down Expand Up @@ -1302,6 +1300,12 @@ mod tests {
minimum_gas_price: BTreeMap::default(),
};
parameters.init_storage(&mut wl_storage).unwrap();
// Initialize pred_epochs to the current height
wl_storage
.storage
.block
.pred_epochs
.new_epoch(wl_storage.storage.block.height);

let epoch_before = wl_storage.storage.last_epoch;
assert_eq!(epoch_before, wl_storage.storage.block.epoch);
Expand Down
14 changes: 4 additions & 10 deletions core/src/types/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ impl Mul for Epoch {
#[derive(
Clone,
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Expand All @@ -1178,15 +1179,6 @@ pub struct Epochs {
/// Invariant: the values must be sorted in ascending order.
pub first_block_heights: Vec<BlockHeight>,
}
impl Default for Epochs {
/// Initialize predecessor epochs, assuming start of the first epoch at
/// block height 1.
fn default() -> Self {
Self {
first_block_heights: vec![BlockHeight(1)],
}
}
}

impl Epochs {
/// Record start of a new epoch at the given block height
Expand Down Expand Up @@ -1630,7 +1622,9 @@ mod tests {

#[test]
fn test_predecessor_epochs_and_heights() {
let mut epochs = Epochs::default();
let mut epochs = Epochs {
first_block_heights: vec![BlockHeight::first()],
};
println!("epochs {:#?}", epochs);
assert_eq!(
epochs.get_start_height_of_epoch(Epoch(0)),
Expand Down
6 changes: 6 additions & 0 deletions ethereum_bridge/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ pub fn init_storage_with_validators(
.write(&protocol_pk_key(validator), protocol_key)
.expect("Test failed");
}
// Initialize pred_epochs to the current height
wl_storage
.storage
.block
.pred_epochs
.new_epoch(wl_storage.storage.block.height);
wl_storage.commit_block().expect("Test failed");

all_keys
Expand Down

0 comments on commit 6fb1984

Please sign in to comment.