Skip to content

Commit cbddb8d

Browse files
chore(platform): make bls sig compatibility an optional feature (#2440)
Co-authored-by: Ivan Shumkov <[email protected]>
1 parent 764684b commit cbddb8d

File tree

15 files changed

+215
-109
lines changed

15 files changed

+215
-109
lines changed

Cargo.lock

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

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ ENV NODE_ENV=${NODE_ENV}
158158
#
159159
# This stage is used to install sccache and configure it.
160160
# Later on, one should source /root/env before building to use sccache.
161-
#
161+
#
162162
# Note that, due to security concerns, each stage needs to declare variables containing authentication secrets, like
163163
# ACTIONS_RUNTIME_TOKEN, AWS_SECRET_ACCESS_KEY. This is to prevent leaking secrets to the final image. The secrets are
164164
# loaded using docker buildx `--secret` flag and need to be explicitly mounted with `--mount=type=secret,id=SECRET_ID`.
@@ -205,7 +205,7 @@ RUN --mount=type=secret,id=AWS <<EOS
205205
echo "export ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}" >> /root/env
206206
# ACTIONS_RUNTIME_TOKEN is a secret so we quote it here, and it will be loaded when `source /root/env` is run
207207
echo 'export ACTIONS_RUNTIME_TOKEN="$(cat /run/secrets/GHA)"' >> /root/env
208-
208+
209209
### AWS S3 ###
210210
elif [ -n "${SCCACHE_BUCKET}" ]; then
211211
echo "export SCCACHE_BUCKET='${SCCACHE_BUCKET}'" >> /root/env
@@ -218,11 +218,11 @@ RUN --mount=type=secret,id=AWS <<EOS
218218
mkdir --mode=0700 -p "$HOME/.aws"
219219
ln -s /run/secrets/AWS "$HOME/.aws/credentials"
220220
echo "export AWS_SHARED_CREDENTIALS_FILE=$HOME/.aws/credentials" >> /root/env
221-
221+
222222
# Check if AWS credentials file is mounted correctly, eg. --mount=type=secret,id=AWS
223-
echo '[ -e "${AWS_SHARED_CREDENTIALS_FILE}" ] || {
224-
echo "$(id -u): Cannot read ${AWS_SHARED_CREDENTIALS_FILE}; did you use RUN --mount=type=secret,id=AWS ?";
225-
exit 1;
223+
echo '[ -e "${AWS_SHARED_CREDENTIALS_FILE}" ] || {
224+
echo "$(id -u): Cannot read ${AWS_SHARED_CREDENTIALS_FILE}; did you use RUN --mount=type=secret,id=AWS ?";
225+
exit 1;
226226
}' >> /root/env
227227

228228
### memcached ###
@@ -233,9 +233,9 @@ RUN --mount=type=secret,id=AWS <<EOS
233233
echo "Error: cannot determine sccache cache backend" >&2
234234
exit 1
235235
fi
236-
236+
237237
echo "export SCCACHE_SERVER_PORT=$((RANDOM+1025))" >> /root/env
238-
238+
239239
# Configure compilers to use sccache
240240
echo "export CXX='sccache clang++'" >> /root/env
241241
echo "export CC='sccache clang'" >> /root/env

