-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtimepoint.rs
36 lines (34 loc) · 1.36 KB
/
timepoint.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use gw_config::ForkConfig;
use gw_types::core::Timepoint;
use gw_types::packed::RollupConfig;
use gw_types::prelude::*;
pub fn block_timepoint(
rollup_config: &RollupConfig,
fork_config: &ForkConfig,
block_number: u64,
block_timestamp: u64,
) -> Timepoint {
if fork_config.use_timestamp_as_timepoint(block_number) {
// block.timepoint is in new form, represents the future finalized timestamp
let finality_time_in_ms = rollup_config.finality_time_in_ms();
Timepoint::from_timestamp(block_timestamp + finality_time_in_ms)
} else {
// block.timepoint is in legacy form, represents the its block number
Timepoint::from_block_number(block_number)
}
}
pub fn global_state_finalized_timepoint(
rollup_config: &RollupConfig,
fork_config: &ForkConfig,
block_number: u64,
block_timestamp: u64,
) -> Timepoint {
if fork_config.use_timestamp_as_timepoint(block_number) {
// GlobalState.last_finalized_timepoint is in new form, represents the current timestamp
Timepoint::from_timestamp(block_timestamp)
} else {
// GlobalState.last_finalized_timepoint is in legacy form, represents the already finalized block number
let finality_as_blocks = rollup_config.finality_blocks().unpack();
Timepoint::from_block_number(block_number.saturating_sub(finality_as_blocks))
}
}