Browse Source

Testnet download safebox bug

Solves download safebox bug on V4 implementation
PascalCoin 7 years ago
parent
commit
83e867faca
3 changed files with 12 additions and 5 deletions
  1. 10 3
      src/core/UAccounts.pas
  2. 1 1
      src/core/UBlockChain.pas
  3. 1 1
      src/core/UConst.pas

+ 10 - 3
src/core/UAccounts.pas

@@ -2725,8 +2725,10 @@ Var
   nPos,posOffsetZone : Int64;
   nPos,posOffsetZone : Int64;
   offsets : Array of Cardinal;
   offsets : Array of Cardinal;
   sbHeader : TPCSafeBoxHeader;
   sbHeader : TPCSafeBoxHeader;
+  tc : TTickCount;
 begin
 begin
   If Assigned(FPreviousSafeBox) then Raise Exception.Create('Cannot loadSafeBoxFromStream on a Safebox in a Separate chain');
   If Assigned(FPreviousSafeBox) then Raise Exception.Create('Cannot loadSafeBoxFromStream on a Safebox in a Separate chain');
+  tc := TPlatform.GetTickCount;
   StartThreadSafe;
   StartThreadSafe;
   try
   try
     Clear;
     Clear;
@@ -2736,12 +2738,12 @@ begin
         errors := 'Invalid stream. Invalid header/version';
         errors := 'Invalid stream. Invalid header/version';
         exit;
         exit;
       end;
       end;
-      errors := 'Invalid version or corrupted stream';
+      errors := 'Invalid protocol version or corrupted stream ('+IntToStr(sbHeader.protocol)+')';
       case sbHeader.protocol of
       case sbHeader.protocol of
         CT_PROTOCOL_1 : FCurrentProtocol := 1;
         CT_PROTOCOL_1 : FCurrentProtocol := 1;
         CT_PROTOCOL_2 : FCurrentProtocol := 2;
         CT_PROTOCOL_2 : FCurrentProtocol := 2;
         CT_PROTOCOL_3 : FCurrentProtocol := 3;
         CT_PROTOCOL_3 : FCurrentProtocol := 3;
-        CT_PROTOCOL_4 : FCurrentProtocol := 4;
+        CT_PROTOCOL_4 : FCurrentProtocol := 3; // In order to allow Upgrade to V4
       else exit;
       else exit;
       end;
       end;
       if (sbHeader.blocksCount=0) Or (sbHeader.startBlock<>0) Or (sbHeader.endBlock<>(sbHeader.blocksCount-1)) then begin
       if (sbHeader.blocksCount=0) Or (sbHeader.startBlock<>0) Or (sbHeader.endBlock<>(sbHeader.blocksCount-1)) then begin
@@ -2767,7 +2769,8 @@ begin
       SetLength(FBufferBlocksHash,sbHeader.blocksCount*32); // Initialize for high speed reading
       SetLength(FBufferBlocksHash,sbHeader.blocksCount*32); // Initialize for high speed reading
       errors := 'Corrupted stream';
       errors := 'Corrupted stream';
       for iblock := 0 to sbHeader.blockscount-1 do begin
       for iblock := 0 to sbHeader.blockscount-1 do begin
-        if (Assigned(progressNotify)) and ((iblock MOD 1000)=0) then begin
+        if (Assigned(progressNotify)) and ((TPlatform.GetElapsedMilliseconds(tc)>=500)) then begin
+          tc := TPlatform.GetTickCount;
           progressNotify(Self,Format('Reading Safebox block %d/%d',[iblock+1,sbHeader.endBlock-sbHeader.startBlock+1]),iblock,sbHeader.endBlock-sbHeader.startBlock+1);
           progressNotify(Self,Format('Reading Safebox block %d/%d',[iblock+1,sbHeader.endBlock-sbHeader.startBlock+1]),iblock,sbHeader.endBlock-sbHeader.startBlock+1);
         end;
         end;
         errors := 'Corrupted stream reading block blockchain '+inttostr(iblock+1)+'/'+inttostr(sbHeader.blockscount);
         errors := 'Corrupted stream reading block blockchain '+inttostr(iblock+1)+'/'+inttostr(sbHeader.blockscount);
@@ -2856,6 +2859,10 @@ begin
         end;
         end;
         LastReadBlock := block;
         LastReadBlock := block;
         Inc(FWorkSum,block.blockchainInfo.compact_target);
         Inc(FWorkSum,block.blockchainInfo.compact_target);
+        // Upgrade to Protocol 4 step:
+        if (block.blockchainInfo.protocol_version>FCurrentProtocol) And (block.blockchainInfo.protocol_version = CT_PROTOCOL_4) then begin
+          FCurrentProtocol := CT_PROTOCOL_4;
+        end;
       end;
       end;
       if (Assigned(progressNotify)) then begin
       if (Assigned(progressNotify)) then begin
         progressNotify(Self,'Checking Safebox integrity',sbHeader.blocksCount,sbHeader.blocksCount);
         progressNotify(Self,'Checking Safebox integrity',sbHeader.blocksCount,sbHeader.blocksCount);

+ 1 - 1
src/core/UBlockChain.pas

@@ -815,7 +815,7 @@ begin
       If Assigned(auxSB) then begin
       If Assigned(auxSB) then begin
         SafeBox.CopyFrom(auxSB);
         SafeBox.CopyFrom(auxSB);
       end else begin
       end else begin
-        Result := SafeBox.LoadSafeBoxFromStream(Stream,false,progressNotify,LastReadBlock,errors);
+        Result := SafeBox.LoadSafeBoxFromStream(Stream,False,progressNotify,LastReadBlock,errors);
       end;
       end;
       If Not Result then exit;
       If Not Result then exit;
       If SafeBox.BlocksCount>0 then FLastOperationBlock := SafeBox.Block(SafeBox.BlocksCount-1).blockchainInfo
       If SafeBox.BlocksCount>0 then FLastOperationBlock := SafeBox.Block(SafeBox.BlocksCount-1).blockchainInfo

+ 1 - 1
src/core/UConst.pas

@@ -105,7 +105,7 @@ Const
   CT_PROTOCOL_4 = 4;
   CT_PROTOCOL_4 = 4;
   CT_BUILD_PROTOCOL = CT_PROTOCOL_3;
   CT_BUILD_PROTOCOL = CT_PROTOCOL_3;
 
 
-  CT_BlockChain_Protocol_Available: Word = $0003; // Protocol 3 flag
+  CT_BlockChain_Protocol_Available: Word = 4; // Protocol 4 flag
   CT_Protocol_Upgrade_v2_MinBlock = {$IFDEF PRODUCTION}115000{$ELSE}50{$ENDIF};
   CT_Protocol_Upgrade_v2_MinBlock = {$IFDEF PRODUCTION}115000{$ELSE}50{$ENDIF};
   CT_Protocol_Upgrade_v3_MinBlock = {$IFDEF PRODUCTION}210000{$ELSE}250{$ENDIF};
   CT_Protocol_Upgrade_v3_MinBlock = {$IFDEF PRODUCTION}210000{$ELSE}250{$ENDIF};
   CT_Protocol_Upgrade_v4_MinBlock = {$IFDEF PRODUCTION}999999{$ELSE}400{$ENDIF}; // NOTE: Upgrade to V4 not decided!   TODO!
   CT_Protocol_Upgrade_v4_MinBlock = {$IFDEF PRODUCTION}999999{$ELSE}400{$ENDIF}; // NOTE: Upgrade to V4 not decided!   TODO!