Skip to content

fix(mining): Fix block template not checking for MAX_FUTURE_TIMESTAMP_ALLOWED #822

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

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

msbrogli
Copy link
Member

@msbrogli msbrogli commented Oct 20, 2023

Background

Some flaky tests using simulator were failing with the following error: hathor.exception.InvalidNewTransaction: Ignoring transaction in the future.

Why?

Because a miner was trying to push a block with a timestamp set too far in the future.

Why?

Because HathorManager.generate_mining_block() was returning a block template with an invalid timestamp.

Why?

After a chain of calls started by Hathor.generate_mining_block(), the method _make_block_template() was called. This method was not taking into consideration the MAX_FUTURE_TIMESTAMP_ALLOWED when calculating the maximum allowed timestamp.

Acceptance criteria

  1. Add the following exceptions: BlockTemplateError and BlockTemplateTimestampError.
  2. Fix HathorManager._make_block_template() to take MAX_FUTURE_TIMESTAMP_ALLOWED into consideration when calculating max_timestamp.
  3. Adjust hathor.simulator.GeometricMiner to handle the BlockTemplateTimestampError trying again in 5 seconds.

@msbrogli msbrogli added the bug Something isn't working label Oct 20, 2023
@msbrogli msbrogli self-assigned this Oct 20, 2023
@msbrogli msbrogli requested a review from jansegre as a code owner October 20, 2023 16:20
@msbrogli msbrogli requested a review from glevco October 20, 2023 16:22
glevco
glevco previously approved these changes Oct 20, 2023
jansegre
jansegre previously approved these changes Oct 20, 2023
@msbrogli msbrogli dismissed stale reviews from jansegre and glevco via 8b6322a October 20, 2023 17:53
@msbrogli msbrogli force-pushed the fix/block-template-timestamp branch from ee9e155 to 8b6322a Compare October 20, 2023 17:53
@msbrogli msbrogli force-pushed the fix/block-template-timestamp branch from 8b6322a to 4adb93f Compare October 20, 2023 18:01
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (613d0ac) 84.58% compared to head (4adb93f) 84.54%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #822      +/-   ##
==========================================
- Coverage   84.58%   84.54%   -0.05%     
==========================================
  Files         269      269              
  Lines       22223    22234      +11     
  Branches     3398     3399       +1     
==========================================
  Hits        18797    18797              
- Misses       2759     2766       +7     
- Partials      667      671       +4     
Files Coverage Δ
hathor/exception.py 100.00% <100.00%> (ø)
hathor/manager.py 80.73% <33.33%> (-0.22%) ⬇️
hathor/simulator/miner/geometric_miner.py 97.14% <80.00%> (-2.86%) ⬇️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@msbrogli msbrogli merged commit 4adb93f into master Oct 20, 2023
@msbrogli msbrogli deleted the fix/block-template-timestamp branch October 20, 2023 18:55
@jansegre jansegre mentioned this pull request Nov 13, 2023
2 tasks
This was referenced Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants