0

I have a program as follows:

  • Some state is initialized with a start_time
  • Another instruction can be executed on that state, but only if the clock sysvar has passed the given start_time

In my tests (using solana_program_test and the banks_client) I've tried the following:

This solution loops forever:

    loop {
        let clock: Clock = banks_client.get_sysvar().await.unwrap();
        if clock.unix_timestamp > data.start_time {
            break;
        }
        std::thread::sleep(std::time::Duration::from_secs(1));
    }

If I manually sleep for the required time, I get an error in the program that makes it seem as though the clock sysvar hasn't moved forward i.e:

    std::thread::sleep(std::time::Duration::from_secs((data.start_time - clock.unix_timestamp) as u64));

Produces this:

[2022-07-18T14:17:20.530662358Z DEBUG solana_runtime::message_processor::stable_log] Program log: 5 seconds until vend starts...
[2022-07-18T14:17:20.531179736Z DEBUG solana_runtime::message_processor::stable_log] Program log: Vend hasn't started yet

This is where start time was initially set to clock.unix_timestamp + 5.

My question is:

  • Does the banks client move the clock forward? If so, when/how?
  • Is it possible to write to the clock sysvar and change the time?

Thanks!

1 Answer 1

1

I think you're blocking the async executor with std::thread::sleep(). Try tokio::time:sleep() instead

1
  • Thanks, but same result as the original post with tokio::time::sleep() - still looks like the clock isn't moving.
    – oscarb.sol
    Commented Jul 19, 2022 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.