mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Stub binaries' code when features binaries is not set
Allows running `cargo build` in monero-serai and message-queue without erroring, since it'd automatically try to build the binaries which require additional features. While we could make those features not optional, it'd increase time to build and disk space required, which is why the features exist for monero-serai and message-queue in the first place (since both are frequently used as libs).
This commit is contained in:
parent
38ad1d4bc4
commit
376b36974f
3 changed files with 323 additions and 297 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2439,6 +2439,7 @@ name = "ff-group-tests"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bls12_381",
|
"bls12_381",
|
||||||
|
"ff",
|
||||||
"group",
|
"group",
|
||||||
"k256",
|
"k256",
|
||||||
"p256",
|
"p256",
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
use std::sync::Arc;
|
#[cfg(feature = "binaries")]
|
||||||
|
mod binaries {
|
||||||
|
pub(crate) use std::sync::Arc;
|
||||||
|
|
||||||
use curve25519_dalek::{
|
pub(crate) use curve25519_dalek::{
|
||||||
scalar::Scalar,
|
scalar::Scalar,
|
||||||
edwards::{CompressedEdwardsY, EdwardsPoint},
|
edwards::{CompressedEdwardsY, EdwardsPoint},
|
||||||
};
|
};
|
||||||
|
|
||||||
use multiexp::BatchVerifier;
|
pub(crate) use multiexp::BatchVerifier;
|
||||||
|
|
||||||
use serde::Deserialize;
|
pub(crate) use serde::Deserialize;
|
||||||
use serde_json::json;
|
pub(crate) use serde_json::json;
|
||||||
|
|
||||||
use monero_serai::{
|
pub(crate) use monero_serai::{
|
||||||
Commitment,
|
Commitment,
|
||||||
ringct::RctPrunable,
|
ringct::RctPrunable,
|
||||||
transaction::{Input, Transaction},
|
transaction::{Input, Transaction},
|
||||||
|
@ -18,9 +20,9 @@ use monero_serai::{
|
||||||
rpc::{RpcError, Rpc, HttpRpc},
|
rpc::{RpcError, Rpc, HttpRpc},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::task::JoinHandle;
|
pub(crate) use tokio::task::JoinHandle;
|
||||||
|
|
||||||
async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
pub(crate) async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
||||||
let hash = loop {
|
let hash = loop {
|
||||||
match rpc.get_block_hash(block_i).await {
|
match rpc.get_block_hash(block_i).await {
|
||||||
Ok(hash) => break hash,
|
Ok(hash) => break hash,
|
||||||
|
@ -237,9 +239,13 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
||||||
|
|
||||||
println!("Deserialized, hashed, and reserialized {block_i} with {} TXs", txs_len);
|
println!("Deserialized, hashed, and reserialized {block_i} with {} TXs", txs_len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "binaries")]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
use binaries::*;
|
||||||
|
|
||||||
let args = std::env::args().collect::<Vec<String>>();
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
|
|
||||||
// Read start block as the first arg
|
// Read start block as the first arg
|
||||||
|
@ -307,3 +313,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "binaries"))]
|
||||||
|
fn main() {
|
||||||
|
panic!("To run binaries, please build with `--feature binaries`.");
|
||||||
|
}
|
||||||
|
|
|
@ -1,27 +1,32 @@
|
||||||
use std::{
|
#[cfg(feature = "binaries")]
|
||||||
|
mod messages;
|
||||||
|
#[cfg(feature = "binaries")]
|
||||||
|
mod queue;
|
||||||
|
|
||||||
|
#[cfg(feature = "binaries")]
|
||||||
|
mod binaries {
|
||||||
|
pub(crate) use std::{
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
pub(crate) use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
||||||
use schnorr_signatures::SchnorrSignature;
|
pub(crate) use schnorr_signatures::SchnorrSignature;
|
||||||
|
|
||||||
use serai_primitives::NetworkId;
|
pub(crate) use serai_primitives::NetworkId;
|
||||||
|
|
||||||
use jsonrpsee::{RpcModule, server::ServerBuilder};
|
pub(crate) use jsonrpsee::{RpcModule, server::ServerBuilder};
|
||||||
|
|
||||||
mod messages;
|
pub(crate) use crate::messages::*;
|
||||||
use messages::*;
|
|
||||||
|
|
||||||
mod queue;
|
pub(crate) use crate::queue::Queue;
|
||||||
use queue::Queue;
|
|
||||||
|
|
||||||
type Db = serai_db::RocksDB;
|
pub(crate) type Db = serai_db::RocksDB;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref KEYS: Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>> =
|
pub(crate) static ref KEYS: Arc<RwLock<HashMap<Service, <Ristretto as Ciphersuite>::G>>> =
|
||||||
Arc::new(RwLock::new(HashMap::new()));
|
Arc::new(RwLock::new(HashMap::new()));
|
||||||
static ref QUEUES: Arc<RwLock<HashMap<Service, RwLock<Queue<Db>>>>> =
|
pub(crate) static ref QUEUES: Arc<RwLock<HashMap<Service, RwLock<Queue<Db>>>>> =
|
||||||
Arc::new(RwLock::new(HashMap::new()));
|
Arc::new(RwLock::new(HashMap::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +38,13 @@ lazy_static::lazy_static! {
|
||||||
independently verify signatures.
|
independently verify signatures.
|
||||||
|
|
||||||
The metadata specifies an intent. Only one message, for a specified intent, will be delivered.
|
The metadata specifies an intent. Only one message, for a specified intent, will be delivered.
|
||||||
This allows services to safely send messages multiple times without them being delivered multiple
|
This allows services to safely send messages multiple times without them being delivered
|
||||||
times.
|
multiple times.
|
||||||
|
|
||||||
The message will be ordered by this service, with the order having no guarantees other than
|
The message will be ordered by this service, with the order having no guarantees other than
|
||||||
successful ordering by the time this call returns.
|
successful ordering by the time this call returns.
|
||||||
*/
|
*/
|
||||||
fn queue_message(meta: Metadata, msg: Vec<u8>, sig: SchnorrSignature<Ristretto>) {
|
pub(crate) fn queue_message(meta: Metadata, msg: Vec<u8>, sig: SchnorrSignature<Ristretto>) {
|
||||||
{
|
{
|
||||||
let from = (*KEYS).read().unwrap()[&meta.from];
|
let from = (*KEYS).read().unwrap()[&meta.from];
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -75,7 +80,7 @@ fn queue_message(meta: Metadata, msg: Vec<u8>, sig: SchnorrSignature<Ristretto>)
|
||||||
The expected index is used to ensure a service didn't fall out of sync with this service. It
|
The expected index is used to ensure a service didn't fall out of sync with this service. It
|
||||||
should always be either the next message's ID or *TODO*.
|
should always be either the next message's ID or *TODO*.
|
||||||
*/
|
*/
|
||||||
fn get_next_message(service: Service, _expected: u64) -> Option<QueuedMessage> {
|
pub(crate) fn get_next_message(service: Service, _expected: u64) -> Option<QueuedMessage> {
|
||||||
// TODO: Verify the expected next message ID matches
|
// TODO: Verify the expected next message ID matches
|
||||||
|
|
||||||
let queue_outer = (*QUEUES).read().unwrap();
|
let queue_outer = (*QUEUES).read().unwrap();
|
||||||
|
@ -89,7 +94,7 @@ fn get_next_message(service: Service, _expected: u64) -> Option<QueuedMessage> {
|
||||||
Acknowledges a message as received and handled, meaning it'll no longer be returned as the next
|
Acknowledges a message as received and handled, meaning it'll no longer be returned as the next
|
||||||
message.
|
message.
|
||||||
*/
|
*/
|
||||||
fn ack_message(service: Service, id: u64, sig: SchnorrSignature<Ristretto>) {
|
pub(crate) fn ack_message(service: Service, id: u64, sig: SchnorrSignature<Ristretto>) {
|
||||||
{
|
{
|
||||||
let from = (*KEYS).read().unwrap()[&service];
|
let from = (*KEYS).read().unwrap()[&service];
|
||||||
assert!(sig.verify(from, ack_challenge(service, from, id, sig.R)));
|
assert!(sig.verify(from, ack_challenge(service, from, id, sig.R)));
|
||||||
|
@ -106,9 +111,13 @@ fn ack_message(service: Service, id: u64, sig: SchnorrSignature<Ristretto>) {
|
||||||
|
|
||||||
(*QUEUES).read().unwrap()[&service].write().unwrap().ack_message(id)
|
(*QUEUES).read().unwrap()[&service].write().unwrap().ack_message(id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "binaries")]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
use binaries::*;
|
||||||
|
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
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()));
|
std::env::set_var("RUST_LOG", serai_env::var("RUST_LOG").unwrap_or_else(|| "info".to_string()));
|
||||||
}
|
}
|
||||||
|
@ -192,3 +201,8 @@ async fn main() {
|
||||||
// Run until stopped, which it never will
|
// Run until stopped, which it never will
|
||||||
server.start(module).unwrap().stopped().await;
|
server.start(module).unwrap().stopped().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "binaries"))]
|
||||||
|
fn main() {
|
||||||
|
panic!("To run binaries, please build with `--feature binaries`.");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue