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

Correct Bank timestamp drift every slot #12737

Merged

Conversation

CriesofCarrots
Copy link
Contributor

@CriesofCarrots CriesofCarrots commented Oct 8, 2020

Problem

The timestamp returned by Bank::unix_timestamp() ends up in the clock sysvar and is used to assess time-based stake account lockouts. However it's based on a theoretical slots-per-second instead of reality, so it's quite inaccurate. This will pose a problem for lockups, since the accounts will not register as lockup-free on (or anytime near) the date the lockup is set to expire.

Block times are estimated using a validator timestamp oracle; this data provides an opportunity to align the bank timestamp more closely with real-world time.

Summary of Changes

  • Adjust Bank::update_clock to set the Clock sysvar timestamp to the stake-weighted timestamp estimate if it is greater than the unix_timestamp from genesis; feature-gated

This adds 50us to each Bank::new_from_parent(), which was not distinguishable in confirmation-time or other metrics on a testnet under moderate TPS load.

Fixes #9874
Toward #10093 (but requires some additional handling to update Bank::slots_per_year)

@codecov
Copy link

codecov bot commented Oct 8, 2020

Codecov Report

Merging #12737 into master will increase coverage by 0.0%.
The diff coverage is 99.1%.

@@           Coverage Diff            @@
##           master   #12737    +/-   ##
========================================
  Coverage    81.9%    81.9%            
========================================
  Files         359      360     +1     
  Lines       84547    84686   +139     
========================================
+ Hits        69277    69412   +135     
- Misses      15270    15274     +4     

@CriesofCarrots CriesofCarrots marked this pull request as ready for review October 8, 2020 22:27
Copy link
Contributor

@garious garious left a comment

Choose a reason for hiding this comment

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

Looks about right

sdk/src/stake_weighted_timestamp.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Outdated Show resolved Hide resolved
runtime/src/bank.rs Show resolved Hide resolved
@mvines mvines added the v1.4 label Oct 9, 2020
mvines
mvines previously approved these changes Oct 9, 2020
Copy link
Member

@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.

Pretty simple, I like it

garious
garious previously approved these changes Oct 9, 2020
@mergify mergify bot dismissed stale reviews from mvines and garious October 9, 2020 16:30

Pull request has been modified.

@CriesofCarrots CriesofCarrots added the automerge Merge this Pull Request automatically once CI passes label Oct 9, 2020
@CriesofCarrots
Copy link
Contributor Author

Oh #12742 💔

@CriesofCarrots CriesofCarrots removed the automerge Merge this Pull Request automatically once CI passes label Oct 9, 2020
@CriesofCarrots CriesofCarrots added the automerge Merge this Pull Request automatically once CI passes label Oct 9, 2020
@mergify mergify bot merged commit b028c47 into solana-labs:master Oct 9, 2020
mergify bot pushed a commit that referenced this pull request Oct 9, 2020
* Move timestamp helper to sdk

* Add Bank method for getting timestamp estimate

* Return sysvar info from Bank::clock

* Add feature-gated timestamp correction

* Rename unix_timestamp method to be more descriptive

* Review comments

* Add timestamp metric

(cherry picked from commit b028c47)

# Conflicts:
#	runtime/src/feature_set.rs
CriesofCarrots added a commit that referenced this pull request Oct 9, 2020
* Move timestamp helper to sdk

* Add Bank method for getting timestamp estimate

* Return sysvar info from Bank::clock

* Add feature-gated timestamp correction

* Rename unix_timestamp method to be more descriptive

* Review comments

* Add timestamp metric

(cherry picked from commit b028c47)

# Conflicts:
#	runtime/src/feature_set.rs
mergify bot added a commit that referenced this pull request Oct 10, 2020
* Move timestamp helper to sdk

* Add Bank method for getting timestamp estimate

* Return sysvar info from Bank::clock

* Add feature-gated timestamp correction

* Rename unix_timestamp method to be more descriptive

* Review comments

* Add timestamp metric

(cherry picked from commit b028c47)

# Conflicts:
#	runtime/src/feature_set.rs

Co-authored-by: Tyera Eulberg <[email protected]>
@CriesofCarrots CriesofCarrots deleted the correct-every-bank-timestamp branch October 21, 2020 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correct bank::unix_timestamp() drift
3 participants