Browse Source

logs and NodeVersion

PascalCoin 6 years ago
parent
commit
3aacae66f7
2 changed files with 28 additions and 20 deletions
  1. 21 19
      src/core/UNetProtocol.pas
  2. 7 1
      src/core/UNode.pas

+ 21 - 19
src/core/UNetProtocol.pas

@@ -2513,7 +2513,7 @@ begin
       FNetLock.Release;
       FNetLock.Release;
     End;
     End;
     if Result then begin
     if Result then begin
-      TLog.NewLog(ltDebug,Classname,'Connected to a possible server at: '+ClientRemoteAddr);
+      {$IFDEF HIGHLOG}TLog.NewLog(ltDebug,Classname,'Connected to a possible server at: '+ClientRemoteAddr);{$ENDIF}
       TNetData.NetData.NodeServersAddresses.GetNodeServerAddress(Client.RemoteHost,Client.RemotePort,true,nsa);
       TNetData.NetData.NodeServersAddresses.GetNodeServerAddress(Client.RemoteHost,Client.RemotePort,true,nsa);
       nsa.netConnection := Self;
       nsa.netConnection := Self;
       nsa.last_connection_by_me := (UnivDateTimeToUnix(DateTime2UnivDateTime(now)));
       nsa.last_connection_by_me := (UnivDateTimeToUnix(DateTime2UnivDateTime(now)));
@@ -3670,22 +3670,24 @@ var operationsComp : TPCOperationsComp;
     end;
     end;
     DoDisconnect := False;
     DoDisconnect := False;
     notFoundOpReferencesCount := 0;
     notFoundOpReferencesCount := 0;
-    // Try TNode locking process
-    If Not TNode.Node.TryLockNode(3000) then Exit; // Cannot lock...
-    Try
-      if (operationsComp.OperationBlock.block<>TNode.Node.Bank.BlocksCount) then Exit; // Meanwhile other threads have added it
-      // Fill not included operations:
-      for i:=0 to High(nfpboarr) do begin
-        iNodeOpReference := TNode.Node.Operations.OperationsHashTree.IndexOfOpReference(nfpboarr[i].opReference);
-        if iNodeOpReference>=0 then begin
-          nfpboarr[i].opStreamData := TNode.Node.Operations.OperationsHashTree.GetOperation(iNodeOpReference).GetOperationStreamData;
-        end else begin
-          inc(notFoundOpReferencesCount);
+    if (oprefcount>0) then begin
+      // Try TNode locking process
+      If Not TNode.Node.TryLockNode(3000) then Exit; // Cannot lock...
+      Try
+        if (operationsComp.OperationBlock.block<>TNode.Node.Bank.BlocksCount) then Exit; // Meanwhile other threads have added it
+        // Fill not included operations:
+        for i:=0 to High(nfpboarr) do begin
+          iNodeOpReference := TNode.Node.Operations.OperationsHashTree.IndexOfOpReference(nfpboarr[i].opReference);
+          if iNodeOpReference>=0 then begin
+            nfpboarr[i].opStreamData := TNode.Node.Operations.OperationsHashTree.GetOperation(iNodeOpReference).GetOperationStreamData;
+          end else begin
+            inc(notFoundOpReferencesCount);
+          end;
         end;
         end;
-      end;
-    Finally
-      TNode.Node.UnlockNode;
-    End;
+      Finally
+        TNode.Node.UnlockNode;
+      End;
+    end;
     if (notFoundOpReferencesCount>CT_MAX_OPS_PER_BLOCKCHAINOPERATIONS) then begin
     if (notFoundOpReferencesCount>CT_MAX_OPS_PER_BLOCKCHAINOPERATIONS) then begin
       // A lot of operations pending! Calling GetBlocks
       // A lot of operations pending! Calling GetBlocks
       TLog.NewLog(ltdebug,ClassName,Format('Too many pending operations (%d of %d) in Fast propagation block %d',[notFoundOpReferencesCount,oprefcount,operationsComp.OperationBlock.block]));
       TLog.NewLog(ltdebug,ClassName,Format('Too many pending operations (%d of %d) in Fast propagation block %d',[notFoundOpReferencesCount,oprefcount,operationsComp.OperationBlock.block]));
@@ -4365,7 +4367,7 @@ begin
       data.Write(nsa.last_connection,4);
       data.Write(nsa.last_connection,4);
     end;
     end;
     // Send client version
     // Send client version
