Rename blocktree SlotMeta::is_rooted to is_connected
is_rooted is now is_connected and (still) indicates the set of connected completed slots. 'rooted' slot terminology is used for a different meaning in bank_forks and replay_stage.
This commit is contained in:
parent
9b7c1d5650
commit
4fb0782892
|
@ -101,8 +101,8 @@ pub struct SlotMeta {
|
||||||
// from this one.
|
// from this one.
|
||||||
pub next_slots: Vec<u64>,
|
pub next_slots: Vec<u64>,
|
||||||
// True if this slot is full (consumed == last_index + 1) and if every
|
// True if this slot is full (consumed == last_index + 1) and if every
|
||||||
// slot that is a parent of this slot is also rooted.
|
// slot that is a parent of this slot is also connected.
|
||||||
pub is_rooted: bool,
|
pub is_connected: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SlotMeta {
|
impl SlotMeta {
|
||||||
|
@ -125,7 +125,7 @@ impl SlotMeta {
|
||||||
received: 0,
|
received: 0,
|
||||||
parent_slot,
|
parent_slot,
|
||||||
next_slots: vec![],
|
next_slots: vec![],
|
||||||
is_rooted: slot == 0,
|
is_connected: slot == 0,
|
||||||
last_index: std::u64::MAX,
|
last_index: std::u64::MAX,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -636,7 +636,7 @@ impl Blocktree {
|
||||||
// from block 0, which is true iff:
|
// from block 0, which is true iff:
|
||||||
// 1) The block with index prev_block_index is itself part of the trunk of consecutive blocks
|
// 1) The block with index prev_block_index is itself part of the trunk of consecutive blocks
|
||||||
// starting from block 0,
|
// starting from block 0,
|
||||||
slot_meta.is_rooted &&
|
slot_meta.is_connected &&
|
||||||
// AND either:
|
// AND either:
|
||||||
// 1) The slot didn't exist in the database before, and now we have a consecutive
|
// 1) The slot didn't exist in the database before, and now we have a consecutive
|
||||||
// block for that slot
|
// block for that slot
|
||||||
|
@ -696,7 +696,7 @@ impl Blocktree {
|
||||||
|
|
||||||
// This is a newly inserted slot so:
|
// This is a newly inserted slot so:
|
||||||
// 1) Chain to the previous slot, and also
|
// 1) Chain to the previous slot, and also
|
||||||
// 2) Determine whether to set the is_rooted flag
|
// 2) Determine whether to set the is_connected flag
|
||||||
self.chain_new_slot_to_prev_slot(
|
self.chain_new_slot_to_prev_slot(
|
||||||
&mut prev_slot.borrow_mut(),
|
&mut prev_slot.borrow_mut(),
|
||||||
slot,
|
slot,
|
||||||
|
@ -707,15 +707,15 @@ impl Blocktree {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_newly_completed_slot(&RefCell::borrow(&*meta_copy), meta_backup)
|
if self.is_newly_completed_slot(&RefCell::borrow(&*meta_copy), meta_backup)
|
||||||
&& RefCell::borrow(&*meta_copy).is_rooted
|
&& RefCell::borrow(&*meta_copy).is_connected
|
||||||
{
|
{
|
||||||
// This is a newly inserted slot and slot.is_rooted is true, so go through
|
// This is a newly inserted slot and slot.is_connected is true, so go through
|
||||||
// and update all child slots with is_rooted if applicable
|
// and update all child slots with is_connected if applicable
|
||||||
let mut next_slots: Vec<(u64, Rc<RefCell<(SlotMeta)>>)> =
|
let mut next_slots: Vec<(u64, Rc<RefCell<(SlotMeta)>>)> =
|
||||||
vec![(slot, meta_copy.clone())];
|
vec![(slot, meta_copy.clone())];
|
||||||
while !next_slots.is_empty() {
|
while !next_slots.is_empty() {
|
||||||
let (_, current_slot) = next_slots.pop().unwrap();
|
let (_, current_slot) = next_slots.pop().unwrap();
|
||||||
current_slot.borrow_mut().is_rooted = true;
|
current_slot.borrow_mut().is_connected = true;
|
||||||
|
|
||||||
let current_slot = &RefCell::borrow(&*current_slot);
|
let current_slot = &RefCell::borrow(&*current_slot);
|
||||||
if current_slot.is_full() {
|
if current_slot.is_full() {
|
||||||
|
@ -741,7 +741,7 @@ impl Blocktree {
|
||||||
current_slot_meta: &mut SlotMeta,
|
current_slot_meta: &mut SlotMeta,
|
||||||
) {
|
) {
|
||||||
prev_slot_meta.next_slots.push(current_slot);
|
prev_slot_meta.next_slots.push(current_slot);
|
||||||
current_slot_meta.is_rooted = prev_slot_meta.is_rooted && prev_slot_meta.is_full();
|
current_slot_meta.is_connected = prev_slot_meta.is_connected && prev_slot_meta.is_full();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_newly_completed_slot(
|
fn is_newly_completed_slot(
|
||||||
|
@ -915,7 +915,7 @@ impl Blocktree {
|
||||||
|
|
||||||
bootstrap_meta.consumed = last.index() + 1;
|
bootstrap_meta.consumed = last.index() + 1;
|
||||||
bootstrap_meta.received = last.index() + 1;
|
bootstrap_meta.received = last.index() + 1;
|
||||||
bootstrap_meta.is_rooted = true;
|
bootstrap_meta.is_connected = true;
|
||||||
|
|
||||||
let mut batch = self.db.batch()?;
|
let mut batch = self.db.batch()?;
|
||||||
batch.put_cf(
|
batch.put_cf(
|
||||||
|
@ -1319,7 +1319,7 @@ pub mod tests {
|
||||||
assert_eq!(meta.parent_slot, 0);
|
assert_eq!(meta.parent_slot, 0);
|
||||||
assert_eq!(meta.last_index, num_entries - 1);
|
assert_eq!(meta.last_index, num_entries - 1);
|
||||||
assert!(meta.next_slots.is_empty());
|
assert!(meta.next_slots.is_empty());
|
||||||
assert!(meta.is_rooted);
|
assert!(meta.is_connected);
|
||||||
|
|
||||||
// Destroying database without closing it first is undefined behavior
|
// Destroying database without closing it first is undefined behavior
|
||||||
drop(ledger);
|
drop(ledger);
|
||||||
|
@ -1755,7 +1755,7 @@ pub mod tests {
|
||||||
let s1 = blocktree.meta(1).unwrap().unwrap();
|
let s1 = blocktree.meta(1).unwrap().unwrap();
|
||||||
assert!(s1.next_slots.is_empty());
|
assert!(s1.next_slots.is_empty());
|
||||||
// Slot 1 is not trunk because slot 0 hasn't been inserted yet
|
// Slot 1 is not trunk because slot 0 hasn't been inserted yet
|
||||||
assert!(!s1.is_rooted);
|
assert!(!s1.is_connected);
|
||||||
assert_eq!(s1.parent_slot, 0);
|
assert_eq!(s1.parent_slot, 0);
|
||||||
assert_eq!(s1.last_index, entries_per_slot - 1);
|
assert_eq!(s1.last_index, entries_per_slot - 1);
|
||||||
|
|
||||||
|
@ -1766,7 +1766,7 @@ pub mod tests {
|
||||||
let s2 = blocktree.meta(2).unwrap().unwrap();
|
let s2 = blocktree.meta(2).unwrap().unwrap();
|
||||||
assert!(s2.next_slots.is_empty());
|
assert!(s2.next_slots.is_empty());
|
||||||
// Slot 2 is not trunk because slot 0 hasn't been inserted yet
|
// Slot 2 is not trunk because slot 0 hasn't been inserted yet
|
||||||
assert!(!s2.is_rooted);
|
assert!(!s2.is_connected);
|
||||||
assert_eq!(s2.parent_slot, 1);
|
assert_eq!(s2.parent_slot, 1);
|
||||||
assert_eq!(s2.last_index, entries_per_slot - 1);
|
assert_eq!(s2.last_index, entries_per_slot - 1);
|
||||||
|
|
||||||
|
@ -1774,7 +1774,7 @@ pub mod tests {
|
||||||
// but still isn't part of the trunk
|
// but still isn't part of the trunk
|
||||||
let s1 = blocktree.meta(1).unwrap().unwrap();
|
let s1 = blocktree.meta(1).unwrap().unwrap();
|
||||||
assert_eq!(s1.next_slots, vec![2]);
|
assert_eq!(s1.next_slots, vec![2]);
|
||||||
assert!(!s1.is_rooted);
|
assert!(!s1.is_connected);
|
||||||
assert_eq!(s1.parent_slot, 0);
|
assert_eq!(s1.parent_slot, 0);
|
||||||
assert_eq!(s1.last_index, entries_per_slot - 1);
|
assert_eq!(s1.last_index, entries_per_slot - 1);
|
||||||
|
|
||||||
|
@ -1795,7 +1795,7 @@ pub mod tests {
|
||||||
assert_eq!(s.parent_slot, i - 1);
|
assert_eq!(s.parent_slot, i - 1);
|
||||||
}
|
}
|
||||||
assert_eq!(s.last_index, entries_per_slot - 1);
|
assert_eq!(s.last_index, entries_per_slot - 1);
|
||||||
assert!(s.is_rooted);
|
assert!(s.is_connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
|
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
|
||||||
|
@ -1849,9 +1849,9 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
assert!(s.is_rooted);
|
assert!(s.is_connected);
|
||||||
} else {
|
} else {
|
||||||
assert!(!s.is_rooted);
|
assert!(!s.is_connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1874,7 +1874,7 @@ pub mod tests {
|
||||||
assert_eq!(s.parent_slot, i - 1);
|
assert_eq!(s.parent_slot, i - 1);
|
||||||
}
|
}
|
||||||
assert_eq!(s.last_index, entries_per_slot - 1);
|
assert_eq!(s.last_index, entries_per_slot - 1);
|
||||||
assert!(s.is_rooted);
|
assert!(s.is_connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1882,8 +1882,8 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_forward_chaining_is_rooted() {
|
pub fn test_forward_chaining_is_connected() {
|
||||||
let blocktree_path = get_tmp_ledger_path("test_forward_chaining_is_rooted");
|
let blocktree_path = get_tmp_ledger_path("test_forward_chaining_is_connected");
|
||||||
{
|
{
|
||||||
let blocktree = Blocktree::open(&blocktree_path).unwrap();
|
let blocktree = Blocktree::open(&blocktree_path).unwrap();
|
||||||
let num_slots = 15;
|
let num_slots = 15;
|
||||||
|
@ -1925,9 +1925,9 @@ pub mod tests {
|
||||||
|
|
||||||
// Other than slot 0, no slots should be part of the trunk
|
// Other than slot 0, no slots should be part of the trunk
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
assert!(!s.is_rooted);
|
assert!(!s.is_connected);
|
||||||
} else {
|
} else {
|
||||||
assert!(s.is_rooted);
|
assert!(s.is_connected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1945,9 +1945,9 @@ pub mod tests {
|
||||||
assert!(s.next_slots.is_empty());
|
assert!(s.next_slots.is_empty());
|
||||||
}
|
}
|
||||||
if i <= slot_index as u64 + 3 {
|
if i <= slot_index as u64 + 3 {
|
||||||
assert!(s.is_rooted);
|
assert!(s.is_connected);
|
||||||
} else {
|
} else {
|
||||||
assert!(!s.is_rooted);
|
assert!(!s.is_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
|
|
@ -315,7 +315,7 @@ impl Replicator {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
while let Ok(meta) = blocktree.meta(current_slot) {
|
while let Ok(meta) = blocktree.meta(current_slot) {
|
||||||
if let Some(meta) = meta {
|
if let Some(meta) = meta {
|
||||||
if meta.is_rooted {
|
if meta.is_connected {
|
||||||
current_slot += 1;
|
current_slot += 1;
|
||||||
warn!("current slot: {}", current_slot);
|
warn!("current slot: {}", current_slot);
|
||||||
if current_slot >= start_slot + ENTRIES_PER_SEGMENT {
|
if current_slot >= start_slot + ENTRIES_PER_SEGMENT {
|
||||||
|
|
Loading…
Reference in New Issue