Browse Source

Protection on Fast propagation with diff operations

A double spend operation can cause invalid fast propagation block when regenerating. Check that block was well produced prior to disconnect
PascalCoin 6 years ago
parent
commit
dc4f767726
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/core/UNetProtocol.pas

+ 14 - 0
src/core/UNetProtocol.pas

@@ -3530,9 +3530,11 @@ var operationsComp : TPCOperationsComp;
     headerData : TNetHeaderData;
     headerData : TNetHeaderData;
     auxOp : TPCOperation;
     auxOp : TPCOperation;
     tc : TTickCount;
     tc : TTickCount;
+    original_OperationBlock : TOperationBlock;
   begin
   begin
     Result := False;
     Result := False;
     DoDisconnect := True;
     DoDisconnect := True;
+    original_OperationBlock := operationsComp.OperationBlock;
     errors := 'Invalid structure data in ProcessNewFastBlockPropagation';
     errors := 'Invalid structure data in ProcessNewFastBlockPropagation';
     tc := TPlatform.GetTickCount;
     tc := TPlatform.GetTickCount;
     SetLength(nfpboarr,0);
     SetLength(nfpboarr,0);
@@ -3623,6 +3625,18 @@ var operationsComp : TPCOperationsComp;
     if (notFoundOpReferencesCount > 0) then begin
     if (notFoundOpReferencesCount > 0) then begin
       TLog.NewLog(ltdebug,ClassName,Format('Processed NewFastBlockPropagation with Pending operations (%d of %d) in Fast propagation block %d for %d miliseconds',[notFoundOpReferencesCount,oprefcount,operationsComp.OperationBlock.block,TPlatform.GetElapsedMilliseconds(tc)]));
       TLog.NewLog(ltdebug,ClassName,Format('Processed NewFastBlockPropagation with Pending operations (%d of %d) in Fast propagation block %d for %d miliseconds',[notFoundOpReferencesCount,oprefcount,operationsComp.OperationBlock.block,TPlatform.GetElapsedMilliseconds(tc)]));
     end;
     end;
+    // Check that operationsComp.operationBlock is equal to received
+    If Not TAccountComp.EqualOperationBlocks(operationsComp.OperationBlock,original_OperationBlock) then begin
+      // This can happen when a OpReference in my MEMPOOL is different to an OpReference in the miner, causing different OperationsHash value
+      // This means a possible double spend found
+      TLog.NewLog(lterror,ClassName,Format('Constructed a distinct FAST PROPAGATION block with my mempool operations. Received: %s Constructed: %s',
+        [TPCOperationsComp.OperationBlockToText(original_OperationBlock),TPCOperationsComp.OperationBlockToText(operationsComp.OperationBlock)]));
+      if Not TPCSafeBox.IsValidOperationBlock(original_OperationBlock,errors) then begin
+        // This means a scammer!
+        DoDisconnect := True;
+      end;
+      Exit;
+    end;
     finally
     finally
       // Clean memory
       // Clean memory
       for i := 0 to High(nfpboarr) do begin
       for i := 0 to High(nfpboarr) do begin