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

We are using Instant::now() and Tai64::now() directly in the block producer, rather than having some time interface #2091

Closed
MitchTurner opened this issue Aug 15, 2024 · 2 comments · Fixed by #2145
Assignees

Comments

@MitchTurner
Copy link
Member

Time is unreliable IO. We should be able to isolate an manipulate it using a fake/mock rather than being dependent on the system clock.

    fn extract_block_info(last_block: &BlockHeader) -> (BlockHeight, Tai64, Instant) {
        let last_timestamp = last_block.time();
        let duration_since_last_block =
            Duration::from_secs(Tai64::now().0.saturating_sub(last_timestamp.0));
        let last_block_created = Instant::now()
            .checked_sub(duration_since_last_block)
            .unwrap_or(Instant::now());
        let last_height = *last_block.height();
        (last_height, last_timestamp, last_block_created)
    }
@MitchTurner
Copy link
Member Author

It seems like we have introduced unnecessary complexity into the code to accommodate manual block production, where we should be able to just advance fake time in our tests.

@netrome
Copy link
Contributor

netrome commented Aug 27, 2024

Note, the provided code snippet is from the PoA consensus provider (crates/services/consensus_module/poa/src/service.rs) and not the block producer (crates/services/producer/src/block_producer.rs). The block producer only seems to have this problem for the dry_run functionality, and takes the time as input in all other cases, so I will focus on doing this for the consensus provider.

@netrome netrome linked a pull request Aug 30, 2024 that will close this issue
2 tasks
@netrome netrome closed this as completed in d5ba082 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants