Update how RPCs are handled

The processor now takes three vars and joins them itself. message-queue uses a
single argument, with defaults, as it's a service we control.
This commit is contained in:
Luke Parker 2023-07-21 14:00:03 -04:00
parent 641077a089
commit 624fb2781d
No known key found for this signature in database
6 changed files with 29 additions and 7 deletions

View file

@ -679,7 +679,7 @@ async fn main() {
let key = Zeroizing::new(<Ristretto as Ciphersuite>::F::ZERO); // TODO
let p2p = LocalP2p::new(1).swap_remove(0); // TODO
let processors = Arc::new(MessageQueue::new(Service::Coordinator));
let processors = Arc::new(MessageQueue::from_env(Service::Coordinator));
let serai = || async {
loop {

View file

@ -5,7 +5,9 @@ export MESSAGE_QUEUE_RPC="http://127.0.0.1:2287"
export DB_PATH="./bitcoin-db"
export ENTROPY="0001020304050607080910111213141516171819202122232425262728293031"
export NETWORK_RPC="http://serai:seraidex@127.0.0.1:18443"
export NETWORK="bitcoin"
export NETWORK_RPC_LOGIN="serai:seraidex"
export NETWORK_RPC_HOSTNAME="127.0.0.1"
export NETWORK_RPC_PORT="18443"
serai-processor

View file

@ -26,8 +26,17 @@ pub struct MessageQueue {
}
impl MessageQueue {
pub fn new(service: Service) -> MessageQueue {
let url = env::var("MESSAGE_QUEUE_RPC").expect("message-queue RPC wasn't specified");
pub fn from_env(service: Service) -> MessageQueue {
// Allow MESSAGE_QUEUE_RPC to either be a full URL or just a hostname
// While we could stitch together multiple env variables, our control over this service makes
// this fine
let mut url = env::var("MESSAGE_QUEUE_RPC").expect("message-queue RPC wasn't specified");
if !url.contains(':') {
url += ":2287";
}
if !url.starts_with("http://") {
url = "http://".to_string() + &url;
}
let priv_key: Zeroizing<<Ristretto as Ciphersuite>::F> = {
let key_str =

View file

@ -110,7 +110,7 @@ fn ack_message(service: Service, id: u64, sig: SchnorrSignature<Ristretto>) {
#[tokio::main]
async fn main() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
std::env::set_var("RUST_LOG", serai_env::var("RUST_LOG").unwrap_or_else(|| "info".to_string()));
}
env_logger::init();

View file

@ -52,6 +52,7 @@ monero-serai = { path = "../coins/monero", features = ["multisig"], optional = t
# Application
log = "0.4"
env_logger = "0.10"
tokio = { version = "1", features = ["full"] }
rocksdb = "0.21"

View file

@ -717,6 +717,11 @@ async fn run<C: Coin, D: Db, Co: Coordinator>(mut raw_db: D, coin: C, mut coordi
#[tokio::main]
async fn main() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", serai_env::var("RUST_LOG").unwrap_or_else(|| "info".to_string()));
}
env_logger::init();
let db = Arc::new(
rocksdb::TransactionDB::<rocksdb::SingleThreaded>::open_default(
env::var("DB_PATH").expect("path to DB wasn't specified"),
@ -725,14 +730,19 @@ async fn main() {
);
// Network configuration
let url = env::var("NETWORK_RPC").expect("network RPC wasn't specified");
let url = {
let login = env::var("NETWORK_RPC_LOGIN").expect("network RPC login wasn't specified");
let hostname = env::var("NETWORK_RPC_HOSTNAME").expect("network RPC hostname wasn't specified");
let port = env::var("NETWORK_RPC_PORT").expect("network port domain wasn't specified");
"http://".to_string() + &login + "@" + &hostname + ":" + &port
};
let network_id = match env::var("NETWORK").expect("network wasn't specified").as_str() {
"bitcoin" => NetworkId::Bitcoin,
"monero" => NetworkId::Monero,
_ => panic!("unrecognized network"),
};
let coordinator = MessageQueue::new(Service::Processor(network_id));
let coordinator = MessageQueue::from_env(Service::Processor(network_id));
match network_id {
#[cfg(feature = "bitcoin")]