Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Add getBlockTime rpc api #7130

Merged
merged 7 commits into from
Nov 26, 2019

Conversation

CriesofCarrots
Copy link
Contributor

Problem

It's strongly desired by some users to have a network-controlled best effort timestamp associated with the production time of each block.
Solana does not offer any RPC apis that return this information.

Summary of Changes

  • Adds getBlockTime method to rpc
  • Plumbs back to blocktree; returns dummy results, where the last median time is always timestamp 0

Toward #7115 (Steps 1 & part of 2)

mvines
mvines previously approved these changes Nov 25, 2019
Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, plumbing looks great. Sneak in a cli/ command for this too? solana get-block-time <SLOT>?

@codecov
Copy link

codecov bot commented Nov 25, 2019

Codecov Report

Merging #7130 into master will decrease coverage by 2.2%.
The diff coverage is 60%.

@@           Coverage Diff            @@
##           master   #7130     +/-   ##
========================================
- Coverage      72%   69.8%   -2.3%     
========================================
  Files         230     230             
  Lines       49393   51123   +1730     
========================================
+ Hits        35576   35697    +121     
- Misses      13817   15426   +1609

@mvines mvines added the v0.21 label Nov 26, 2019
@mergify mergify bot dismissed mvines’s stale review November 26, 2019 04:37

Pull request has been modified.

@CriesofCarrots
Copy link
Contributor Author

@mvines , do you mind taking a look at the changes I made to PohConfig::default and genesis::main?
There was some really unfortunate rounding due to use of Duration::from_millis() on our particular clock defaults (which meant I could never get slot_duration = 400ms from slots_per_year). Since we are stashing a Duration anyway, I saw no reason not to use Duration::from_micros().

Copy link
Contributor

@mvines mvines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some really unfortunate rounding due to use of Duration::from_millis() on our particular clock defaults (which meant I could never get slot_duration = 400ms from slots_per_year).

What duration where you getting? Just curious

Since we are stashing a Duration anyway, I saw no reason not to use Duration::from_micros().

It feels a little weird to be using such a small unit (micro seconds) on the solana-genesis command-line, wdyt about keeping --target-tick-duration as ms and converting to μs internally

@CriesofCarrots
Copy link
Contributor Author

What duration where you getting? Just curious

384ms (1000/64 rounds to 6, instead of 6.25)

It feels a little weird to be using such a small unit (micro seconds) on the solana-genesis command-line, wdyt about keeping --target-tick-duration as ms and converting to μs internally

👌

@CriesofCarrots CriesofCarrots force-pushed the get-block-time branch 4 times, most recently from 663d0f6 to 2d8096d Compare November 26, 2019 05:27
@CriesofCarrots CriesofCarrots merged commit 58c144e into solana-labs:master Nov 26, 2019
mergify bot pushed a commit that referenced this pull request Nov 26, 2019
* Add getBlockTime rpc api

* Add getBlockTime to docs

* Fix duration rounding for common tick/slot durations; add slot duration calculation

* Expose slots_per_year

* Use genesis values instead of clock defaults to calculate block offset

* Add get-block-time cli subcommand

* Fix test_rent: decrease magic number usage

(cherry picked from commit 58c144e)
solana-grimes pushed a commit that referenced this pull request Nov 26, 2019
@CriesofCarrots CriesofCarrots deleted the get-block-time branch January 15, 2020 01:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants