Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the consensus enclave aware of the master minters #1684

Merged
merged 29 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9975348
Add master minters configuration to TokensConfig (#1504)
eranrund Feb 22, 2022
bca47f0
Minting data types and initial LedgerDb support (#1537)
eranrund Mar 2, 2022
70d6efb
MintTx/Config protobuf conversions (#1558)
eranrund Mar 2, 2022
46056c3
Store mint-related transations in LedgerDb (#1587)
eranrund Mar 10, 2022
9a1aba3
Expose LedgerDb API for looking up txs by nonce (#1602)
eranrund Mar 11, 2022
4a8639e
Minting transaction validation (#1593)
eranrund Mar 11, 2022
20f43d8
SetMintConfigTx -> MintConfigTx (#1607)
eranrund Mar 11, 2022
6492656
Small fixes following the confidential-token-id merging (#1609)
eranrund Mar 11, 2022
4198b9a
Eran/merge master 2022 03 14 (#1629)
eranrund Mar 15, 2022
b7f1da3
Support reaching consensus on MintConfigTxs (#1630)
eranrund Mar 16, 2022
639d69c
Support for reaching consensus on MintTx, mint client improvements (#…
eranrund Mar 17, 2022
63e779e
Merge branch 'master' into feature/minting
eranrund Mar 17, 2022
c2486d5
Update ledger/db/src/mint_tx_store.rs
eranrund Mar 17, 2022
b2238de
pr comments
eranrund Mar 17, 2022
5ec6dad
improve comment
eranrund Mar 17, 2022
2d8030a
use const
eranrund Mar 17, 2022
b51bc1e
Update ledger/db/src/mint_tx_store.rs
eranrund Mar 17, 2022
169f6d1
Merge branch 'master' into feature/minting
eranrund Mar 21, 2022
17cbe3a
lint
eranrund Mar 21, 2022
794f737
add MasterMintersMap
eranrund Mar 18, 2022
ba0b757
pass MasterMintersMap around
eranrund Mar 18, 2022
59abda3
enclave validates MintConfigTxs
eranrund Mar 18, 2022
56d784c
fix typo
eranrund Mar 22, 2022
c4fcbf2
lint
eranrund Mar 22, 2022
0477dea
more lint
eranrund Mar 22, 2022
7796872
fix block index
eranrund Mar 22, 2022
0e4209f
try less concurrency
eranrund Mar 22, 2022
2918407
Merge branch 'master' into eran/enclave-master-minters
eranrund Mar 22, 2022
44d960d
Revert "try less concurrency"
eranrund Mar 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions consensus/enclave/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mc-common = { path = "../../../common", default-features = false }
mc-crypto-digestible = { path = "../../../crypto/digestible", features = ["derive"] }
mc-crypto-keys = { path = "../../../crypto/keys", default-features = false }
mc-crypto-message-cipher = { path = "../../../crypto/message-cipher" }
mc-crypto-multisig = { path = "../../../crypto/multisig" }
mc-sgx-compat = { path = "../../../sgx/compat" }
mc-sgx-report-cache-api = { path = "../../../sgx/report-cache/api" }
mc-transaction-core = { path = "../../../transaction/core" }
Expand Down
70 changes: 66 additions & 4 deletions consensus/enclave/api/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::FeeMap;
use crate::{FeeMap, MasterMintersMap};
use alloc::{format, string::String};
use mc_common::ResponderId;
use mc_crypto_digestible::{Digestible, MerlinTranscript};
Expand All @@ -12,17 +12,22 @@ use serde::{Deserialize, Serialize};
/// signing key)
#[derive(Clone, Deserialize, Debug, Digestible, Eq, Hash, PartialEq, Serialize)]
pub struct BlockchainConfig {
/// The map from tokens to their minimum fees
/// The map from tokens to their minimum fees.
pub fee_map: FeeMap,

/// The map from tokens to master minters.
pub master_minters_map: MasterMintersMap,

/// The block version that this enclave will be applying rules for and
/// publishing
/// publishing.
pub block_version: BlockVersion,
}

impl Default for BlockchainConfig {
fn default() -> Self {
Self {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::MAX,
}
}
Expand Down Expand Up @@ -76,7 +81,9 @@ impl BlockchainConfigWithDigest {
#[cfg(test)]
mod test {
use super::*;
use alloc::string::ToString;
use alloc::{string::ToString, vec};
use mc_crypto_keys::Ed25519Public;
use mc_crypto_multisig::SignerSet;
use mc_transaction_core::{tokens::Mob, Token, TokenId};

/// Different block_version/fee maps/responder ids should result in
Expand All @@ -85,16 +92,19 @@ mod test {
fn different_fee_maps_result_in_different_responder_ids() {
let config1: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 2000)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
let config2: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
let config3: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
}
.into();
Expand Down Expand Up @@ -129,6 +139,7 @@ mod test {

let config4: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::TWO,
}
.into();
Expand All @@ -143,4 +154,55 @@ mod test {
config4.responder_id(&responder_id2)
);
}

// Different master minter maps result in differnet responder ids.
#[test]
fn different_master_minter_maps_result_in_different_responder_ids() {
let config1: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(1),
SignerSet::new(vec![Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();
let config2: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(2),
SignerSet::new(vec![Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();
let config3: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::default(),
master_minters_map: MasterMintersMap::try_from_iter([(
TokenId::from(2),
SignerSet::new(vec![Ed25519Public::default(), Ed25519Public::default()], 1),
)])
.unwrap(),
block_version: BlockVersion::ONE,
}
.into();

let responder_id1 = ResponderId("1.2.3.4:5".to_string());
assert_ne!(
config1.responder_id(&responder_id1),
config2.responder_id(&responder_id1)
);

assert_ne!(
config1.responder_id(&responder_id1),
config3.responder_id(&responder_id1)
);

assert_ne!(
config2.responder_id(&responder_id1),
config3.responder_id(&responder_id1)
);
}
}
11 changes: 10 additions & 1 deletion consensus/enclave/api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mc_attest_enclave_api::Error as AttestEnclaveError;
use mc_crypto_keys::SignatureError;
use mc_crypto_message_cipher::CipherError as MessageCipherError;
use mc_sgx_compat::sync::PoisonError;
use mc_transaction_core::validation::TransactionValidationError;
use mc_transaction_core::{mint::MintValidationError, validation::TransactionValidationError};
use mc_util_serial::{
decode::Error as RmpDecodeError, encode::Error as RmpEncodeError,
DecodeError as ProstDecodeError, EncodeError as ProstEncodeError,
Expand Down Expand Up @@ -38,6 +38,9 @@ pub enum Error {
/// Malformed transaction: {0}
MalformedTx(TransactionValidationError),

/// Malformed minting transaction: {0}
MalformedMintingTx(MintValidationError),

/// Invalid membership proof provided by local system
InvalidLocalMembershipProof,

Expand Down Expand Up @@ -126,6 +129,12 @@ impl From<TransactionValidationError> for Error {
}
}

impl From<MintValidationError> for Error {
fn from(src: MintValidationError) -> Error {
Error::MalformedMintingTx(src)
}
}

impl From<AttestEnclaveError> for Error {
fn from(src: AttestEnclaveError) -> Error {
Error::Attest(src)
Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/api/src/fee_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mc_crypto_digestible::Digestible;
use mc_transaction_core::{tokens::Mob, Token, TokenId};
use serde::{Deserialize, Serialize};

/// A thread-safe object that contains a map of fee value by token id.
/// A map of fee value by token id.
#[derive(Clone, Debug, Deserialize, Digestible, Eq, Hash, PartialEq, Serialize)]
pub struct FeeMap {
/// The actual map of token_id to fee.
Expand Down
2 changes: 2 additions & 0 deletions consensus/enclave/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ extern crate alloc;
mod config;
mod error;
mod fee_map;
mod master_minters_map;
mod messages;

pub use crate::{
config::{BlockchainConfig, BlockchainConfigWithDigest},
error::Error,
fee_map::{Error as FeeMapError, FeeMap},
master_minters_map::{Error as MasterMintersMapError, MasterMintersMap},
messages::EnclaveCall,
};

Expand Down
Loading