Browse Source

Allow assume old protocols PoW are valid (testing purpose only)

PascalCoin 5 years ago
parent
commit
af79454036
2 changed files with 21 additions and 1 deletions
  1. 6 1
      src/config.inc
  2. 15 0
      src/core/UAccounts.pas

+ 6 - 1
src/config.inc

@@ -57,6 +57,11 @@
 
 
   // This will allow check safebox names list. Warning: This will slow app
   // This will allow check safebox names list. Warning: This will slow app
   {.$DEFINE Check_Safebox_Names_Consistency}
   {.$DEFINE Check_Safebox_Names_Consistency}
+  
+  // This will assume that PoW on old protocols are true and will not check, usefull after enough time to increase validation speed. 
+  // Warning: Use only on versions after enough time since last protocol upgrade and non main-node versions
+  {.$DEFINE ASSUME_VALID_POW_OLD_PROTOCOLS}
+  
 
 
 { ********************************************************************
 { ********************************************************************
   Don't touch more code, it will addapt based on your preferences
   Don't touch more code, it will addapt based on your preferences
@@ -66,7 +71,7 @@
 ERROR: You must select ONLY ONE option: PRODUCTION or TESTNET
 ERROR: You must select ONLY ONE option: PRODUCTION or TESTNET
 {$ENDIF}{$ELSE}{$DEFINE PRODUCTION}{$ENDIF}
 {$ENDIF}{$ELSE}{$DEFINE PRODUCTION}{$ENDIF}
 
 
-{$IF (not Defined(Use_OpenSSL)) or (not Defined(Use_CryptoLib4Pascal))}
+{$IF (not Defined(Use_OpenSSL)) and (not Defined(Use_CryptoLib4Pascal))}
   {$DEFINE Use_OpenSSL}
   {$DEFINE Use_OpenSSL}
   {$UNDEF Use_CryptoLib4Pascal}
   {$UNDEF Use_CryptoLib4Pascal}
 {$ENDIF}
 {$ENDIF}

+ 15 - 0
src/core/UAccounts.pas

@@ -828,6 +828,10 @@ var LTmp : TPCHardcodedRandomHashTable;
   LInternalHardcodedSha256 : TRawBytes;
   LInternalHardcodedSha256 : TRawBytes;
 begin
 begin
   Result := False;
   Result := False;
+  {$IFDEF ASSUME_VALID_POW_OLD_PROTOCOLS}
+  // In this case will not use Hardcoded RandomHash Table
+  Exit;
+  {$ENDIF}
   If Not FileExists(AHardcodedFileName) then begin
   If Not FileExists(AHardcodedFileName) then begin
     TLog.NewLog(ltdebug,ClassName,Format('Hardcoded RandomHash from file not found:%s',
     TLog.NewLog(ltdebug,ClassName,Format('Hardcoded RandomHash from file not found:%s',
       [AHardcodedFileName] ));
       [AHardcodedFileName] ));
@@ -3383,7 +3387,11 @@ begin
               // For TESTNET increase speed purposes, will only check latests blocks
               // For TESTNET increase speed purposes, will only check latests blocks
             if ((iblock + (CT_BankToDiskEveryNBlocks * 10)) >= sbHeader.blockscount) then begin
             if ((iblock + (CT_BankToDiskEveryNBlocks * 10)) >= sbHeader.blockscount) then begin
             {$ENDIF}
             {$ENDIF}
+              {$IFDEF ASSUME_VALID_POW_OLD_PROTOCOLS}
+              LAddToMultiThreadOperationsBlockValidator := (LUseMultiThreadOperationsBlockValidator) and (LBlock.blockchainInfo.protocol_version>=CT_PROTOCOL_5) and (Assigned(LPCOperationsBlockValidator));
+              {$ELSE}
               LAddToMultiThreadOperationsBlockValidator := (LUseMultiThreadOperationsBlockValidator) and (LBlock.blockchainInfo.protocol_version>=CT_PROTOCOL_4) and (Assigned(LPCOperationsBlockValidator));
               LAddToMultiThreadOperationsBlockValidator := (LUseMultiThreadOperationsBlockValidator) and (LBlock.blockchainInfo.protocol_version>=CT_PROTOCOL_4) and (Assigned(LPCOperationsBlockValidator));
+              {$ENDIF}
               If not IsValidNewOperationsBlock(LBlock.blockchainInfo,False,Not LAddToMultiThreadOperationsBlockValidator,aux_errors) then begin
               If not IsValidNewOperationsBlock(LBlock.blockchainInfo,False,Not LAddToMultiThreadOperationsBlockValidator,aux_errors) then begin
                 errors := errors + ' > ' + aux_errors;
                 errors := errors + ' > ' + aux_errors;
                 exit;
                 exit;
@@ -4121,11 +4129,18 @@ begin
   end;
   end;
   // proof_of_work:
   // proof_of_work:
   {$IFnDEF TESTING_NO_POW_CHECK}
   {$IFnDEF TESTING_NO_POW_CHECK}
+  {$IFDEF ASSUME_VALID_POW_OLD_PROTOCOLS}
+  if (newOperationBlock.protocol_version>=CT_PROTOCOL_5) then begin
+  {$ENDIF}
   TPascalCoinProtocol.CalcProofOfWork(newOperationBlock,pow);
   TPascalCoinProtocol.CalcProofOfWork(newOperationBlock,pow);
   if (Not TBaseType.Equals(pow,newOperationBlock.proof_of_work)) then begin
   if (Not TBaseType.Equals(pow,newOperationBlock.proof_of_work)) then begin
     errors := 'Proof of work is bad calculated '+TCrypto.ToHexaString(newOperationBlock.proof_of_work)+' <> Good: '+TCrypto.ToHexaString(pow);
     errors := 'Proof of work is bad calculated '+TCrypto.ToHexaString(newOperationBlock.proof_of_work)+' <> Good: '+TCrypto.ToHexaString(pow);
     exit;
     exit;
   end;
   end;
+  {$IFDEF ASSUME_VALID_POW_OLD_PROTOCOLS}
+  end;
+  {$ENDIF}
+
   {$ENDIF}
   {$ENDIF}
   Result := true;
   Result := true;
 end;
 end;