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] - detect double atx-merging malfeasance #6135

Closed
wants to merge 9 commits into from

Conversation

poszu
Copy link
Contributor

@poszu poszu commented Jul 12, 2024

Motivation

Publishing two merged ATXs in the same epoch is forbidden, even if the sets of IDs participating in both are disjoint.

For example, given a married set of IDs (A, B, C, D), it's not allowed to publish two merged ATXs, one with IDs (A, B) and the second with (C, D). The C and D can publish separately.

Description

Added a marriage_atx column to atxs table to quickly identify if a given marriage_atx was already used in a given epoch (only a merged ATX references a marriage_atx).

Updated the checkpoint-recovery to persist marriage_atx.

Test Plan

added tests

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 91.78082% with 6 lines in your changes missing coverage. Please review.

Project coverage is 82.0%. Comparing base (5b79e45) to head (9ca3fce).

Files Patch % Lines
activation/handler_v2.go 84.6% 3 Missing and 1 partial ⚠️
sql/atxs/atxs.go 94.7% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #6135   +/-   ##
=======================================
  Coverage     82.0%   82.0%           
=======================================
  Files          308     308           
  Lines        33844   33905   +61     
=======================================
+ Hits         27761   27813   +52     
- Misses        4310    4317    +7     
- Partials      1773    1775    +2     

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

Copy link
Member

@noamnelke noamnelke left a comment

Choose a reason for hiding this comment

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

other than the tiny logging comment - LGTM

activation/handler_v2.go Outdated Show resolved Hide resolved
@@ -62,6 +63,10 @@ func decoder(fn decoderCallback) sql.Decoder {
stmt.ColumnBytes(12, a.CommitmentATX[:])
}
a.Weight = uint64(stmt.ColumnInt64(13))
if stmt.ColumnType(14) != sqlite.SQLITE_NULL {
a.MarriageATX = new(types.ATXID)
stmt.ColumnBytes(14, a.MarriageATX[:])
Copy link
Member

Choose a reason for hiding this comment

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

NIT:

Suggested change
stmt.ColumnBytes(14, a.MarriageATX[:])
stmt.ColumnBytes(14, a.MarriageATX.Bytes())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why prefer .Bytes() over [:]?

Copy link
Member

Choose a reason for hiding this comment

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

Mostly because of readability 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it depends 🤷. Slicing is the idiomatic way of getting bytes from an array.

catx.Units = make(map[types.NodeID]uint32)
if stmt.ColumnType(9) != sqlite.SQLITE_NULL {
catx.MarriageATX = new(types.ATXID)
stmt.ColumnBytes(9, catx.MarriageATX[:])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
stmt.ColumnBytes(9, catx.MarriageATX[:])
stmt.ColumnBytes(9, catx.MarriageATX.Bytes())

sql/atxs/atxs.go Outdated Show resolved Hide resolved
checkpoint/runner_test.go Outdated Show resolved Hide resolved
activation/handler_v2_test.go Outdated Show resolved Hide resolved
poszu and others added 3 commits August 5, 2024 11:58
Co-authored-by: Matthias Fasching <5011972+fasmat@users.noreply.github.com>
@poszu
Copy link
Contributor Author

poszu commented Aug 5, 2024

bors merge

@spacemesh-bors
Copy link

spacemesh-bors bot commented Aug 5, 2024

Merge conflict.

@poszu
Copy link
Contributor Author

poszu commented Aug 6, 2024

bors merge

spacemesh-bors bot pushed a commit that referenced this pull request Aug 6, 2024
## Motivation

Publishing two merged ATXs in the same epoch is forbidden, even if the sets of IDs participating in both are disjoint.

For example, given a married set of IDs (A, B, C, D), it's not allowed to publish two merged ATXs, one with IDs (A, B) and the second with (C, D). The C and D can publish **separately**.
@spacemesh-bors
Copy link

spacemesh-bors bot commented Aug 6, 2024

Pull request successfully merged into develop.

Build succeeded:

@spacemesh-bors spacemesh-bors bot changed the title detect double atx-merging malfeasance [Merged by Bors] - detect double atx-merging malfeasance Aug 6, 2024
@spacemesh-bors spacemesh-bors bot closed this Aug 6, 2024
@spacemesh-bors spacemesh-bors bot deleted the atxmerge/detect-double-merge branch August 6, 2024 08:58
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.

4 participants