Skip to content
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

feat: Core v0.20 support #516

Merged
merged 13 commits into from
Nov 8, 2023
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.11'
s.dependency 'DashSharedCore', '0.4.14'
s.dependency 'CocoaLumberjack', '3.7.2'
s.ios.dependency 'DWAlertController', '0.2.1'
s.dependency 'DSDynamicOptions', '0.1.2'
Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/Categories/NSData/NSMutableData+Dash.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void secureDeallocate(void *ptr, void *info) {
}

// Since iOS does not page memory to storage, all we need to do is cleanse allocated memory prior to deallocation.
CFAllocatorRef SecureAllocator() {
CFAllocatorRef SecureAllocator(void) {
static CFAllocatorRef alloc = NULL;
static dispatch_once_t onceToken = 0;

Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/DashSync.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>DashSync 19.xcdatamodel</string>
<string>DashSync 20.xcdatamodel</string>
</dict>
</plist>
518 changes: 518 additions & 0 deletions DashSync/shared/DashSync.xcdatamodeld/DashSync 20.xcdatamodel/contents

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions DashSync/shared/Libraries/DSLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

NS_ASSUME_NONNULL_BEGIN

@interface NoTimestampLogFormatter : NSObject <DDLogFormatter>
@end
@implementation NoTimestampLogFormatter
- (nullable NSString *)formatLogMessage:(DDLogMessage *)logMessage {
return logMessage.message;
}
@end

@interface DSLogger ()

@property (readonly, nonatomic, strong) DDFileLogger *fileLogger;
Expand All @@ -44,6 +52,7 @@ - (instancetype)init {
DDFileLogger *fileLogger = [[DDFileLogger alloc] init];
fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
fileLogger.logFileManager.maximumNumberOfLogFiles = 3; // keep a 3 days worth of log files
//[fileLogger setLogFormatter:[[NoTimestampLogFormatter alloc] init]]; // Use the custom formatter
[DDLog addLogger:fileLogger];
_fileLogger = fileLogger;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ - (NSTimeInterval)timeIntervalAndCalculateNext {

#define EXPT_MODULO ((u_int32_t)RAND_MAX)
#define EXPT_MODULO_F64 ((double)(EXPT_MODULO))
NS_INLINE double SPTExptRandom() {
NS_INLINE double SPTExptRandom(void) {
// We need [0, 1) interval
return arc4random_uniform(EXPT_MODULO);
}
Expand Down
4 changes: 2 additions & 2 deletions DashSync/shared/Models/Chain/DSChainConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
#define PROTOCOL_VERSION_MAINNET 70228
#define DEFAULT_MIN_PROTOCOL_VERSION_MAINNET 70228

#define PROTOCOL_VERSION_TESTNET 70228
#define PROTOCOL_VERSION_TESTNET 70230
#define DEFAULT_MIN_PROTOCOL_VERSION_TESTNET 70228

#define PROTOCOL_VERSION_DEVNET 70228
#define PROTOCOL_VERSION_DEVNET 70230
#define DEFAULT_MIN_PROTOCOL_VERSION_DEVNET 70228

#define PLATFORM_PROTOCOL_VERSION_MAINNET 1
Expand Down
4 changes: 2 additions & 2 deletions DashSync/shared/Models/Chain/DSChainLock.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ - (BOOL)verifySignatureAgainstQuorum:(DSQuorumEntry *)quorumEntry {
UInt256 signId = [self signIDForQuorumEntry:quorumEntry];
BOOL verified = key_bls_verify(quorumEntry.quorumPublicKey.u8, quorumEntry.useLegacyBLSScheme, signId.u8, self.signature.u8);
#if DEBUG
DSLog(@"verifySignatureAgainstQuorum (%u): %u: %u: %@: %@: %@: %@: %u", verified, quorumEntry.llmqType, quorumEntry.verified, uint256_hex(quorumEntry.llmqQuorumHash), @"<REDACTED>", uint384_hex(quorumEntry.quorumPublicKey), @"<REDACTED>", quorumEntry.useLegacyBLSScheme);
DSLog(@"verifySignatureAgainstQuorum (%u): %u: %u: %@: %@: %@: %u", verified, quorumEntry.llmqType, quorumEntry.verified, @"<REDACTED>", uint384_hex(quorumEntry.quorumPublicKey), @"<REDACTED>", quorumEntry.useLegacyBLSScheme);
#else
DSLogPrivate(@"verifySignatureAgainstQuorum (%u): %u: %u: %@: %@: %@: %@: %u", verified, quorumEntry.llmqType, quorumEntry.verified, uint256_hex(quorumEntry.llmqQuorumHash), uint256_hex(signId), uint384_hex(quorumEntry.quorumPublicKey), uint768_hex(self.signature), quorumEntry.useLegacyBLSScheme);
DSLogPrivate(@"verifySignatureAgainstQuorum (%u): %u: %u: %@: %@: %@: %u", verified, quorumEntry.llmqType, quorumEntry.verified, uint256_hex(signId), uint384_hex(quorumEntry.quorumPublicKey), uint768_hex(self.signature), quorumEntry.useLegacyBLSScheme);
#endif
return verified;
}
Expand Down
2 changes: 1 addition & 1 deletion DashSync/shared/Models/Chain/DSFullBlock.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (instancetype)initWithMessage:(NSData *)message onChain:(DSChain *)chain {
}

- (instancetype)initWithCoinbaseTransaction:(DSCoinbaseTransaction *)coinbaseTransaction transactions:(NSSet<DSTransaction *> *)transactions previousBlockHash:(UInt256)previousBlockHash previousBlocks:(NSDictionary *)previousBlocks timestamp:(uint32_t)timestamp height:(uint32_t)height onChain:(DSChain *)chain {
if (!(self = [super initWithVersion:2 timestamp:timestamp height:height onChain:chain])) return nil;
if (!(self = [super initWithVersion:COINBASE_TX_CORE_19 timestamp:timestamp height:height onChain:chain])) return nil;
NSMutableSet *totalTransactionsSet = [transactions mutableCopy];
[totalTransactionsSet addObject:coinbaseTransaction];
self.totalTransactions = (uint32_t)[totalTransactionsSet count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ - (instancetype)setAttributesFromTransaction:(DSTransaction *)tx {
self.specialTransactionVersion = coinbaseTransaction.coinbaseTransactionVersion;
self.height = coinbaseTransaction.height;
self.merkleRootMNList = uint256_data(coinbaseTransaction.merkleRootMNList);
if (self.specialTransactionVersion >= COINBASE_TX_CORE_19) {
self.merkleRootLLMQList = uint256_data(coinbaseTransaction.merkleRootLLMQList);
if (self.specialTransactionVersion >= COINBASE_TX_CORE_20) {
self.bestCLHeightDiff = coinbaseTransaction.bestCLHeightDiff;
self.bestCLSignature = uint768_data(coinbaseTransaction.bestCLSignature);
self.creditPoolBalance = coinbaseTransaction.creditPoolBalance;
}
}
}];

return self;
Expand All @@ -32,11 +40,22 @@ - (DSTransaction *)transactionForChain:(DSChain *)chain {
transaction.coinbaseTransactionVersion = self.specialTransactionVersion;
transaction.height = self.height;
transaction.merkleRootMNList = self.merkleRootMNList.UInt256;

if (self.specialTransactionVersion >= COINBASE_TX_CORE_19) {
transaction.merkleRootLLMQList = self.merkleRootLLMQList.UInt256;
if (self.specialTransactionVersion >= COINBASE_TX_CORE_20) {
transaction.bestCLHeightDiff = self.bestCLHeightDiff;
transaction.bestCLSignature = self.bestCLSignature.UInt768;
transaction.creditPoolBalance = self.creditPoolBalance;
}
}
}];

return transaction;
}



- (Class)transactionClass {
return [DSCoinbaseTransaction class];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSFetchRequest<DSCoinbaseTransactionEntity *> *)fetchRequest;

@property (assign, nonatomic) uint32_t height;

@property (nullable, nonatomic, retain) NSData *merkleRootMNList;
@property (nullable, nonatomic, retain) NSData *merkleRootLLMQList;

@property (assign, nonatomic) uint32_t bestCLHeightDiff;
@property (nullable, nonatomic, retain) NSData *bestCLSignature;
@property (assign, nonatomic) int64_t creditPoolBalance;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ @implementation DSCoinbaseTransactionEntity (CoreDataProperties)

@dynamic height;
@dynamic merkleRootMNList;
@dynamic merkleRootLLMQList;
@dynamic bestCLHeightDiff;
@dynamic bestCLSignature;
@dynamic creditPoolBalance;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ typedef void (^MultipleBlockMiningCompletionBlock)(NSArray<DSFullBlock *> *block

- (void)mineBlockAfterBlock:(DSBlock *)block toPaymentAddress:(NSString *)paymentAddress withTransactions:(NSArray<DSTransaction *> *_Nullable)transactions previousBlocks:(NSDictionary<NSValue *, DSBlock *> *)previousBlocks nonceOffset:(uint32_t)nonceOffset withTimeout:(NSTimeInterval)timeout completion:(BlockMiningCompletionBlock)completion;

- (DSChainLock * _Nullable)chainLockForBlockHash:(UInt256)blockHash;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ - (void)chainFinishedSyncingTransactionsAndBlocks:(DSChain *)chain fromPeer:(DSP
}

- (void)syncBlockchain {
DSLog(@"syncBlockchain connected peers: %d phase: %d", self.peerManager.connectedPeerCount, self.syncPhase);
DSLog(@"syncBlockchain connected peers: %lu phase: %d", self.peerManager.connectedPeerCount, self.syncPhase);
if (self.peerManager.connectedPeerCount == 0) {
if (self.syncPhase == DSChainSyncPhase_InitialTerminalBlocks) {
self.syncPhase = DSChainSyncPhase_ChainSync;
Expand Down Expand Up @@ -794,4 +794,8 @@ - (void)wipeMasternodeInfo {
[self.masternodeManager wipeMasternodeInfo];
}

- (DSChainLock * _Nullable)chainLockForBlockHash:(UInt256)blockHash {
return [self.transactionManager chainLockForBlockHash:blockHash];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
MasternodeList *getMasternodeListByBlockHash(uint8_t (*block_hash)[32], const void *context);
bool saveMasternodeList(uint8_t (*block_hash)[32], MasternodeList *masternode_list, const void *context);
void destroyMasternodeList(MasternodeList *masternode_list);
void destroyHash(uint8_t *block_hash);
void destroyU8(uint8_t *block_hash);
uint32_t getBlockHeightByHash(uint8_t (*block_hash)[32], const void *context);
uint8_t *getBlockHashByHeight(uint32_t block_height, const void *context);
uint8_t *getMerkleRootByHash(uint8_t (*block_hash)[32], const void *context);
Expand Down
Loading
Loading