Skip to content

Commit 60aaeae

Browse files
authored
chore: feature gate dcipher-agents (#39)
* chore(dcipher-agents): add feature gates * chore: enable correct features for dsigner, blocklock-agent, and randomness-agent * ci: use cargo hack to test each individual features * chore: remove unnecessary solidity deps from dsigner, blocklock-agent, and randomness-agent dockerfiles
1 parent dbfa16c commit 60aaeae

21 files changed

Lines changed: 210 additions & 205 deletions

File tree

.github/actions/rust-test-action/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ runs:
1919
# Pull cargo nextest binaries
2020
- uses: taiki-e/install-action@v2
2121
with:
22-
tool: nextest
22+
tool: nextest,cargo-hack
2323

2424
- name: Check formatting
2525
working-directory: ${{ inputs.working-directory }}
@@ -31,6 +31,11 @@ runs:
3131
run: cargo clippy --all-features --all-targets --target-dir ${{ inputs.target-folder }} -- -Dwarnings ${{ inputs.additional-flags }}
3232
shell: bash
3333

34+
- name: Check clippy (each features)
35+
working-directory: ${{ inputs.working-directory }}
36+
run: cargo hack clippy --each-feature --all-targets --target-dir ${{ inputs.target-folder }} -- -Dwarnings ${{ inputs.additional-flags }}
37+
shell: bash
38+
3439
- name: Run all tests
3540
working-directory: ${{ inputs.working-directory }}
3641
run: cargo nextest run --target-dir ${{ inputs.target-folder }} --no-tests warn

Cargo.lock

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocklock-agent/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition.workspace = true
66
[dependencies]
77
# blockchain
88
alloy = { workspace = true, features = ["default", "provider-ws"] }
9-
dcipher-agents = { workspace = true }
9+
dcipher-agents = { workspace = true, features = ["blocklock"] }
1010

1111
# async
1212
futures = { workspace = true }

blocklock-agent/Dockerfile

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ RUN npm install
1818
COPY ./blocklock-solidity ./
1919
RUN FOUNDRY_PROFILE=build forge install --no-git && FOUNDRY_PROFILE=build forge build
2020

21-
FROM sol_builder AS sol_randomness
22-
WORKDIR /app/randomness-solidity
23-
COPY ./randomness-solidity/package.json ./
24-
COPY ./randomness-solidity/package-lock.json ./
25-
RUN npm install
26-
27-
COPY ./randomness-solidity ./
28-
RUN FOUNDRY_PROFILE=build forge install --no-git && FOUNDRY_PROFILE=build forge build
29-
3021
# Base image for rust
3122
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
3223
WORKDIR /app
@@ -43,7 +34,6 @@ RUN cargo chef cook --release --recipe-path recipe.json
4334

4435
# Build application
4536
COPY --from=sol_blocklock /app/blocklock-solidity/out ./blocklock-solidity/out
46-
COPY --from=sol_randomness /app/randomness-solidity/out ./randomness-solidity/out
4737
COPY . .
4838
RUN cargo build --release -p blocklock-agent --example blocklock
4939

dcipher-agents/Cargo.toml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ version.workspace = true
44
edition.workspace = true
55

66
[features]
7-
rayon = ["dep:rayon"]
7+
# agents
8+
agents = ["evm"]
9+
blocklock = ["agents", "decryption_sender", "payment"]
10+
randomness = ["agents", "signature_sender", "payment"]
11+
payment = []
12+
13+
# schemes
14+
decryption_sender = ["fulfiller", "ibe", "evm"]
15+
signature_sender = ["fulfiller", "evm"]
16+
ibe = []
17+
18+
# misc
19+
evm = ["dep:alloy"]
20+
fulfiller = ["signer"]
21+
signer = ["dep:dcipher-signer", "dcipher-signer/libp2p"]
22+
rayon = ["dcipher-signer/rayon"]
823

924
[dependencies]
1025
# workspace crates
11-
dcipher-signer.workspace = true
26+
dcipher-signer = { workspace = true, optional = true }
1227

13-
alloy = { workspace = true, features = ["default", "provider-ws"] }
28+
alloy = { workspace = true, features = ["default", "provider-ws"], optional = true}
1429

1530
# crypto
1631
ark-bn254 = { workspace = true }
@@ -32,18 +47,11 @@ tokio-util = { workspace = true }
3247
prometheus = { workspace = true }
3348
tracing = { workspace = true }
3449

35-
# network
36-
libp2p = { workspace = true, features = ["tcp", "dns", "noise", "tokio", "ping", "yamux", "macros", "floodsub", "serde"] }
37-
3850
# serde
3951
serde = { workspace = true, features = ["derive"] }
40-
serde_cbor = "0.10"
4152

4253
# misc
43-
itertools = { workspace = true }
4454
thiserror = { workspace = true }
45-
lru = "0.14"
46-
rayon = { version = "1.10", optional = true }
4755

4856
[dev-dependencies]
4957
hex = { workspace = true }

dcipher-agents/src/agents.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
//! Module for agent-specific code such as blocklock.
22
3+
use serde::{Deserialize, Serialize};
4+
5+
#[cfg(feature = "blocklock")]
36
pub mod blocklock;
4-
mod payment;
7+
8+
#[cfg(feature = "randomness")]
59
pub mod randomness;
10+
11+
#[cfg(feature = "payment")]
12+
mod payment;
13+
14+
#[derive(
15+
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Serialize, serde::Deserialize, Debug,
16+
)]
17+
pub struct RequestId(pub alloy::primitives::U256);
18+
19+
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)]
20+
pub struct BlockNumber(pub u64);
21+
22+
impl From<RequestId> for alloy::primitives::U256 {
23+
fn from(value: RequestId) -> Self {
24+
value.0
25+
}
26+
}
27+
28+
impl From<alloy::primitives::U256> for RequestId {
29+
fn from(value: alloy::primitives::U256) -> Self {
30+
Self(value)
31+
}
32+
}
33+
34+
impl AsRef<alloy::primitives::U256> for RequestId {
35+
fn as_ref(&self) -> &alloy::primitives::U256 {
36+
&self.0
37+
}
38+
}
39+
40+
impl From<u64> for BlockNumber {
41+
fn from(number: u64) -> Self {
42+
BlockNumber(number)
43+
}
44+
}
45+
46+
impl From<BlockNumber> for u64 {
47+
fn from(number: BlockNumber) -> Self {
48+
number.0
49+
}
50+
}
51+
52+
impl AsRef<u64> for BlockNumber {
53+
fn as_ref(&self) -> &u64 {
54+
&self.0
55+
}
56+
}

