Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vesting file (old timestamp) #3654

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,18 +1441,18 @@ impl ExecutionState {
})?;

let get_slot_at_timestamp = |config: &ExecutionConfig, timestamp: MassaTime| {
match massa_models::timeslots::get_latest_block_slot_at_timestamp(
massa_models::timeslots::get_latest_block_slot_at_timestamp(
config.thread_count,
config.t0,
config.genesis_timestamp,
timestamp,
) {
Ok(opts) => Ok(opts.unwrap()),
Err(_) => Err(ExecutionError::InitVestingError(format!(
"can no get the slot at timestamp : {}",
timestamp
))),
}
)
.map_err(|e| {
ExecutionError::InitVestingError(format!(
"can no get the slot at timestamp {} : {}",
timestamp, e
))
})
};

for v in hashmap.values_mut() {
Expand All @@ -1470,16 +1470,25 @@ impl ExecutionState {
if prev.timestamp.eq(&MassaTime::from(0)) {
// first range with timestamp = 0
prev.start_slot = Slot::min();
} else {
prev.start_slot = get_slot_at_timestamp(config, prev.timestamp)?;
} else if let Some(slot) = get_slot_at_timestamp(config, prev.timestamp)? {
prev.start_slot = slot;
}

// retrieve the end_slot
let next_range_slot = get_slot_at_timestamp(config, next.timestamp)?;
prev.end_slot = next_range_slot.get_prev_slot(config.thread_count)?;
if let Some(next_range_slot) =
get_slot_at_timestamp(config, next.timestamp)?
{
prev.end_slot = next_range_slot.get_prev_slot(config.thread_count)?;
}

Ok(prev)
})
// we don't need range with StartSlot(0,0) && EndSlot(0,0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the range with the start timestamp at genesis otherwise from genesis to X there is no vesting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we have it, my filter is && not ||.

Here we don't want vesting range with start_slot(0,0) and end_slot(0,0).
This happens when the timestamp in vesting_file is passed for the first launch of BC. There is no block at the timestamp.

So the next range (and the first in the map) has start_slot(0,0) and end_slot(Slot valide timestamp).

Sorry if i don't explain well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

// this can happen when the timestamp is passed
.filter(|a| {
!(a.as_ref().unwrap().end_slot == Slot::min()
&& a.as_ref().unwrap().start_slot == Slot::min())
})
.collect::<Result<Vec<VestingRange>, ExecutionError>>()?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-worker/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn get_initials_vesting(with_value: bool) -> NamedTempFile {
let vesting1 = VestingRange {
start_slot: Slot::min(),
end_slot: Slot::min(),
timestamp: MassaTime::from(0),
timestamp: MassaTime::from(1678126410000),
min_balance: Amount::from_str("200000").unwrap(),
max_rolls: 150,
};
Expand Down