Browse Source

Some logs changes

Some minor logs changes
PascalCoin 8 years ago
parent
commit
463f552790
3 changed files with 24 additions and 16 deletions
  1. 5 4
      Units/PascalCoin/UBlockChain.pas
  2. 14 9
      Units/PascalCoin/UNode.pas
  3. 5 3
      Units/PascalCoin/UTCPIP.pas

+ 5 - 4
Units/PascalCoin/UBlockChain.pas

@@ -436,12 +436,13 @@ begin
     Result := False;
     Result := False;
     errors := '';
     errors := '';
     Try
     Try
-      If Not Operations.ValidateOperationBlock(errors) then begin
-        exit;
-      end;
       // Check valid data
       // Check valid data
       if (BlocksCount <> Operations.OperationBlock.block) then begin
       if (BlocksCount <> Operations.OperationBlock.block) then begin
-        errors := 'block ('+inttostr(Operations.OperationBlock.block)+') is not new position ('+inttostr(BlocksCount)+')';
+        errors := 'block ('+inttostr(Operations.OperationBlock.block)+') is not new position ('+inttostr(BlocksCount)+') - Duplicate or orphan/dual blockchain candidate';
+        exit;
+      end;
+      // 1.5.2.2 Changed position to allow first checking valid block number prior to check operations. This shows better logs info
+      If Not Operations.ValidateOperationBlock(errors) then begin
         exit;
         exit;
       end;
       end;
       if Not Assigned(Operations.FSafeBoxTransaction) then begin
       if Not Assigned(Operations.FSafeBoxTransaction) then begin

+ 14 - 9
Units/PascalCoin/UNode.pas

@@ -153,12 +153,17 @@ Var i,j : Integer;
   OpBlock : TOperationBlock;
   OpBlock : TOperationBlock;
 begin
 begin
   Result := false;
   Result := false;
+  errors := '';
   if FDisabledsNewBlocksCount>0 then begin
   if FDisabledsNewBlocksCount>0 then begin
     TLog.NewLog(ltinfo,Classname,Format('Cannot Add new BlockChain due is adding disabled - Connection:%s NewBlock:%s',[
     TLog.NewLog(ltinfo,Classname,Format('Cannot Add new BlockChain due is adding disabled - Connection:%s NewBlock:%s',[
     Inttohex(PtrInt(SenderConnection),8),TPCOperationsComp.OperationBlockToText(NewBlockOperations.OperationBlock)]));
     Inttohex(PtrInt(SenderConnection),8),TPCOperationsComp.OperationBlockToText(NewBlockOperations.OperationBlock)]));
+    errors := 'Adding blocks is disabled';
+    exit;
+  end;
+  If NewBlockOperations.OperationBlock.block<>Bank.BlocksCount then begin
+    errors := 'New block number ('+IntToStr(NewBlockOperations.OperationBlock.block)+') not valid! (Expected '+IntToStr(Bank.BlocksCount)+')';
     exit;
     exit;
   end;
   end;
-  If NewBlockOperations.OperationBlock.block<>Bank.BlocksCount then exit;
   OpBlock := NewBlockOperations.OperationBlock;
   OpBlock := NewBlockOperations.OperationBlock;
   TLog.NewLog(ltdebug,Classname,Format('AddNewBlockChain Connection:%s NewBlock:%s',[
   TLog.NewLog(ltdebug,Classname,Format('AddNewBlockChain Connection:%s NewBlock:%s',[
     Inttohex(PtrInt(SenderConnection),8),TPCOperationsComp.OperationBlockToText(OpBlock)]));
     Inttohex(PtrInt(SenderConnection),8),TPCOperationsComp.OperationBlockToText(OpBlock)]));
@@ -175,19 +180,19 @@ begin
       Result := Bank.AddNewBlockChainBlock(NewBlockOperations,newBlockAccount,errors);
       Result := Bank.AddNewBlockChainBlock(NewBlockOperations,newBlockAccount,errors);
       if Result then begin
       if Result then begin
         if Assigned(SenderConnection) then begin
         if Assigned(SenderConnection) then begin
