-
Notifications
You must be signed in to change notification settings - Fork 86
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
feat(sequencer, charts)!: support uds for abci #1877
base: main
Are you sure you want to change the base?
Changes from 1 commit
3daee25
9d53b1c
d007498
5fc2db8
7f470b9
ee48c78
aa95d03
d1f07cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,3 @@ if [ ! -d "/cometbft/config" ]; then | |
else | ||
cp /config/* /cometbft/config/ | ||
fi | ||
|
||
chmod -R 0777 /cometbft |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use astria_eyre::{ | |
eyre::{ | ||
eyre, | ||
OptionExt as _, | ||
Report, | ||
Result, | ||
WrapErr as _, | ||
}, | ||
|
@@ -33,6 +34,7 @@ use tracing::{ | |
info, | ||
info_span, | ||
}; | ||
use url::Url; | ||
|
||
use crate::{ | ||
app::App, | ||
|
@@ -95,26 +97,7 @@ impl Sequencer { | |
.await | ||
.wrap_err("failed to initialize app")?; | ||
|
||
let consensus_service = tower::ServiceBuilder::new() | ||
.layer(request_span::layer(|req: &ConsensusRequest| { | ||
req.create_span() | ||
})) | ||
.service(tower_actor::Actor::new(10, |queue: _| { | ||
let storage = storage.clone(); | ||
async move { service::Consensus::new(storage, app, queue).run().await } | ||
})); | ||
let mempool_service = service::Mempool::new(storage.clone(), mempool.clone(), metrics); | ||
let info_service = | ||
service::Info::new(storage.clone()).wrap_err("failed initializing info service")?; | ||
let snapshot_service = service::Snapshot; | ||
|
||
let server = Server::builder() | ||
.consensus(consensus_service) | ||
.info(info_service) | ||
.mempool(mempool_service) | ||
.snapshot(snapshot_service) | ||
.finish() | ||
.ok_or_eyre("server builder didn't return server; are all fields set?")?; | ||
|
||
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel(); | ||
let (server_exit_tx, server_exit_rx) = tokio::sync::oneshot::channel(); | ||
|
@@ -125,20 +108,15 @@ impl Sequencer { | |
.wrap_err("failed to parse grpc_addr address")?; | ||
let grpc_server_handle = start_grpc_server(&storage, mempool, grpc_addr, shutdown_rx); | ||
|
||
span.in_scope(|| info!(config.listen_addr, "starting sequencer")); | ||
let server_handle = tokio::spawn(async move { | ||
match server.listen_tcp(&config.listen_addr).await { | ||
Ok(()) => { | ||
// this shouldn't happen, as there isn't a way for the ABCI server to exit | ||
info_span!("abci_server").in_scope(|| info!("ABCI server exited successfully")); | ||
} | ||
Err(e) => { | ||
error_span!("abci_server") | ||
.in_scope(|| error!(err = e.as_ref(), "ABCI server exited with error")); | ||
} | ||
} | ||
let _ = server_exit_tx.send(()); | ||
}); | ||
span.in_scope(|| info!(config.abci_listener_url, "starting abci sequencer")); | ||
let abci_server_handle = start_abci_server( | ||
&storage, | ||
app, | ||
mempool_service, | ||
&config.abci_listener_url, | ||
server_exit_tx, | ||
) | ||
.wrap_err("failed to start ABCI server")?; | ||
|
||
select! { | ||
_ = signals.stop_rx.changed() => { | ||
|
@@ -157,7 +135,7 @@ impl Sequencer { | |
.await | ||
.wrap_err("grpc server task failed")? | ||
.wrap_err("grpc server failed")?; | ||
server_handle.abort(); | ||
abci_server_handle.abort(); | ||
Ok(()) | ||
} | ||
} | ||
|
@@ -210,6 +188,83 @@ fn start_grpc_server( | |
) | ||
} | ||
|
||
fn start_abci_server( | ||
storage: &cnidarium::Storage, | ||
app: App, | ||
mempool_service: service::Mempool, | ||
listen_url: &str, | ||
server_exit_tx: oneshot::Sender<()>, | ||
) -> Result<JoinHandle<()>, Report> { | ||
// Setup services required for the ABCI server | ||
let consensus_service = tower::ServiceBuilder::new() | ||
.layer(request_span::layer(|req: &ConsensusRequest| { | ||
req.create_span() | ||
})) | ||
.service(tower_actor::Actor::new(10, |queue: _| { | ||
let storage = storage.clone(); | ||
async move { service::Consensus::new(storage, app, queue).run().await } | ||
})); | ||
let info_service = | ||
service::Info::new(storage.clone()).wrap_err("failed initializing info service")?; | ||
let snapshot_service = service::Snapshot; | ||
|
||
// Builds the server but does not start listening. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment |
||
let server = Server::builder() | ||
.consensus(consensus_service) | ||
.info(info_service) | ||
.mempool(mempool_service) | ||
.snapshot(snapshot_service) | ||
.finish() | ||
.ok_or_eyre("server builder didn't return server; are all fields set?")?; | ||
|
||
// Validate and parse the listen_url received from the config. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (as well as the subsequent server start) could be done more elegantly by providing a type |
||
let abci_url = Url::parse(listen_url).wrap_err("failed to parse listen_addr")?; | ||
let validated_listen_addr = match abci_url.scheme() { | ||
"unix" => match abci_url.to_file_path() { | ||
Ok(_) => Ok(abci_url.path().to_string()), | ||
Err(e) => Err(eyre!( | ||
"failed parsing unix listen_addr file path, error: {:?}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure eyre!(e).wrap_err("failed rasing unix listen_addr file path") |
||
e | ||
)), | ||
}, | ||
"tcp" => { | ||
let host_str = abci_url | ||
.host_str() | ||
.ok_or_eyre("missing host in tcp listen_addr")?; | ||
let port = abci_url | ||
.port() | ||
.ok_or_eyre("missing port in tcp listen_addr")?; | ||
Ok(format!("{host_str}:{port}")) | ||
} | ||
// If more options are added here will also need to update the server startup | ||
// immediately below to support more than two protocols. | ||
_ => Err(eyre!( | ||
"unsupported protocol in `abci_listener_url`, only unix and tcp are supported" | ||
)), | ||
}?; | ||
|
||
let server_handle = tokio::spawn(async move { | ||
let server_listen_result = if abci_url.scheme() == "unix" { | ||
server.listen_unix(validated_listen_addr).await | ||
} else { | ||
server.listen_tcp(validated_listen_addr).await | ||
}; | ||
match server_listen_result { | ||
Ok(()) => { | ||
// this shouldn't happen, as there isn't a way for the ABCI server to exit | ||
info_span!("abci_server").in_scope(|| info!("ABCI server exited successfully")); | ||
} | ||
Err(e) => { | ||
error_span!("abci_server") | ||
.in_scope(|| error!(err = e.as_ref(), "ABCI server exited with error")); | ||
} | ||
} | ||
let _ = server_exit_tx.send(()); | ||
}); | ||
|
||
Ok(server_handle) | ||
} | ||
|
||
struct SignalReceiver { | ||
stop_rx: watch::Receiver<()>, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this by the
eyre::Result
type alias: