-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dag] broadcast nodes within window till all validators ack (#11751)
* [dag] broadcast nodes within window till all validators ack * [dag] use DropGuard to drop handles * move BoundedVecDeque to aptos-collections * use BoundedVecDeque in MetadataAdapter
- Loading branch information
1 parent
e173271
commit 2b3cce4
Showing
8 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "aptos-collections" | ||
description = "Aptos Collections Library" | ||
version = "0.1.0" | ||
|
||
# Workspace inherited keys | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
publish = { workspace = true } | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
use std::collections::{ | ||
vec_deque::{IntoIter, Iter}, | ||
VecDeque, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct BoundedVecDeque<T> { | ||
inner: VecDeque<T>, | ||
capacity: usize, | ||
} | ||
|
||
impl<T> BoundedVecDeque<T> { | ||
pub fn new(capacity: usize) -> Self { | ||
assert!(capacity > 0); | ||
Self { | ||
inner: VecDeque::with_capacity(capacity), | ||
capacity, | ||
} | ||
} | ||
|
||
pub fn is_full(&self) -> bool { | ||
self.inner.len() == self.capacity | ||
} | ||
|
||
pub fn push_back(&mut self, item: T) -> Option<T> { | ||
let oldest = if self.is_full() { | ||
self.inner.pop_front() | ||
} else { | ||
None | ||
}; | ||
|
||
self.inner.push_back(item); | ||
assert!(self.inner.len() <= self.capacity); | ||
oldest | ||
} | ||
|
||
pub fn push_front(&mut self, item: T) -> Option<T> { | ||
let oldest = if self.is_full() { | ||
self.inner.pop_back() | ||
} else { | ||
None | ||
}; | ||
|
||
self.inner.push_front(item); | ||
assert!(self.inner.len() <= self.capacity); | ||
oldest | ||
} | ||
|
||
pub fn iter(&self) -> Iter<'_, T> { | ||
self.inner.iter() | ||
} | ||
} | ||
|
||
impl<T> IntoIterator for BoundedVecDeque<T> { | ||
type IntoIter = IntoIter<T>; | ||
type Item = T; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.inner.into_iter() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::BoundedVecDeque; | ||
|
||
#[test] | ||
fn test_bounded_vec_deque_capacity() { | ||
let capacity = 10; | ||
let mut queue = BoundedVecDeque::new(capacity); | ||
for i in 0..capacity { | ||
queue.push_back(i); | ||
} | ||
|
||
assert!(queue.is_full()); | ||
|
||
assert_eq!(queue.push_back(capacity), Some(0)); | ||
|
||
assert_eq!(queue.push_front(0), Some(capacity)); | ||
} | ||
|
||
#[test] | ||
fn test_bounded_vec_deque_iter() { | ||
let capacity = 10; | ||
let mut queue = BoundedVecDeque::new(capacity); | ||
for i in 0..capacity { | ||
queue.push_back(i); | ||
} | ||
|
||
for (i, item) in queue.iter().enumerate() { | ||
assert_eq!(i, *item); | ||
} | ||
|
||
for (i, item) in queue.into_iter().enumerate() { | ||
assert_eq!(i, item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
mod bounded_vec_deque; | ||
|
||
pub use bounded_vec_deque::BoundedVecDeque; |