-          FNodeLog.NotifyNewLog(ltupdate,SenderConnection.ClassName,Format(';%d;%s;%s;;%d;%d;%d',[OpBlock.block,SenderConnection.ClientRemoteAddr,OpBlock.block_payload,
-            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp]));
+          FNodeLog.NotifyNewLog(ltupdate,SenderConnection.ClassName,Format(';%d;%s;%s;;%d;%d;%d;%s',[OpBlock.block,SenderConnection.ClientRemoteAddr,OpBlock.block_payload,
+            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp,IntToHex(OpBlock.compact_target,8)]));
         end else begin
         end else begin
-          FNodeLog.NotifyNewLog(ltupdate,ClassName,Format(';%d;%s;%s;;%d;%d;%d',[OpBlock.block,'NIL',OpBlock.block_payload,
-            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp]));
+          FNodeLog.NotifyNewLog(ltupdate,ClassName,Format(';%d;%s;%s;;%d;%d;%d;%s',[OpBlock.block,'NIL',OpBlock.block_payload,
+            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp,IntToHex(OpBlock.compact_target,8)]));
         end;
         end;
       end else begin
       end else begin
         if Assigned(SenderConnection) then begin
         if Assigned(SenderConnection) then begin
-          FNodeLog.NotifyNewLog(lterror,SenderConnection.ClassName,Format(';%d;%s;%s;%s;%d;%d;%d',[OpBlock.block,SenderConnection.ClientRemoteAddr,OpBlock.block_payload,errors,
-            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp]));
+          FNodeLog.NotifyNewLog(lterror,SenderConnection.ClassName,Format(';%d;%s;%s;%s;%d;%d;%d;%s',[OpBlock.block,SenderConnection.ClientRemoteAddr,OpBlock.block_payload,errors,
+            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp,IntToHex(OpBlock.compact_target,8)]));
         end else begin
         end else begin
-          FNodeLog.NotifyNewLog(lterror,ClassName,Format(';%d;%s;%s;%s;%d;%d;%d',[OpBlock.block,'NIL',OpBlock.block_payload,errors,
-            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp]));
+          FNodeLog.NotifyNewLog(lterror,ClassName,Format(';%d;%s;%s;%s;%d;%d;%d;%s',[OpBlock.block,'NIL',OpBlock.block_payload,errors,
+            OpBlock.timestamp,UnivDateTimeToUnix(DateTime2UnivDateTime(Now)),UnivDateTimeToUnix(DateTime2UnivDateTime(Now)) - OpBlock.timestamp,IntToHex(OpBlock.compact_target,8)]));
         end;
         end;
       end;
       end;
       FOperations.Clear(true);
       FOperations.Clear(true);

+ 5 - 3
Units/PascalCoin/UTCPIP.pas

@@ -865,9 +865,11 @@ begin
   finally
   finally
     // Finalize all threads
     // Finalize all threads
     for i := 0 to lSockets.Count - 1 do begin
     for i := 0 to lSockets.Count - 1 do begin
-      // Here we no wait until terminated...
       TTcpIpSocketThread(lSockets[i]).FListenerThread := Nil;
       TTcpIpSocketThread(lSockets[i]).FListenerThread := Nil;
       TTcpIpSocketThread(lSockets[i]).Terminate;
       TTcpIpSocketThread(lSockets[i]).Terminate;
+    end;
+    // Wait until terminated...
+    for i := 0 to lSockets.Count - 1 do begin
       TTcpIpSocketThread(lSockets[i]).WaitFor;
       TTcpIpSocketThread(lSockets[i]).WaitFor;
       TTcpIpSocketThread(lSockets[i]).Free;
       TTcpIpSocketThread(lSockets[i]).Free;
     end;
     end;
@@ -914,14 +916,14 @@ begin
     end;
     end;
   Except
   Except
     On E:Exception do begin
     On E:Exception do begin
-      TLog.NewLog(lterror,ClassName,'Error closign socket: '+E.Message);
+      TLog.NewLog(lterror,ClassName,'Exception closing socket ('+E.ClassName+'):' +E.Message);
     end;
     end;
   End;
   End;
   Try
   Try
     FreeAndNil(FSock);
     FreeAndNil(FSock);
   Except
   Except
     On E:Exception do begin
     On E:Exception do begin
-      TLog.NewLog(lterror,ClassName,'Error destroying socket: '+E.Message);
+      TLog.NewLog(lterror,ClassName,'Exception destroying socket ('+E.ClassName+'):' +E.Message);
     end;
     end;
   End;
   End;
   inherited;
   inherited;