|
@@ -53,6 +53,11 @@ pub enum BlockRelation {
|
|
|
pub trait ForkGraph {
|
|
pub trait ForkGraph {
|
|
|
/// Returns the BlockRelation of A to B
|
|
/// Returns the BlockRelation of A to B
|
|
|
fn relationship(&self, a: Slot, b: Slot) -> BlockRelation;
|
|
fn relationship(&self, a: Slot, b: Slot) -> BlockRelation;
|
|
|
|
|
+
|
|
|
|
|
+ /// Returns the epoch of the given slot
|
|
|
|
|
+ fn slot_epoch(&self, _slot: Slot) -> Option<Epoch> {
|
|
|
|
|
+ Some(0)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Provides information about current working slot, and its ancestors
|
|
/// Provides information about current working slot, and its ancestors
|
|
@@ -759,14 +764,29 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
|
|
let environments = self.get_environments_for_epoch(working_slot.current_epoch());
|
|
let environments = self.get_environments_for_epoch(working_slot.current_epoch());
|
|
|
let mut missing = Vec::new();
|
|
let mut missing = Vec::new();
|
|
|
let mut unloaded = Vec::new();
|
|
let mut unloaded = Vec::new();
|
|
|
|
|
+ let current_slot = working_slot.current_slot();
|
|
|
let found = keys
|
|
let found = keys
|
|
|
.filter_map(|(key, (match_criteria, count))| {
|
|
.filter_map(|(key, (match_criteria, count))| {
|
|
|
if let Some(second_level) = self.entries.get(&key) {
|
|
if let Some(second_level) = self.entries.get(&key) {
|
|
|
for entry in second_level.iter().rev() {
|
|
for entry in second_level.iter().rev() {
|
|
|
- let current_slot = working_slot.current_slot();
|
|
|
|
|
|
|
+ let is_ancestor = if let Some(fork_graph) = &self.fork_graph {
|
|
|
|
|
+ fork_graph
|
|
|
|
|
+ .read()
|
|
|
|
|
+ .map(|fork_graph_r| {
|
|
|
|
|
+ matches!(
|
|
|
|
|
+ fork_graph_r
|
|
|
|
|
+ .relationship(entry.deployment_slot, current_slot),
|
|
|
|
|
+ BlockRelation::Ancestor
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ .unwrap_or(false)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ working_slot.is_ancestor(entry.deployment_slot)
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
if entry.deployment_slot <= self.latest_root_slot
|
|
if entry.deployment_slot <= self.latest_root_slot
|
|
|
|| entry.deployment_slot == current_slot
|
|
|| entry.deployment_slot == current_slot
|
|
|
- || working_slot.is_ancestor(entry.deployment_slot)
|
|
|
|
|
|
|
+ || is_ancestor
|
|
|
{
|
|
{
|
|
|
if current_slot >= entry.effective_slot {
|
|
if current_slot >= entry.effective_slot {
|
|
|
if !Self::is_entry_usable(entry, current_slot, &match_criteria) {
|
|
if !Self::is_entry_usable(entry, current_slot, &match_criteria) {
|
|
@@ -818,7 +838,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
|
|
ExtractedPrograms {
|
|
ExtractedPrograms {
|
|
|
loaded: LoadedProgramsForTxBatch {
|
|
loaded: LoadedProgramsForTxBatch {
|
|
|
entries: found,
|
|
entries: found,
|
|
|
- slot: working_slot.current_slot(),
|
|
|
|
|
|
|
+ slot: current_slot,
|
|
|
environments: environments.clone(),
|
|
environments: environments.clone(),
|
|
|
},
|
|
},
|
|
|
missing,
|
|
missing,
|
|
@@ -1488,52 +1508,19 @@ mod tests {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- struct TestWorkingSlot {
|
|
|
|
|
- slot: Slot,
|
|
|
|
|
- fork: Vec<Slot>,
|
|
|
|
|
- slot_pos: usize,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- impl TestWorkingSlot {
|
|
|
|
|
- fn new(slot: Slot, fork: &[Slot]) -> Self {
|
|
|
|
|
- let mut fork = fork.to_vec();
|
|
|
|
|
- fork.sort();
|
|
|
|
|
- let slot_pos = fork
|
|
|
|
|
- .iter()
|
|
|
|
|
- .position(|current| *current == slot)
|
|
|
|
|
- .expect("The fork didn't have the slot in it");
|
|
|
|
|
- TestWorkingSlot {
|
|
|
|
|
- slot,
|
|
|
|
|
- fork,
|
|
|
|
|
- slot_pos,
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fn update_slot(&mut self, slot: Slot) {
|
|
|
|
|
- self.slot = slot;
|
|
|
|
|
- self.slot_pos = self
|
|
|
|
|
- .fork
|
|
|
|
|
- .iter()
|
|
|
|
|
- .position(|current| *current == slot)
|
|
|
|
|
- .expect("The fork didn't have the slot in it");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ struct TestWorkingSlot(pub Slot);
|
|
|
|
|
|
|
|
impl WorkingSlot for TestWorkingSlot {
|
|
impl WorkingSlot for TestWorkingSlot {
|
|
|
fn current_slot(&self) -> Slot {
|
|
fn current_slot(&self) -> Slot {
|
|
|
- self.slot
|
|
|
|
|
|
|
+ self.0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn current_epoch(&self) -> Epoch {
|
|
fn current_epoch(&self) -> Epoch {
|
|
|
0
|
|
0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fn is_ancestor(&self, other: Slot) -> bool {
|
|
|
|
|
- self.fork
|
|
|
|
|
- .iter()
|
|
|
|
|
- .position(|current| *current == other)
|
|
|
|
|
- .map(|other_pos| other_pos < self.slot_pos)
|
|
|
|
|
- .unwrap_or(false)
|
|
|
|
|
|
|
+ fn is_ancestor(&self, _other: Slot) -> bool {
|
|
|
|
|
+ false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1571,7 +1558,7 @@ mod tests {
|
|
|
|
|
|
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
|
- fork_graph.insert_fork(&[0, 5, 11, 15, 16, 19, 21, 23]);
|
|
|
|
|
|
|
+ fork_graph.insert_fork(&[0, 5, 11, 15, 16, 18, 19, 21, 23]);
|
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
|
|
|
|
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
@@ -1628,13 +1615,12 @@ mod tests {
|
|
|
// 23
|
|
// 23
|
|
|
|
|
|
|
|
// Testing fork 0 - 10 - 12 - 22 with current slot at 22
|
|
// Testing fork 0 - 10 - 12 - 22 with current slot at 22
|
|
|
- let working_slot = TestWorkingSlot::new(22, &[0, 10, 20, 22]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(22),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 2)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 2)),
|
|
@@ -1651,14 +1637,13 @@ mod tests {
|
|
|
assert!(missing.contains(&(program3, 3)));
|
|
assert!(missing.contains(&(program3, 3)));
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
- // Testing fork 0 - 5 - 11 - 15 - 16 with current slot at 16
|
|
|
|
|
- let mut working_slot = TestWorkingSlot::new(15, &[0, 5, 11, 15, 16, 18, 19, 23]);
|
|
|
|
|
|
|
+ // Testing fork 0 - 5 - 11 - 15 - 16 with current slot at 15
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(15),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1681,13 +1666,12 @@ mod tests {
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
// Testing the same fork above, but current slot is now 18 (equal to effective slot of program4).
|
|
// Testing the same fork above, but current slot is now 18 (equal to effective slot of program4).
|
|
|
- working_slot.update_slot(18);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(18),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1707,13 +1691,12 @@ mod tests {
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
// Testing the same fork above, but current slot is now 23 (future slot than effective slot of program4).
|
|
// Testing the same fork above, but current slot is now 23 (future slot than effective slot of program4).
|
|
|
- working_slot.update_slot(23);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(23),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1733,13 +1716,12 @@ mod tests {
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 with current slot at 11
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 with current slot at 11
|
|
|
- let working_slot = TestWorkingSlot::new(11, &[0, 5, 11, 15, 16]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(11),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1772,13 +1754,12 @@ mod tests {
|
|
|
assert!(!cache.replenish(program4, test_program).0);
|
|
assert!(!cache.replenish(program4, test_program).0);
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
|
- let working_slot = TestWorkingSlot::new(19, &[0, 5, 11, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(19),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1798,13 +1779,12 @@ mod tests {
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 21
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 21
|
|
|
// This would cause program4 deployed at slot 19 to be expired.
|
|
// This would cause program4 deployed at slot 19 to be expired.
|
|
|
- let working_slot = TestWorkingSlot::new(21, &[0, 5, 11, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(21),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1843,14 +1823,13 @@ mod tests {
|
|
|
// |
|
|
// |
|
|
|
// 23
|
|
// 23
|
|
|
|
|
|
|
|
- // Testing fork 11 - 15 - 16- 19 - 22 with root at 5 and current slot at 22
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(22, &[5, 11, 15, 16, 19, 22, 23]);
|
|
|
|
|
|
|
+ // Testing fork 11 - 15 - 16- 19 - 22 with root at 5 and current slot at 21
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(21),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1861,21 +1840,20 @@ mod tests {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Since the fork was pruned, we should not find the entry deployed at slot 20.
|
|
// Since the fork was pruned, we should not find the entry deployed at slot 20.
|
|
|
- assert!(match_slot(&found, &program1, 0, 22));
|
|
|
|
|
- assert!(match_slot(&found, &program2, 11, 22));
|
|
|
|
|
- assert!(match_slot(&found, &program4, 15, 22));
|
|
|
|
|
|
|
+ assert!(match_slot(&found, &program1, 0, 21));
|
|
|
|
|
+ assert!(match_slot(&found, &program2, 11, 21));
|
|
|
|
|
+ assert!(match_slot(&found, &program4, 15, 21));
|
|
|
|
|
|
|
|
assert!(missing.contains(&(program3, 1)));
|
|
assert!(missing.contains(&(program3, 1)));
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 25 - 27 with current slot at 27
|
|
// Testing fork 0 - 5 - 11 - 25 - 27 with current slot at 27
|
|
|
- let working_slot = TestWorkingSlot::new(27, &[11, 25, 27]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing: _,
|
|
missing: _,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(27),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1909,13 +1887,12 @@ mod tests {
|
|
|
// 23
|
|
// 23
|
|
|
|
|
|
|
|
// Testing fork 16, 19, 23, with root at 15, current slot at 23
|
|
// Testing fork 16, 19, 23, with root at 15, current slot at 23
|
|
|
- let working_slot = TestWorkingSlot::new(23, &[16, 19, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(23),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -1955,7 +1932,7 @@ mod tests {
|
|
|
|
|
|
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
|
- fork_graph.insert_fork(&[0, 5, 11, 15, 16, 19, 21, 23]);
|
|
|
|
|
|
|
+ fork_graph.insert_fork(&[0, 5, 11, 12, 15, 16, 18, 19, 21, 23]);
|
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
|
|
|
|
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
@@ -1973,13 +1950,12 @@ mod tests {
|
|
|
assert!(!cache.replenish(program3, new_test_loaded_program(25, 26)).0);
|
|
assert!(!cache.replenish(program3, new_test_loaded_program(25, 26)).0);
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
|
- let working_slot = TestWorkingSlot::new(12, &[0, 5, 11, 12, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(12),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2000,7 +1976,7 @@ mod tests {
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(12),
|
|
|
vec![
|
|
vec![
|
|
|
(
|
|
(
|
|
|
program1,
|
|
program1,
|
|
@@ -2078,13 +2054,12 @@ mod tests {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
|
- let working_slot = TestWorkingSlot::new(19, &[0, 5, 11, 12, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(19),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2100,13 +2075,12 @@ mod tests {
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 25 - 27 with current slot at 27
|
|
// Testing fork 0 - 5 - 11 - 25 - 27 with current slot at 27
|
|
|
- let working_slot = TestWorkingSlot::new(27, &[0, 5, 11, 25, 27]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(27),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2122,13 +2096,12 @@ mod tests {
|
|
|
assert!(missing.is_empty());
|
|
assert!(missing.is_empty());
|
|
|
|
|
|
|
|
// Testing fork 0 - 10 - 20 - 22 with current slot at 22
|
|
// Testing fork 0 - 10 - 20 - 22 with current slot at 22
|
|
|
- let working_slot = TestWorkingSlot::new(22, &[0, 10, 20, 22]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(22),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2164,7 +2137,7 @@ mod tests {
|
|
|
|
|
|
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
fork_graph.insert_fork(&[0, 10, 20, 22]);
|
|
|
- fork_graph.insert_fork(&[0, 5, 11, 15, 16, 19, 21, 23]);
|
|
|
|
|
|
|
+ fork_graph.insert_fork(&[0, 5, 11, 12, 15, 16, 18, 19, 21, 23]);
|
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
fork_graph.insert_fork(&[0, 5, 11, 25, 27]);
|
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
|
cache.set_fork_graph(fork_graph);
|
|
cache.set_fork_graph(fork_graph);
|
|
@@ -2193,13 +2166,12 @@ mod tests {
|
|
|
assert!(!cache.replenish(program1, test_program).0);
|
|
assert!(!cache.replenish(program1, test_program).0);
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
// Testing fork 0 - 5 - 11 - 15 - 16 - 19 - 21 - 23 with current slot at 19
|
|
|
- let working_slot = TestWorkingSlot::new(12, &[0, 5, 11, 12, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(12),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2217,13 +2189,12 @@ mod tests {
|
|
|
|
|
|
|
|
// Testing fork 0 - 5 - 11 - 12 - 15 - 16 - 19 - 21 - 23 with current slot at 15
|
|
// Testing fork 0 - 5 - 11 - 12 - 15 - 16 - 19 - 21 - 23 with current slot at 15
|
|
|
// This would cause program4 deployed at slot 15 to be expired.
|
|
// This would cause program4 deployed at slot 15 to be expired.
|
|
|
- let working_slot = TestWorkingSlot::new(15, &[0, 5, 11, 15, 16, 18, 19, 21, 23]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(15),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2290,13 +2261,12 @@ mod tests {
|
|
|
|
|
|
|
|
cache.prune(10, 0);
|
|
cache.prune(10, 0);
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(20, &[0, 10, 20]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing: _,
|
|
missing: _,
|
|
|
unloaded,
|
|
unloaded,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(20),
|
|
|
vec![(program1, (LoadedProgramMatchCriteria::NoCriteria, 1))].into_iter(),
|
|
vec![(program1, (LoadedProgramMatchCriteria::NoCriteria, 1))].into_iter(),
|
|
|
);
|
|
);
|
|
|
assert!(unloaded.is_empty());
|
|
assert!(unloaded.is_empty());
|
|
@@ -2328,7 +2298,7 @@ mod tests {
|
|
|
// deployed at slot 0.
|
|
// deployed at slot 0.
|
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
let mut fork_graph = TestForkGraphSpecific::default();
|
|
|
fork_graph.insert_fork(&[0, 10, 20]);
|
|
fork_graph.insert_fork(&[0, 10, 20]);
|
|
|
- fork_graph.insert_fork(&[0, 5]);
|
|
|
|
|
|
|
+ fork_graph.insert_fork(&[0, 5, 6]);
|
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
let fork_graph = Arc::new(RwLock::new(fork_graph));
|
|
|
cache.set_fork_graph(fork_graph);
|
|
cache.set_fork_graph(fork_graph);
|
|
|
|
|
|
|
@@ -2339,13 +2309,12 @@ mod tests {
|
|
|
let program2 = Pubkey::new_unique();
|
|
let program2 = Pubkey::new_unique();
|
|
|
assert!(!cache.replenish(program2, new_test_loaded_program(10, 11)).0);
|
|
assert!(!cache.replenish(program2, new_test_loaded_program(10, 11)).0);
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(20, &[0, 10, 20]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing: _,
|
|
missing: _,
|
|
|
unloaded: _,
|
|
unloaded: _,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(20),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2356,13 +2325,12 @@ mod tests {
|
|
|
assert!(match_slot(&found, &program1, 0, 20));
|
|
assert!(match_slot(&found, &program1, 0, 20));
|
|
|
assert!(match_slot(&found, &program2, 10, 20));
|
|
assert!(match_slot(&found, &program2, 10, 20));
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(6, &[0, 5, 6]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded: _,
|
|
unloaded: _,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(6),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2377,13 +2345,12 @@ mod tests {
|
|
|
// On fork chaining from slot 5, the entry deployed at slot 0 will become visible.
|
|
// On fork chaining from slot 5, the entry deployed at slot 0 will become visible.
|
|
|
cache.prune_by_deployment_slot(5);
|
|
cache.prune_by_deployment_slot(5);
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(20, &[0, 10, 20]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing: _,
|
|
missing: _,
|
|
|
unloaded: _,
|
|
unloaded: _,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(20),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2394,13 +2361,12 @@ mod tests {
|
|
|
assert!(match_slot(&found, &program1, 0, 20));
|
|
assert!(match_slot(&found, &program1, 0, 20));
|
|
|
assert!(match_slot(&found, &program2, 10, 20));
|
|
assert!(match_slot(&found, &program2, 10, 20));
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(6, &[0, 5, 6]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing,
|
|
missing,
|
|
|
unloaded: _,
|
|
unloaded: _,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(6),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
@@ -2415,13 +2381,12 @@ mod tests {
|
|
|
// As there is no other entry for program2, extract() will return it as missing.
|
|
// As there is no other entry for program2, extract() will return it as missing.
|
|
|
cache.prune_by_deployment_slot(10);
|
|
cache.prune_by_deployment_slot(10);
|
|
|
|
|
|
|
|
- let working_slot = TestWorkingSlot::new(20, &[0, 10, 20]);
|
|
|
|
|
let ExtractedPrograms {
|
|
let ExtractedPrograms {
|
|
|
loaded: found,
|
|
loaded: found,
|
|
|
missing: _,
|
|
missing: _,
|
|
|
unloaded: _,
|
|
unloaded: _,
|
|
|
} = cache.extract(
|
|
} = cache.extract(
|
|
|
- &working_slot,
|
|
|
|
|
|
|
+ &TestWorkingSlot(20),
|
|
|
vec![
|
|
vec![
|
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program1, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|
|
(program2, (LoadedProgramMatchCriteria::NoCriteria, 1)),
|