Migrate to note-spending-v6 branch (#35)

* Migrate to note-spending-v6 branch

* Rename sendToAddress -> createToAddress

* cargo update

* Disable multicore proving temporarily

createToAddress breaks when called from a background thread if multicore
is enabled.

* Modify expectations. Single thread librustzcash needs more time
This commit is contained in:
str4d 2019-12-03 17:11:24 +00:00 committed by Francisco Gindre
parent d8affaebd3
commit cff6ec5505
12 changed files with 422 additions and 531 deletions

875
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,19 +12,21 @@ hex = "0.3"
[dependencies.zcash_client_backend]
git = "https://github.com/str4d/librustzcash.git"
branch = "note-spending-v5"
branch = "note-spending-v6"
[dependencies.zcash_client_sqlite]
git = "https://github.com/str4d/librustzcash.git"
branch = "note-spending-v5"
branch = "note-spending-v6"
[dependencies.zcash_primitives]
git = "https://github.com/str4d/librustzcash.git"
branch = "note-spending-v5"
branch = "note-spending-v6"
[dependencies.zcash_proofs]
git = "https://github.com/str4d/librustzcash.git"
branch = "note-spending-v5"
branch = "note-spending-v6"
default-features = false
features = ["local-prover"]
[build-dependencies]
cbindgen = "0.8"

View File

@ -126,13 +126,13 @@ class ZcashRustBackend: ZcashRustBackendWelding {
return zcashlc_scan_blocks(dbCache.0, dbCache.1, dbData.0, dbData.1) != 0
}
static func sendToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64 {
static func createToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64 {
let dbData = dbData.osStr()
let spendParams = spendParams.osStr()
let outputParams = outputParams.osStr()
let memoBytes = memo ?? ""
return zcashlc_send_to_address(dbData.0, dbData.1, account, extsk, to, value, memoBytes, spendParams.0, spendParams.1, outputParams.0, outputParams.1)
return zcashlc_create_to_address(dbData.0, dbData.1, account, extsk, to, value, memoBytes, spendParams.0, spendParams.1, outputParams.0, outputParams.1)
}
}

View File

@ -74,6 +74,6 @@ public protocol ZcashRustBackendWelding {
*/
static func scanBlocks(dbCache: URL, dbData: URL) -> Bool
static func sendToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64
static func createToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64
}

View File

@ -57,7 +57,7 @@ class WalletTransactionEncoder: TransactionEncoder {
}
let txId = rustBackend.sendToAddress(dbData: initializer.dataDbURL, account: Int32(accountIndex), extsk: spendingKey, to: address, value: Int64(zatoshi), memo: memo, spendParams: spend, outputParams: output)
let txId = rustBackend.createToAddress(dbData: initializer.dataDbURL, account: Int32(accountIndex), extsk: spendingKey, to: address, value: Int64(zatoshi), memo: memo, spendParams: spend, outputParams: output)
guard txId > 0 else {
throw rustBackend.lastError() ?? RustWeldingError.genericError(message: "create spend failed")

View File

@ -86,7 +86,7 @@ class CompactBlockProcessorTests: XCTestCase {
startedValidatingNotificationExpectation,
startedScanningNotificationExpectation,
idleNotificationExpectation,
], timeout: 130,enforceOrder: true)
], timeout: 260,enforceOrder: true)
}
func testProgressNotifications() {
@ -95,7 +95,7 @@ class CompactBlockProcessorTests: XCTestCase {
updatedNotificationExpectation.expectedFulfillmentCount = expectedUpdates
startProcessing()
wait(for: [updatedNotificationExpectation], timeout: 130)
wait(for: [updatedNotificationExpectation], timeout: 300)
}

View File

@ -113,7 +113,7 @@ class CompactBlockReorgTests: XCTestCase {
startedScanningNotificationExpectation,
reorgNotificationExpectation,
idleNotificationExpectation,
], timeout: 130,enforceOrder: true)
], timeout: 300,enforceOrder: true)
}
private func expectedBatches(currentHeight: BlockHeight, targetHeight: BlockHeight, batchSize: Int) -> Int {

View File

@ -40,7 +40,7 @@ class DownloadOperationTests: XCTestCase {
operationQueue.addOperation(downloadOperation)
wait(for: [expect], timeout: 5)
wait(for: [expect], timeout: 10)
XCTAssertEqual(try! storage.latestHeight(),range.endIndex)
}

View File

@ -34,14 +34,14 @@ class LightWalletServiceTests: XCTestCase {
expect.fulfill()
}
wait(for: [expect], timeout: 5)
wait(for: [expect], timeout: 20)
}
func testHundredBlocks() {
let expect = XCTestExpectation(description: self.description)
let count = 100
let lowerRange: BlockHeight = SAPLING_ACTIVATION_HEIGHT
let upperRange: BlockHeight = SAPLING_ACTIVATION_HEIGHT + 99
let upperRange: BlockHeight = SAPLING_ACTIVATION_HEIGHT + count
let blockRange = Range<BlockHeight>(uncheckedBounds: (lower: lowerRange, upper: upperRange))
service.blockRange(blockRange) { (result) in
@ -51,12 +51,12 @@ class LightWalletServiceTests: XCTestCase {
XCTFail("failed with error \(error)")
case .success(let blocks):
XCTAssertEqual(blocks.count, 100)
XCTAssertEqual(blocks.count, count)
XCTAssertEqual(blocks[0].height, lowerRange)
}
}
wait(for: [expect], timeout: 5)
wait(for: [expect], timeout: 10)
}
func testSyncBlockRange() {
@ -84,7 +84,7 @@ class LightWalletServiceTests: XCTestCase {
}
}
wait(for: [expect], timeout: 5)
wait(for: [expect], timeout: 10)
}
}

View File

@ -67,7 +67,7 @@ class ZcashRustBackendTests: XCTestCase {
func testSendToAddress() {
let tx = try! ZcashRustBackend.sendToAddress(dbData: dataDbHandle.readWriteDb, account: 0, extsk: spendingKey, to: recipientAddress, value: Int64(zpend), memo: nil, spendParams: URL(string: __spendParamsURL().path)!, outputParams: URL(string: __outputParamsURL().path)!)
let tx = try! ZcashRustBackend.createToAddress(dbData: dataDbHandle.readWriteDb, account: 0, extsk: spendingKey, to: recipientAddress, value: Int64(zpend), memo: nil, spendParams: URL(string: __spendParamsURL().path)!, outputParams: URL(string: __outputParamsURL().path)!)
XCTAssert(tx > 0)
XCTAssertNil(ZcashRustBackend.lastError())
}

View File

@ -62,7 +62,7 @@ class MockRustBackend: ZcashRustBackendWelding {
static var mockValidateCombinedChainKeepFailing = false
static var mockValidateCombinedChainFailureHeight: BlockHeight = 0
static var mockScanblocksSuccessRate: Float?
static var mockSendToAddress: Int64?
static var mockCreateToAddress: Int64?
static var rustBackend = ZcashRustBackend.self
@ -159,8 +159,8 @@ class MockRustBackend: ZcashRustBackendWelding {
return rustBackend.scanBlocks(dbCache: dbCache, dbData: dbData)
}
static func sendToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64 {
mockSendToAddress ?? rustBackend.sendToAddress(dbData: dbData, account: account, extsk: extsk, to: to, value: value, memo: memo, spendParams: spendParams, outputParams: outputParams)
static func createToAddress(dbData: URL, account: Int32, extsk: String, to: String, value: Int64, memo: String?, spendParams: URL, outputParams: URL) -> Int64 {
mockCreateToAddress ?? rustBackend.createToAddress(dbData: dbData, account: account, extsk: extsk, to: to, value: value, memo: memo, spendParams: spendParams, outputParams: outputParams)
}
static func shouldSucceed(successRate: Float) -> Bool {

View File

@ -13,9 +13,14 @@ use zcash_client_backend::{
use zcash_client_sqlite::{
address::RecipientAddress,
chain::{rewind_to_height, validate_combined_chain},
get_address, get_balance, get_received_memo_as_utf8, get_sent_memo_as_utf8,
get_verified_balance, init_accounts_table, init_blocks_table, init_data_database,
scan_cached_blocks, send_to_address, ErrorKind,
error::ErrorKind,
init::{init_accounts_table, init_blocks_table, init_data_database},
query::{
get_address, get_balance, get_received_memo_as_utf8, get_sent_memo_as_utf8,
get_verified_balance,
},
scan::scan_cached_blocks,
transact::create_to_address,
};
use zcash_primitives::{
block::BlockHash, note_encryption::Memo, transaction::components::Amount,
@ -207,7 +212,7 @@ pub extern "C" fn zcashlc_get_balance(db_data: *const u8, db_data_len: usize, ac
};
match get_balance(&db_data, account) {
Ok(balance) => Ok(balance.0),
Ok(balance) => Ok(balance.into()),
Err(e) => Err(format_err!("Error while fetching balance: {}", e)),
}
});
@ -233,7 +238,7 @@ pub extern "C" fn zcashlc_get_verified_balance(
};
match get_verified_balance(&db_data, account) {
Ok(balance) => Ok(balance.0),
Ok(balance) => Ok(balance.into()),
Err(e) => Err(format_err!("Error while fetching verified balance: {}", e)),
}
});
@ -411,7 +416,7 @@ pub extern "C" fn zcashlc_scan_blocks(
/// Do not call this multiple times in parallel, or you will generate transactions that
/// double-spend the same notes.
#[no_mangle]
pub extern "C" fn zcashlc_send_to_address(
pub extern "C" fn zcashlc_create_to_address(
db_data: *const u8,
db_data_len: usize,
account: i32,
@ -435,7 +440,11 @@ pub extern "C" fn zcashlc_send_to_address(
};
let extsk = unsafe { CStr::from_ptr(extsk) }.to_str()?;
let to = unsafe { CStr::from_ptr(to) }.to_str()?;
let value = Amount(value);
let value =
Amount::from_i64(value).map_err(|()| format_err!("Invalid amount, out of range"))?;
if value.is_negative() {
return Err(format_err!("Amount is negative"));
}
let memo = unsafe { CStr::from_ptr(memo) }.to_str()?;
let spend_params = Path::new(OsStr::from_bytes(unsafe {
slice::from_raw_parts(spend_params, spend_params_len)
@ -455,20 +464,17 @@ pub extern "C" fn zcashlc_send_to_address(
};
let to = match RecipientAddress::from_str(&to) {
Ok(Some(to)) => to,
Ok(None) => {
Some(to) => to,
None => {
return Err(format_err!("PaymentAddress is for the wrong network"));
}
Err(e) => {
return Err(format_err!("Invalid address: {}", e));
}
};
let memo = Memo::from_str(&memo);
let prover = LocalTxProver::new(spend_params, output_params);
send_to_address(
create_to_address(
&db_data,
SAPLING_CONSENSUS_BRANCH_ID,
prover,