dcipher-agents/src/agents/blocklock.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Module for the blocklock agent.
22
3+
use crate::agents::BlockNumber;
4+
use crate::decryption_sender::DecryptionRequest;
5+
use crate::ibe_helper::IbeIdentityOnBn254G1Ciphertext;
6+
use crate::ser::{EvmDeserialize, IbeIdentityOnBn254G1CiphertextError};
37
use alloy::primitives::U256;
48
use alloy::sol_types::SolValue;
5-
use serde::{Deserialize, Serialize};
69

710
pub mod agent;
811
mod condition_resolver;
@@ -16,9 +19,6 @@ pub enum BlocklockCondition {
1619
BlockNumber(BlockNumber),
1720
}
1821

19-
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize, Debug)]
20-
pub struct BlockNumber(pub u64);
21-
2222
#[derive(thiserror::Error, Debug)]
2323
pub enum BlocklockConditionDecodeError {
2424
#[error("missing block number prefix")]
@@ -82,20 +82,18 @@ impl From<BlocklockCondition> for alloy::primitives::Bytes {
8282
}
8383
}
8484

85-
impl From<u64> for BlockNumber {
86-
fn from(number: u64) -> Self {
87-
BlockNumber(number)
88-
}
89-
}
85+
impl TryFrom<&DecryptionRequest> for IbeIdentityOnBn254G1Ciphertext {
86+
type Error = IbeIdentityOnBn254G1CiphertextError;
9087

91-
impl From<BlockNumber> for u64 {
92-
fn from(number: BlockNumber) -> Self {
93-
number.0
88+
fn try_from(value: &DecryptionRequest) -> Result<Self, Self::Error> {
89+
EvmDeserialize::deser(&value.ciphertext)
9490
}
9591
}
9692

97-
impl AsRef<u64> for BlockNumber {
98-
fn as_ref(&self) -> &u64 {
99-
&self.0
93+
impl TryFrom<DecryptionRequest> for IbeIdentityOnBn254G1Ciphertext {
94+
type Error = IbeIdentityOnBn254G1CiphertextError;
95+
96+
fn try_from(value: DecryptionRequest) -> Result<Self, Self::Error> {
97+
EvmDeserialize::deser(&value.ciphertext)
10098
}
10199
}

dcipher-agents/src/agents/randomness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod fulfiller;
66
pub mod metrics;
77

88
use crate::RequestId;
9-
use crate::agents::blocklock::BlockNumber;
9+
use crate::agents::BlockNumber;
1010
use crate::agents::randomness::metrics::Metrics;
1111
use crate::fulfiller::RequestChannel;
1212
use crate::signature_sender::SignatureRequest;

dcipher-agents/src/decryption_sender.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use crate::decryption_sender::contracts::DecryptionSender;
1010
use crate::fulfiller::RetryStrategy;
1111
use crate::fulfiller::ticker::TickerFulfiller;
1212
use crate::fulfiller::{Identifier, TransactionFulfiller};
13-
use crate::ibe_helper::{IbeIdentityOnBn254G1Ciphertext, PairingIbeCipherSuite};
14-
use crate::ser::{EvmDeserialize, IbeIdentityOnBn254G1CiphertextError};
13+
use crate::ibe_helper::PairingIbeCipherSuite;
1514
use crate::signer::AsynchronousSigner;
1615
use alloy::primitives::{Bytes, U256};
1716
use serde::{Deserialize, Serialize};
@@ -97,22 +96,6 @@ impl Identifier for SignedDecryptionRequest<'_> {
9796
}
9897
}
9998

100-
impl TryFrom<&DecryptionRequest> for IbeIdentityOnBn254G1Ciphertext {
101-
type Error = IbeIdentityOnBn254G1CiphertextError;
102-
103-
fn try_from(value: &DecryptionRequest) -> Result<Self, Self::Error> {
104-
EvmDeserialize::deser(&value.ciphertext)
105-
}
106-
}
107-
108-
impl TryFrom<DecryptionRequest> for IbeIdentityOnBn254G1Ciphertext {
109-
type Error = IbeIdentityOnBn254G1CiphertextError;
110-
111-
fn try_from(value: DecryptionRequest) -> Result<Self, Self::Error> {
112-
EvmDeserialize::deser(&value.ciphertext)
113-
}
114-
}
115-
11699
impl From<DecryptionSender::DecryptionRequested> for DecryptionRequest {
117100
fn from(value: DecryptionSender::DecryptionRequested) -> Self {
118101
Self {

dcipher-agents/src/decryption_sender/async_signer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ where
7777
}
7878

7979
#[cfg(test)]
80+
#[cfg(feature = "blocklock")] // need blocklock types for ibe
8081
pub(crate) mod tests {
8182
use super::*;
8283
use crate::decryption_sender::DecryptionRequest;

0 commit comments

Comments
 (0)