Skip to content

Commit

Permalink
Uprev mobilecoin and deal with new Rust version fallbacks (#136)
Browse files Browse the repository at this point in the history
* get future clippy happy, some mobilecoin uprev fixes

* new rust fixes and uprev

* update rustfmt

* Ensure rebase didnt mess anything

* fix hardcoded fee

* another test fix

* test fixes
  • Loading branch information
eranrund authored and christian-oudard committed May 4, 2021
1 parent 1ae8db0 commit 2b83bcd
Show file tree
Hide file tree
Showing 24 changed files with 593 additions and 550 deletions.
166 changes: 112 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ overflow-checks = false
prost = { git = "https://github.com/danburkert/prost", rev = "6113789f70b69709820becba4242824b4fb3ffec" }
prost-derive = { git = "https://github.com/danburkert/prost", rev = "6113789f70b69709820becba4242824b4fb3ffec" }

# Patched to depend on crates that depend on digest 0.9
bulletproofs = { git = "https://github.com/eranrund/bulletproofs", rev = "e8e8ef45ecc6d31f1a9525140edc977351d0f780" }
# Not-yet-released version that depends on newer crates.
bulletproofs = { git = "https://github.com/eranrund/bulletproofs", rev = "8a7c9cdd1efafa3ad68cd65676302f925de68373" }

# We need to patch aes-gcm so we can make some fields/functions/structs pub in order to have a constant time decrypt
aes-gcm = { git = "https://github.com/mobilecoinofficial/AEADs", rev = "d1a8517d3dd867ed9c5794002add67992a42f6aa" }
Expand All @@ -37,3 +37,14 @@ grpcio-compiler = { git = "https://github.com/jcape/grpc-rs", rev = "2ad042e9e65

# Overridden in order to bump libsqlite3-sys. This allows us to statically link a more recent version of SQLite3.
diesel = { git = "https://github.com/eranrund/diesel", rev = "25592f0383a1d1628db7d2db6c1fb02614a978c1" }

# ed25519-dalek depends on rand 0.7 which in turns depends on a broken version of packed_simd
# This is a PR that moves it to newer rand
# See https://github.com/dalek-cryptography/ed25519-dalek/pull/160
ed25519-dalek = { git = "https://github.com/eranrund/ed25519-dalek.git", rev = "484369672f45d776fe13fdd17618aed2f4047909" }

# Bump curve25519-dalek version to 4.0.0-pre0
x25519-dalek = { git = "https://github.com/eranrund/x25519-dalek.git", rev = "57c04e5c5aca3551c015167d8176393fbe76dc65" }

# Overridden since we need a commit that uprevs a bunch of dependencies.
schnorrkel = { git = "https://github.com/mobilecoinofficial/schnorrkel", rev = "fa27d0ed32d251a27399a23d3ef69611acb14d56" }
2 changes: 1 addition & 1 deletion full-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ hex = {version = "0.4", default-features = false }
libsqlite3-sys = { version = ">=0.8.0, <=0.22.1", features = ["min_sqlite_version_3_7_16", "bundled"] }
num_cpus = "1.12"
prost = { version = "0.6.1", default-features = false, features = ["prost-derive"] }
rand = { version = "0.7", default-features = false }
rand = { version = "0.8", default-features = false }
reqwest = { version = "0.10", default-features = false, features = ["rustls-tls", "gzip"] }
retry = "1.2"
rocket = { version = "0.4.5", default-features = false }
Expand Down
110 changes: 54 additions & 56 deletions full-service/src/db/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,56 +257,54 @@ impl AccountModel for Account {
let account_id = AccountID::from(account_key);
let fb = first_block_index.unwrap_or(DEFAULT_FIRST_BLOCK_INDEX);

Ok(
conn.transaction::<(AccountID, String), WalletDbError, _>(|| {
let new_account = NewAccount {
account_id_hex: &account_id.to_string(),
account_key: &mc_util_serial::encode(account_key), /* FIXME: WS-6 - add
* encryption */
entropy: &entropy,
key_derivation_version: key_derivation_version as i32,
main_subaddress_index: DEFAULT_SUBADDRESS_INDEX as i64,
change_subaddress_index: DEFAULT_CHANGE_SUBADDRESS_INDEX as i64,
next_subaddress_index: next_subaddress_index
.unwrap_or(DEFAULT_NEXT_SUBADDRESS_INDEX)
as i64,
first_block_index: fb as i64,
next_block_index: fb as i64,
import_block_index: import_block_index.map(|i| i as i64),
name,
};

diesel::insert_into(accounts::table)
.values(&new_account)
.execute(conn)?;
conn.transaction::<(AccountID, String), WalletDbError, _>(|| {
let new_account = NewAccount {
account_id_hex: &account_id.to_string(),
account_key: &mc_util_serial::encode(account_key), /* FIXME: WS-6 - add
* encryption */
entropy: &entropy,
key_derivation_version: key_derivation_version as i32,
main_subaddress_index: DEFAULT_SUBADDRESS_INDEX as i64,
change_subaddress_index: DEFAULT_CHANGE_SUBADDRESS_INDEX as i64,
next_subaddress_index: next_subaddress_index
.unwrap_or(DEFAULT_NEXT_SUBADDRESS_INDEX)
as i64,
first_block_index: fb as i64,
next_block_index: fb as i64,
import_block_index: import_block_index.map(|i| i as i64),
name,
};

diesel::insert_into(accounts::table)
.values(&new_account)
.execute(conn)?;

let main_subaddress_b58 = AssignedSubaddress::create(
&account_key,
None, /* FIXME: WS-8 - Address Book Entry if details provided, or None
* always for main? */
DEFAULT_SUBADDRESS_INDEX,
"Main",
&conn,
)?;

let _change_subaddress_b58 = AssignedSubaddress::create(
&account_key,
None, /* FIXME: WS-8 - Address Book Entry if details provided, or None
* always for main? */
DEFAULT_CHANGE_SUBADDRESS_INDEX,
"Change",
&conn,
)?;

for subaddress_index in
2..next_subaddress_index.unwrap_or(DEFAULT_NEXT_SUBADDRESS_INDEX)
{
AssignedSubaddress::create(&account_key, None, subaddress_index, "", &conn)?;
}
let main_subaddress_b58 = AssignedSubaddress::create(
&account_key,
None, /* FIXME: WS-8 - Address Book Entry if details provided, or None
* always for main? */
DEFAULT_SUBADDRESS_INDEX,
"Main",
&conn,
)?;

Ok((account_id, main_subaddress_b58))
})?,
)
let _change_subaddress_b58 = AssignedSubaddress::create(
&account_key,
None, /* FIXME: WS-8 - Address Book Entry if details provided, or None
* always for main? */
DEFAULT_CHANGE_SUBADDRESS_INDEX,
"Change",
&conn,
)?;

for subaddress_index in
2..next_subaddress_index.unwrap_or(DEFAULT_NEXT_SUBADDRESS_INDEX)
{
AssignedSubaddress::create(&account_key, None, subaddress_index, "", &conn)?;
}

Ok((account_id, main_subaddress_b58))
})
}

fn import(
Expand All @@ -320,7 +318,7 @@ impl AccountModel for Account {
fog_authority_spki: Option<String>,
conn: &PooledConnection<ConnectionManager<SqliteConnection>>,
) -> Result<Account, WalletDbError> {
Ok(conn.transaction::<Account, WalletDbError, _>(|| {
conn.transaction::<Account, WalletDbError, _>(|| {
let (account_id, _public_address_b58) = Account::create_from_mnemonic(
mnemonic,
first_block_index,
Expand All @@ -332,8 +330,8 @@ impl AccountModel for Account {
fog_authority_spki,
conn,
)?;
Ok(Account::get(&account_id, &conn)?)
})?)
Account::get(&account_id, &conn)
})
}

fn import_legacy(
Expand All @@ -347,7 +345,7 @@ impl AccountModel for Account {
fog_authority_spki: Option<String>,
conn: &PooledConnection<ConnectionManager<SqliteConnection>>,
) -> Result<Account, WalletDbError> {
Ok(conn.transaction::<Account, WalletDbError, _>(|| {
conn.transaction::<Account, WalletDbError, _>(|| {
let (account_id, _public_address_b58) = Account::create_from_root_entropy(
root_entropy,
first_block_index,
Expand All @@ -359,8 +357,8 @@ impl AccountModel for Account {
fog_authority_spki,
conn,
)?;
Ok(Account::get(&account_id, &conn)?)
})?)
Account::get(&account_id, &conn)
})
}

fn list_all(
Expand Down Expand Up @@ -440,7 +438,7 @@ impl AccountModel for Account {
txos::dsl::{txo_id_hex, txos},
};

Ok(conn.transaction::<(), WalletDbError, _>(|| {
conn.transaction::<(), WalletDbError, _>(|| {
for key_image in key_images {
// Get the txo by key_image
let matches = crate::db::schema::txos::table
Expand Down Expand Up @@ -489,7 +487,7 @@ impl AccountModel for Account {
.set(crate::db::schema::accounts::next_block_index.eq(spent_block_index + 1))
.execute(conn)?;
Ok(())
})?)
})
}

/// Delete an account.
Expand Down
6 changes: 3 additions & 3 deletions full-service/src/db/assigned_subaddress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl AssignedSubaddressModel for AssignedSubaddress {
},
};

Ok(conn.transaction::<(String, i64), WalletDbError, _>(|| {
conn.transaction::<(String, i64), WalletDbError, _>(|| {
let account = Account::get(&AccountID(account_id_hex.to_string()), conn)?;

let account_key: AccountKey = mc_util_serial::decode(&account.account_key)?;
Expand Down Expand Up @@ -228,7 +228,7 @@ impl AssignedSubaddressModel for AssignedSubaddress {
}

Ok((subaddress_b58, subaddress_index))
})?)
})
}

fn get(
Expand Down Expand Up @@ -268,7 +268,7 @@ impl AssignedSubaddressModel for AssignedSubaddress {
let subaddress = account_key.subaddress(index as u64);

let subaddress_b58 = b58_encode(&subaddress)?;
Ok(Self::get(&subaddress_b58, &conn)?)
Self::get(&subaddress_b58, &conn)
}

fn find_by_subaddress_spend_public_key(
Expand Down
12 changes: 6 additions & 6 deletions full-service/src/db/transaction_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl TransactionLogModel for TransactionLog {
) -> Result<(), WalletDbError> {
use crate::db::schema::transaction_logs::dsl::{transaction_id_hex, transaction_logs};

Ok(conn.transaction::<(), WalletDbError, _>(|| {
conn.transaction::<(), WalletDbError, _>(|| {
let associated_transaction_logs = Self::select_for_txo(txo_id_hex, conn)?;

for transaction_log in associated_transaction_logs {
Expand Down Expand Up @@ -393,7 +393,7 @@ impl TransactionLogModel for TransactionLog {
}
}
Ok(())
})?)
})
}

fn log_received(
Expand All @@ -404,7 +404,7 @@ impl TransactionLogModel for TransactionLog {
) -> Result<(), WalletDbError> {
use crate::db::schema::transaction_txo_types;

Ok(conn.transaction::<(), WalletDbError, _>(|| {
conn.transaction::<(), WalletDbError, _>(|| {
for (subaddress_index, output_txo_ids) in subaddress_to_output_txo_ids {
let txos = Txo::select_by_id(&output_txo_ids, conn)?;
for (txo, _account_txo_status) in txos {
Expand Down Expand Up @@ -459,7 +459,7 @@ impl TransactionLogModel for TransactionLog {
}
}
Ok(())
})?)
})
}

fn log_submitted(
Expand Down Expand Up @@ -545,7 +545,7 @@ impl TransactionLogModel for TransactionLog {
}
Ok(transaction_id.to_string())
})?;
Ok(TransactionLog::get(&transaction_log_id, conn)?)
TransactionLog::get(&transaction_log_id, conn)
}

fn delete_all_for_account(
Expand Down Expand Up @@ -798,7 +798,7 @@ mod tests {
&wallet_db.get_conn().unwrap(),
)
.unwrap();
assert_eq!(change_details.txo.value, 19990000000000); // 19.99 * MOB
assert_eq!(change_details.txo.value, 20 * MOB - MINIMUM_FEE as i64);
assert_eq!(
change_details
.minted_from_account
Expand Down
10 changes: 5 additions & 5 deletions full-service/src/db/txo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,13 @@ impl TxoModel for Txo {
confirmation: &TxOutConfirmationNumber,
conn: &PooledConnection<ConnectionManager<SqliteConnection>>,
) -> Result<bool, WalletDbError> {
Ok(conn.transaction::<bool, WalletDbError, _>(|| {
conn.transaction::<bool, WalletDbError, _>(|| {
let txo_details = Txo::get(txo_id_hex, conn)?;
let public_key: RistrettoPublic = mc_util_serial::decode(&txo_details.txo.public_key)?;
let account = Account::get(account_id, conn)?;
let account_key: AccountKey = mc_util_serial::decode(&account.account_key)?;
Ok(confirmation.validate(&public_key, account_key.view_private_key()))
})?)
})
}
}

Expand Down Expand Up @@ -1085,7 +1085,7 @@ mod tests {
logger.clone(),
);
assert_eq!(output_value, 33 * MOB);
assert_eq!(change_value, (966.99 * (MOB as f64)) as i64);
assert_eq!(change_value, 967 * MOB - MINIMUM_FEE as i64);

add_block_with_db_txos(
&mut ledger_db,
Expand Down Expand Up @@ -1292,7 +1292,7 @@ mod tests {
logger.clone(),
);
assert_eq!(output_value, 72 * MOB);
assert_eq!(change_value, (927.98 * (MOB as f64)) as i64);
assert_eq!(change_value, 928 * MOB - (2 * MINIMUM_FEE as i64));

// Add the minted Txos to the ledger
add_block_with_db_txos(
Expand Down Expand Up @@ -1542,7 +1542,7 @@ mod tests {
);
assert!(minted_txo_details.received_to_assigned_subaddress.is_none());

assert_eq!(change_value, (4998.99 * (MOB as f64)) as i64);
assert_eq!(change_value, 4999 * MOB - MINIMUM_FEE as i64);
let change_txo_details = Txo::get(&change_txo_id, &wallet_db.get_conn().unwrap()).unwrap();
assert_eq!(change_txo_details.txo.value, change_value);
assert_eq!(
Expand Down
Loading

0 comments on commit 2b83bcd

Please sign in to comment.