Herman Schoenfeld 7 éve
szülő
commit
e3825c9da8
2 módosított fájl, 25 hozzáadás és 19 törlés
  1. 18 17
      src/core/UFileStorage.pas
  2. 7 2
      src/core/UNetProtocol.pas

+ 18 - 17
src/core/UFileStorage.pas

@@ -20,7 +20,7 @@ unit UFileStorage;
 interface
 
 uses
-  Classes, {$IFDEF FPC}fileutil,{$ELSE} Windows,{$ENDIF} UBlockChain, SyncObjs, UThread, UAccounts, UCrypto;
+  Classes, {$IFnDEF FPC}Windows,{$ENDIF} UBlockChain, SyncObjs, UThread, UAccounts, UCrypto;
 {$I config.inc}
 
 Type
@@ -337,25 +337,26 @@ begin
   End;
 end;
 
-function TFileStorage.DoMoveBlockChain(Start_Block: Cardinal; const DestOrphan: TOrphan; DestStorage : TStorage): Boolean;
-  Procedure DoCopyFile(sourcefn,destfn : AnsiString);
-  var sourceFS, destFS : TFileStream;
-  Begin
-    if Not FileExists(sourcefn) then Raise Exception.Create('Source file not found: '+sourcefn);
-    sourceFS := TFileStream.Create(sourcefn,fmOpenRead+fmShareDenyNone);
+Procedure DoCopyFile(sourcefn,destfn : AnsiString);
+var sourceFS, destFS : TFileStream;
+Begin
+  if Not FileExists(sourcefn) then Raise Exception.Create('Source file not found: '+sourcefn);
+  sourceFS := TFileStream.Create(sourcefn,fmOpenRead+fmShareDenyNone);
+  try
+    sourceFS.Position:=0;
+    destFS := TFileStream.Create(destfn,fmCreate+fmShareDenyWrite);
     try
-      sourceFS.Position:=0;
-      destFS := TFileStream.Create(destfn,fmCreate+fmShareDenyWrite);
-      try
-        destFS.Size:=0;
-        destFS.CopyFrom(sourceFS,sourceFS.Size);
-      finally
-        destFS.Free;
-      end;
+      destFS.Size:=0;
+      destFS.CopyFrom(sourceFS,sourceFS.Size);
     finally
-      sourceFS.Free;
+      destFS.Free;
     end;
+  finally
+    sourceFS.Free;
   end;
+end;
+
+function TFileStorage.DoMoveBlockChain(Start_Block: Cardinal; const DestOrphan: TOrphan; DestStorage : TStorage): Boolean;
 
   Procedure DoCopySafebox;
   var sr: TSearchRec;
@@ -518,7 +519,7 @@ begin
       aux_newfilename := GetFolder('') + PathDelim+'checkpoint_'+ inttostr(Bank.BlocksCount)+'.safebox';
       try
         {$IFDEF FPC}
-        CopyFile(bankfilename,aux_newfilename);
+        DoCopyFile(bankfilename,aux_newfilename);
         {$ELSE}
         CopyFile(PWideChar(bankfilename),PWideChar(aux_newfilename),False);
         {$ENDIF}

+ 7 - 2
src/core/UNetProtocol.pas

@@ -1910,9 +1910,14 @@ begin
           GetNewBank(-1);
         end;
       end else begin
-        TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op));
         // Move operations to orphan folder... (temporal... waiting for a confirmation)
-        GetNewBank(client_op.block+1);
+        if (TNode.Node.Bank.Storage.FirstBlock<client_op.block) then begin
+          TLog.NewLog(ltinfo,CT_LogSender,'Found base new block: '+TPCOperationsComp.OperationBlockToText(client_op));
+          GetNewBank(client_op.block+1);
+        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));
+          DownloadSafeBox(False);
+        end;
       end;
     end else begin
       TLog.NewLog(ltinfo,CT_LogSender,'My blockchain is ok! Need to download new blocks starting at '+inttostr(my_op.block+1));