Check shred type in is_duplicate (#14050)
This commit is contained in:
parent
164b7895b3
commit
aa2751e614
|
@ -88,9 +88,12 @@ fn run_check_duplicate(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let check_duplicate = |shred: Shred| -> Result<()> {
|
let check_duplicate = |shred: Shred| -> Result<()> {
|
||||||
if !blockstore.has_duplicate_shreds_in_slot(shred.slot()) {
|
if !blockstore.has_duplicate_shreds_in_slot(shred.slot()) {
|
||||||
if let Some(existing_shred_payload) =
|
if let Some(existing_shred_payload) = blockstore.is_shred_duplicate(
|
||||||
blockstore.is_shred_duplicate(shred.slot(), shred.index(), &shred.payload)
|
shred.slot(),
|
||||||
{
|
shred.index(),
|
||||||
|
&shred.payload,
|
||||||
|
shred.is_data(),
|
||||||
|
) {
|
||||||
blockstore.store_duplicate_slot(
|
blockstore.store_duplicate_slot(
|
||||||
shred.slot(),
|
shred.slot(),
|
||||||
existing_shred_payload,
|
existing_shred_payload,
|
||||||
|
|
|
@ -2714,10 +2714,20 @@ impl Blockstore {
|
||||||
// Returns the existing shred if `new_shred` is not equal to the existing shred at the
|
// Returns the existing shred if `new_shred` is not equal to the existing shred at the
|
||||||
// given slot and index as this implies the leader generated two different shreds with
|
// given slot and index as this implies the leader generated two different shreds with
|
||||||
// the same slot and index
|
// the same slot and index
|
||||||
pub fn is_shred_duplicate(&self, slot: u64, index: u32, new_shred: &[u8]) -> Option<Vec<u8>> {
|
pub fn is_shred_duplicate(
|
||||||
let res = self
|
&self,
|
||||||
.get_data_shred(slot, index as u64)
|
slot: u64,
|
||||||
.expect("fetch from DuplicateSlots column family failed");
|
index: u32,
|
||||||
|
new_shred: &[u8],
|
||||||
|
is_data: bool,
|
||||||
|
) -> Option<Vec<u8>> {
|
||||||
|
let res = if is_data {
|
||||||
|
self.get_data_shred(slot, index as u64)
|
||||||
|
.expect("fetch from DuplicateSlots column family failed")
|
||||||
|
} else {
|
||||||
|
self.get_coding_shred(slot, index as u64)
|
||||||
|
.expect("fetch from DuplicateSlots column family failed")
|
||||||
|
};
|
||||||
|
|
||||||
res.map(|existing_shred| {
|
res.map(|existing_shred| {
|
||||||
if existing_shred != new_shred {
|
if existing_shred != new_shred {
|
||||||
|
@ -7279,11 +7289,21 @@ pub mod tests {
|
||||||
|
|
||||||
// Check if shreds are duplicated
|
// Check if shreds are duplicated
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
blockstore.is_shred_duplicate(slot, 0, &duplicate_shred.payload),
|
blockstore.is_shred_duplicate(
|
||||||
|
slot,
|
||||||
|
0,
|
||||||
|
&duplicate_shred.payload,
|
||||||
|
duplicate_shred.is_data()
|
||||||
|
),
|
||||||
Some(shred.payload.clone())
|
Some(shred.payload.clone())
|
||||||
);
|
);
|
||||||
assert!(blockstore
|
assert!(blockstore
|
||||||
.is_shred_duplicate(slot, 0, &non_duplicate_shred.payload)
|
.is_shred_duplicate(
|
||||||
|
slot,
|
||||||
|
0,
|
||||||
|
&non_duplicate_shred.payload,
|
||||||
|
duplicate_shred.is_data()
|
||||||
|
)
|
||||||
.is_none());
|
.is_none());
|
||||||
|
|
||||||
// Store a duplicate shred
|
// Store a duplicate shred
|
||||||
|
|
Loading…
Reference in New Issue