Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DashSync.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Pod::Spec.new do |s|
s.ios.framework = 'UIKit'
s.macos.framework = 'Cocoa'
s.compiler_flags = '-Wno-comma'
s.dependency 'DashSharedCore', '0.4.0'
s.dependency 'DashSharedCore', '0.4.5'
s.dependency 'CocoaLumberjack', '3.7.2'
s.ios.dependency 'DWAlertController', '0.2.1'
s.dependency 'DSDynamicOptions', '0.1.2'
Expand Down
Binary file removed DashSync/shared/MasternodeLists/MNT530000.dat
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions DashSync/shared/Models/Chain/DSChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ typedef NS_ENUM(uint16_t, DSChainSyncPhase)
- (BOOL)isDevnetAny;
- (BOOL)isEvolutionEnabled;
- (BOOL)isDevnetWithGenesisHash:(UInt256)genesisHash;
- (BOOL)isCore19Active;
- (KeyKind)getActiveBLSType;

@end

@protocol DSChainTransactionsDelegate
Expand Down
8 changes: 8 additions & 0 deletions DashSync/shared/Models/Chain/DSChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ - (void)setUp {

// MARK: - Helpers

- (BOOL)isCore19Active {
return self.lastTerminalBlockHeight >= chain_core19_activation_height(self.chainType);
}

- (KeyKind)getActiveBLSType {
Comment thread
pankcuf marked this conversation as resolved.
return [self isCore19Active] ? KeyKind_BLSBasic : KeyKind_BLS;
}

- (NSDictionary<NSValue *, DSBlock *> *)syncBlocks {
return [self.mSyncBlocks copy];
}
Expand Down
8 changes: 4 additions & 4 deletions DashSync/shared/Models/Chain/DSChainCheckpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static checkpoint testnet_checkpoint_array[] = {
{370368, "000001702422af778c9d1e16a891f58fbaabb6ff82dea8fc1910ab80552bdf9c", 1598642620, 0x1e02336eu, "", "717beedaa6da0d5c1124b9d0788d040ca18eb1fe6ed49c126ea9a2d30d11921c", "00000000000000000000000000000000000000000000000002239b4ac0e84dc4"}, //for tests
{414106, "00000674c5269b59d6d3bb6bb08b58add4b3e0eab11136be47bb8e0d4ec86e69", 1609043444, 0x1e0dd96eu, "", "e8c45fabdb650ac2c42105083cb63998142e18be89b61bd034b3714498e6622f", "000000000000000000000000000000000000000000000000022f14058d3b2efc"}, //fork height
{480000, "000001210c081f763d18db332b38ec1ac14fac62170a0d1a2028cabe8cecc799", 1618235036, 0x1e01eec7u, "", "d9fae96cce9bf0edcf9ece1b7894e0356165c0a5dcdc6f2e0784461c4168cbec", "000000000000000000000000000000000000000000000000022f14bf215f8016"},
// {530000, "0000060db4b6bdb17f0617d15637bdf0f18ad738ccb438ee2cd000fef11c7130", 1625277934, 0x1e0fffffu, "MNT530000", "7a6a78a22df2d9dc8c44afd48dfe4a60f75428f5e6004cf4cdf82e4f81a0a68b", "000000000000000000000000000000000000000000000000022f1524ad0dacd3"},
// {760000, "000000b80d3010bb62b309aec9a7dd748777cc5e2640a26b1981cb3c61c66211", 1657592023, 0x1e01f865u, "", "8302c05bdca60e7dfcac26cebea8d797bda1b87111cf3a3dc33050c43f2abfbe", "000000000000000000000000000000000000000000000000027baba1fe003e84"},
{530000, "0000060db4b6bdb17f0617d15637bdf0f18ad738ccb438ee2cd000fef11c7130", 1625277934, 0x1e0fffffu, "MNT530000__70228", "7a6a78a22df2d9dc8c44afd48dfe4a60f75428f5e6004cf4cdf82e4f81a0a68b", "000000000000000000000000000000000000000000000000022f1524ad0dacd3"},
{760000, "000000b80d3010bb62b309aec9a7dd748777cc5e2640a26b1981cb3c61c66211", 1657592023, 0x1e01f865u, "", "8302c05bdca60e7dfcac26cebea8d797bda1b87111cf3a3dc33050c43f2abfbe", "000000000000000000000000000000000000000000000000027baba1fe003e84"},
};

// blockchain checkpoints - these are also used as starting points for partial chain downloads, so they need to be at
Expand Down Expand Up @@ -83,7 +83,7 @@ static checkpoint mainnet_checkpoint_array[] = {
{1060000, "00000000000000132447e6bac9fe0d7d756851450eab29358787dc05d809bf07", 1556260812, 0x191f6aceu, "", "", "000000000000000000000000000000000000000000001392c164c11ca344daec"},
{1080000, "00000000000000099c5cc38bac7878f771408537e520a1ef9e31b5c1040d2d2a", 1559412342, 0x192a9588u, "", "", "0000000000000000000000000000000000000000000015a7e09c202c817e33d8"},
{1088640, "00000000000000112e41e4b3afda8b233b8cc07c532d2eac5de097b68358c43e", 1560773201, 0x1922ae0bu, "", "379fd491044a273372a8e901866fbe6ed9bab7ce2de0968a71d38de5d5eac340", "0000000000000000000000000000000000000000000016a12b2d3216341ba998"},
// {1088640, "00000000000000112e41e4b3afda8b233b8cc07c532d2eac5de097b68358c43e", 1560773201, 0x1922ae0bu, "ML1088640", "379fd491044a273372a8e901866fbe6ed9bab7ce2de0968a71d38de5d5eac340", "0000000000000000000000000000000000000000000016a12b2d3216341ba998"},
{1088640, "00000000000000112e41e4b3afda8b233b8cc07c532d2eac5de097b68358c43e", 1560773201, 0x1922ae0bu, "ML1088640__70218", "379fd491044a273372a8e901866fbe6ed9bab7ce2de0968a71d38de5d5eac340", "0000000000000000000000000000000000000000000016a12b2d3216341ba998"},
{1100000, "00000000000000190560ed4b128c156e489fdbe0814bf62c8ab53ab3259d7908", 1562561033, 0x191a9f05u, "", "", "0000000000000000000000000000000000000000000017ffbd499dd0911202a4"},
{1120000, "0000000000000011103eae768e6a322b991c5c20569d95930b87e1305fa19c75", 1565712301, 0x19200768u, "", "", "000000000000000000000000000000000000000000001a7cca810db5e54e95ca"},
{1140000, "00000000000000083ac0e592e180487cb237f659a305d2be19e883ed564fe20f", 1568864488, 0x1923198bu, "", "", "000000000000000000000000000000000000000000001ccf1b2b6718aad9bb8d"},
Expand Down Expand Up @@ -115,5 +115,5 @@ static checkpoint mainnet_checkpoint_array[] = {
{1680000, "000000000000001d4107019248ea733abc4fd02b31db202f6bfd38f8848c7100", 1653989911, 0x192af7edu, "", "dd516ade3a5b599a6989a36e137be9e14f0fd77dad036c6c0748bfbbd73d9805", "0000000000000000000000000000000000000000000073575a368d41c4d9641c"},
{1700000, "000000000000001d7579a371e782fd9c4480f626a62b916fa4eb97e16a49043a", 1657142113, 0x1927e30eu, "", "dafe57cefc3bc265dfe8416e2f2e3a22af268fd587a48f36affd404bec738305", "000000000000000000000000000000000000000000007562df93a26b81386288"},
{1720000, "000000000000001ef1f8a3d33bbe304c1d12f59f2c8aa989099dc215fd10903e", 1660295895, 0x19362176u, "", "67c6348c35bc42aa4cabd25e29560f5d22c6a9fba274bf0c52fe73021d0e8d5e", "000000000000000000000000000000000000000000007715a9ae4dd7ff1d3902"},
// {1720000, "000000000000001ef1f8a3d33bbe304c1d12f59f2c8aa989099dc215fd10903e", 1660295895, 0x19362176u, "ML1720000", "67c6348c35bc42aa4cabd25e29560f5d22c6a9fba274bf0c52fe73021d0e8d5e", "000000000000000000000000000000000000000000007715a9ae4dd7ff1d3902"},
{1720000, "000000000000001ef1f8a3d33bbe304c1d12f59f2c8aa989099dc215fd10903e", 1660295895, 0x19362176u, "ML1720000__70218", "67c6348c35bc42aa4cabd25e29560f5d22c6a9fba274bf0c52fe73021d0e8d5e", "000000000000000000000000000000000000000000007715a9ae4dd7ff1d3902"},
};
18 changes: 10 additions & 8 deletions DashSync/shared/Models/Chain/DSChainConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#define TESTNET_DAPI_GRPC_STANDARD_PORT 3010
#define DEVNET_DAPI_GRPC_STANDARD_PORT 3010

#define PROTOCOL_VERSION_MAINNET 70227
#define DEFAULT_MIN_PROTOCOL_VERSION_MAINNET 70224
#define PROTOCOL_VERSION_MAINNET 70228
#define DEFAULT_MIN_PROTOCOL_VERSION_MAINNET 70228

#define PROTOCOL_VERSION_TESTNET 70227
#define DEFAULT_MIN_PROTOCOL_VERSION_TESTNET 70224
#define PROTOCOL_VERSION_TESTNET 70228
#define DEFAULT_MIN_PROTOCOL_VERSION_TESTNET 70228

#define PROTOCOL_VERSION_DEVNET 70227
#define DEFAULT_MIN_PROTOCOL_VERSION_DEVNET 70224
#define PROTOCOL_VERSION_DEVNET 70228
#define DEFAULT_MIN_PROTOCOL_VERSION_DEVNET 70228

#define PLATFORM_PROTOCOL_VERSION_MAINNET 1
#define DEFAULT_MIN_PLATFORM_PROTOCOL_VERSION_MAINNET 1
Expand All @@ -49,8 +49,10 @@
#define PLATFORM_PROTOCOL_VERSION_DEVNET 1
#define DEFAULT_MIN_PLATFORM_PROTOCOL_VERSION_DEVNET 1

#define MAX_VALID_MIN_PROTOCOL_VERSION 70227
#define MIN_VALID_MIN_PROTOCOL_VERSION 70224
#define DEFAULT_CHECKPOINT_PROTOCOL_VERSION 70218

#define MAX_VALID_MIN_PROTOCOL_VERSION 70228
#define MIN_VALID_MIN_PROTOCOL_VERSION 70228

#define MAX_TARGET_PROOF_OF_WORK_MAINNET 0x1e0fffffu // highest value for difficulty target (higher values are less difficult)
#define MAX_TARGET_PROOF_OF_WORK_TESTNET 0x1e0fffffu
Expand Down
1 change: 1 addition & 0 deletions DashSync/shared/Models/Chain/DSCheckpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef NS_ENUM(uint8_t, DSCheckpointOptions)
@property (nonatomic, readonly) uint32_t timestamp;
@property (nonatomic, readonly) uint32_t target;
@property (nonatomic, readonly) NSString *masternodeListName;
@property (nonatomic, readonly) uint32_t protocolVersion;
@property (nonatomic, readonly) UInt256 merkleRoot;
@property (nonatomic, readonly) UInt256 chainWork;

Expand Down
23 changes: 23 additions & 0 deletions DashSync/shared/Models/Chain/DSCheckpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ - (uint8_t)parameters {
return parameters;
}

// This is the old protocol version used for creating checkpoints
// Now when storing list diff we add version at the end of masternode list name like this: MNT530000__70228
- (uint32_t)protocolVersion {
uint32_t protocolVersion = DEFAULT_CHECKPOINT_PROTOCOL_VERSION;
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"__(\\d+)"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSTextCheckingResult *match = [regex
firstMatchInString:self.masternodeListName
options:0
range:NSMakeRange(0, [self.masternodeListName length])];
if (match) {
NSString *numberString = [self.masternodeListName substringWithRange:[match rangeAtIndex:1]];
if (numberString) {
protocolVersion = (uint32_t)[numberString integerValue];
}
}
return protocolVersion;
}


- (NSData *)serialize {
NSMutableData *mData = [NSMutableData data];
[mData appendUInt8:[self parameters]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ + (instancetype)providerOwnerKeysDerivationPathForChain:(DSChain *)chain {
+ (instancetype)providerOperatorKeysDerivationPathForChain:(DSChain *)chain {
UInt256 indexes[] = {uint256_from_long(FEATURE_PURPOSE), uint256_from_long(chain_coin_type(chain.chainType)), uint256_from_long(3), uint256_from_long(3)};
BOOL hardenedIndexes[] = {YES, YES, YES, YES};
return [DSAuthenticationKeysDerivationPath derivationPathWithIndexes:indexes hardened:hardenedIndexes length:4 type:DSDerivationPathType_SingleUserAuthentication signingAlgorithm:KeyKind_BLS reference:DSDerivationPathReference_ProviderOperatorKeys onChain:chain];
return [DSAuthenticationKeysDerivationPath derivationPathWithIndexes:indexes hardened:hardenedIndexes length:4 type:DSDerivationPathType_SingleUserAuthentication signingAlgorithm:[chain getActiveBLSType] reference:DSDerivationPathReference_ProviderOperatorKeys onChain:chain];
}

+ (instancetype)platformNodeKeysDerivationPathForChain:(DSChain *)chain {
Expand All @@ -107,7 +107,7 @@ + (instancetype)blockchainIdentityECDSAKeysDerivationPathForChain:(DSChain *)cha
+ (instancetype)blockchainIdentityBLSKeysDerivationPathForChain:(DSChain *)chain {
UInt256 indexes[] = {uint256_from_long(FEATURE_PURPOSE), uint256_from_long(chain_coin_type(chain.chainType)), uint256_from_long(FEATURE_PURPOSE_IDENTITIES), uint256_from_long(FEATURE_PURPOSE_IDENTITIES_SUBFEATURE_AUTHENTICATION), uint256_from_long(1)};
BOOL hardenedIndexes[] = {YES, YES, YES, YES, YES};
DSAuthenticationKeysDerivationPath *blockchainIdentityBLSKeysDerivationPath = [DSAuthenticationKeysDerivationPath derivationPathWithIndexes:indexes hardened:hardenedIndexes length:5 type:DSDerivationPathType_MultipleUserAuthentication signingAlgorithm:KeyKind_BLS reference:DSDerivationPathReference_BlockchainIdentities onChain:chain];
DSAuthenticationKeysDerivationPath *blockchainIdentityBLSKeysDerivationPath = [DSAuthenticationKeysDerivationPath derivationPathWithIndexes:indexes hardened:hardenedIndexes length:5 type:DSDerivationPathType_MultipleUserAuthentication signingAlgorithm:[chain getActiveBLSType] reference:DSDerivationPathReference_BlockchainIdentities onChain:chain];
blockchainIdentityBLSKeysDerivationPath.shouldStoreExtendedPrivateKey = YES;
blockchainIdentityBLSKeysDerivationPath.usesHardenedKeys = YES;
return blockchainIdentityBLSKeysDerivationPath;
Expand Down
17 changes: 11 additions & 6 deletions DashSync/shared/Models/Derivation Paths/DSDerivationPath.m
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,19 @@ - (NSData *)extendedPublicKeyData {
return nil;
}

//- (DSKey *)extendedPublicKey {
- (OpaqueKey *)extendedPublicKey {
if (!_extendedPublicKey) {
if (self.wallet && (self.length || self.reference == DSDerivationPathReference_Root)) {
NSData *extendedPublicKeyData = getKeychainData([self walletBasedExtendedPublicKeyLocationString], nil);
// NSAssert(extendedPublicKeyData, @"extended public key data not set");
if (extendedPublicKeyData) {
_extendedPublicKey = key_create_from_extended_public_key_data(extendedPublicKeyData.bytes, extendedPublicKeyData.length, (int16_t) self.signingAlgorithm);
// _extendedPublicKey = [DSKey keyWithExtendedPublicKeyData:extendedPublicKeyData forKeyType:self.signingAlgorithm];
if (!_extendedPublicKey && self.signingAlgorithm == KeyKind_BLSBasic) {
// Migrate BLS key from keychain: legacy -> basic
_extendedPublicKey = key_bls_migrate_from_legacy_extended_public_key_data(extendedPublicKeyData.bytes, extendedPublicKeyData.length);
if (_extendedPublicKey) {
setKeychainData([DSKeyManager extendedPublicKeyData:_extendedPublicKey], [self standaloneExtendedPublicKeyLocationString], NO);
}
}
NSAssert(_extendedPublicKey, @"extended public key not set");
}
} else {
Expand All @@ -289,10 +293,11 @@ - (OpaqueKey *)extendedPublicKey {
}
}
#endif
// NSAssert(extendedPublicKeyData, @"extended public key data not set");
_extendedPublicKey = key_create_from_extended_public_key_data(extendedPublicKeyData.bytes, extendedPublicKeyData.length, (int16_t) self.signingAlgorithm);
// _extendedPublicKey = [DSKey keyWithExtendedPublicKeyData:extendedPublicKeyData forKeyType:self.signingAlgorithm];
// NSAssert(_extendedPublicKey, @"extended public key not set");
if (!_extendedPublicKey && self.signingAlgorithm == KeyKind_BLSBasic) {
// Migrate BLS key from keychain: legacy -> basic
_extendedPublicKey = key_bls_migrate_from_legacy_extended_public_key_data(extendedPublicKeyData.bytes, extendedPublicKeyData.length);
}
}
}
return _extendedPublicKey;
Expand Down
10 changes: 4 additions & 6 deletions DashSync/shared/Models/Managers/Chain Managers/DSChainManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -673,24 +673,22 @@ - (void)chainFinishedSyncingTransactionsAndBlocks:(DSChain *)chain fromPeer:(DSP
}

- (void)syncBlockchain {
DSLog(@"syncBlockchain connected peers: %d phase: %d", self.peerManager.connectedPeerCount, self.syncPhase);
if (self.peerManager.connectedPeerCount == 0) {
if (self.syncPhase == DSChainSyncPhase_InitialTerminalBlocks) {
self.syncPhase = DSChainSyncPhase_ChainSync;
}
[self.peerManager connect];
} else if (!self.peerManager.masternodeList && self.masternodeManager.currentMasternodeList) {
[self.peerManager useMasternodeList:self.masternodeManager.currentMasternodeList withConnectivityNonce:self.sessionConnectivityNonce];
} else {
if (self.syncPhase == DSChainSyncPhase_InitialTerminalBlocks) {
self.syncPhase = DSChainSyncPhase_ChainSync;
[self chainShouldStartSyncingBlockchain:self.chain onPeer:self.peerManager.downloadPeer];
}
} else if (self.syncPhase == DSChainSyncPhase_InitialTerminalBlocks) {
self.syncPhase = DSChainSyncPhase_ChainSync;
[self chainShouldStartSyncingBlockchain:self.chain onPeer:self.peerManager.downloadPeer];
}
}

- (void)chainFinishedSyncingMasternodeListsAndQuorums:(DSChain *)chain {
DSLog(@"Chain finished syncing masternode list and quorums, it should start syncing chain");

if (chain.isEvolutionEnabled) {
[self.identitiesManager syncBlockchainIdentitiesWithCompletion:^(NSArray<DSBlockchainIdentity *> *_Nullable blockchainIdentities) {
[self syncBlockchain];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ProcessingError shouldProcessDiffWithRange(uint8_t (*base_block_hash)[32], uint8
+ (MasternodeProcessorCache *)createProcessorCache;
+ (void)destroyProcessorCache:(MasternodeProcessorCache *)processorCache;

- (DSMnDiffProcessingResult *)processMasternodeDiffMessage:(NSData *)message withContext:(DSMasternodeProcessorContext *)context;
- (DSMnDiffProcessingResult *)processMasternodeDiffFromFile:(NSData *)message protocolVersion:(uint32_t)protocolVersion withContext:(DSMasternodeProcessorContext *)context;

- (void)processMasternodeDiffWith:(NSData *)message context:(DSMasternodeProcessorContext *)context completion:(void (^)(DSMnDiffProcessingResult *result))completion;
- (void)processQRInfoWith:(NSData *)message context:(DSMasternodeProcessorContext *)context completion:(void (^)(DSQRInfoProcessingResult *result))completion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ - (void)processQRInfoWith:(NSData *)message context:(DSMasternodeProcessorContex
completion(processingResult);
}

- (DSMnDiffProcessingResult *)processMasternodeDiffMessage:(NSData *)message withContext:(DSMasternodeProcessorContext *)context {
- (DSMnDiffProcessingResult *)processMasternodeDiffFromFile:(NSData *)message protocolVersion:(uint32_t)protocolVersion withContext:(DSMasternodeProcessorContext *)context {
NSAssert(self.processor, @"processMasternodeDiffMessage: No processor created");
DSLog(@"processMasternodeDiffMessage: %@", context);
MNListDiffResult *result = NULL;
Expand All @@ -291,12 +291,7 @@ - (DSMnDiffProcessingResult *)processMasternodeDiffMessage:(NSData *)message wit
context.chain.chainType,
context.useInsightAsBackup,
context.isFromSnapshot,
// TODO: re-orient diff-processor to rely on is_from_snapshot + protocol_version,
// TODO: since now we can't process diff for checkpoint with the protocol version >= 70221
// TODO: or we can include protocol version into checkpoint obj, probably it's even better
// TODO: or to recreate checkpoints for the latest protocol version after mainnet upgrading
70221,
// context.chain.protocolVersion,
protocolVersion,
self.processor,
self.processorCache,
(__bridge void *)(context));
Expand Down
Loading