Add a binaries feature to the processor to reduce dependencies when used as a lib

processor isn't intended to be used as a library, yet serai-processor-tests
does pull it in as a lib. This caused serai-processor-tests to need to compile
rocksdb, which added multiple minutes to the compilation time.
This commit is contained in:
Luke Parker 2023-11-25 04:02:47 -05:00
parent b296be8515
commit d60e007126
No known key found for this signature in database
11 changed files with 23 additions and 26 deletions

1
Cargo.lock generated
View file

@ -7526,6 +7526,7 @@ dependencies = [
"serai-docker-tests",
"serai-runtime",
"sp-core",
"sp-runtime",
"subxt",
"thiserror",
"tokio",

View file

@ -39,7 +39,7 @@ env_logger = { version = "0.10", default-features = false, features = ["humantim
# Uses a single threaded runtime since this shouldn't ever be CPU-bound
tokio = { version = "1", default-features = false, features = ["rt", "time", "macros"] }
serai-db = { path = "../common/db", optional = true }
serai-db = { path = "../common/db", features = ["rocksdb"], optional = true }
serai-env = { path = "../common/env" }
@ -49,4 +49,4 @@ jsonrpsee = { version = "0.16", default-features = false, features = ["server"],
simple-request = { path = "../common/request", default-features = false }
[features]
binaries = ["serai-db", "serai-db/rocksdb", "jsonrpsee"]
binaries = ["serai-db", "jsonrpsee"]

View file

@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build --release --features bitcoin -p serai-processor && \
cargo build --release --features "binaries bitcoin" -p serai-processor && \
mv /serai/target/release/serai-processor /serai/bin
FROM debian:bookworm-slim as image

View file

@ -1,2 +1,2 @@
cargo build --release --features bitcoin -p serai-processor && \
cargo build --release --features "binaries bitcoin" -p serai-processor && \
mv /serai/target/release/serai-processor /serai/bin

View file

@ -46,7 +46,7 @@ RUN --mount=type=cache,target=/root/.cargo \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/serai/target \
mkdir /serai/bin && \
cargo build --release --features monero -p serai-processor && \
cargo build --release --features "binaries monero" -p serai-processor && \
mv /serai/target/release/serai-processor /serai/bin
FROM debian:bookworm-slim as image

View file

@ -1,2 +1,2 @@
cargo build --release --features monero -p serai-processor && \
cargo build --release --features "binaries monero" -p serai-processor && \
mv /serai/target/release/serai-processor /serai/bin

View file

@ -49,16 +49,16 @@ monero-serai = { path = "../coins/monero", default-features = false, features =
# Application
log = { version = "0.4", default-features = false, features = ["std"] }
env_logger = { version = "0.10", default-features = false, features = ["humantime"] }
env_logger = { version = "0.10", default-features = false, features = ["humantime"], optional = true }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "sync", "time", "macros"] }
serai-db = { path = "../common/db", features = ["rocksdb"] }
serai-env = { path = "../common/env" }
serai-db = { path = "../common/db", features = ["rocksdb"], optional = true }
serai-env = { path = "../common/env", optional = true }
serai-client = { path = "../substrate/client", default-features = false }
messages = { package = "serai-processor-messages", path = "./messages" }
messages = { package = "serai-processor-messages", path = "./messages", optional = true }
message-queue = { package = "serai-message-queue", path = "../message-queue" }
message-queue = { package = "serai-message-queue", path = "../message-queue", optional = true }
[dev-dependencies]
futures = { version = "0.3", default-features = false }
@ -76,3 +76,5 @@ bitcoin = ["dep:secp256k1", "secp256k1", "bitcoin-serai", "serai-client/bitcoin"
ed25519 = ["dalek-ff-group", "frost/ed25519"]
monero = ["ed25519", "monero-serai", "serai-client/monero"]
binaries = ["env_logger", "serai-db", "serai-env", "messages", "message-queue"]

View file

@ -12,9 +12,7 @@ use in_instructions_primitives::{Batch, SignedBatch};
use coins_primitives::OutInstructionWithBalance;
use validator_sets_primitives::{ValidatorSet, KeyPair};
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Zeroize, Encode, Decode, BorshSerialize, BorshDeserialize,
)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
pub struct SubstrateContext {
pub serai_time: u64,
pub network_latest_finalized_block: BlockHash,
@ -239,9 +237,7 @@ pub mod coordinator {
}
}
#[derive(
Clone, PartialEq, Eq, Debug, Zeroize, Encode, Decode, BorshSerialize, BorshDeserialize,
)]
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
pub struct PlanMeta {
pub key: Vec<u8>,
pub id: [u8; 32],
@ -261,7 +257,7 @@ pub mod coordinator {
pub mod substrate {
use super::*;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, BorshSerialize, BorshDeserialize)]
#[derive(Clone, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)]
pub enum CoordinatorMessage {
ConfirmKeyPair {
context: SubstrateContext,
@ -287,9 +283,7 @@ pub mod substrate {
}
}
#[derive(
Clone, PartialEq, Eq, Debug, Zeroize, Encode, Decode, BorshSerialize, BorshDeserialize,
)]
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, BorshSerialize, BorshDeserialize)]
pub enum ProcessorMessage {
Batch { batch: Batch },
SignedBatch { batch: SignedBatch },

View file

@ -23,9 +23,10 @@ hex = "0.4"
scale = { package = "parity-scale-codec", version = "3" }
scale-info = { version = "2", optional = true }
sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-runtime = { git = "https://github.com/serai-dex/substrate" }
serai-runtime = { path = "../runtime", version = "0.1" }
sp-core = { git = "https://github.com/serai-dex/substrate" }
subxt = { version = "0.29", default-features = false, features = ["jsonrpsee-ws"], optional = true }
bitcoin = { version = "0.31", optional = true }

View file

@ -168,15 +168,14 @@ impl Serai {
const TX_VERSION: u32 = 1;
const EXTRINSIC_FORMAT_VERSION: u8 = 4;
let era = subxt::config::substrate::Era::Immortal;
let era = sp_runtime::generic::Era::Immortal;
let extra = (era, Compact(nonce), tip);
let genesis = self.0.genesis_hash();
let mortality_checkpoint = genesis;
let mut signature_payload =
(call, extra, SPEC_VERSION, TX_VERSION, genesis, mortality_checkpoint).encode();
if signature_payload.len() > 256 {
use subxt::config::Hasher;
signature_payload = BlakeTwo256::hash(&signature_payload).0.to_vec();
signature_payload = sp_core::blake2_256(&signature_payload).to_vec();
}
let signature = signer.sign(&signature_payload);

View file

@ -26,7 +26,7 @@ serai-primitives = { path = "../../primitives", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
[features]
std = ["zeroize", "borsh?/std", "serde/std", "scale/std", "scale-info/std", "sp-runtime/std", "serai-primitives/std"]
std = ["zeroize", "borsh?/std", "serde?/std", "scale/std", "scale-info/std", "sp-runtime/std", "serai-primitives/std"]
borsh = ["dep:borsh", "serai-primitives/borsh"]
serde = ["dep:serde", "serai-primitives/serde"]
default = ["std"]