Browse Source

highest blockchain on previous protocol protection

PascalCoin 6 years ago
parent
commit
a476c7029c
2 changed files with 10 additions and 0 deletions
  1. 3 0
      src/core/UAccounts.pas
  2. 7 0
      src/core/UNetProtocol.pas

+ 3 - 0
src/core/UAccounts.pas

@@ -2644,6 +2644,9 @@ procedure TPCSafeBox.RollBackToSnapshot(snapshotBlock: Cardinal);
 Var i,iPrevSnapshotTarget : Integer;
 Var i,iPrevSnapshotTarget : Integer;
   Psnapshot : PSafeboxSnapshot;
   Psnapshot : PSafeboxSnapshot;
   PBlock : PBlockAccount;
   PBlock : PBlockAccount;
+  {$IFDEF Check_Safebox_Names_Consistency}
+  errors : AnsiString;
+  {$ENDIF}
 begin
 begin
   StartThreadSafe;
   StartThreadSafe;
   Try
   Try

+ 7 - 0
src/core/UNetProtocol.pas

@@ -1955,6 +1955,12 @@ begin
     end;
     end;
 
 
     if (NOT TPCOperationsComp.EqualsOperationBlock(my_op,client_op)) then begin
     if (NOT TPCOperationsComp.EqualsOperationBlock(my_op,client_op)) then begin
+      if (my_op.protocol_version > client_op.protocol_version) then begin // Version 4.0.2 protection against going back to previous protocol with highest blockchain
+        TPCOperationsComp.OperationBlockToText(my_op);
+        TLog.NewLog(lterror,CT_LogSender,Format('Detected an orphan highest blockchain in an old protocol. Detected: %s - My data: %s',[TPCOperationsComp.OperationBlockToText(client_op),TPCOperationsComp.OperationBlockToText(my_op)]));
+        Connection.DisconnectInvalidClient(false,'Detected an orphan highest blockchain in an old protocol');
+        Exit;
+      end;
       TLog.NewLog(ltinfo,CT_LogSender,'My blockchain is not equal... received: '+TPCOperationsComp.OperationBlockToText(client_op)+' My: '+TPCOperationsComp.OperationBlockToText(my_op));
       TLog.NewLog(ltinfo,CT_LogSender,'My blockchain is not equal... received: '+TPCOperationsComp.OperationBlockToText(client_op)+' My: '+TPCOperationsComp.OperationBlockToText(my_op));
       if Not FindLastSameBlockByOperationsBlock(0,client_op.block,client_op) then begin
       if Not FindLastSameBlockByOperationsBlock(0,client_op.block,client_op) then begin
         TLog.NewLog(ltinfo,CT_LogSender,'No found base block to start process... Receiving ALL');
         TLog.NewLog(ltinfo,CT_LogSender,'No found base block to start process... Receiving ALL');
@@ -2706,6 +2712,7 @@ begin
        exit;
        exit;
      end;
      end;
      if (b_end>=TNetData.NetData.Bank.BlocksCount) then begin
      if (b_end>=TNetData.NetData.Bank.BlocksCount) then begin
+       errors := Format('b_end:%d >= current block:%d b_start:%d',[b_end,TNetData.NetData.Bank.BlocksCount,b_start]);
        b_end := TNetData.NetData.Bank.BlocksCount-1;
        b_end := TNetData.NetData.Bank.BlocksCount-1;
        if (b_start>b_end) then begin
        if (b_start>b_end) then begin
          // No data:
          // No data: