Update to latest librustzcash

This commit is contained in:
Kris Nuttycombe 2022-10-17 14:54:04 -06:00
parent d36c42da8f
commit 91ea6f5476
8 changed files with 47 additions and 93 deletions

View File

@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-swift.git",
"state" : {
"revision" : "4c63368b7462305903507e8acebd77264c0fb695",
"version" : "1.8.2"
"revision" : "87cecdeb2aae6b359b754d0dc7099e8237cf1824",
"version" : "1.11.0"
}
},
{
@ -18,13 +18,31 @@
"version" : "0.13.3"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version" : "1.0.2"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729",
"version" : "1.0.3"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
"version" : "1.4.2"
"revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c",
"version" : "1.4.4"
}
},
{
@ -32,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "124119f0bb12384cef35aa041d7c3a686108722d",
"version" : "2.40.0"
"revision" : "bc4c55b9f9584f09eb971d67d956e28d08caa9d0",
"version" : "2.43.1"
}
},
{
@ -41,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "a75e92bde3683241c15df3dd905b7a6dcac4d551",
"version" : "1.12.1"
"revision" : "6c84d247754ad77487a6f0694273b89b83efd056",
"version" : "1.14.0"
}
},
{
@ -50,8 +68,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "108ac15087ea9b79abb6f6742699cf31de0e8772",
"version" : "1.22.0"
"revision" : "00576e6f1efa5c46dca2ca3081dc56dd233b402d",
"version" : "1.23.0"
}
},
{
@ -59,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "42436a25ff32c390465567f5c089a9a8ce8d7baf",
"version" : "2.20.0"
"revision" : "ba7c0d7f82affc518147ea61d240330bf7f7ea9b",
"version" : "2.22.1"
}
},
{
@ -68,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "2cb54f91ddafc90832c5fa247faf5798d0a7c204",
"version" : "1.13.0"
"revision" : "b6e37a0d442745760d6ed0195d8f283d3ce0414a",
"version" : "1.14.1"
}
},
{
@ -77,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "e1499bc69b9040b29184f7f2996f7bab467c1639",
"version" : "1.19.0"
"revision" : "88c7d15e1242fdb6ecbafbc7926426a19be1e98a",
"version" : "1.20.2"
}
},
{
@ -86,8 +104,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi",
"state" : {
"branch" : "bin/librustzcash_0_7",
"revision" : "e8fbb84c1bec44af9dbef7e27c85f25e8f51a5af"
"revision" : "8eefbd8d70356b426d8e1dd7b07d2703a5a8e222"
}
}
],

View File

