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

Detect duplicates in the same insert batch #32528

Merged
merged 2 commits into from
Jul 20, 2023

Conversation

carllin
Copy link
Contributor

@carllin carllin commented Jul 19, 2023

Problem

There's a race condition where duplicate shreds in the same insert batch might not get detected as duplicate. The order of events is as follows:

  1. A batch of shreds with both duplicate A and B arrive to insert_shreds_handle_duplicate() from window_service: https://github.com/solana-labs/solana/blob/cfb028819a63de8f726bab3c9c981eb3155e9886/core/src/window_service.rs#L283C42-L283C72
  2. Duplicate A is inserted into just_inserted_shreds here:
    &mut just_inserted_shreds,
    , but is not committed to blockstore yet
  3. Duplicate B is detected here:
    handle_duplicate(shred);
    , and the shred is sent to the duplicate thread detection via the dup handler:
    let _ = check_duplicate_sender.send(shred);
  4. The duplicate thread checker doesn't detect a duplicate:
    if let Some(existing_shred_payload) =
    blockstore.is_shred_duplicate(shred.id(), shred.payload().clone())
    because duplicate A hasn't been inserted yet

Summary of Changes

Only invoke the duplicate handler after the shreds have been committed in insert. That way all shreds are findable.

Crux of change:

for shred in duplicate_shreds {
handle_duplicate(shred);
}

Fixes #

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #32528 (d263794) into master (dba39d9) will increase coverage by 0.0%.
The diff coverage is 98.8%.

@@           Coverage Diff           @@
##           master   #32528   +/-   ##
=======================================
  Coverage    82.0%    82.0%           
=======================================
  Files         780      780           
  Lines      210704   210764   +60     
=======================================
+ Hits       172874   172926   +52     
- Misses      37830    37838    +8     

Copy link
Contributor

@steviez steviez left a comment

Choose a reason for hiding this comment

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

Nice catch, definitely a sneaky bug. Really just two nit comments

core/src/window_service.rs Show resolved Hide resolved
ledger/src/blockstore.rs Show resolved Hide resolved
core/src/window_service.rs Show resolved Hide resolved
core/src/window_service.rs Show resolved Hide resolved
Copy link
Contributor

@AshwinSekar AshwinSekar left a comment

Choose a reason for hiding this comment

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

Nice find!

@carllin carllin merged commit b6927db into solana-labs:master Jul 20, 2023
@AshwinSekar
Copy link
Contributor

should we backport this to 1.16?

@carllin carllin added the v1.16 PRs that should be backported to v1.16 label Jul 20, 2023
mergify bot pushed a commit that referenced this pull request Jul 20, 2023
@carllin carllin added the v1.14 label Jul 21, 2023
carllin added a commit that referenced this pull request Jul 21, 2023
#32557)

Detect duplicates in the same insert batch (#32528)

(cherry picked from commit b6927db)

Co-authored-by: carllin <[email protected]>
mergify bot pushed a commit that referenced this pull request Jul 21, 2023
(cherry picked from commit b6927db)

# Conflicts:
#	ledger/src/blockstore.rs
carllin added a commit that referenced this pull request Jul 25, 2023
(cherry picked from commit b6927db)

# Conflicts:
#	ledger/src/blockstore.rs
carllin added a commit that referenced this pull request Jul 28, 2023
#32591)

* Detect duplicates in the same insert batch (#32528)

(cherry picked from commit b6927db)

# Conflicts:
#	ledger/src/blockstore.rs

* Resolve conflicts

---------

Co-authored-by: carllin <[email protected]>
@ruuda
Copy link
Contributor

ruuda commented Jul 31, 2023

What would be the impact of a duplicate not being detected? Is it only wasteful, or is it a correctness issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.16 PRs that should be backported to v1.16
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants