Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit c9dcc7b

Browse files
bors[bot]tomtau
andauthored
Merge #676
676: Problem: complex feature-guarding of chain-core (CRO-628) r=tomtau a=tomtau Solution: simplified feature guards to be just a switch on "mesalock_sgx" instead of various combinations of required crates, as the feature guarding is only needed for reduced dependencies in the enclave compilation Co-authored-by: Tomas Tauber <2410580+tomtau@users.noreply.github.com>
2 parents 304620f + a39642f commit c9dcc7b

File tree

18 files changed

+181
-156
lines changed

18 files changed

+181
-156
lines changed

chain-core/src/init/address.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,45 @@
1111
//! These 20 bytes are the address.
1212
//!
1313
//! [Recommended Read](https://kobl.one/blog/create-full-ethereum-keypair-and-address/)
14-
#[cfg(feature = "bech32")]
14+
#[cfg(not(feature = "mesalock_sgx"))]
1515
use bech32::{self, u5, FromBase32, ToBase32};
1616
use parity_scale_codec::{Decode, Encode};
1717
use std::ops;
1818
use std::prelude::v1::String;
19-
#[cfg(feature = "hex")]
19+
#[cfg(not(feature = "mesalock_sgx"))]
2020
use std::str::FromStr;
2121

22-
#[cfg(feature = "hex")]
22+
#[cfg(not(feature = "mesalock_sgx"))]
2323
use hex;
2424
use secp256k1::key::PublicKey;
25-
#[cfg(feature = "serde")]
25+
#[cfg(not(feature = "mesalock_sgx"))]
2626
use serde::de::Error;
27-
#[cfg(feature = "serde")]
27+
#[cfg(not(feature = "mesalock_sgx"))]
2828
use serde::{Deserialize, Deserializer, Serialize, Serializer};
29-
#[cfg(feature = "hex")]
29+
#[cfg(not(feature = "mesalock_sgx"))]
3030
use std::fmt;
3131
use tiny_keccak::{Hasher, Keccak};
3232

3333
use crate::common::{H256, HASH_SIZE_256};
34-
#[cfg(feature = "bech32")]
34+
#[cfg(not(feature = "mesalock_sgx"))]
3535
use crate::init::network::{get_bech32_human_part_from_network, Network};
3636

3737
#[derive(Debug, PartialEq)]
38-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
38+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
3939
pub enum CroAddressError {
4040
// TODO: use directly bech32::Error or wrap it
4141
Bech32Error(String),
4242
InvalidNetwork,
4343
ConvertError,
4444
}
4545

46-
#[cfg(feature = "bech32")]
46+
#[cfg(not(feature = "mesalock_sgx"))]
4747
impl ::std::error::Error for CroAddressError {}
4848

4949
// CRO: mainnet transfer
5050
// TCRO: testnet transfer
5151
// DCRO: devnet/regnet transfer
52-
#[cfg(feature = "bech32")]
52+
#[cfg(not(feature = "mesalock_sgx"))]
5353
pub trait CroAddress<T> {
5454
fn to_cro(&self, network: Network) -> Result<String, CroAddressError>;
5555
fn from_cro(encoded: &str, network: Network) -> Result<T, CroAddressError>;
@@ -85,7 +85,7 @@ where
8585

8686
/// Core domain logic errors
8787
#[derive(Debug)]
88-
#[cfg(feature = "hex")]
88+
#[cfg(not(feature = "mesalock_sgx"))]
8989
pub enum ErrorAddress {
9090
/// An invalid length
9191
InvalidLength(usize),
@@ -103,21 +103,21 @@ pub enum ErrorAddress {
103103
InvalidCroAddress,
104104
}
105105

106-
#[cfg(feature = "hex")]
106+
#[cfg(not(feature = "mesalock_sgx"))]
107107
impl From<hex::FromHexError> for ErrorAddress {
108108
fn from(err: hex::FromHexError) -> Self {
109109
ErrorAddress::UnexpectedHexEncoding(err)
110110
}
111111
}
112112

113-
#[cfg(feature = "hex")]
113+
#[cfg(not(feature = "mesalock_sgx"))]
114114
impl From<secp256k1::Error> for ErrorAddress {
115115
fn from(err: secp256k1::Error) -> Self {
116116
ErrorAddress::EcdsaCrypto(err)
117117
}
118118
}
119119

120-
#[cfg(feature = "hex")]
120+
#[cfg(not(feature = "mesalock_sgx"))]
121121
impl fmt::Display for ErrorAddress {
122122
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123123
match *self {
@@ -134,7 +134,7 @@ impl fmt::Display for ErrorAddress {
134134
}
135135
}
136136

137-
#[cfg(feature = "bech32")]
137+
#[cfg(not(feature = "mesalock_sgx"))]
138138
impl fmt::Display for CroAddressError {
139139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140140
match self {
@@ -145,7 +145,7 @@ impl fmt::Display for CroAddressError {
145145
}
146146
}
147147

148-
#[cfg(feature = "hex")]
148+
#[cfg(not(feature = "mesalock_sgx"))]
149149
impl std::error::Error for ErrorAddress {
150150
fn description(&self) -> &str {
151151
"Core error"
@@ -167,10 +167,10 @@ pub type RedeemAddressRaw = [u8; REDEEM_ADDRESS_BYTES];
167167

168168
/// Eth-style Account address (20 bytes)
169169
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
170-
#[cfg_attr(not(feature = "hex"), derive(Debug))]
170+
#[cfg_attr(feature = "mesalock_sgx", derive(Debug))]
171171
pub struct RedeemAddress(pub RedeemAddressRaw);
172172

173-
#[cfg(feature = "hex")]
173+
#[cfg(not(feature = "mesalock_sgx"))]
174174
impl RedeemAddress {
175175
/// Try to convert a byte vector to `RedeemAddress`.
176176
///
@@ -187,7 +187,7 @@ impl RedeemAddress {
187187
}
188188
}
189189

190-
#[cfg(all(feature = "bech32", feature = "hex"))]
190+
#[cfg(not(feature = "mesalock_sgx"))]
191191
impl CroAddress<RedeemAddress> for RedeemAddress {
192192
fn to_cro(&self, network: Network) -> Result<String, CroAddressError> {
193193
let checked_data: Vec<u5> = self.0.to_vec().to_base32();
@@ -231,7 +231,7 @@ impl From<[u8; REDEEM_ADDRESS_BYTES]> for RedeemAddress {
231231
}
232232
}
233233

234-
#[cfg(feature = "hex")]
234+
#[cfg(not(feature = "mesalock_sgx"))]
235235
impl FromStr for RedeemAddress {
236236
type Err = ErrorAddress;
237237

@@ -250,21 +250,21 @@ impl FromStr for RedeemAddress {
250250
}
251251
}
252252

253-
#[cfg(feature = "hex")]
253+
#[cfg(not(feature = "mesalock_sgx"))]
254254
impl fmt::Display for RedeemAddress {
255255
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
256256
write!(f, "0x{}", hex::encode(self.0))
257257
}
258258
}
259259

260-
#[cfg(feature = "hex")]
260+
#[cfg(not(feature = "mesalock_sgx"))]
261261
impl fmt::Debug for RedeemAddress {
262262
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263263
write!(f, "(0x{}", hex::encode(self.0))
264264
}
265265
}
266266

267-
#[cfg(all(feature = "serde", feature = "hex"))]
267+
#[cfg(not(feature = "mesalock_sgx"))]
268268
impl Serialize for RedeemAddress {
269269
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
270270
where
@@ -274,7 +274,7 @@ impl Serialize for RedeemAddress {
274274
}
275275
}
276276

277-
#[cfg(all(feature = "serde", feature = "hex"))]
277+
#[cfg(not(feature = "mesalock_sgx"))]
278278
impl<'de> Deserialize<'de> for RedeemAddress {
279279
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
280280
where

chain-core/src/init/coin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
//! Copyright (c) 2018, Input Output HK (licensed under the MIT License)
44
//! Modifications Copyright (c) 2018 - 2019, Foris Limited (licensed under the Apache License, Version 2.0)
55
6-
#[cfg(feature = "base64")]
6+
#[cfg(not(feature = "mesalock_sgx"))]
77
use crate::init::config::SlashRatio;
88
use crate::init::{MAX_COIN, MAX_COIN_DECIMALS, MAX_COIN_UNITS};
99
use crate::state::tendermint::TendermintVotePower;
1010
use crate::state::tendermint::TENDERMINT_MAX_VOTE_POWER;
1111
use parity_scale_codec::{Decode, Encode, Error as ScaleError, Input};
1212

13-
#[cfg(feature = "serde")]
13+
#[cfg(not(feature = "mesalock_sgx"))]
1414
use serde::de::{Deserializer, Error, Visitor};
15-
#[cfg(feature = "serde")]
15+
#[cfg(not(feature = "mesalock_sgx"))]
1616
use serde::{Deserialize, Serialize, Serializer};
1717

1818
use static_assertions::const_assert;
@@ -39,7 +39,7 @@ pub enum CoinError {
3939
Overflow,
4040
}
4141

42-
#[cfg(feature = "serde")]
42+
#[cfg(not(feature = "mesalock_sgx"))]
4343
impl Serialize for Coin {
4444
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
4545
where
@@ -50,7 +50,7 @@ impl Serialize for Coin {
5050
}
5151
}
5252

53-
#[cfg(feature = "serde")]
53+
#[cfg(not(feature = "mesalock_sgx"))]
5454
impl<'de> Deserialize<'de> for Coin {
5555
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
5656
where
@@ -239,7 +239,7 @@ impl ops::Rem<u64> for Coin {
239239
}
240240
}
241241

242-
#[cfg(feature = "base64")]
242+
#[cfg(not(feature = "mesalock_sgx"))]
243243
impl ops::Mul<SlashRatio> for Coin {
244244
type Output = Self;
245245

chain-core/src/init/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::state::account::{
99
};
1010
use crate::state::tendermint::{TendermintValidatorPubKey, TendermintVotePower};
1111
use crate::state::RewardsPoolState;
12-
#[cfg(feature = "serde")]
12+
#[cfg(not(feature = "mesalock_sgx"))]
1313
use serde::{Deserialize, Serialize};
1414
use std::collections::{BTreeMap, HashSet};
1515
use std::fmt;
@@ -73,7 +73,7 @@ impl fmt::Display for DistributionError {
7373
/// Initial configuration ("app_state" in genesis.json of Tendermint config)
7474
/// TODO: reward/treasury config, extra validator config...
7575
#[derive(Debug, PartialEq, Eq, Clone)]
76-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
76+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
7777
pub struct InitConfig {
7878
// Redeem mapping of ERC20 snapshot: Eth address => (StakedStateDestination,CRO tokens)
7979
// (doesn't include the rewards pool amount)

chain-core/src/init/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ pub mod address;
66
/// Fixed supply coin/amounts
77
pub mod coin;
88
/// Configuration in JSON passed to InitChain
9-
#[cfg(feature = "base64")]
9+
#[cfg(not(feature = "mesalock_sgx"))]
1010
pub mod config;
1111

1212
/// Network static configuration
13-
#[cfg(all(feature = "bech32", feature = "hex"))]
13+
#[cfg(not(feature = "mesalock_sgx"))]
1414
pub mod network;
1515

1616
/// Network parameters

chain-core/src/init/params.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::tx::fee::{Fee, FeeAlgorithm};
55
use crate::tx::fee::{LinearFee, Milli, MilliError};
66
use blake2::Blake2s;
77
use parity_scale_codec::{Decode, Encode};
8-
#[cfg(feature = "serde")]
8+
#[cfg(not(feature = "mesalock_sgx"))]
99
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
1010
use std::convert::TryFrom;
1111
use std::fmt;
@@ -15,7 +15,7 @@ use std::str::FromStr;
1515
const MAX_SLASH_RATIO: Milli = Milli::new(1, 0); // 1.0
1616

1717
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
18-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
1919
pub struct InitNetworkParameters {
2020
/// Initial fee setting
2121
/// -- TODO: perhaps change to be against T: FeeAlgorithm
@@ -36,7 +36,7 @@ pub struct InitNetworkParameters {
3636
}
3737

3838
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
39-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
39+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
4040
pub enum NetworkParameters {
4141
/// parameters specified at genesis time
4242
Genesis(InitNetworkParameters),
@@ -147,7 +147,7 @@ impl NetworkParameters {
147147
}
148148

149149
#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, Decode)]
150-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
150+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
151151
pub struct JailingParameters {
152152
/// Minimum jailing time for punished accounts (in seconds)
153153
pub jail_duration: u32,
@@ -159,7 +159,7 @@ pub struct JailingParameters {
159159
}
160160

161161
#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, Decode)]
162-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
162+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
163163
pub struct SlashingParameters {
164164
/// Percentage of funds (bonded + unbonded) slashed when validator is not live (liveness is calculated by jailing
165165
/// parameters)
@@ -171,7 +171,7 @@ pub struct SlashingParameters {
171171
}
172172

173173
#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, Decode)]
174-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
174+
#[cfg_attr(not(feature = "mesalock_sgx"), derive(Serialize, Deserialize))]
175175
pub struct RewardsParameters {
176176
/// Maximum monetary expansion for rewards.
177177
pub monetary_expansion_cap: Coin,
@@ -249,7 +249,7 @@ impl fmt::Display for SlashRatio {
249249
}
250250
}
251251

252-
#[cfg(feature = "serde")]
252+
#[cfg(not(feature = "mesalock_sgx"))]
253253
impl Serialize for SlashRatio {
254254
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
255255
where
@@ -259,7 +259,7 @@ impl Serialize for SlashRatio {
259259
}
260260
}
261261

262-
#[cfg(feature = "serde")]
262+
#[cfg(not(feature = "mesalock_sgx"))]
263263
impl<'de> Deserialize<'de> for SlashRatio {
264264
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
265265
where

0 commit comments

Comments
 (0)