fixed time conversion

This commit is contained in:
alessandrokonrad
2022-09-24 23:59:58 +02:00
parent 3eb4fb7523
commit 35d09c642b
6 changed files with 23 additions and 4 deletions

View File

@@ -68,12 +68,13 @@ pub fn eval_phase_two(
/// This function is the same as [`eval_phase_two`]
/// but the inputs are raw bytes.
/// initial_budget expects (cpu, mem).
/// slot_config (zero_time, zero_slot, slot_length)
pub fn eval_phase_two_raw(
tx_bytes: &[u8],
utxos_bytes: &[(Vec<u8>, Vec<u8>)],
cost_mdls_bytes: &[u8],
initial_budget: (u64, u64),
slot_config: (u64, u64),
slot_config: (u64, u64, u64),
run_phase_one: bool,
) -> Result<Vec<Vec<u8>>, Error> {
let multi_era_tx = MultiEraTx::decode(Era::Babbage, tx_bytes)
@@ -97,7 +98,8 @@ pub fn eval_phase_two_raw(
let sc = SlotConfig {
zero_time: slot_config.0,
slot_length: slot_config.1,
zero_slot: slot_config.1,
slot_length: slot_config.2,
};
match multi_era_tx {

View File

@@ -24,7 +24,7 @@ use super::{
};
fn slot_to_begin_posix_time(slot: u64, sc: &SlotConfig) -> u64 {
let ms_after_begin = slot * sc.slot_length;
let ms_after_begin = (slot - sc.zero_slot) * sc.slot_length;
sc.zero_time + ms_after_begin
}

View File

@@ -84,6 +84,7 @@ pub struct TimeRange {
pub struct SlotConfig {
pub slot_length: u64,
pub zero_slot: u64,
pub zero_time: u64,
}
@@ -91,7 +92,8 @@ impl Default for SlotConfig {
fn default() -> Self {
Self {
slot_length: 1000,
zero_time: 1596491091,
zero_slot: 4492800,
zero_time: 1596059091000,
}
}
}

View File

@@ -42,6 +42,7 @@ fn test_eval() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -292,6 +293,7 @@ fn test_eval_1() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -561,6 +563,7 @@ fn test_eval_2() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -659,6 +662,7 @@ fn test_eval_3() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -925,6 +929,7 @@ fn test_eval_4() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -1006,6 +1011,7 @@ fn test_eval_5() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -1108,6 +1114,7 @@ fn test_eval_6() {
let slot_config = SlotConfig {
zero_time: 1596059091000, // Mainnet network
zero_slot: 4492800,
slot_length: 1000,
};
@@ -1211,6 +1218,7 @@ fn test_eval_7() {
let slot_config = SlotConfig {
zero_time: 1596059091000, // Mainnet network
zero_slot: 4492800,
slot_length: 1000,
};
@@ -1301,6 +1309,7 @@ fn test_eval_8() {
let slot_config = SlotConfig {
zero_time: 1596059091000, // Mainnet network
zero_slot: 4492800,
slot_length: 1000,
};
@@ -1564,6 +1573,7 @@ fn eval_missing_redeemer() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};
@@ -1642,6 +1652,7 @@ fn eval_extraneous_redeemer() {
let slot_config = SlotConfig {
zero_time: 1660003200000, // Preview network
zero_slot: 0,
slot_length: 1000,
};