changes Blockstore::is_shred_duplicate arg type to ShredType
This commit is contained in:
parent
57057f8d39
commit
48dfdfb4d5
|
@ -218,8 +218,8 @@ fn run_check_duplicate(
|
||||||
if let Some(existing_shred_payload) = blockstore.is_shred_duplicate(
|
if let Some(existing_shred_payload) = blockstore.is_shred_duplicate(
|
||||||
shred_slot,
|
shred_slot,
|
||||||
shred.index(),
|
shred.index(),
|
||||||
&shred.payload,
|
shred.payload.clone(),
|
||||||
shred.is_data(),
|
shred.shred_type(),
|
||||||
) {
|
) {
|
||||||
cluster_info.push_duplicate_shred(&shred, &existing_shred_payload)?;
|
cluster_info.push_duplicate_shred(&shred, &existing_shred_payload)?;
|
||||||
blockstore.store_duplicate_slot(
|
blockstore.store_duplicate_slot(
|
||||||
|
|
|
@ -13,7 +13,10 @@ use {
|
||||||
erasure::ErasureConfig,
|
erasure::ErasureConfig,
|
||||||
leader_schedule_cache::LeaderScheduleCache,
|
leader_schedule_cache::LeaderScheduleCache,
|
||||||
next_slots_iterator::NextSlotsIterator,
|
next_slots_iterator::NextSlotsIterator,
|
||||||
shred::{Result as ShredResult, Shred, ShredType, Shredder, MAX_DATA_SHREDS_PER_FEC_BLOCK},
|
shred::{
|
||||||
|
Result as ShredResult, Shred, ShredType, Shredder, MAX_DATA_SHREDS_PER_FEC_BLOCK,
|
||||||
|
SHRED_PAYLOAD_SIZE,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
bincode::deserialize,
|
bincode::deserialize,
|
||||||
log::*,
|
log::*,
|
||||||
|
@ -1326,7 +1329,6 @@ impl Blockstore {
|
||||||
leader_schedule: Option<&LeaderScheduleCache>,
|
leader_schedule: Option<&LeaderScheduleCache>,
|
||||||
shred_source: ShredSource,
|
shred_source: ShredSource,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
use crate::shred::SHRED_PAYLOAD_SIZE;
|
|
||||||
let shred_index = u64::from(shred.index());
|
let shred_index = u64::from(shred.index());
|
||||||
let slot = shred.slot();
|
let slot = shred.slot();
|
||||||
let last_in_slot = if shred.last_in_slot() {
|
let last_in_slot = if shred.last_in_slot() {
|
||||||
|
@ -1555,7 +1557,6 @@ impl Blockstore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_shred(&self, slot: Slot, index: u64) -> Result<Option<Vec<u8>>> {
|
pub fn get_data_shred(&self, slot: Slot, index: u64) -> Result<Option<Vec<u8>>> {
|
||||||
use crate::shred::SHRED_PAYLOAD_SIZE;
|
|
||||||
self.data_shred_cf.get_bytes((slot, index)).map(|data| {
|
self.data_shred_cf.get_bytes((slot, index)).map(|data| {
|
||||||
data.map(|mut d| {
|
data.map(|mut d| {
|
||||||
// Only data_header.size bytes stored in the blockstore so
|
// Only data_header.size bytes stored in the blockstore so
|
||||||
|
@ -3033,32 +3034,18 @@ impl Blockstore {
|
||||||
&self,
|
&self,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
index: u32,
|
index: u32,
|
||||||
new_shred_raw: &[u8],
|
mut payload: Vec<u8>,
|
||||||
// TODO: change arg type to ShredType.
|
shred_type: ShredType,
|
||||||
is_data: bool,
|
|
||||||
) -> Option<Vec<u8>> {
|
) -> Option<Vec<u8>> {
|
||||||
let res = if is_data {
|
let existing_shred = match shred_type {
|
||||||
self.get_data_shred(slot, index as u64)
|
ShredType::Data => self.get_data_shred(slot, index as u64),
|
||||||
.expect("fetch from DuplicateSlots column family failed")
|
ShredType::Code => self.get_coding_shred(slot, index as u64),
|
||||||
} else {
|
}
|
||||||
self.get_coding_shred(slot, index as u64)
|
.expect("fetch from DuplicateSlots column family failed")?;
|
||||||
.expect("fetch from DuplicateSlots column family failed")
|
let size = payload.len().max(SHRED_PAYLOAD_SIZE);
|
||||||
};
|
payload.resize(size, 0u8);
|
||||||
|
|
||||||
let mut payload = new_shred_raw.to_vec();
|
|
||||||
payload.resize(
|
|
||||||
std::cmp::max(new_shred_raw.len(), crate::shred::SHRED_PAYLOAD_SIZE),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
let new_shred = Shred::new_from_serialized_shred(payload).unwrap();
|
let new_shred = Shred::new_from_serialized_shred(payload).unwrap();
|
||||||
res.map(|existing_shred| {
|
(existing_shred != new_shred.payload).then(|| existing_shred)
|
||||||
if existing_shred != new_shred.payload {
|
|
||||||
Some(existing_shred)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.unwrap_or(None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_duplicate_shreds_in_slot(&self, slot: Slot) -> bool {
|
pub fn has_duplicate_shreds_in_slot(&self, slot: Slot) -> bool {
|
||||||
|
@ -8115,8 +8102,8 @@ pub mod tests {
|
||||||
blockstore.is_shred_duplicate(
|
blockstore.is_shred_duplicate(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
&duplicate_shred.payload,
|
duplicate_shred.payload.clone(),
|
||||||
duplicate_shred.is_data()
|
duplicate_shred.shred_type(),
|
||||||
),
|
),
|
||||||
Some(shred.payload.to_vec())
|
Some(shred.payload.to_vec())
|
||||||
);
|
);
|
||||||
|
@ -8124,8 +8111,8 @@ pub mod tests {
|
||||||
.is_shred_duplicate(
|
.is_shred_duplicate(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
&non_duplicate_shred.payload,
|
non_duplicate_shred.payload.clone(),
|
||||||
duplicate_shred.is_data()
|
non_duplicate_shred.shred_type(),
|
||||||
)
|
)
|
||||||
.is_none());
|
.is_none());
|
||||||
|
|
||||||
|
@ -8595,8 +8582,8 @@ pub mod tests {
|
||||||
.is_shred_duplicate(
|
.is_shred_duplicate(
|
||||||
slot,
|
slot,
|
||||||
even_smaller_last_shred_duplicate.index(),
|
even_smaller_last_shred_duplicate.index(),
|
||||||
&even_smaller_last_shred_duplicate.payload,
|
even_smaller_last_shred_duplicate.payload.clone(),
|
||||||
true
|
ShredType::Data,
|
||||||
)
|
)
|
||||||
.is_some());
|
.is_some());
|
||||||
blockstore
|
blockstore
|
||||||
|
|
Loading…
Reference in New Issue