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

Hook up getBlockTime rpc to real data #7476

Merged
merged 4 commits into from
Dec 14, 2019

Conversation

CriesofCarrots
Copy link
Contributor

@CriesofCarrots CriesofCarrots commented Dec 13, 2019

Problem

Users have no way to know when a Solana block was produced in real-world time.
Validators are now including intermittent timestamps in their votes, but JSON RPC is not using that data to return an estimated block time.

Summary of Changes

Adds blocktree apis to return real block time data. The get_block_time method does the following:

  1. Checks to see if requested block is a root.
    Only rooted slots have static block times.
  2. Gets base slot to use to look for timestamp transactions.
    If the requested block is right after genesis, uses slot 0 as the base slot. Else if the requested block is after one or more TIMESTAMP_SLOT_INTERVALs, uses as base slot the most recent TIMESTAMP_SLOT_INTERVAL or (if that slot is not seen/rooted on the fork) the oldest subsequent slot. (If there are not "enough" slots between the base slot and the requested block, uses the previous TIMESTAMP_SLOT_INTERVAL or oldest subsequent slot as the base slot. See Research PoS implementations #3 for what constitutes enough.)
  3. Checks base slot and some following slots for timestamp Vote transactions.
    The number of slots to check is set in TIMESTAMP_SLOT_RANGE, and currently set to 5 slots. This is pretty arbitrary. This setting gives validators 2sec-worth of slots to get their timestamp in. This seems fairly luxurious, but if votes are taking multiple slots to process on the cluster, this might need to be tuned.
  4. Determines slot offset duration between timestamp Votes and requested block, and cross-references timestamp Votes with epoch_vote_accounts to calculate the stake-weighted mean timestamp for the block

Fixes #7115

@codecov
Copy link

codecov bot commented Dec 14, 2019

Codecov Report

Merging #7476 into master will decrease coverage by 14.4%.
The diff coverage is 73.2%.

@@            Coverage Diff            @@
##           master   #7476      +/-   ##
=========================================
- Coverage    80.7%   66.3%   -14.5%     
=========================================
  Files         244     245       +1     
  Lines       48920   59655   +10735     
=========================================
+ Hits        39499   39562      +63     
- Misses       9421   20093   +10672

mvines
mvines previously approved these changes Dec 14, 2019
ledger/src/blocktree.rs Outdated Show resolved Hide resolved
ledger/src/blocktree.rs Outdated Show resolved Hide resolved
@mergify mergify bot dismissed mvines’s stale review December 14, 2019 18:42

Pull request has been modified.

@CriesofCarrots CriesofCarrots merged commit 6b88da2 into solana-labs:master Dec 14, 2019
@CriesofCarrots CriesofCarrots deleted the timestamps branch January 15, 2020 00:59
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 this pull request may close these issues.

Add getBlockTime RPC API
2 participants