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(consensus): Change meta.score and meta.accumulated_weight to int type #572

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

msbrogli
Copy link
Member

@msbrogli msbrogli commented Apr 27, 2023

Motivation

The metadata accumulated_weight and score are calculated summing up the vertices' weight. Even though both metadata can be integer numbers, they are calculated as the logarithm of their integer value. This might lead to minor issues caused by precision error. We currently use the calculate_min_significant_weight() to prevent precision error on mining activity.

This PR converts both metadata to integer values, simplifying parts of the code that had to take float precision into consideration.

Acceptance criteria

  1. Change meta.score and meta.accumulated_weight to type int.
  2. Change the calculation of meta.score to use weight_to_work().
  3. Change the calculation of meta.accumulated_weight to use weight_to_work().
  4. Change the consensus algorithm to do direct comparisons (instead of comparisons using WEIGHT_TOL).
  5. Replace sum_weights(a, b) to weight_to_work(a) + weight_to_work(b).
  6. Replace sum_weights(score, a) to score + weight_to_work(a).
  7. Replace sum_weights(accumulated_weight, a) to accumulated_weight + weight_to_work(a).
  8. Remove sum_weights().
  9. Serialize meta.score and meta.accumulated_weight as strings to prevent precision issues with JSON parsers.

@msbrogli msbrogli added the enhancement New feature or request label Apr 27, 2023
@msbrogli msbrogli requested a review from jansegre as a code owner April 27, 2023 02:26
@msbrogli msbrogli self-assigned this Apr 27, 2023
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch 4 times, most recently from 265afc8 to 65ccfdd Compare April 27, 2023 04:49
@msbrogli msbrogli changed the base branch from master to refactor/consensus-multiple-files April 27, 2023 04:49
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch from 65ccfdd to 21acfdb Compare April 27, 2023 05:03
@msbrogli msbrogli force-pushed the refactor/consensus-multiple-files branch from 69098cf to fd2bf10 Compare April 27, 2023 05:04
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch 5 times, most recently from 1b625ad to 12084a4 Compare April 27, 2023 17:56
@msbrogli msbrogli force-pushed the refactor/consensus-multiple-files branch 2 times, most recently from 0bf14d9 to 86ce84c Compare April 27, 2023 18:08
Base automatically changed from refactor/consensus-multiple-files to master April 27, 2023 18:41
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch 5 times, most recently from a48df48 to 83760be Compare April 27, 2023 21:06
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch 3 times, most recently from 289dc7f to b0d8f5c Compare June 13, 2023 18:58
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch from b0d8f5c to 81b60c9 Compare June 15, 2023 15:30
@msbrogli msbrogli force-pushed the feat/score-acc-weight-types branch 3 times, most recently from 8e4ecfe to 464fb5b Compare November 11, 2023 06:08
@glevco glevco force-pushed the refactor/metadata/migrate-static-metadata-2 branch 4 times, most recently from fcbcac1 to 701b787 Compare August 22, 2024 16:35
Base automatically changed from refactor/metadata/migrate-static-metadata-2 to master August 22, 2024 17:30
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from 93d9f89 to da4ac0d Compare August 22, 2024 21:45
Copy link

github-actions bot commented Aug 22, 2024

🐰 Bencher Report

Branchfeat/score-acc-weight-types
Testbedubuntu-22.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Lower Boundary
nanoseconds (ns)
(Limit %)
Upper Boundary
nanoseconds (ns)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
101,412,264,859.14
(-0.43%)
91,669,666,935.48
(90.39%)
112,040,704,032.25
(90.51%)
🐰 View full continuous benchmarking report in Bencher

@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from da4ac0d to b74fa0d Compare September 3, 2024 15:44
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from b74fa0d to 45884e3 Compare September 10, 2024 16:05
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from 45884e3 to b21d67c Compare September 24, 2024 14:30
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from b21d67c to 2f2d7a8 Compare October 3, 2024 21:40
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from 2f2d7a8 to 1a3e1d0 Compare October 3, 2024 21:51
@jansegre jansegre mentioned this pull request Oct 4, 2024
2 tasks
glevco
glevco previously approved these changes Oct 4, 2024
hathor/utils/weight.py Show resolved Hide resolved
hathor/transaction/base_transaction.py Show resolved Hide resolved
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch 2 times, most recently from 4a182f4 to d870605 Compare October 8, 2024 13:54
@glevco glevco mentioned this pull request Oct 8, 2024
1 task
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch 2 times, most recently from fb35bfb to 17eac7c Compare October 18, 2024 16:38
… type

Co-authored-by: Jan Segre <jan@hathor.network>
@jansegre jansegre force-pushed the feat/score-acc-weight-types branch from 17eac7c to 26a36c0 Compare October 23, 2024 12:54
Copy link
Member Author

@msbrogli msbrogli left a comment

Choose a reason for hiding this comment

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

Approved!

@jansegre
Copy link
Member

Just as a report, last night I synced a node from scratch using this branch, it synced correctly up to the same block as the network, and this is a comparison of the score of the best block (which accumulates tiny errors in the current release):

# my node
❯ curl localhost:9080/v1a/transaction\?id=0000000000000000046147a92a42b4e2f50ef587ecb17775efda3628150f2c32 -s | jq .meta.score
88.71139817081715
# public node
❯ curl https://node2.mainnet.hathor.network/v1a/transaction\?id=0000000000000000046147a92a42b4e2f50ef587ecb17775efda3628150f2c32 -s | jq .meta.score
88.71139817083098

Even after the tiny accumulated errors the difference is currently minimal. I'm going forward with the merge.

@jansegre jansegre merged commit 5586f8d into master Oct 24, 2024
11 of 13 checks passed
@jansegre jansegre deleted the feat/score-acc-weight-types branch October 24, 2024 16:41
@jansegre jansegre mentioned this pull request Dec 11, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants