-
Notifications
You must be signed in to change notification settings - Fork 15
fix: multithreading issue part 2 #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb9d4ff
11a0d08
2bbece5
d25ce51
2617c7a
1d5fce3
25994dd
24cb890
c471c4b
f244348
7086777
766046d
78316d2
fb194b4
0dd60c9
5ddc7db
e50aa01
e2c34f3
88e9145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,10 +346,8 @@ - (double)combinedSyncProgress { | |
| DSLog(@"combinedSyncProgress breakdown %f %f %f", self.terminalHeaderSyncProgress, self.masternodeManager.masternodeListAndQuorumsSyncProgress, self.chainSyncProgress); | ||
| #endif | ||
| if ((self.terminalHeaderSyncWeight + self.chainSyncWeight + self.masternodeListSyncWeight) == 0) { | ||
| if (self.peerManager.connected) { | ||
| return 1; | ||
| } else { | ||
| return 0; | ||
| @synchronized (self.peerManager) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pankcuf I don't think |
||
| return self.peerManager.connected ? 1 : 0; | ||
| } | ||
| } else { | ||
| double progress = self.terminalHeaderSyncProgress * self.terminalHeaderSyncWeight + self.masternodeManager.masternodeListAndQuorumsSyncProgress * self.masternodeListSyncWeight + self.chainSyncProgress * self.chainSyncWeight; | ||
|
|
@@ -471,11 +469,12 @@ - (void)startSync { | |
| object:nil | ||
| userInfo:@{DSChainManagerNotificationChainKey: self.chain}]; | ||
| }); | ||
| DSLog(@"startSync -> peerManager::connect"); | ||
| [self.peerManager connect]; | ||
| } | ||
|
|
||
| - (void)stopSync { | ||
| [self.peerManager disconnect]; | ||
| [self.peerManager disconnect:DSDisconnectReason_ChainSwitch]; | ||
| self.syncPhase = DSChainSyncPhase_Offline; | ||
| } | ||
|
|
||
|
|
@@ -497,6 +496,7 @@ - (void)disconnectedMasternodeListAndBlocksRescan { | |
| object:nil | ||
| userInfo:@{DSChainManagerNotificationChainKey: self.chain}]; | ||
| }); | ||
| DSLog(@"disconnectedMasternodeListAndBlocksRescan -> peerManager::connect"); | ||
| [self.peerManager connect]; | ||
| } | ||
|
|
||
|
|
@@ -510,6 +510,7 @@ - (void)disconnectedMasternodeListRescan { | |
| object:nil | ||
| userInfo:@{DSChainManagerNotificationChainKey: self.chain}]; | ||
| }); | ||
| DSLog(@"disconnectedMasternodeListRescan -> peerManager::connect"); | ||
| [self.peerManager connect]; | ||
| } | ||
|
|
||
|
|
@@ -523,6 +524,7 @@ - (void)disconnectedSyncBlocksRescan { | |
| object:nil | ||
| userInfo:@{DSChainManagerNotificationChainKey: self.chain}]; | ||
| }); | ||
| DSLog(@"disconnectedSyncBlocksRescan -> peerManager::connect"); | ||
| [self.peerManager connect]; | ||
| } | ||
|
|
||
|
|
@@ -650,7 +652,8 @@ - (void)chainShouldStartSyncingBlockchain:(DSChain *)chain onPeer:(DSPeer *)peer | |
| } | ||
|
|
||
| - (void)chainFinishedSyncingInitialHeaders:(DSChain *)chain fromPeer:(DSPeer *)peer onMainChain:(BOOL)onMainChain { | ||
| if (onMainChain && peer && (peer == self.peerManager.downloadPeer)) self.lastChainRelayTime = [NSDate timeIntervalSince1970]; | ||
| if (onMainChain && peer && (peer == self.peerManager.downloadPeer)) [self relayedNewItem]; | ||
|
|
||
| [self.peerManager chainSyncStopped]; | ||
| if (([[DSOptionsManager sharedInstance] syncType] & DSSyncType_MasternodeList)) { | ||
| // make sure we care about masternode lists | ||
|
|
@@ -659,7 +662,7 @@ - (void)chainFinishedSyncingInitialHeaders:(DSChain *)chain fromPeer:(DSPeer *)p | |
| } | ||
|
|
||
| - (void)chainFinishedSyncingTransactionsAndBlocks:(DSChain *)chain fromPeer:(DSPeer *)peer onMainChain:(BOOL)onMainChain { | ||
| if (onMainChain && peer && (peer == self.peerManager.downloadPeer)) self.lastChainRelayTime = [NSDate timeIntervalSince1970]; | ||
| if (onMainChain && peer && (peer == self.peerManager.downloadPeer)) [self relayedNewItem]; | ||
| DSLog(@"chain finished syncing"); | ||
| self.chainSyncStartHeight = 0; | ||
| self.syncPhase = DSChainSyncPhase_Synced; | ||
|
|
@@ -678,6 +681,7 @@ - (void)syncBlockchain { | |
| if (self.syncPhase == DSChainSyncPhase_InitialTerminalBlocks) { | ||
| self.syncPhase = DSChainSyncPhase_ChainSync; | ||
| } | ||
| DSLog(@"syncBlockchain -> peerManager::connect"); | ||
| [self.peerManager connect]; | ||
| } else if (!self.peerManager.masternodeList && self.masternodeManager.currentMasternodeList) { | ||
| [self.peerManager useMasternodeList:self.masternodeManager.currentMasternodeList withConnectivityNonce:self.sessionConnectivityNonce]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,13 +184,15 @@ - (uint32_t)estimatedMasternodeListsToSync { | |
| } | ||
|
|
||
| - (double)masternodeListAndQuorumsSyncProgress { | ||
| double amountLeft = self.masternodeListRetrievalQueueCount; | ||
| double maxAmount = self.masternodeListRetrievalQueueMaxAmount; | ||
| if (!amountLeft) { | ||
| return self.store.masternodeListsAndQuorumsIsSynced; | ||
| @synchronized (self) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pankcuf I don't think |
||
| double amountLeft = self.masternodeListRetrievalQueueCount; | ||
| double maxAmount = self.masternodeListRetrievalQueueMaxAmount; | ||
| if (!amountLeft) { | ||
| return self.store.masternodeListsAndQuorumsIsSynced; | ||
| } | ||
| double progress = MAX(MIN((maxAmount - amountLeft) / maxAmount, 1), 0); | ||
| return progress; | ||
| } | ||
| double progress = MAX(MIN((maxAmount - amountLeft) / maxAmount, 1), 0); | ||
| return progress; | ||
| } | ||
|
|
||
| - (BOOL)currentMasternodeListIsInLast24Hours { | ||
|
|
@@ -361,7 +363,9 @@ - (BOOL)requestMasternodeListForBlockHeight:(uint32_t)blockHeight error:(NSError | |
| - (BOOL)requestMasternodeListForBlockHash:(UInt256)blockHash { | ||
| self.store.lastQueriedBlockHash = blockHash; | ||
| NSData *blockHashData = uint256_data(blockHash); | ||
| [self.store.masternodeListQueriesNeedingQuorumsValidated addObject:blockHashData]; | ||
| @synchronized (self.store.masternodeListQueriesNeedingQuorumsValidated) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pankcuf I don't think @synchronized is a real solution, I personally against using @synchronized because it can lead performance decreasing and other "unknowns" |
||
| [self.store.masternodeListQueriesNeedingQuorumsValidated addObject:blockHashData]; | ||
| } | ||
| // this is safe | ||
| [self getMasternodeListsForBlockHashes:[NSOrderedSet orderedSetWithObject:blockHashData]]; | ||
| return TRUE; | ||
|
|
@@ -501,14 +505,21 @@ - (void)processMasternodeListDiffResult:(DSMnDiffProcessingResult *)result forPe | |
| DSLog(@"•••• processMasternodeListDiffResult: missingMasternodeLists: %@", [self logListSet:neededMissingMasternodeLists]); | ||
| UInt256 masternodeListBlockHash = masternodeList.blockHash; | ||
| NSData *masternodeListBlockHashData = uint256_data(masternodeListBlockHash); | ||
| if ([neededMissingMasternodeLists count] && [self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:masternodeListBlockHashData]) { | ||
| BOOL hasAwaitingQuorumValidation; | ||
| @synchronized (self.store.masternodeListQueriesNeedingQuorumsValidated) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pankcuf I don't think @synchronized is a real solution, I personally against using @synchronized because it can lead performance decreasing and other "unknowns" |
||
| hasAwaitingQuorumValidation = [self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:masternodeListBlockHashData]; | ||
| } | ||
|
|
||
| if ([neededMissingMasternodeLists count] && hasAwaitingQuorumValidation) { | ||
| [self.masternodeListDiffService removeFromRetrievalQueue:masternodeListBlockHashData]; | ||
| [self processMissingMasternodeLists:neededMissingMasternodeLists forMasternodeList:masternodeList]; | ||
| completion(); | ||
| } else { | ||
| if (uint256_eq(self.store.lastQueriedBlockHash, masternodeListBlockHash)) { | ||
| self.masternodeListDiffService.currentMasternodeList = masternodeList; | ||
| [self.store.masternodeListQueriesNeedingQuorumsValidated removeObject:masternodeListBlockHashData]; | ||
| @synchronized (self.store.masternodeListQueriesNeedingQuorumsValidated) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pankcuf I don't think @synchronized is a real solution, I personally against using @synchronized because it can lead performance decreasing and other "unknowns" |
||
| [self.store.masternodeListQueriesNeedingQuorumsValidated removeObject:masternodeListBlockHashData]; | ||
| } | ||
| } | ||
| DSLog(@"••• updateStoreWithMasternodeList: %u: %@ (%@)", masternodeList.height, uint256_hex(masternodeListBlockHash), uint256_reverse_hex(masternodeListBlockHash)); | ||
| [self updateStoreWithMasternodeList:masternodeList addedMasternodes:result.addedMasternodes modifiedMasternodes:result.modifiedMasternodes addedQuorums:result.addedQuorums completion:^(NSError *error) { | ||
|
|
@@ -579,47 +590,53 @@ - (void)processQRInfoResult:(DSQRInfoProcessingResult *)result forPeer:(DSPeer * | |
| NSData *blockHashDataAtH2C = uint256_data(blockHashAtH2C); | ||
| NSData *blockHashDataAtH3C = uint256_data(blockHashAtH3C); | ||
| NSData *blockHashDataAtH4C = uint256_data(blockHashAtH4C); | ||
| NSMutableSet<NSData *> *masternodeListQueriesNeedingQuorumsValidated; | ||
| @synchronized (self.store.masternodeListQueriesNeedingQuorumsValidated) { | ||
| masternodeListQueriesNeedingQuorumsValidated = self.store.masternodeListQueriesNeedingQuorumsValidated; | ||
| } | ||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtH4C skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![missingMasternodeListsAtH4C count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH4C]) { | ||
| } else if (![missingMasternodeListsAtH4C count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH4C]) { | ||
| DSLog(@"••• updateStoreWithMasternodeList (h-4c): %u: %@ (%@)", masternodeListAtH4C.height, uint256_hex(blockHashAtH4C), uint256_reverse_hex(blockHashAtH4C)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtH4C addedMasternodes:mnListDiffResultAtH4C.addedMasternodes modifiedMasternodes:mnListDiffResultAtH4C.modifiedMasternodes addedQuorums:mnListDiffResultAtH4C.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtH3C skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![missingMasternodeListsAtH3C count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH3C]) { | ||
| } else if (![missingMasternodeListsAtH3C count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH3C]) { | ||
| DSLog(@"••• updateStoreWithMasternodeList (h-3c): %u: %@ (%@)", masternodeListAtH3C.height, uint256_hex(blockHashAtH3C), uint256_reverse_hex(blockHashAtH3C)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtH3C addedMasternodes:mnListDiffResultAtH3C.addedMasternodes modifiedMasternodes:mnListDiffResultAtH3C.modifiedMasternodes addedQuorums:mnListDiffResultAtH3C.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtH2C skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![missingMasternodeListsAtH2C count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH2C]) { | ||
| } else if (![missingMasternodeListsAtH2C count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH2C]) { | ||
| DSLog(@"••• updateStoreWithMasternodeList (h-2c): %u: %@ (%@)", masternodeListAtH2C.height, uint256_hex(blockHashAtH2C), uint256_reverse_hex(blockHashAtH2C)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtH2C addedMasternodes:mnListDiffResultAtH2C.addedMasternodes modifiedMasternodes:mnListDiffResultAtH2C.modifiedMasternodes addedQuorums:mnListDiffResultAtH2C.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtHC skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![missingMasternodeListsAtHC count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtHC]) { | ||
| } else if (![missingMasternodeListsAtHC count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtHC]) { | ||
| DSLog(@"••• updateStoreWithMasternodeList (h-c): %u: %@ (%@)", masternodeListAtHC.height, uint256_hex(blockHashAtHC), uint256_reverse_hex(blockHashAtHC)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtHC addedMasternodes:mnListDiffResultAtHC.addedMasternodes modifiedMasternodes:mnListDiffResultAtHC.modifiedMasternodes addedQuorums:mnListDiffResultAtHC.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtH skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![missingMasternodeListsAtH count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH]) { | ||
| } else if (![missingMasternodeListsAtH count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtH]) { | ||
| DSLog(@"••• updateStoreWithMasternodeList (h): %u: %@ (%@)", masternodeListAtH.height, uint256_hex(blockHashAtH), uint256_reverse_hex(blockHashAtH)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtH addedMasternodes:mnListDiffResultAtH.addedMasternodes modifiedMasternodes:mnListDiffResultAtH.modifiedMasternodes addedQuorums:mnListDiffResultAtH.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
|
|
||
| if (![self.quorumRotationService shouldProcessDiffResult:mnListDiffResultAtTip skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else { | ||
| if ([missingMasternodeListsAtTip count] && [self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtTip]) { | ||
| if ([missingMasternodeListsAtTip count] && [masternodeListQueriesNeedingQuorumsValidated containsObject:blockHashDataAtTip]) { | ||
| [self.quorumRotationService removeFromRetrievalQueue:blockHashDataAtTip]; | ||
| [self processMissingMasternodeLists:missingMasternodeLists forMasternodeList:masternodeListAtTip]; | ||
| } else { | ||
| if (uint256_eq(self.store.lastQueriedBlockHash, blockHashAtTip)) { | ||
| self.quorumRotationService.currentMasternodeList = masternodeListAtTip; | ||
| [self.store.masternodeListQueriesNeedingQuorumsValidated removeObject:blockHashDataAtTip]; | ||
| @synchronized (self.store.masternodeListQueriesNeedingQuorumsValidated) { | ||
| [self.store.masternodeListQueriesNeedingQuorumsValidated removeObject:blockHashDataAtTip]; | ||
| } | ||
| } | ||
| DSLog(@"••• updateStoreWithMasternodeList (tip): %u: %@ (%@)", masternodeListAtTip.height, uint256_hex(blockHashAtTip), uint256_reverse_hex(blockHashAtTip)); | ||
| [self updateStoreWithMasternodeList:masternodeListAtTip addedMasternodes:mnListDiffResultAtTip.addedMasternodes modifiedMasternodes:mnListDiffResultAtTip.modifiedMasternodes addedQuorums:mnListDiffResultAtTip.addedQuorums completion:^(NSError *error) {}]; | ||
|
|
@@ -639,7 +656,7 @@ - (void)processQRInfoResult:(DSQRInfoProcessingResult *)result forPeer:(DSPeer * | |
| NSData *diffBlockHashData = uint256_data(diffBlockHash); | ||
| if (![self.quorumRotationService shouldProcessDiffResult:diffResult skipPresenceInRetrieval:YES]) { | ||
| [self.quorumRotationService issueWithMasternodeListFromPeer:peer]; | ||
| } else if (![diffResult.neededMissingMasternodeLists count] || ![self.store.masternodeListQueriesNeedingQuorumsValidated containsObject:diffBlockHashData]) { | ||
| } else if (![diffResult.neededMissingMasternodeLists count] || ![masternodeListQueriesNeedingQuorumsValidated containsObject:diffBlockHashData]) { | ||
| [self updateStoreWithMasternodeList:diffMasternodeList addedMasternodes:diffResult.addedMasternodes modifiedMasternodes:diffResult.modifiedMasternodes addedQuorums:diffResult.addedQuorums completion:^(NSError *error) {}]; | ||
| } | ||
| } | ||
|
|
@@ -684,7 +701,9 @@ - (void)updateStoreWithMasternodeList:(DSMasternodeList *)masternodeList addedMa | |
|
|
||
| - (void)peer:(DSPeer *)peer relayedMasternodeDiffMessage:(NSData *)message { | ||
| DSLog(@"•••• -> received mnlistdiff: %@", uint256_hex(message.SHA256)); | ||
| self.masternodeListDiffService.timedOutAttempt = 0; | ||
| @synchronized (self.masternodeListDiffService) { | ||
| self.masternodeListDiffService.timedOutAttempt = 0; | ||
| } | ||
| dispatch_async(self.processingQueue, ^{ | ||
| dispatch_group_enter(self.processingGroup); | ||
| DSMasternodeProcessorContext *ctx = [self createDiffMessageContext:self.chain.isTestnet isFromSnapshot:NO isDIP0024:NO peer:peer merkleRootLookup:^UInt256(UInt256 blockHash) { | ||
|
|
@@ -719,7 +738,9 @@ - (void)peer:(DSPeer *)peer relayedMasternodeDiffMessage:(NSData *)message { | |
|
|
||
| - (void)peer:(DSPeer *)peer relayedQuorumRotationInfoMessage:(NSData *)message { | ||
| DSLog(@"•••• -> received qrinfo: %@", uint256_hex(message.SHA256)); | ||
| self.quorumRotationService.timedOutAttempt = 0; | ||
| @synchronized (self.quorumRotationService) { | ||
| self.quorumRotationService.timedOutAttempt = 0; | ||
| } | ||
| dispatch_async(self.processingQueue, ^{ | ||
| dispatch_group_enter(self.processingGroup); | ||
| MerkleRootFinder merkleRootLookup = ^UInt256(UInt256 blockHash) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pankcuf Why commented?