@ -16,7 +16,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.0"),
.package(name:"libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", branch: "bin/librustzcash_0_7")
.package(name:"libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", revision: "8eefbd8d70356b426d8e1dd7b07d2703a5a8e222")
],
targets: [
.target(

View File

@ -1059,14 +1059,6 @@ extension CompactBlockProcessor {
for try await utxo in stream {
utxos.append(utxo)
}
guard try rustBackend.clearUtxos(
dbData: dataDb,
address: tAddress,
sinceHeight: startHeight - 1,
networkType: self.config.network.networkType
) >= 0 else {
throw CompactBlockProcessorError.generalError(message: "attempted to clear utxos but -1 was returned")
}
return storeUTXOs(utxos, in: dataDb)
} catch {
throw mapError(error)

View File

@ -30,21 +30,6 @@ extension CompactBlockProcessor {
}
.flatMap({ $0 })
do {
for tAddress in tAddresses {
guard try rustBackend.clearUtxos(
dbData: config.dataDb,
address: tAddress,
sinceHeight: config.walletBirthday - 1,
networkType: config.network.networkType
) >= 0 else {
throw rustBackend.lastError() ?? .genericError(message: "clearUtxos failed. no error message available")
}
}
} catch {
throw FetchUTXOError.clearingFailed(error)
}
var utxos: [UnspentTransactionOutputEntity] = []
let stream: AsyncThrowingStream<UnspentTransactionOutputEntity, Error> = downloader.fetchUnspentTransactionOutputs(tAddresses: tAddresses.map { $0.stringEncoded }, startHeight: config.walletBirthday)
for try await transaction in stream {

View File

@ -13,12 +13,12 @@ public protocol PendingTransactionEntity: SignedTransactionEntity, AbstractTrans
/**
recipient address
*/
var toAddress: String { get set }
var toAddress: String { get }
/**
index of the account from which the funds were sent
*/
var accountIndex: Int { get set }
var accountIndex: Int { get }
/**
height which the block was mined at.
@ -34,7 +34,7 @@ public protocol PendingTransactionEntity: SignedTransactionEntity, AbstractTrans
/**
value is 1 if the transaction was cancelled
*/
var cancelled: Int { get set }
var cancelled: Int { get }
/**
how many times this transaction encoding was attempted
@ -61,7 +61,7 @@ public protocol PendingTransactionEntity: SignedTransactionEntity, AbstractTrans
- Note: represented in timeIntervalySince1970
*/
var createTime: TimeInterval { get set }
var createTime: TimeInterval { get }
/**
Checks whether this transaction is the same as the given transaction

View File

@ -12,28 +12,6 @@ import libzcashlc
class ZcashRustBackend: ZcashRustBackendWelding {
static let minimumConfirmations: UInt32 = 10
static func clearUtxos(
dbData: URL,
address: TransparentAddress,
sinceHeight: BlockHeight,
networkType: NetworkType
) throws -> Int32 {
let dbData = dbData.osStr()
let result = zcashlc_clear_utxos(
dbData.0,
dbData.1,
[CChar](address.stringEncoded.utf8CString),
Int32(sinceHeight),
networkType.networkId
)
guard result >= 0 else {
throw lastError() ?? .genericError(message: "No error message available")
}
return result
}
static func createAccount(dbData: URL, seed: [UInt8], networkType: NetworkType) throws -> UnifiedSpendingKey {
let dbData = dbData.osStr()
@ -69,7 +47,6 @@ class ZcashRustBackend: ZcashRustBackendWelding {
zcashlc_create_to_address(
dbData.0,
dbData.1,
Int32(usk.account),
uskPtr.baseAddress,
UInt(usk.bytes.count),
[CChar](address.utf8CString),
@ -597,7 +574,6 @@ class ZcashRustBackend: ZcashRustBackendWelding {
zcashlc_shield_funds(
dbData.0,
dbData.1,
Int32(usk.account),
uskBuffer.baseAddress,
UInt(usk.bytes.count),
memo.bytes,

View File

@ -31,23 +31,6 @@ public enum DbInitResult {
}
protocol ZcashRustBackendWelding {
/// clears the cached utxos for the given address from the specified height on for the
/// provided addresses. This will clear all UTXOs for the address from the database.
/// if there are unspent funds, the balance will be zero after clearing up UTXOs,
/// needing to put them back again to restore the balance (if they weren't spent)
/// - Parameters:
/// - dbData: location of the data db file
/// - address: the address of the UTXO
/// - sinceheight: clear the UXTOs from that address on
/// - networkType: network type of this key
/// - Returns: the amount of UTXOs cleared or -1 on error
static func clearUtxos(
dbData: URL,
address: TransparentAddress,
sinceHeight: BlockHeight,
networkType: NetworkType
) throws -> Int32
/// Adds the next available account-level spend authority, given the current set of [ZIP 316]
/// account identifiers known, to the wallet database.
///

View File

@ -124,8 +124,6 @@ class PendingTransactionRepositoryTests: XCTestCase {
}
func testUpdate() {
let newAccountIndex = 1
let newValue = Zatoshi(123_456)
let transaction = createAndStoreMockedTransaction()
guard let id = transaction.id else {
@ -141,9 +139,12 @@ class PendingTransactionRepositoryTests: XCTestCase {
XCTFail("failed to store tx")
return
}
let oldEncodeAttempts = stored!.encodeAttempts
let oldSubmitAttempts = stored!.submitAttempts
stored!.accountIndex = newAccountIndex
stored!.value = newValue
stored!.encodeAttempts += 1
stored!.submitAttempts += 5
XCTAssertNoThrow(try pendingRepository.update(stored!))
@ -152,8 +153,8 @@ class PendingTransactionRepositoryTests: XCTestCase {
return
}
XCTAssertEqual(updatedTransaction.value, newValue)
XCTAssertEqual(updatedTransaction.accountIndex, newAccountIndex)
XCTAssertEqual(updatedTransaction.encodeAttempts, oldEncodeAttempts + 1)
XCTAssertEqual(updatedTransaction.submitAttempts, oldSubmitAttempts + 5)
XCTAssertEqual(updatedTransaction.toAddress, stored!.toAddress)
}