Skip to content

Commit

Permalink
chore: refine progress
Browse files Browse the repository at this point in the history
  • Loading branch information
pankcuf committed Jul 12, 2024
1 parent 3a6b246 commit 7515954
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions DashSync/shared/Models/Notifications/DSSyncState.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ typedef NS_ENUM(uint16_t, DSSyncStateKind) {

@interface DSMasternodeListSyncState : NSObject <NSCopying>

@property (nonatomic, assign) double retrievalQueueCount;
@property (nonatomic, assign) double retrievalQueueMaxAmount;
@property (nonatomic, assign) uint32_t retrievalQueueCount;
@property (nonatomic, assign) uint32_t retrievalQueueMaxAmount;
@property (nonatomic, assign) double storedCount;
@property (nonatomic, assign) uint32_t lastBlockHeight;

Expand Down
36 changes: 18 additions & 18 deletions DashSync/shared/Models/Notifications/DSSyncState.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (id)copyWithZone:(NSZone *)zone {
return copy;
}
- (NSString *)description {
return [NSString stringWithFormat:@"%f/%f/%f/%u",
return [NSString stringWithFormat:@"%u/%u/%u/%u",
self.retrievalQueueCount,
self.retrievalQueueMaxAmount,
self.storedCount,
Expand Down Expand Up @@ -60,7 +60,7 @@ - (id)copyWithZone:(NSZone *)zone {
}

- (NSString *)description {
return [NSString stringWithFormat:@"SyncState: { phase: %u, peer: %u, connected: %u, estimated: %u, chain: [%u/%u/%f] headers: [%u/%u/%f], mn: [%@/%f/%f] == %f",
return [NSString stringWithFormat:@"SyncState: { phase: %u, peer: %u, connected: %u, estimated: %u, chain: [%u/%u/%f] headers: [%u/%u/%f], mn: [%@/%u/%f] == %f",
self.syncPhase,
self.hasDownloadPeer,
self.peerManagerConnected,
Expand All @@ -72,24 +72,24 @@ - (NSString *)description {
self.lastTerminalBlockHeight,
self.terminalHeaderSyncProgress,
self.masternodeListSyncInfo,
self.masternodeListProgress,
self.masternodeListsToSync,
self.masternodeListProgress,
self.combinedSyncProgress
];
}

- (double)masternodeListProgress {
double amountLeft = self.masternodeListSyncInfo.retrievalQueueCount;
double maxAmount = self.masternodeListSyncInfo.retrievalQueueMaxAmount;
double lastBlockHeight = self.masternodeListSyncInfo.lastBlockHeight;
double estimatedBlockHeight = self.estimatedBlockHeight;
uint32_t amountLeft = self.masternodeListSyncInfo.retrievalQueueCount;
uint32_t maxAmount = self.masternodeListSyncInfo.retrievalQueueMaxAmount;
uint32_t lastBlockHeight = self.masternodeListSyncInfo.lastBlockHeight;
uint32_t estimatedBlockHeight = self.estimatedBlockHeight;
return amountLeft ? MAX(MIN((maxAmount - amountLeft) / maxAmount, 1), 0) : lastBlockHeight != UINT32_MAX && estimatedBlockHeight != 0 && lastBlockHeight + 16 >= estimatedBlockHeight;
}

- (double)chainSyncProgress {
double chainSyncStartHeight = self.chainSyncStartHeight;
double lastSyncBlockHeight = self.lastSyncBlockHeight;
double estimatedBlockHeight = self.estimatedBlockHeight;
uint32_t chainSyncStartHeight = self.chainSyncStartHeight;
uint32_t lastSyncBlockHeight = self.lastSyncBlockHeight;
uint32_t estimatedBlockHeight = self.estimatedBlockHeight;
if (!self.hasDownloadPeer && chainSyncStartHeight == 0)
return 0.0;
else if (lastSyncBlockHeight >= estimatedBlockHeight)
Expand All @@ -103,9 +103,9 @@ - (double)chainSyncProgress {
}

- (double)terminalHeaderSyncProgress {
double terminalSyncStartHeight = self.terminalSyncStartHeight;
double lastTerminalBlockHeight = self.lastTerminalBlockHeight;
double estimatedBlockHeight = self.estimatedBlockHeight;
uint32_t terminalSyncStartHeight = self.terminalSyncStartHeight;
uint32_t lastTerminalBlockHeight = self.lastTerminalBlockHeight;
uint32_t estimatedBlockHeight = self.estimatedBlockHeight;
if (!self.hasDownloadPeer && terminalSyncStartHeight == 0)
return 0.0;
else if (lastTerminalBlockHeight >= estimatedBlockHeight)
Expand All @@ -114,13 +114,13 @@ - (double)terminalHeaderSyncProgress {
return MIN(1.0, MAX(0.0, 0.1 + 0.9 * (terminalSyncStartHeight > lastTerminalBlockHeight ? lastTerminalBlockHeight / estimatedBlockHeight : (lastTerminalBlockHeight - terminalSyncStartHeight) / (estimatedBlockHeight - terminalSyncStartHeight))));
}

- (double)masternodeListsToSync {
- (uint32_t)masternodeListsToSync {
uint32_t estimatedBlockHeight = self.estimatedBlockHeight;
double amountLeft = self.masternodeListSyncInfo.retrievalQueueCount;
uint32_t amountLeft = self.masternodeListSyncInfo.retrievalQueueCount;
uint32_t lastMasternodeListHeight = self.masternodeListSyncInfo.lastBlockHeight;
double maxAmount = self.masternodeListSyncInfo.retrievalQueueMaxAmount;
uint32_t maxAmount = self.masternodeListSyncInfo.retrievalQueueMaxAmount;
uint32_t storedCount = self.masternodeListSyncInfo.storedCount;
uint32_t masternodeListsToSync;
uint32_t masternodeListsToSync;
if (!([[DSOptionsManager sharedInstance] syncType] & DSSyncType_MasternodeList))
masternodeListsToSync = 0;
else if (!maxAmount || storedCount <= 1) // 1 because there might be a default
Expand All @@ -144,7 +144,7 @@ - (double)combinedSyncProgress {
uint32_t lastSyncBlockHeight = self.lastSyncBlockHeight;
double chainWeight = lastSyncBlockHeight >= estimatedBlockHeight ? 0 : estimatedBlockHeight - lastSyncBlockHeight;
double terminalWeight = lastTerminalBlockHeight >= estimatedBlockHeight ? 0 : (estimatedBlockHeight - lastTerminalBlockHeight) / 4;
double listsToSync = [self masternodeListsToSync];
uint32_t listsToSync = [self masternodeListsToSync];
double masternodeWeight = listsToSync ? (20000 + 2000 * (listsToSync - 1)) : 0;
double totalWeight = chainWeight + terminalWeight + masternodeWeight;
if (totalWeight == 0) {
Expand Down

0 comments on commit 7515954

Please sign in to comment.