TreeState support
- @str4d please check this implementation, I believe it's what you were looking for. - the new service's method getTreeState needs some documentation though TreeState support - Fixed the build, the swiftlint was complaining about a tuple length, we might consider to refactor is sometime later, for now I disabled swiftlint - fromState fix -1 TreeState support (#1394) - some fixes for offlineTests
This commit is contained in:
parent
90dcb0e3bb
commit
be06b3d403
|
@ -23,6 +23,7 @@ protocol BlockScanner {
|
||||||
struct BlockScannerImpl {
|
struct BlockScannerImpl {
|
||||||
let config: BlockScannerConfig
|
let config: BlockScannerConfig
|
||||||
let rustBackend: ZcashRustBackendWelding
|
let rustBackend: ZcashRustBackendWelding
|
||||||
|
let service: LightWalletService
|
||||||
let transactionRepository: TransactionRepository
|
let transactionRepository: TransactionRepository
|
||||||
let metrics: SDKMetrics
|
let metrics: SDKMetrics
|
||||||
let logger: Logger
|
let logger: Logger
|
||||||
|
@ -56,7 +57,9 @@ extension BlockScannerImpl: BlockScanner {
|
||||||
let scanSummary: ScanSummary
|
let scanSummary: ScanSummary
|
||||||
let scanStartTime = Date()
|
let scanStartTime = Date()
|
||||||
do {
|
do {
|
||||||
scanSummary = try await self.rustBackend.scanBlocks(fromHeight: Int32(startHeight), limit: batchSize)
|
let fromState = try await service.getTreeState(BlockID(height: startHeight - 1))
|
||||||
|
|
||||||
|
scanSummary = try await self.rustBackend.scanBlocks(fromHeight: Int32(startHeight), fromState: fromState, limit: batchSize)
|
||||||
} catch {
|
} catch {
|
||||||
logger.debug("block scanning failed with error: \(String(describing: error))")
|
logger.debug("block scanning failed with error: \(String(describing: error))")
|
||||||
throw error
|
throw error
|
||||||
|
|
|
@ -277,6 +277,10 @@ extension LightWalletGRPCService: LightWalletService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTreeState(_ id: BlockID) async throws -> TreeState {
|
||||||
|
try await compactTxStreamer.getTreeState(id)
|
||||||
|
}
|
||||||
|
|
||||||
func closeConnection() {
|
func closeConnection() {
|
||||||
_ = channel.close()
|
_ = channel.close()
|
||||||
|
|
|
@ -196,4 +196,6 @@ protocol LightWalletService: AnyObject {
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - request: Request to send to GetSubtreeRoots.
|
/// - request: Request to send to GetSubtreeRoots.
|
||||||
func getSubtreeRoots(_ request: GetSubtreeRootsArg) -> AsyncThrowingStream<SubtreeRoot, Error>
|
func getSubtreeRoots(_ request: GetSubtreeRootsArg) -> AsyncThrowingStream<SubtreeRoot, Error>
|
||||||
|
|
||||||
|
func getTreeState(_ id: BlockID) async throws -> TreeState
|
||||||
}
|
}
|
||||||
|
|
|
@ -859,6 +859,7 @@ extension FfiScanProgress {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swiftlint:disable large_tuple line_length
|
||||||
struct FfiTxId {
|
struct FfiTxId {
|
||||||
var tuple: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
|
var tuple: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
|
||||||
var array: [UInt8] {
|
var array: [UInt8] {
|
||||||
|
|
|
@ -120,6 +120,7 @@ enum Dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.register(type: BlockScanner.self, isSingleton: true) { di in
|
container.register(type: BlockScanner.self, isSingleton: true) { di in
|
||||||
|
let service = di.resolve(LightWalletService.self)
|
||||||
let rustBackend = di.resolve(ZcashRustBackendWelding.self)
|
let rustBackend = di.resolve(ZcashRustBackendWelding.self)
|
||||||
let transactionRepository = di.resolve(TransactionRepository.self)
|
let transactionRepository = di.resolve(TransactionRepository.self)
|
||||||
let metrics = di.resolve(SDKMetrics.self)
|
let metrics = di.resolve(SDKMetrics.self)
|
||||||
|
@ -133,6 +134,7 @@ enum Dependencies {
|
||||||
return BlockScannerImpl(
|
return BlockScannerImpl(
|
||||||
config: blockScannerConfig,
|
config: blockScannerConfig,
|
||||||
rustBackend: rustBackend,
|
rustBackend: rustBackend,
|
||||||
|
service: service,
|
||||||
transactionRepository: transactionRepository,
|
transactionRepository: transactionRepository,
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
logger: logger
|
logger: logger
|
||||||
|
|
|
@ -190,6 +190,10 @@ class DarksideWalletService: LightWalletService {
|
||||||
func getSubtreeRoots(_ request: ZcashLightClientKit.GetSubtreeRootsArg) -> AsyncThrowingStream<ZcashLightClientKit.SubtreeRoot, Error> {
|
func getSubtreeRoots(_ request: ZcashLightClientKit.GetSubtreeRootsArg) -> AsyncThrowingStream<ZcashLightClientKit.SubtreeRoot, Error> {
|
||||||
service.getSubtreeRoots(request)
|
service.getSubtreeRoots(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTreeState(_ id: BlockID) async throws -> TreeState {
|
||||||
|
try await service.getTreeState(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DarksideWalletDConstants: NetworkConstants {
|
enum DarksideWalletDConstants: NetworkConstants {
|
||||||
|
|
|
@ -82,4 +82,8 @@ class MockLightWalletService: LightWalletService {
|
||||||
func getSubtreeRoots(_ request: ZcashLightClientKit.GetSubtreeRootsArg) -> AsyncThrowingStream<ZcashLightClientKit.SubtreeRoot, Error> {
|
func getSubtreeRoots(_ request: ZcashLightClientKit.GetSubtreeRootsArg) -> AsyncThrowingStream<ZcashLightClientKit.SubtreeRoot, Error> {
|
||||||
service.getSubtreeRoots(request)
|
service.getSubtreeRoots(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTreeState(_ id: BlockID) async throws -> TreeState {
|
||||||
|
try await service.getTreeState(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -963,6 +963,30 @@ class LightWalletServiceMock: LightWalletService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - getTreeState
|
||||||
|
|
||||||
|
var getTreeStateThrowableError: Error?
|
||||||
|
var getTreeStateCallsCount = 0
|
||||||
|
var getTreeStateCalled: Bool {
|
||||||
|
return getTreeStateCallsCount > 0
|
||||||
|
}
|
||||||
|
var getTreeStateReceivedId: BlockID?
|
||||||
|
var getTreeStateReturnValue: TreeState!
|
||||||
|
var getTreeStateClosure: ((BlockID) async throws -> TreeState)?
|
||||||
|
|
||||||
|
func getTreeState(_ id: BlockID) async throws -> TreeState {
|
||||||
|
if let error = getTreeStateThrowableError {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
getTreeStateCallsCount += 1
|
||||||
|
getTreeStateReceivedId = id
|
||||||
|
if let closure = getTreeStateClosure {
|
||||||
|
return try await closure(id)
|
||||||
|
} else {
|
||||||
|
return getTreeStateReturnValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class LightWalletdInfoMock: LightWalletdInfo {
|
class LightWalletdInfoMock: LightWalletdInfo {
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,8 @@ class RustBackendMockHelper {
|
||||||
try await rustBackend.suggestScanRanges()
|
try await rustBackend.suggestScanRanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
await rustBackendMock.setScanBlocksFromHeightLimitClosure() { fromHeight, limit in
|
await rustBackendMock.setScanBlocksFromHeightFromStateLimitClosure { fromHeight, fromState, limit in
|
||||||
try await rustBackend.scanBlocks(fromHeight: fromHeight, limit: limit)
|
try await rustBackend.scanBlocks(fromHeight: fromHeight, fromState: fromState, limit: limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue