Browse Source

Fix DownloadNewBlockchain

Provide info of "IsMyBlockchainOk" in order to prevent downloading new bank if not necessary
PascalCoin 6 years ago
parent
commit
56667ffc61
2 changed files with 6 additions and 6 deletions
  1. 1 1
      src/core/UBlockChain.pas
  2. 5 5
      src/core/UNetProtocol.pas

+ 1 - 1
src/core/UBlockChain.pas

@@ -842,7 +842,7 @@ begin
   FLastOperationBlock := TPCOperationsComp.GetFirstBlock;
   FLastOperationBlock := TPCOperationsComp.GetFirstBlock;
   FLastOperationBlock.initial_safe_box_hash := TCrypto.DoSha256(CT_Genesis_Magic_String_For_Old_Block_Hash); // Genesis hash
   FLastOperationBlock.initial_safe_box_hash := TCrypto.DoSha256(CT_Genesis_Magic_String_For_Old_Block_Hash); // Genesis hash
   FLastBlockCache.Clear(true);
   FLastBlockCache.Clear(true);
-  NewLog(Nil, ltupdate, 'Clear Bank');
+  {$IFDEF HIGHLOG}NewLog(Nil, ltdebug, 'Clear Bank');{$ENDIF}
 end;
 end;
 
 
 constructor TPCBank.Create(AOwner: TComponent);
 constructor TPCBank.Create(AOwner: TComponent);

+ 5 - 5
src/core/UNetProtocol.pas

@@ -1942,7 +1942,7 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
     end;
     end;
   end;
   end;
 
 
-  procedure DownloadNewBlockchain(start_block : Int64);
+  procedure DownloadNewBlockchain(start_block : Int64; IsMyBlockChainOk : Boolean);
   var safeboxStream : TMemoryStream;
   var safeboxStream : TMemoryStream;
     newTmpBank : TPCBank;
     newTmpBank : TPCBank;
     safebox_last_operation_block : TOperationBlock;
     safebox_last_operation_block : TOperationBlock;
@@ -2026,8 +2026,8 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
         safeboxStream.Free;
         safeboxStream.Free;
       End;
       End;
     end else begin
     end else begin
-      if start_block = TNode.Node.Bank.LastOperationBlock.block+1 then begin
-        Connection.Send_GetBlocks(start_block,100,rid);
+      if IsMyBlockChainOk then begin
+        Connection.Send_GetBlocks(start_block,1,rid);
       end else begin
       end else begin
         GetNewBank(start_block);
         GetNewBank(start_block);
       end;
       end;
@@ -2095,7 +2095,7 @@ begin
         // Move operations to orphan folder... (temporal... waiting for a confirmation)
         // Move operations to orphan folder... (temporal... waiting for a confirmation)
         if (TNode.Node.Bank.Storage.FirstBlock<client_op.block) then begin
         if (TNode.Node.Bank.Storage.FirstBlock<client_op.block) then begin
           TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op));
           TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op));
-          DownloadNewBlockchain(client_op.block+1);
+          DownloadNewBlockchain(client_op.block+1,False);
         end else begin
         end else begin
           TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op)+' lower than saved:'+IntToStr(TNode.Node.Bank.Storage.FirstBlock));
           TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op)+' lower than saved:'+IntToStr(TNode.Node.Bank.Storage.FirstBlock));
           DownloadSafeBox(False);
           DownloadSafeBox(False);
@@ -2104,7 +2104,7 @@ begin
     end else begin
     end else begin
       TLog.NewLog(ltinfo,CT_LogSender,'My blockchain is ok! Need to download new blocks starting at '+inttostr(my_op.block+1));
       TLog.NewLog(ltinfo,CT_LogSender,'My blockchain is ok! Need to download new blocks starting at '+inttostr(my_op.block+1));
       // High to new value:
       // High to new value:
-      DownloadNewBlockchain(my_op.block+1);
+      DownloadNewBlockchain(my_op.block+1,True);
     end;
     end;
   Finally
   Finally
     TLog.NewLog(ltdebug,CT_LogSender,'Finalizing');
     TLog.NewLog(ltdebug,CT_LogSender,'Finalizing');