packages/rs-dpp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ chrono = { version = "0.4.35", default-features = false, features = [
2121
"wasmbind",
2222
"clock",
2323
] }
24-
ciborium = { git = "https://github.com/qrayven/ciborium", branch = "feat-ser-null-as-undefined", optional = true }
24+
ciborium = { version = "0.2.2", optional = true }
2525
dashcore = { git = "https://github.com/dashpay/rust-dashcore", features = [
2626
"std",
2727
"secp-recovery",

packages/rs-dpp/src/util/cbor_value/canonical.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ impl CborCanonicalMap {
114114

115115
let map = CborValue::Map(self.inner);
116116

117-
ciborium::ser::SerializerOptions::default()
118-
.serialize_null_as_undefined(true)
119-
.into_writer(&map, &mut bytes)?;
117+
ciborium::ser::into_writer(&map, &mut bytes)?;
120118

121119
Ok(bytes)
122120
}

packages/rs-drive-abci/Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ license = "MIT"
1515
[dependencies]
1616
arc-swap = "1.7.0"
1717
bincode = { version = "2.0.0-rc.3", features = ["serde"] }
18-
ciborium = { git = "https://github.com/qrayven/ciborium", branch = "feat-ser-null-as-undefined" }
18+
ciborium = { version = "0.2.2" }
1919
chrono = "0.4.35"
2020
serde = { version = "1.0.197", features = ["derive"] }
2121
serde_json = { version = "1.0", features = ["preserve_order"] }
@@ -73,7 +73,7 @@ tokio-util = { version = "0.7" }
7373
derive_more = { version = "1.0", features = ["from", "deref", "deref_mut"] }
7474
async-trait = "0.1.77"
7575
console-subscriber = { version = "0.4", optional = true }
76-
bls-signatures = { git = "https://github.com/dashpay/bls-signatures", tag = "1.3.3" }
76+
bls-signatures = { git = "https://github.com/dashpay/bls-signatures", tag = "1.3.3", optional = true}
7777

7878
[dev-dependencies]
7979
bs58 = { version = "0.5.0" }
@@ -93,19 +93,20 @@ dpp = { path = "../rs-dpp", features = [
9393
"data-contract-json-conversion",
9494
"data-contract-cbor-conversion",
9595
] }
96-
drive = { path = "../rs-drive" }
96+
drive = { path = "../rs-drive", features = ["fixtures-and-mocks"] }
9797
strategy-tests = { path = "../strategy-tests" }
9898
assert_matches = "1.5.0"
99-
drive-abci = { path = ".", features = ["testing-config"] }
99+
drive-abci = { path = ".", features = ["testing-config", "mocks"] }
100+
bls-signatures = { git = "https://github.com/dashpay/bls-signatures", tag = "1.3.3"}
101+
mockall = { version = "0.13" }
100102

101103
# For tests of grovedb verify
102104
rocksdb = { version = "0.23.0" }
103105
integer-encoding = { version = "4.0.0" }
104106

105107
[features]
106-
107-
default = ["mocks"]
108-
mocks = ["mockall", "drive/fixtures-and-mocks"]
108+
default = []
109+
mocks = ["mockall", "drive/fixtures-and-mocks", "bls-signatures"]
109110
console = ["console-subscriber", "tokio/tracing"]
110111
testing-config = []
111112
grovedbg = ["drive/grovedbg"]

packages/rs-drive-abci/src/platform_types/platform_state/v0/old_structures/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ pub(super) struct OldStructureValidatorSetV0 {
3232
/// The list of masternodes
3333
pub members: BTreeMap<ProTxHash, ValidatorV0>,
3434
/// The threshold quorum public key
35+
#[cfg(feature = "bls-signatures")]
3536
pub threshold_public_key: bls_signatures::PublicKey,
37+
38+
/// Extra fields for forward compatibility.
39+
#[cfg(not(feature = "bls-signatures"))]
40+
#[serde(flatten)]
41+
pub extra_fields: std::collections::HashMap<String, serde_json::Value>,
3642
}
3743

3844
impl From<OldStructureValidatorSetV0> for dpp::core_types::validator_set::v0::ValidatorSetV0 {
@@ -42,7 +48,9 @@ impl From<OldStructureValidatorSetV0> for dpp::core_types::validator_set::v0::Va
4248
quorum_index,
4349
core_height,
4450
members,
51+
#[cfg(feature = "bls-signatures")]
4552
threshold_public_key,
53+
..
4654
} = value;
4755
Self {
4856
quorum_hash,
@@ -52,8 +60,11 @@ impl From<OldStructureValidatorSetV0> for dpp::core_types::validator_set::v0::Va
5260
.into_iter()
5361
.map(|(pro_tx_hash, validator)| (pro_tx_hash, validator.into()))
5462
.collect(),
63+
#[cfg(feature = "bls-signatures")]
5564
threshold_public_key: PublicKey::try_from(threshold_public_key.to_bytes().as_slice())
5665
.expect("this should not be possible to error as the threshold_public_key was already verified on disk"),
66+
#[cfg(not(feature = "bls-signatures"))]
67+
threshold_public_key: Default::default(),
5768
}
5869
}
5970
}
@@ -64,6 +75,7 @@ pub(super) struct ValidatorV0 {
6475
/// The proTxHash
6576
pub pro_tx_hash: ProTxHash,
6677
/// The public key share of this validator for this quorum
78+
#[cfg(feature = "bls-signatures")]
6779
pub public_key: Option<bls_signatures::PublicKey>,
6880
/// The node address
6981
pub node_ip: String,
@@ -83,6 +95,7 @@ impl From<ValidatorV0> for dpp::core_types::validator::v0::ValidatorV0 {
8395
fn from(value: ValidatorV0) -> Self {
8496
let ValidatorV0 {
8597
pro_tx_hash,
98+
#[cfg(feature = "bls-signatures")]
8699
public_key,
87100
node_ip,
88101
node_id,
@@ -93,7 +106,10 @@ impl From<ValidatorV0> for dpp::core_types::validator::v0::ValidatorV0 {
93106
} = value;
94107
Self {
95108
pro_tx_hash,
109+
#[cfg(feature = "bls-signatures")]
96110
public_key: public_key.map(|pk| PublicKey::try_from(pk.to_bytes().as_slice()).expect("this should not be possible to error as the public_key was already verified on disk")),
111+
#[cfg(not(feature = "bls-signatures"))]
112+
public_key: None,
97113
node_ip,
98114
node_id,
99115
core_port,

packages/rs-drive-abci/src/platform_types/signature_verification_quorum_set/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ mod v0;
33
use crate::config::QuorumLikeConfig;
44
use crate::error::execution::ExecutionError;
55
use crate::error::Error;
6-
use crate::platform_types::signature_verification_quorum_set::v0::for_saving::SignatureVerificationQuorumSetForSavingV0;
6+
use crate::platform_types::signature_verification_quorum_set::v0::for_saving_v0::SignatureVerificationQuorumSetForSavingV0;
77
use crate::platform_types::signature_verification_quorum_set::v0::for_saving_v1::SignatureVerificationQuorumSetForSavingV1;
8+
use crate::platform_types::signature_verification_quorum_set::v0::for_saving_v2::SignatureVerificationQuorumSetForSavingV2;
89
pub use crate::platform_types::signature_verification_quorum_set::v0::quorum_set::{
910
QuorumConfig, QuorumsWithConfig, SelectedQuorumSetIterator, SignatureVerificationQuorumSetV0,
1011
SignatureVerificationQuorumSetV0Methods, SIGN_OFFSET,
@@ -121,13 +122,15 @@ pub enum SignatureVerificationQuorumSetForSaving {
121122
V0(SignatureVerificationQuorumSetForSavingV0),
122123
/// Version 1 of the signature verification quorums
123124
V1(SignatureVerificationQuorumSetForSavingV1),
125+
/// Version 2 of the signature verification quorums
126+
V2(SignatureVerificationQuorumSetForSavingV2),
124127
}
125128

126129
impl From<SignatureVerificationQuorumSet> for SignatureVerificationQuorumSetForSaving {
127130
fn from(value: SignatureVerificationQuorumSet) -> Self {
128131
match value {
129132
SignatureVerificationQuorumSet::V0(v0) => {
130-
SignatureVerificationQuorumSetForSaving::V1(v0.into())
133+
SignatureVerificationQuorumSetForSaving::V2(v0.into())
131134
}
132135
}
133136
}
@@ -142,6 +145,9 @@ impl From<SignatureVerificationQuorumSetForSaving> for SignatureVerificationQuor
142145
SignatureVerificationQuorumSetForSaving::V1(v1) => {
143146
SignatureVerificationQuorumSet::V0(v1.into())
144147
}
148+
SignatureVerificationQuorumSetForSaving::V2(v2) => {
149+
SignatureVerificationQuorumSet::V0(v2.into())
150+
}
145151
}
146152
}
147153
}

0 commit comments

Comments
 (0)