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

[Merged by Bors] - vm, api: add smesherID to rewards #5199

Closed
wants to merge 42 commits into from

Conversation

lrettig
Copy link
Member

@lrettig lrettig commented Oct 25, 2023

Motivation

See #4863

Based on #4850

Closes #4529
Closes #4850
Closes #4863
Closes #4964
Closes #5183

Changes

  • Refactors rewards table. Adds smesherID column, migrates data. Does not update old data (smesherID will be NULL for old data, unless resynced).
  • Updates database queries.
  • Returns smesherID in all API queries

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

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

Comparison is base (3ae2bf3) 77.5% compared to head (190ac14) 77.5%.

Files Patch % Lines
sql/rewards/rewards.go 82.0% 8 Missing and 1 partial ⚠️
mesh/mesh.go 0.0% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #5199   +/-   ##
=======================================
  Coverage     77.5%   77.5%           
=======================================
  Files          253     252    -1     
  Lines        29641   29650    +9     
=======================================
+ Hits         22972   22983   +11     
- Misses        5208    5209    +1     
+ Partials      1461    1458    -3     

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

@lrettig lrettig marked this pull request as ready for review November 9, 2023 20:38
genvm/vm_test.go Outdated Show resolved Hide resolved
sql/migrations/state/0007_next.sql Outdated Show resolved Hide resolved
sql/rewards/rewards.go Show resolved Hide resolved
genvm/vm.go Outdated Show resolved Hide resolved
sql/rewards/rewards.go Outdated Show resolved Hide resolved
@dshulyak dshulyak changed the title Add smesherID to rewards vm, api: add smesherID to rewards Nov 14, 2023
Drop "WITHOUT ROWID" to prevent NOT NULL error on new primary key
column.
@lrettig
Copy link
Member Author

lrettig commented Nov 16, 2023

@fasmat @dshulyak please take a look at the latest commit: 1595ea9

I had to remove the WITHOUT ROWID from the new rewards table definition to allow the migration of the old data, since it obviously doesn't have pubkey data (and this column is part of the primary key). This is a constraint on sqlite. Do we have concerns that this might impact performance?

sql/database.go Outdated Show resolved Hide resolved
@fasmat
Copy link
Member

fasmat commented Nov 23, 2023

@fasmat @dshulyak please take a look at the latest commit: 1595ea9

I had to remove the WITHOUT ROWID from the new rewards table definition to allow the migration of the old data, since it obviously doesn't have pubkey data (and this column is part of the primary key). This is a constraint on sqlite. Do we have concerns that this might impact performance?

I think this will add 8 bytes per row that are persisted in the DB but not really needed even at ~ 1 mio entries we have for that table that's probably negligible since the PR also adds 32 bytes for the smesher ID. I don't think queries are slower with a Row ID, so I'd be OK with the change.

@dshulyak
Copy link
Contributor

what it does is that you have to query 2 b-trees instead of one. so if you have small unique key it is always better to have one b-tree. i can't tell without measuring, but generally single tree will be much better for range queries that hit that exact primary index (for example all rewards from smesher X, or all rewards inbetween from smesher X inbeetween layers Y and Z)

@lrettig
Copy link
Member Author

lrettig commented Nov 27, 2023

The only other option here is to force a resync from scratch, or to rerun all transactions through the VM to reconstruct the missing data. Even if we merge this PR as-is, those options are still on the table for the future - that would be my preference.

@dshulyak
Copy link
Contributor

dshulyak commented Dec 1, 2023

yes i don't mind looking into any perf issues later

@lrettig
Copy link
Member Author

lrettig commented Dec 2, 2023

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Dec 2, 2023
## Motivation

See #4863

Based on #4850

Closes #4529
Closes #4850 
Closes #4863
Closes #4964
Closes #5183

## Changes
- Refactors `rewards` table. Adds smesherID column, migrates data. Does not update old data (smesherID will be NULL for old data, unless resynced).
- Updates database queries.
- Returns smesherID in all API queries



Co-authored-by: Piers Powlesland <pierspowlesland@gmail.com>
Co-authored-by: piersy <pierspowlesland@gmail.com>
Co-authored-by: Dmitry Shulyak <yashulyak@gmail.com>
@spacemesh-bors
Copy link

spacemesh-bors bot commented Dec 2, 2023

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title vm, api: add smesherID to rewards [Merged by Bors] - vm, api: add smesherID to rewards Dec 2, 2023
@spacemesh-bors spacemesh-bors bot closed this Dec 2, 2023
@spacemesh-bors spacemesh-bors bot deleted the fix_rewards branch December 2, 2023 01:37
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.

Tracking rewards Send SmesherId in grpc reward object.
4 participants