2021-11-12 11:16:48 -08:00
|
|
|
use {
|
2022-04-29 13:28:00 -07:00
|
|
|
crate::shred::{Shred, ShredType},
|
2021-12-11 06:47:20 -08:00
|
|
|
serde::{Deserialize, Deserializer, Serialize, Serializer},
|
2022-05-20 16:46:23 -07:00
|
|
|
solana_sdk::{
|
|
|
|
clock::{Slot, UnixTimestamp},
|
|
|
|
hash::Hash,
|
|
|
|
},
|
2021-11-12 11:16:48 -08:00
|
|
|
std::{
|
|
|
|
collections::BTreeSet,
|
|
|
|
ops::{Range, RangeBounds},
|
|
|
|
},
|
|
|
|
};
|
2019-04-11 14:14:57 -07:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
|
|
|
|
// The Meta column family
|
|
|
|
pub struct SlotMeta {
|
|
|
|
// The number of slots above the root (the genesis block). The first
|
|
|
|
// slot has slot 0.
|
2019-11-02 00:38:30 -07:00
|
|
|
pub slot: Slot,
|
2019-11-14 11:49:31 -08:00
|
|
|
// The total number of consecutive shreds starting from index 0
|
2019-04-11 14:14:57 -07:00
|
|
|
// we have received for this slot.
|
|
|
|
pub consumed: u64,
|
2019-11-07 11:08:09 -08:00
|
|
|
// The index *plus one* of the highest shred received for this slot. Useful
|
|
|
|
// for checking if the slot has received any shreds yet, and to calculate the
|
2019-04-11 14:14:57 -07:00
|
|
|
// range where there is one or more holes: `(consumed..received)`.
|
|
|
|
pub received: u64,
|
2019-11-07 11:08:09 -08:00
|
|
|
// The timestamp of the first time a shred was added for this slot
|
|
|
|
pub first_shred_timestamp: u64,
|
|
|
|
// The index of the shred that is flagged as the last shred for this slot.
|
2021-12-14 10:57:11 -08:00
|
|
|
// None until the shred with LAST_SHRED_IN_SLOT flag is received.
|
2021-12-11 06:47:20 -08:00
|
|
|
#[serde(with = "serde_compat")]
|
|
|
|
pub last_index: Option<u64>,
|
2019-04-11 14:14:57 -07:00
|
|
|
// The slot height of the block this one derives from.
|
2021-12-14 10:57:11 -08:00
|
|
|
// The parent slot of the head of a detached chain of slots is None.
|
|
|
|
#[serde(with = "serde_compat")]
|
|
|
|
pub parent_slot: Option<Slot>,
|
2019-11-02 00:38:30 -07:00
|
|
|
// The list of slots, each of which contains a block that derives
|
2019-04-11 14:14:57 -07:00
|
|
|
// from this one.
|
2019-11-02 00:38:30 -07:00
|
|
|
pub next_slots: Vec<Slot>,
|
2019-04-11 14:14:57 -07:00
|
|
|
// True if this slot is full (consumed == last_index + 1) and if every
|
|
|
|
// slot that is a parent of this slot is also connected.
|
|
|
|
pub is_connected: bool,
|
2021-10-31 05:56:25 -07:00
|
|
|
// Shreds indices which are marked data complete.
|
|
|
|
pub completed_data_indexes: BTreeSet<u32>,
|
2019-04-11 14:14:57 -07:00
|
|
|
}
|
|
|
|
|
2021-12-11 06:47:20 -08:00
|
|
|
// Serde implementation of serialize and deserialize for Option<u64>
|
|
|
|
// where None is represented as u64::MAX; for backward compatibility.
|
|
|
|
mod serde_compat {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub(super) fn serialize<S>(val: &Option<u64>, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
val.unwrap_or(u64::MAX).serialize(serializer)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(super) fn deserialize<'de, D>(deserializer: D) -> Result<Option<u64>, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
|
|
|
let val = u64::deserialize(deserializer)?;
|
|
|
|
Ok((val != u64::MAX).then(|| val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2019-11-07 11:08:09 -08:00
|
|
|
/// Index recording presence/absence of shreds
|
2019-07-10 11:08:17 -07:00
|
|
|
pub struct Index {
|
2019-11-02 00:38:30 -07:00
|
|
|
pub slot: Slot,
|
2020-01-13 12:03:19 -08:00
|
|
|
data: ShredIndex,
|
|
|
|
coding: ShredIndex,
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2020-01-13 12:03:19 -08:00
|
|
|
pub struct ShredIndex {
|
|
|
|
/// Map representing presence/absence of shreds
|
2020-04-24 15:04:23 -07:00
|
|
|
index: BTreeSet<u64>,
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
|
2021-11-12 11:02:22 -08:00
|
|
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
|
2019-07-10 11:08:17 -07:00
|
|
|
/// Erasure coding information
|
|
|
|
pub struct ErasureMeta {
|
|
|
|
/// Which erasure set in the slot this is
|
2021-11-12 11:16:48 -08:00
|
|
|
set_index: u64,
|
2021-12-10 12:08:04 -08:00
|
|
|
/// First coding index in the FEC set
|
|
|
|
first_coding_index: u64,
|
2019-07-10 11:08:17 -07:00
|
|
|
/// Size of shards in this erasure set
|
2021-11-12 11:16:40 -08:00
|
|
|
#[serde(rename = "size")]
|
|
|
|
__unused_size: usize,
|
2019-07-11 13:58:33 -07:00
|
|
|
/// Erasure configuration for this erasure set
|
2021-11-12 11:16:48 -08:00
|
|
|
config: ErasureConfig,
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
|
2022-04-29 13:28:00 -07:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub(crate) struct ErasureConfig {
|
|
|
|
num_data: usize,
|
|
|
|
num_coding: usize,
|
|
|
|
}
|
|
|
|
|
2020-01-13 17:21:39 -08:00
|
|
|
#[derive(Deserialize, Serialize)]
|
|
|
|
pub struct DuplicateSlotProof {
|
|
|
|
#[serde(with = "serde_bytes")]
|
|
|
|
pub shred1: Vec<u8>,
|
|
|
|
#[serde(with = "serde_bytes")]
|
|
|
|
pub shred2: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2019-07-10 11:08:17 -07:00
|
|
|
pub enum ErasureMetaStatus {
|
|
|
|
CanRecover,
|
|
|
|
DataFull,
|
|
|
|
StillNeed(usize),
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
|
2021-07-12 20:59:16 -07:00
|
|
|
pub enum FrozenHashVersioned {
|
|
|
|
Current(FrozenHashStatus),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FrozenHashVersioned {
|
|
|
|
pub fn frozen_hash(&self) -> Hash {
|
|
|
|
match self {
|
|
|
|
FrozenHashVersioned::Current(frozen_hash_status) => frozen_hash_status.frozen_hash,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_duplicate_confirmed(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
FrozenHashVersioned::Current(frozen_hash_status) => {
|
|
|
|
frozen_hash_status.is_duplicate_confirmed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
|
2021-07-12 20:59:16 -07:00
|
|
|
pub struct FrozenHashStatus {
|
|
|
|
pub frozen_hash: Hash,
|
|
|
|
pub is_duplicate_confirmed: bool,
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
impl Index {
|
2019-11-02 00:38:30 -07:00
|
|
|
pub(crate) fn new(slot: Slot) -> Self {
|
2019-07-10 11:08:17 -07:00
|
|
|
Index {
|
|
|
|
slot,
|
2020-01-13 12:03:19 -08:00
|
|
|
data: ShredIndex::default(),
|
|
|
|
coding: ShredIndex::default(),
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:03:19 -08:00
|
|
|
pub fn data(&self) -> &ShredIndex {
|
2019-07-10 11:08:17 -07:00
|
|
|
&self.data
|
|
|
|
}
|
2020-01-13 12:03:19 -08:00
|
|
|
pub fn coding(&self) -> &ShredIndex {
|
2019-07-10 11:08:17 -07:00
|
|
|
&self.coding
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
pub(crate) fn data_mut(&mut self) -> &mut ShredIndex {
|
2019-07-10 11:08:17 -07:00
|
|
|
&mut self.data
|
|
|
|
}
|
2021-12-16 11:17:32 -08:00
|
|
|
pub(crate) fn coding_mut(&mut self) -> &mut ShredIndex {
|
2019-07-10 11:08:17 -07:00
|
|
|
&mut self.coding
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 12:03:19 -08:00
|
|
|
impl ShredIndex {
|
|
|
|
pub fn num_shreds(&self) -> usize {
|
2019-12-09 00:13:36 -08:00
|
|
|
self.index.len()
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
pub(crate) fn range<R>(&self, bounds: R) -> impl Iterator<Item = &u64>
|
|
|
|
where
|
|
|
|
R: RangeBounds<u64>,
|
|
|
|
{
|
|
|
|
self.index.range(bounds)
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
pub(crate) fn contains(&self, index: u64) -> bool {
|
2019-07-10 11:08:17 -07:00
|
|
|
self.index.contains(&index)
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
pub(crate) fn insert(&mut self, index: u64) {
|
|
|
|
self.index.insert(index);
|
2021-05-26 16:12:57 -07:00
|
|
|
}
|
2019-07-10 11:08:17 -07:00
|
|
|
}
|
|
|
|
|
2019-04-11 14:14:57 -07:00
|
|
|
impl SlotMeta {
|
|
|
|
pub fn is_full(&self) -> bool {
|
2021-12-11 06:47:20 -08:00
|
|
|
// last_index is None when it has no information about how
|
2019-11-07 11:08:09 -08:00
|
|
|
// many shreds will fill this slot.
|
|
|
|
// Note: A full slot with zero shreds is not possible.
|
2019-04-25 00:04:49 -07:00
|
|
|
// Should never happen
|
2021-12-11 06:47:20 -08:00
|
|
|
if self
|
|
|
|
.last_index
|
|
|
|
.map(|ix| self.consumed > ix + 1)
|
|
|
|
.unwrap_or_default()
|
|
|
|
{
|
2020-02-14 11:11:55 -08:00
|
|
|
datapoint_error!(
|
2020-01-13 13:13:52 -08:00
|
|
|
"blockstore_error",
|
2019-05-10 08:33:58 -07:00
|
|
|
(
|
|
|
|
"error",
|
|
|
|
format!(
|
2021-12-11 06:47:20 -08:00
|
|
|
"Observed a slot meta with consumed: {} > meta.last_index + 1: {:?}",
|
2019-05-10 08:33:58 -07:00
|
|
|
self.consumed,
|
2021-12-11 06:47:20 -08:00
|
|
|
self.last_index.map(|ix| ix + 1),
|
2019-05-10 08:33:58 -07:00
|
|
|
),
|
|
|
|
String
|
|
|
|
)
|
2019-04-25 00:04:49 -07:00
|
|
|
);
|
|
|
|
}
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2021-12-11 06:47:20 -08:00
|
|
|
Some(self.consumed) == self.last_index.map(|ix| ix + 1)
|
2021-11-19 19:17:30 -08:00
|
|
|
}
|
|
|
|
|
2020-05-05 14:07:21 -07:00
|
|
|
pub fn clear_unconfirmed_slot(&mut self) {
|
|
|
|
let mut new_self = SlotMeta::new_orphan(self.slot);
|
|
|
|
std::mem::swap(&mut new_self.next_slots, &mut self.next_slots);
|
|
|
|
std::mem::swap(self, &mut new_self);
|
|
|
|
}
|
|
|
|
|
2021-12-14 10:57:11 -08:00
|
|
|
pub(crate) fn new(slot: Slot, parent_slot: Option<Slot>) -> Self {
|
2019-04-11 14:14:57 -07:00
|
|
|
SlotMeta {
|
|
|
|
slot,
|
|
|
|
parent_slot,
|
|
|
|
is_connected: slot == 0,
|
2021-10-31 05:56:25 -07:00
|
|
|
..SlotMeta::default()
|
2019-04-11 14:14:57 -07:00
|
|
|
}
|
|
|
|
}
|
2020-05-05 14:07:21 -07:00
|
|
|
|
|
|
|
pub(crate) fn new_orphan(slot: Slot) -> Self {
|
2021-12-14 10:57:11 -08:00
|
|
|
Self::new(slot, /*parent_slot:*/ None)
|
2020-05-05 14:07:21 -07:00
|
|
|
}
|
2019-04-11 14:14:57 -07:00
|
|
|
}
|
|
|
|
|
2019-06-20 20:15:33 -07:00
|
|
|
impl ErasureMeta {
|
2021-12-10 12:08:04 -08:00
|
|
|
pub(crate) fn from_coding_shred(shred: &Shred) -> Option<Self> {
|
|
|
|
match shred.shred_type() {
|
|
|
|
ShredType::Data => None,
|
|
|
|
ShredType::Code => {
|
2022-04-29 13:28:00 -07:00
|
|
|
let config = ErasureConfig {
|
|
|
|
num_data: usize::from(shred.num_data_shreds().ok()?),
|
|
|
|
num_coding: usize::from(shred.num_coding_shreds().ok()?),
|
|
|
|
};
|
2021-12-10 12:08:04 -08:00
|
|
|
let first_coding_index = u64::from(shred.first_coding_index()?);
|
|
|
|
let erasure_meta = ErasureMeta {
|
|
|
|
set_index: u64::from(shred.fec_set_index()),
|
|
|
|
config,
|
|
|
|
first_coding_index,
|
|
|
|
__unused_size: 0,
|
|
|
|
};
|
|
|
|
Some(erasure_meta)
|
|
|
|
}
|
2019-07-11 13:58:33 -07:00
|
|
|
}
|
2019-04-11 14:14:57 -07:00
|
|
|
}
|
|
|
|
|
2021-12-10 12:08:04 -08:00
|
|
|
// Returns true if the erasure fields on the shred
|
|
|
|
// are consistent with the erasure-meta.
|
|
|
|
pub(crate) fn check_coding_shred(&self, shred: &Shred) -> bool {
|
|
|
|
let mut other = match Self::from_coding_shred(shred) {
|
|
|
|
Some(erasure_meta) => erasure_meta,
|
|
|
|
None => return false,
|
|
|
|
};
|
|
|
|
other.__unused_size = self.__unused_size;
|
|
|
|
self == &other
|
|
|
|
}
|
|
|
|
|
2021-11-12 11:16:48 -08:00
|
|
|
pub(crate) fn config(&self) -> ErasureConfig {
|
|
|
|
self.config
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn data_shreds_indices(&self) -> Range<u64> {
|
2022-04-29 13:28:00 -07:00
|
|
|
let num_data = self.config.num_data as u64;
|
2021-11-12 11:16:48 -08:00
|
|
|
self.set_index..self.set_index + num_data
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn coding_shreds_indices(&self) -> Range<u64> {
|
2022-04-29 13:28:00 -07:00
|
|
|
let num_coding = self.config.num_coding as u64;
|
2022-03-30 06:55:11 -07:00
|
|
|
self.first_coding_index..self.first_coding_index + num_coding
|
2021-11-12 11:16:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn status(&self, index: &Index) -> ErasureMetaStatus {
|
2019-07-10 11:08:17 -07:00
|
|
|
use ErasureMetaStatus::*;
|
2019-06-20 20:15:33 -07:00
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
let num_coding = index.coding().range(self.coding_shreds_indices()).count();
|
|
|
|
let num_data = index.data().range(self.data_shreds_indices()).count();
|
2019-07-10 11:08:17 -07:00
|
|
|
|
2020-02-04 15:45:01 -08:00
|
|
|
let (data_missing, num_needed) = (
|
2022-04-29 13:28:00 -07:00
|
|
|
self.config.num_data.saturating_sub(num_data),
|
|
|
|
self.config.num_data.saturating_sub(num_data + num_coding),
|
2019-07-11 13:58:33 -07:00
|
|
|
);
|
2019-06-20 20:15:33 -07:00
|
|
|
|
2020-02-04 15:45:01 -08:00
|
|
|
if data_missing == 0 {
|
2020-01-21 11:48:09 -08:00
|
|
|
DataFull
|
2020-02-04 15:45:01 -08:00
|
|
|
} else if num_needed == 0 {
|
|
|
|
CanRecover
|
2019-06-20 20:15:33 -07:00
|
|
|
} else {
|
2020-02-04 15:45:01 -08:00
|
|
|
StillNeed(num_needed)
|
2019-06-20 20:15:33 -07:00
|
|
|
}
|
2019-04-19 20:22:51 -07:00
|
|
|
}
|
2019-06-20 20:15:33 -07:00
|
|
|
}
|
2019-04-18 21:56:43 -07:00
|
|
|
|
2020-01-13 17:21:39 -08:00
|
|
|
impl DuplicateSlotProof {
|
|
|
|
pub(crate) fn new(shred1: Vec<u8>, shred2: Vec<u8>) -> Self {
|
|
|
|
DuplicateSlotProof { shred1, shred2 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2020-04-04 20:24:06 -07:00
|
|
|
pub struct TransactionStatusIndexMeta {
|
|
|
|
pub max_slot: Slot,
|
|
|
|
pub frozen: bool,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2020-04-08 12:50:39 -07:00
|
|
|
pub struct AddressSignatureMeta {
|
|
|
|
pub writeable: bool,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2020-09-22 12:26:32 -07:00
|
|
|
pub struct PerfSample {
|
|
|
|
pub num_transactions: u64,
|
|
|
|
pub num_slots: u64,
|
|
|
|
pub sample_period_secs: u16,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2021-07-01 09:32:41 -07:00
|
|
|
pub struct ProgramCost {
|
|
|
|
pub cost: u64,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
2022-05-20 16:46:23 -07:00
|
|
|
pub struct OptimisticSlotMetaV0 {
|
|
|
|
pub hash: Hash,
|
|
|
|
pub timestamp: UnixTimestamp,
|
|
|
|
}
|
|
|
|
|
2022-05-22 18:00:42 -07:00
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
|
2022-05-20 16:46:23 -07:00
|
|
|
pub enum OptimisticSlotMetaVersioned {
|
|
|
|
V0(OptimisticSlotMetaV0),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OptimisticSlotMetaVersioned {
|
|
|
|
pub fn new(hash: Hash, timestamp: UnixTimestamp) -> Self {
|
|
|
|
OptimisticSlotMetaVersioned::V0(OptimisticSlotMetaV0 { hash, timestamp })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn hash(&self) -> Hash {
|
|
|
|
match self {
|
|
|
|
OptimisticSlotMetaVersioned::V0(meta) => meta.hash,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timestamp(&self) -> UnixTimestamp {
|
|
|
|
match self {
|
|
|
|
OptimisticSlotMetaVersioned::V0(meta) => meta.timestamp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-10 11:08:17 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2021-12-03 09:00:31 -08:00
|
|
|
use {
|
|
|
|
super::*,
|
|
|
|
rand::{seq::SliceRandom, thread_rng},
|
|
|
|
};
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
#[test]
|
|
|
|
fn test_erasure_meta_status() {
|
|
|
|
use ErasureMetaStatus::*;
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
let set_index = 0;
|
2022-04-29 13:28:00 -07:00
|
|
|
let erasure_config = ErasureConfig {
|
|
|
|
num_data: 8,
|
|
|
|
num_coding: 16,
|
|
|
|
};
|
2021-12-10 12:08:04 -08:00
|
|
|
let e_meta = ErasureMeta {
|
|
|
|
set_index,
|
|
|
|
first_coding_index: set_index,
|
|
|
|
config: erasure_config,
|
|
|
|
__unused_size: 0,
|
|
|
|
};
|
2019-07-10 11:08:17 -07:00
|
|
|
let mut rng = thread_rng();
|
|
|
|
let mut index = Index::new(0);
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2022-04-29 13:28:00 -07:00
|
|
|
let data_indexes = 0..erasure_config.num_data as u64;
|
|
|
|
let coding_indexes = 0..erasure_config.num_coding as u64;
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2022-04-29 13:28:00 -07:00
|
|
|
assert_eq!(e_meta.status(&index), StillNeed(erasure_config.num_data));
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
for ix in data_indexes.clone() {
|
|
|
|
index.data_mut().insert(ix);
|
|
|
|
}
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
assert_eq!(e_meta.status(&index), DataFull);
|
2019-04-11 14:14:57 -07:00
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
for ix in coding_indexes.clone() {
|
|
|
|
index.coding_mut().insert(ix);
|
|
|
|
}
|
2019-04-18 21:56:43 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
for &idx in data_indexes
|
|
|
|
.clone()
|
|
|
|
.collect::<Vec<_>>()
|
2022-04-29 13:28:00 -07:00
|
|
|
.choose_multiple(&mut rng, erasure_config.num_data)
|
2019-07-10 11:08:17 -07:00
|
|
|
{
|
2021-12-16 11:17:32 -08:00
|
|
|
index.data_mut().index.remove(&idx);
|
2019-04-18 21:56:43 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
assert_eq!(e_meta.status(&index), CanRecover);
|
|
|
|
}
|
2019-04-18 21:56:43 -07:00
|
|
|
|
2021-12-16 11:17:32 -08:00
|
|
|
for ix in data_indexes {
|
|
|
|
index.data_mut().insert(ix);
|
|
|
|
}
|
2019-06-20 20:15:33 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
for &idx in coding_indexes
|
|
|
|
.collect::<Vec<_>>()
|
2022-04-29 13:28:00 -07:00
|
|
|
.choose_multiple(&mut rng, erasure_config.num_coding)
|
2019-07-10 11:08:17 -07:00
|
|
|
{
|
2021-12-16 11:17:32 -08:00
|
|
|
index.coding_mut().index.remove(&idx);
|
2019-06-20 20:15:33 -07:00
|
|
|
|
2019-07-10 11:08:17 -07:00
|
|
|
assert_eq!(e_meta.status(&index), DataFull);
|
|
|
|
}
|
2019-04-18 21:56:43 -07:00
|
|
|
}
|
2020-05-05 14:07:21 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_clear_unconfirmed_slot() {
|
|
|
|
let mut slot_meta = SlotMeta::new_orphan(5);
|
|
|
|
slot_meta.consumed = 5;
|
|
|
|
slot_meta.received = 5;
|
|
|
|
slot_meta.next_slots = vec![6, 7];
|
|
|
|
slot_meta.clear_unconfirmed_slot();
|
|
|
|
|
|
|
|
let mut expected = SlotMeta::new_orphan(5);
|
|
|
|
expected.next_slots = vec![6, 7];
|
|
|
|
assert_eq!(slot_meta, expected);
|
|
|
|
}
|
2019-04-11 14:14:57 -07:00
|
|
|
}
|