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

feat(anvil): add getLastBlockWallTime debug RPC method #8217

Open
Tracked by #8269
transmissions11 opened this issue Jun 20, 2024 · 2 comments
Open
Tracked by #8269

feat(anvil): add getLastBlockWallTime debug RPC method #8217

transmissions11 opened this issue Jun 20, 2024 · 2 comments
Assignees
Labels
C-anvil Command: anvil T-feature Type: feature

Comments

@transmissions11
Copy link
Contributor

transmissions11 commented Jun 20, 2024

Component

Anvil

Describe the feature you would like

To sync clocks effectively for real-time games, it would be really helpful to be able to get the unix wall time in ms when the last block was created. What I've been doing up until now is start anvil with a script like this:

function checkTimestamp() {
  const timestamp = Date.now();
  if ((timestamp + 25) % 1000 === 0) {
    console.log(`Timestamp ${timestamp} is divisible by 1000.`);
    process.exit(0); // Stop the program
  } else {
    setImmediate(checkTimestamp);
  }
}

console.log("Waiting for a timestamp divisible by 1000...");
checkTimestamp();

// startup anvil

But the interval between anvil's blocks sometimes drifts a little, resulting in timestamps drifting backwards or ahead of real time. Having an rpc method to get the exact offset would allow clients to adjust to any minor timestamp offset without the need for anvil to robustly sync to wall time.

Additional context

No response

@transmissions11 transmissions11 added the T-feature Type: feature label Jun 20, 2024
@transmissions11 transmissions11 changed the title request; getLastBlockWallTime debug rpc method request: getLastBlockWallTime debug rpc method Jun 20, 2024
@ktarun1419
Copy link

Hi @transmissions11 i want to work on this one

@zerosnacks zerosnacks added the C-anvil Command: anvil label Jun 27, 2024
@zerosnacks zerosnacks changed the title request: getLastBlockWallTime debug rpc method feat(anvil): add getLastBlockWallTime debug RPC method Jul 16, 2024
@zerosnacks
Copy link
Member

Looks like this could be added relatively easy in https://github.com/foundry-rs/foundry/pull/8010/files (cc @yash-atreya) once the implementation is finished

@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil T-feature Type: feature
Projects
Status: Todo
Development

No branches or pull requests

5 participants