-    TStreamOp.WriteAnsiString(data,CT_ClientAppVersion{$IFDEF LINUX}+'l'{$ELSE}+'w'{$ENDIF}{$IFDEF FPC}{$IFDEF LCL}+'L'{$ELSE}+'F'{$ENDIF}{$ENDIF});
+    TStreamOp.WriteAnsiString(data,TNode.NodeVersion);
     // Build 1.5 send accumulated work
     // Build 1.5 send accumulated work
     data.Write(TNode.Node.Bank.SafeBox.WorkSum,SizeOf(TNode.Node.Bank.SafeBox.WorkSum));
     data.Write(TNode.Node.Bank.SafeBox.WorkSum,SizeOf(TNode.Node.Bank.SafeBox.WorkSum));
     //
     //
@@ -4490,7 +4492,7 @@ end;
 procedure TNetConnection.TcpClient_OnConnect(Sender: TObject);
 procedure TNetConnection.TcpClient_OnConnect(Sender: TObject);
 begin
 begin
   TNetData.NetData.IncStatistics(1,0,1,0,0,0);
   TNetData.NetData.IncStatistics(1,0,1,0,0,0);
-  TLog.NewLog(ltInfo,Classname,'Connected to a server '+ClientRemoteAddr);
+  TLog.NewLog(ltdebug,Classname,'Connected to a server '+ClientRemoteAddr);
   TNetData.NetData.NotifyNetConnectionUpdated;
   TNetData.NetData.NotifyNetConnectionUpdated;
 end;
 end;
 
 
@@ -5046,7 +5048,7 @@ begin
     for i := 0 to list.Count - 1 do begin
     for i := 0 to list.Count - 1 do begin
       s := s + ',' + IntToStr(PNetworkAdjustedTimeReg(list[i])^.timeOffset);
       s := s + ',' + IntToStr(PNetworkAdjustedTimeReg(list[i])^.timeOffset);
     end;
     end;
-    TLog.NewLog(ltinfo,ClassName,
+    TLog.NewLog(ltdebug,ClassName,
       Format('Updated NAT median offset. My offset is now %d (before %d) based on %d/%d connections %s',[FTimeOffset,last,list.Count,FTotalCounter,s]));
       Format('Updated NAT median offset. My offset is now %d (before %d) based on %d/%d connections %s',[FTimeOffset,last,list.Count,FTotalCounter,s]));
   end;
   end;
 end;
 end;

+ 7 - 1
src/core/UNode.pas

@@ -108,6 +108,7 @@ Type
     Property BroadcastData : Boolean read FBroadcastData write FBroadcastData;
     Property BroadcastData : Boolean read FBroadcastData write FBroadcastData;
     Property UpdateBlockchain : Boolean read FUpdateBlockchain write FUpdateBlockchain;
     Property UpdateBlockchain : Boolean read FUpdateBlockchain write FUpdateBlockchain;
     procedure MarkVerifiedECDSASignaturesFromMemPool(newOperationsToValidate : TPCOperationsComp);
     procedure MarkVerifiedECDSASignaturesFromMemPool(newOperationsToValidate : TPCOperationsComp);
+    class function NodeVersion : AnsiString;
   End;
   End;
 
 
   TNodeNotifyEvents = Class;
   TNodeNotifyEvents = Class;
@@ -549,7 +550,7 @@ begin
   FNodeLog.ProcessGlobalLogs := false;
   FNodeLog.ProcessGlobalLogs := false;
   RegisterOperationsClass;
   RegisterOperationsClass;
   if Assigned(_Node) then raise Exception.Create('Duplicate nodes protection');
   if Assigned(_Node) then raise Exception.Create('Duplicate nodes protection');
-  TLog.NewLog(ltInfo,ClassName,'TNode.Create');
+  TLog.NewLog(ltInfo,ClassName,'TNode.Create '+NodeVersion);
   inherited;
   inherited;
   FDisabledsNewBlocksCount := 0;
   FDisabledsNewBlocksCount := 0;
   FLockNodeOperations := TPCCriticalSection.Create('TNode_LockNodeOperations');
   FLockNodeOperations := TPCCriticalSection.Create('TNode_LockNodeOperations');
@@ -778,6 +779,11 @@ begin
   Result := Assigned(_Node);
   Result := Assigned(_Node);
 end;
 end;
 
 
+class function TNode.NodeVersion: AnsiString;
+begin
+  Result := CT_ClientAppVersion{$IFDEF LINUX}+'l'{$ELSE}+'w'{$ENDIF}{$IFDEF FPC}{$IFDEF LCL}+'L'{$ELSE}+'F'{$ENDIF}{$ENDIF}{$IFDEF FPC}{$IFDEF CPU32}+'32b'{$ELSE}+'64b'{$ENDIF}{$ELSE}{$IFDEF CPU32BITS}+'32b'{$ELSE}+'64b'{$ENDIF}{$ENDIF};
+end;
+
 procedure TNode.Notification(AComponent: TComponent; Operation: TOperation);
 procedure TNode.Notification(AComponent: TComponent; Operation: TOperation);
 begin
 begin
   inherited;
   inherited;