From 9159ae96c277bbbdce0cbe6117185d021004221d Mon Sep 17 00:00:00 2001 From: pankcuf Date: Tue, 18 Jul 2023 15:40:34 +0700 Subject: [PATCH 1/6] chore: attach rust log file for sending --- DashSync/shared/Libraries/DSLogger.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DashSync/shared/Libraries/DSLogger.m b/DashSync/shared/Libraries/DSLogger.m index 302e32009..4089ed18b 100644 --- a/DashSync/shared/Libraries/DSLogger.m +++ b/DashSync/shared/Libraries/DSLogger.m @@ -59,7 +59,14 @@ - (instancetype)init { [logFiles addObject:fileURL]; } } + // add rust log file located at $CACHE/Logs/processor.log + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *cacheDirectory = [paths objectAtIndex:0]; + NSString *rustLogPath = [cacheDirectory stringByAppendingPathComponent:@"Logs/processor.log"]; + if ([[NSFileManager defaultManager] fileExistsAtPath:rustLogPath]) { + [logFiles addObject:[NSURL fileURLWithPath:rustLogPath]]; + } return [logFiles copy]; } From d473eecdc36e660e755e0492160f9c1df777a95c Mon Sep 17 00:00:00 2001 From: pankcuf Date: Wed, 19 Jul 2023 14:18:53 +0700 Subject: [PATCH 2/6] chore: log peers count when connect --- DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m b/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m index ae53a7073..19cac82e6 100644 --- a/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m +++ b/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m @@ -695,7 +695,7 @@ - (void)useMasternodeList:(DSMasternodeList *)masternodeList withConnectivityNon // MARK: - Connectivity - (void)connect { - DSLog(@"[DSPeerManager] connect (%d)", self.connectedPeers); + DSLog(@"[DSPeerManager] connect (%d)", [self.connectedPeers count]); self.desiredState = DSPeerManagerDesiredState_Connected; dispatch_async(self.networkingQueue, ^{ if ([self.chain syncsBlockchain] && ![self.chain canConstructAFilter]) return; // check to make sure the wallet has been created if only are a basic wallet with no dash features From d2e34619c97caf85027b610debdc78d560f0348e Mon Sep 17 00:00:00 2001 From: pankcuf Date: Wed, 19 Jul 2023 14:19:33 +0700 Subject: [PATCH 3/6] fix: wrap thread-unsafe code into @synchronized --- .../Derivation Paths/DSFundsDerivationPath.m | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/DashSync/shared/Models/Derivation Paths/DSFundsDerivationPath.m b/DashSync/shared/Models/Derivation Paths/DSFundsDerivationPath.m index f173e3d92..6de0e83f5 100644 --- a/DashSync/shared/Models/Derivation Paths/DSFundsDerivationPath.m +++ b/DashSync/shared/Models/Derivation Paths/DSFundsDerivationPath.m @@ -137,24 +137,22 @@ - (NSArray *)registerAddressesWithGapLimit:(NSUInteger)gapLimit internal:(BOOL)i if (!self.account.wallet.isTransient) { NSAssert(self.addressesLoaded, @"addresses must be loaded before calling this function"); } + @synchronized(self) { + NSMutableArray *a = [NSMutableArray arrayWithArray:(internal) ? self.internalAddresses : self.externalAddresses]; + NSUInteger i = a.count; + // keep only the trailing contiguous block of addresses with no transactions + while (i > 0 && ![self.usedAddresses containsObject:a[i - 1]]) { + i--; + } - NSMutableArray *a = [NSMutableArray arrayWithArray:(internal) ? self.internalAddresses : self.externalAddresses]; - NSUInteger i = a.count; - - // keep only the trailing contiguous block of addresses with no transactions - while (i > 0 && ![self.usedAddresses containsObject:a[i - 1]]) { - i--; - } - - if (i > 0) [a removeObjectsInRange:NSMakeRange(0, i)]; - if (a.count >= gapLimit) return [a subarrayWithRange:NSMakeRange(0, gapLimit)]; + if (i > 0) [a removeObjectsInRange:NSMakeRange(0, i)]; + if (a.count >= gapLimit) return [a subarrayWithRange:NSMakeRange(0, gapLimit)]; - if (gapLimit > 1) { // get receiveAddress and changeAddress first to avoid blocking - [self receiveAddress]; - [self changeAddress]; - } + if (gapLimit > 1) { // get receiveAddress and changeAddress first to avoid blocking + [self receiveAddress]; + [self changeAddress]; + } - @synchronized(self) { //It seems weird to repeat this, but it's correct because of the original call receive address and change address [a setArray:(internal) ? self.internalAddresses : self.externalAddresses]; i = a.count; From c2328266308ca6c701494992ff15fad0b83435ea Mon Sep 17 00:00:00 2001 From: pankcuf Date: Wed, 19 Jul 2023 16:05:41 +0700 Subject: [PATCH 4/6] fix: make mutable access to group operation errors thread-safe --- .../AdvancedOperations/Operations/DSGroupOperation.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DashSync/shared/Libraries/AdvancedOperations/Operations/DSGroupOperation.m b/DashSync/shared/Libraries/AdvancedOperations/Operations/DSGroupOperation.m index fe0c6fadf..bd8f1d384 100644 --- a/DashSync/shared/Libraries/AdvancedOperations/Operations/DSGroupOperation.m +++ b/DashSync/shared/Libraries/AdvancedOperations/Operations/DSGroupOperation.m @@ -92,7 +92,9 @@ - (void)operationQueue:(DSOperationQueue *)operationQueue willAddOperation:(NSOp } - (void)operationQueue:(DSOperationQueue *)operationQueue operationDidFinish:(NSOperation *)operation withErrors:(NSArray *)errors { - [self.aggregatedErrors addObjectsFromArray:errors]; + @synchronized(self.aggregatedErrors) { + [self.aggregatedErrors addObjectsFromArray:errors]; + } if (operation == self.finishingOperation) { self.internalQueue.suspended = YES; From f06a1815fe46c1c3d88c52abf4556cabf9cfeba7 Mon Sep 17 00:00:00 2001 From: pankcuf Date: Wed, 19 Jul 2023 16:42:16 +0700 Subject: [PATCH 5/6] fix: remove logs with useless thread unsafe stuff --- .../shared/Models/Managers/Chain Managers/DSPeerManager.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m b/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m index 19cac82e6..1b2de112d 100644 --- a/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m +++ b/DashSync/shared/Models/Managers/Chain Managers/DSPeerManager.m @@ -695,7 +695,7 @@ - (void)useMasternodeList:(DSMasternodeList *)masternodeList withConnectivityNon // MARK: - Connectivity - (void)connect { - DSLog(@"[DSPeerManager] connect (%d)", [self.connectedPeers count]); + DSLog(@"[DSPeerManager] connect"); self.desiredState = DSPeerManagerDesiredState_Connected; dispatch_async(self.networkingQueue, ^{ if ([self.chain syncsBlockchain] && ![self.chain canConstructAFilter]) return; // check to make sure the wallet has been created if only are a basic wallet with no dash features @@ -770,7 +770,6 @@ - (void)connect { } if (peers.count == 0) { - DSLog(@"[DSPeerManager] connect failed peers: (%d) connected: (%d) mutableConnected: (%d)", peers, self.connectedPeers, self.mutableConnectedPeers); [self chainSyncStopped]; dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = [NSError errorWithCode:1 localizedDescriptionKey:@"No peers found"]; @@ -995,8 +994,7 @@ - (void)peer:(DSPeer *)peer disconnectedWithError:(NSError *)error { [self.managedObjectContext deleteObject:obj]; } }]; - - DSLog(@"[DSPeerManager] disconnectedWithError: peers: (%d) connected: (%d) mutableConnected: (%d) connectFailures: (%d)", _peers, self.connectedPeers, self.mutableConnectedPeers, self.connectFailures); + DSLog(@"[DSPeerManager] disconnectedWithError: max connect failures exceeded"); @synchronized(self) { _peers = nil; } From 82ef6b62973704b8d49d43e628110a13e198d5f7 Mon Sep 17 00:00:00 2001 From: pankcuf Date: Wed, 19 Jul 2023 16:43:39 +0700 Subject: [PATCH 6/6] chore: remove boilerplate --- DashSync/shared/Models/Messages/DSPingRequest.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/DashSync/shared/Models/Messages/DSPingRequest.m b/DashSync/shared/Models/Messages/DSPingRequest.m index 0e8dff5f0..741d05f72 100644 --- a/DashSync/shared/Models/Messages/DSPingRequest.m +++ b/DashSync/shared/Models/Messages/DSPingRequest.m @@ -17,7 +17,7 @@ #import "DSPingRequest.h" #import "DSPeer.h" -#import "NSMutableData+Dash.h" +#import "NSData+Dash.h" @implementation DSPingRequest @@ -34,8 +34,6 @@ - (instancetype)initWithLocalNonce:(uint64_t)localNonce type:(NSString *)type { } - (NSData *)toData { - NSMutableData *msg = [NSMutableData data]; - [msg appendUInt64:self.localNonce]; - return msg; + return [NSData dataWithUInt64:self.localNonce]; } @end