Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mio for Tcp management in bootstrap system #3780

Merged
merged 103 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
7ae5b2d
Make establisher `get_listener` non-async
Ben-PH Feb 27, 2023
bdd8e54
Make establisher `fn get_connector` non-async
Ben-PH Feb 27, 2023
b77875c
Set the mockers to use a TcpStream as a duplex
Ben-PH Feb 27, 2023
4e6c89f
fix(bootstrap) : fix base_bootstrap_ip
Feb 28, 2023
bf0301c
Duplex -> tokio::net::TcpStream. same for Listener
Ben-PH Mar 3, 2023
baac844
unify listener interface through trait
Ben-PH Mar 3, 2023
1e00ce4
remove `#[cfg(test)]` from bootstrap establisher
Ben-PH Mar 3, 2023
77d0b8e
Add FIXME to where static lifetime is being used as a hot-fix
Ben-PH Mar 3, 2023
710a8c8
Light house-keeping
Ben-PH Mar 3, 2023
4d14a09
Clear clippy lint
Ben-PH Mar 3, 2023
7c131db
Some code-comments
Ben-PH Mar 3, 2023
2150b03
Using a blocking tcp interface, but things lock up
Ben-PH Mar 13, 2023
2e086c1
Fix blocking by making the tokio conversion using non-blocking objects
Ben-PH Mar 14, 2023
a637e00
Remove the async Tcp stuff from mock connector
Ben-PH Mar 14, 2023
725902f
Use less async channels. Use Arc<AtomicBool> as signaller
Ben-PH Mar 14, 2023
0236535
Fewer async channels
Ben-PH Mar 14, 2023
b32246b
So close to not using tokio...
Ben-PH Mar 14, 2023
a7f3c51
accept method now synchronous!!!
Ben-PH Mar 14, 2023
c1c0936
Merge remote-tracking branch 'origin/testnet_21' into bootstrap/sync-…
Ben-PH Mar 15, 2023
e8d53f1
make connect synchronous
Ben-PH Mar 15, 2023
2cc4256
Some cleanup
Ben-PH Mar 15, 2023
fcdf28e
Clear clippy lint
Ben-PH Mar 15, 2023
5732529
Fix upstream merge error
Ben-PH Mar 15, 2023
bf7f89f
more cleanup
Ben-PH Mar 15, 2023
78459e0
Make listener blocking
Ben-PH Mar 22, 2023
dffa060
Make the Duplex a trait, thus mockable
Ben-PH Mar 24, 2023
ea51448
Start the server with the listener instead of estab trait
Ben-PH Mar 27, 2023
436517b
Update comments
Ben-PH Mar 27, 2023
11a3b24
Remove mock-establisher interface entirely
Ben-PH Mar 27, 2023
e0a3089
Move the default get-listener into a struct method
Ben-PH Mar 27, 2023
17783ad
Give mock setup variables clearer names
Ben-PH Mar 27, 2023
660e7e2
Add mocking todos
Ben-PH Mar 27, 2023
4802558
Remove `dbg!`s
Ben-PH Mar 29, 2023
e990892
Self review
Ben-PH Mar 29, 2023
c53a842
Make the network command sender mockable
Ben-PH Mar 27, 2023
40e8f60
Use auto-mock to get the bootstrap peers
Ben-PH Mar 27, 2023
e224356
Mock the consensus controller implementation when testing bootstrap
Ben-PH Mar 27, 2023
ed056e8
Replace the mock establisher with `automock` of listener and connector
Ben-PH Mar 29, 2023
877fb00
Clarify the mock-connection setup
Ben-PH Mar 29, 2023
512a4ff
Remove the vestigial mock_establisher.rs file
Ben-PH Mar 29, 2023
337d3fd
Move some of `get_stat` pre-loop code to helper functions
Ben-PH Mar 29, 2023
4bc6611
Move everything from tokio to std::net::TcpStream
Ben-PH Mar 29, 2023
c9f107d
Comment out the use of tokio timeeouts
Ben-PH Mar 29, 2023
210e52e
Propogate errors instead of unwrapping
Ben-PH Mar 29, 2023
840cfa5
Don't panic if you don't have a bootstrap listen address
Ben-PH Mar 29, 2023
dcf2351
Merge remote-tracking branch 'origin/testnet_21' into bootstrap/sync-…
Ben-PH Mar 29, 2023
0721d10
Remove vestigial `DefaultEstablisher`
Ben-PH Mar 29, 2023
04f30e7
Merge branch 'bootstrap/sync-accept' into bootstrap/mocked-and-sync
Ben-PH Mar 29, 2023
f128231
Refactor the connector
Ben-PH Mar 29, 2023
36d6101
General Cleanup
Ben-PH Mar 29, 2023
7cc9e45
De-async more methods and start working on `next` blockage
Ben-PH Mar 30, 2023
aa38179
Fix clippy and compilation warn/error
Ben-PH Mar 30, 2023
757ac3c
Make the boostrap test sync
Ben-PH Mar 30, 2023
6282b68
Integrate timeouts into sending and receiving messages
Ben-PH Mar 30, 2023
af20c1e
Fully clear out async in the bootstrap test
Ben-PH Mar 30, 2023
2bbd6ac
Get bootstrap test passing!
Ben-PH Mar 30, 2023
3b73bda
Make message sending from server sync
Ben-PH Mar 30, 2023
7c5c3d6
Get binder tests working
Ben-PH Mar 30, 2023
54954a7
Merge branch 'bootstrap/sync-accept' into bootstrap/mocked-and-sync
Ben-PH Mar 30, 2023
38d5fc2
Fix issues created by merge
Ben-PH Mar 30, 2023
22c5d96
Merge remote-tracking branch 'origin/testnet_21' into bootstrap/mocke…
Ben-PH Mar 30, 2023
a8e5d57
clear clippy lints
Ben-PH Mar 30, 2023
b1a4e35
Remove unused dependency
Ben-PH Mar 30, 2023
68c1efe
Remove `dbg!`s
Ben-PH Mar 30, 2023
cd8392c
Add timed-out variant to bootstrap error
Ben-PH Mar 31, 2023
f706b85
remove clippy::result_large_err (#3751)
modship Apr 3, 2023
c674533
remove #[allow(clippy::result_large_err)] in white_black_list.rs
Apr 3, 2023
45e37f6
why unwrap, when you have ?... ?
Ben-PH Apr 3, 2023
eb46446
improve error and readability (#3757)
modship Apr 4, 2023
3b299cf
Remove the Duplex trait.
Ben-PH Apr 4, 2023
d87fccc
Merge remote-tracking branch 'origin/testnet_21' into bootstrap/mocke…
Ben-PH Apr 4, 2023
805ce36
Fix Duplex deletion commit
Ben-PH Apr 4, 2023
5794404
Merge branch 'testnet_21' into bootstrap/mocked-and-sync
Ben-PH Apr 5, 2023
3c60733
refactor(bootstrap) : first step setup listener
Apr 6, 2023
492c9c8
setup stop listener
Apr 6, 2023
ec51674
using new listener for bootstrap
Apr 6, 2023
06af1c6
make 'node_stop' cmd works
Apr 6, 2023
e59909a
remove selector
Apr 6, 2023
d838074
comment
Apr 6, 2023
fb3bcda
start_bootstrap_server should return Result, not Result<Option<T>>
Apr 6, 2023
d9672dd
remove fn that are no longer needed
Apr 6, 2023
15f4496
Merge remote-tracking branch 'origin/testnet_21' into bootstrap/mocke…
Ben-PH Apr 6, 2023
e1d6443
use tcpstream from std and restore timeout
Apr 6, 2023
df2478f
Merge branch 'bootstrap/mocked-and-sync' into bootstrap/listener
Apr 6, 2023
2a140f7
update (actually broken)
Apr 6, 2023
60aafe2
dependencies
Apr 6, 2023
3e725cc
remove non_blocking
Apr 6, 2023
dba3091
transfer ownership of mio_server to the bs_listener thread
Apr 6, 2023
f2b5ce0
remove line
Apr 7, 2023
8de21c6
test first step auto gen manager
Apr 7, 2023
a2da610
Reference changes: Update mio-pollable std-net listener to not requir…
Ben-PH Apr 19, 2023
5fc069b
Merge branch 'testnet_22' into bootstrap/listener
Ben-PH Apr 24, 2023
a49a3c8
Fix clippy lints
Ben-PH May 2, 2023
d25f902
Fix poll block by keeping waker allive long enough
Ben-PH May 2, 2023
710ca1e
Self-review
Ben-PH May 2, 2023
d8a4777
Merge remote-tracking branch 'origin/testnet_22' into bootstrap/listener
Ben-PH May 2, 2023
30cfea5
include newly introduced fields following upstream update
Ben-PH May 2, 2023
8c4b246
Update massa-bootstrap/src/listener.rs comment
Ben-PH May 2, 2023
bc2ba95
Setup `FinalStateConfig` in scenarios more intelligently
Ben-PH May 2, 2023
db82251
Clean up the testing a touch
Ben-PH May 2, 2023
78dc321
try 127.0.0.1 instead of 0.0.0.0 for testing
Ben-PH May 2, 2023
4943f00
Merge remote-tracking branch 'origin/testnet_22' into bootstrap/listener
Ben-PH May 3, 2023
2566d18
Fix up post-update errors
Ben-PH May 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 165 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions massa-bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tracing = "0.1"
substruct = { git = "https://github.com/sydhds/substruct" }
socket2 = "0.4.7"
crossbeam = "0.8.2"
mio = { version = "0.8", features = ["net", "os-poll"] }

# custom modules
massa_async_pool = { path = "../massa-async-pool" }
Expand Down
12 changes: 7 additions & 5 deletions massa-bootstrap/src/establisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ use std::{
net::{SocketAddr, TcpListener, TcpStream},
};

use crate::{error::BootstrapError, listener::PollEvent};

/// Specifies a common interface that can be used by standard, or mockers
#[cfg_attr(test, mockall::automock)]
pub trait BSListener {
fn accept(&mut self) -> io::Result<(TcpStream, SocketAddr)>;
pub trait BSEventPoller {
fn poll(&mut self) -> Result<PollEvent, BootstrapError>;
}

/// Specifies a common interface that can be used by standard, or mockers
Expand Down Expand Up @@ -49,14 +51,14 @@ impl DefaultListener {
}
}

impl BSListener for DefaultListener {
impl BSEventPoller for DefaultListener {
/// Accepts a new incoming connection from this listener.
fn accept(&mut self) -> io::Result<(TcpStream, SocketAddr)> {
fn poll(&mut self) -> Result<PollEvent, BootstrapError> {
// accept
let (sock, mut remote_addr) = self.0.accept()?;
// normalize address
remote_addr.set_ip(remote_addr.ip().to_canonical());
Ok((sock, remote_addr))
Ok(PollEvent::NewConnection((sock, remote_addr)))
}
}
/// Initiates a connection with given timeout in milliseconds
Expand Down
2 changes: 2 additions & 0 deletions massa-bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mod client;
mod client_binder;
mod error;
mod establisher;
mod listener;
pub use listener::BootstrapTcpListener;
mod messages;
mod server;
mod server_binder;
Expand Down
84 changes: 84 additions & 0 deletions massa-bootstrap/src/listener.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::net::{SocketAddr, TcpListener, TcpStream};

use mio::net::TcpListener as MioTcpListener;

use mio::{Events, Interest, Poll, Token, Waker};
use tracing::info;

use crate::error::BootstrapError;
use crate::establisher::BSEventPoller;

const NEW_CONNECTION: Token = Token(0);
const STOP_LISTENER: Token = Token(10);

/// TODO: this should be crate-private. currently needed for models testing
pub struct BootstrapTcpListener {
Ben-PH marked this conversation as resolved.
Show resolved Hide resolved
poll: Poll,
events: Events,
server: TcpListener,
// HACK : create variable to move ownership of mio_server to the thread
// if mio_server is not moved, poll does not receive any event from listener
_mio_server: MioTcpListener,
}

pub struct BootstrapListenerStopHandle(Waker);
Ben-PH marked this conversation as resolved.
Show resolved Hide resolved

pub enum PollEvent {
Ben-PH marked this conversation as resolved.
Show resolved Hide resolved
NewConnection((TcpStream, SocketAddr)),
Stop,
}
impl BootstrapTcpListener {
/// Setup a mio-listener that functions as a `select!` on a connection, or a waker
///
/// * `addr` - the address to listen on
pub fn new(addr: SocketAddr) -> Result<(BootstrapListenerStopHandle, Self), BootstrapError> {
info!("Starting bootstrap listener on {}", &addr);
let server = TcpListener::bind(addr)?;
let mut mio_server =
MioTcpListener::from_std(server.try_clone().expect("Unable to clone server socket"));

let poll = Poll::new()?;

// wake up the poll when we want to stop the listener
let waker = BootstrapListenerStopHandle(Waker::new(poll.registry(), STOP_LISTENER)?);

poll.registry()
.register(&mut mio_server, NEW_CONNECTION, Interest::READABLE)?;

// TODO use config for capacity ?
let events = Events::with_capacity(32);
Ok((
waker,
BootstrapTcpListener {
poll,
server,
events,
_mio_server: mio_server,
},
))
}
}

impl BSEventPoller for BootstrapTcpListener {
fn poll(&mut self) -> Result<PollEvent, BootstrapError> {
self.poll.poll(&mut self.events, None).unwrap();

// Confirm that we are not being signalled to shut down
if self.events.iter().any(|ev| ev.token() == STOP_LISTENER) {
return Ok(PollEvent::Stop);
}

// Ther could be more than one connection ready, but we want to re-check for the stop
// signal after processing each connection.
Ok(PollEvent::NewConnection(
self.server.accept().map_err(BootstrapError::from)?,
))
}
}

impl BootstrapListenerStopHandle {
/// Stop the bootstrap listener.
pub fn stop(&self) -> Result<(), BootstrapError> {
self.0.wake().map_err(BootstrapError::from)
}
}
Loading