Просмотр исходного кода

Merge pull request #74 from PascalCoinDev/master

Build 5.8
Albert M 1 год назад
Родитель
Сommit
780934e2e3

+ 6 - 0
CHANGELOG.md

@@ -7,6 +7,12 @@
 - Implementation of PIP-0044 (Induplicatable NFT) -> https://github.com/PascalCoin/PascalCoin/blob/master/PIP/PIP-0044.md
 - Improvements on downloading Safebox (fresh installation)
 
+## Build 5.8 - 2024-01-17
+- Accumulative release, including:
+- Minor bugs fixed
+- Usage of AbstractMem v1.8
+- Improvements on speed and data storage (see Github commits since last release)
+- Clean code and documentation
 
 ## Build 5.7 - 2021-12-23
 - This version will not propagate 0-Fee operations, but will allow 0-Fee operations to the blockchain (CT_AllowPropagate0feeOperations=False)

+ 1 - 1
README.md

@@ -12,7 +12,7 @@
 
 
 ```
-Copyright (c) 2016-2023 Pascal developers based on original Albert Molina source code
+Copyright (c) 2016-2024 Pascal developers based on original Albert Molina source code
 ```
 
 Please use at your own risk.

+ 36 - 1
src/core/UAbstractMemBlockchainStorage.pas

@@ -265,6 +265,7 @@ type
   TAbstractMemBlockchainStorageSecondary = Class(TAbstractMemBlockchainStorage)
   private
     FAuxStorage : TStorage;
+    FSaving : Boolean;
   protected
     procedure SetReadOnly(const Value: Boolean); override;
     Function DoSaveBlockChain(Operations : TPCOperationsComp) : Boolean; override;
@@ -1981,6 +1982,7 @@ constructor TAbstractMemBlockchainStorageSecondary.Create(AOwner: TComponent);
 begin
   inherited;
   FAuxStorage := Nil;
+  FSaving := False;
 end;
 
 destructor TAbstractMemBlockchainStorageSecondary.Destroy;
@@ -1995,6 +1997,7 @@ begin
   inherited;
   AFound := False;
   if (Assigned(FAuxStorage)) then begin
+    FSaving := True;
     LOperationsComp := TPCOperationsComp.Create(Nil);
     Try
       if FAuxStorage.LoadBlockChainBlock(LOperationsComp,ABlock) then begin
@@ -2003,6 +2006,7 @@ begin
       end;
     Finally
       LOperationsComp.Free;
+      FSaving := False;
     End;
   end;
 end;
@@ -2017,6 +2021,35 @@ begin
 end;
 
 function TAbstractMemBlockchainStorageSecondary.DoInitialize: Boolean;
+  procedure FillSecondary;
+  var i, LTotal, LNotFound : Integer;
+    Ltc : TTickCount;
+    LOpComp : TPCOperationsComp;
+  begin
+    i := FAuxStorage.LastBlock;
+    if i>=Self.LastBlock then Exit;
+    TLog.NewLog(ltdebug,ClassName,Format('Start filling secondary storage with blocks from %d to %d',[i,Self.LastBlock]));
+    Ltc := TPlatform.GetTickCount;
+    LOpComp := TPCOperationsComp.Create(Nil);
+    try
+      LTotal := 0; LNotFound := 0;
+      while (i<=Self.LastBlock) do begin
+        if (Self.DoLoadBlockChain(LOpComp,i)) then begin
+          inc(LTotal);
+          FAuxStorage.SaveBlockChainBlock(LOpComp);
+        end else inc(LNotFound);
+        inc(i);
+        if TPlatform.GetElapsedMilliseconds(Ltc)>10000 then begin
+          TLog.NewLog(ltdebug,ClassName,Format('Filling secondary storage with blocks current %d to %d done %d not found %d',[i,Self.LastBlock,LTotal,LNotFound]));
+          Ltc := TPlatform.GetTickCount;
+        end;
+      end;
+    finally
+      LOpComp.Free;
+    end;
+    TLog.NewLog(ltdebug,ClassName,Format('Finalized filling secondary storage with blocks to %d done %d not found %d',[Self.LastBlock,LTotal,LNotFound]));
+  end;
+
 begin
   Result := inherited DoInitialize;
   if (Result) And (Not Assigned(FAuxStorage)) then begin
@@ -2024,6 +2057,8 @@ begin
     FAuxStorage.Bank := Self.Bank;
     FAuxStorage.ReadOnly := Self.ReadOnly;
     Result := FAuxStorage.Initialize;
+    // Try to fill secondary with newest blocks...
+    FillSecondary;
   end;
 end;
 
@@ -2040,7 +2075,7 @@ function TAbstractMemBlockchainStorageSecondary.DoSaveBlockChain(
   Operations: TPCOperationsComp): Boolean;
 begin
   Result := inherited;
-  if (Result) and (Assigned(FAuxStorage)) then begin
+  if (Result) and (Assigned(FAuxStorage)) and (Not FSaving) then begin
     Result := FAuxStorage.SaveBlockChainBlock(Operations);
   end;
 end;

+ 0 - 10
src/core/UBlockChain.pas

@@ -1097,7 +1097,6 @@ var fs: TFileStream;
     LBankfilename,Laux_newfilename: AnsiString;
     ms : TMemoryStream;
   LTC : TTickCount;
-  LOldB : Boolean;
 begin
   Result := true;
   LBankfilename := GetSafeboxCheckpointingFileName(GetStorageFolder(Orphan),BlocksCount);
@@ -1142,16 +1141,7 @@ begin
         end;
       end;
     end;
-    // Flush pending
-    if (FStorage is TAbstractMemBlockchainStorage) then begin
-      LOldB := TAbstractMemBlockchainStorage(FStorage).UseMultithread;
-      TAbstractMemBlockchainStorage(FStorage).UseMultithread := False;
-      TAbstractMemBlockchainStorage(FStorage).UseMultithread := LOldB;
-
-    end;
   end;
-
-
 end;
 
 procedure TPCBank.UpdateValuesFromSafebox;

+ 1 - 1
src/core/UConst.pas

@@ -199,7 +199,7 @@ Const
   CT_OpSubtype_Data_Signer                = 103;
   CT_OpSubtype_Data_Receiver              = 104;
 
-  CT_ClientAppVersion : String = {$IFDEF PRODUCTION}'5.7.2'{$ELSE}{$IFDEF TESTNET}'TESTNET 5.7.2'{$ELSE}{$ENDIF}{$ENDIF};
+  CT_ClientAppVersion : String = {$IFDEF PRODUCTION}'5.8'{$ELSE}{$IFDEF TESTNET}'TESTNET 5.8'{$ELSE}{$ENDIF}{$ENDIF};
 
   CT_Discover_IPs = {$IFDEF PRODUCTION}'bpascal1.dynamic-dns.net;bpascal2.dynamic-dns.net;pascalcoin1.dynamic-dns.net;pascalcoin2.dynamic-dns.net;pascalcoin1.dns1.us;pascalcoin2.dns1.us;pascalcoin1.dns2.us;pascalcoin2.dns2.us'
                     {$ELSE}'pascaltestnet1.dynamic-dns.net;pascaltestnet2.dynamic-dns.net;pascaltestnet1.dns1.us;pascaltestnet2.dns1.us'{$ENDIF};

+ 18 - 5
src/core/UNetProtocol.pas

@@ -36,7 +36,7 @@ Uses
   UPCDataTypes,
   {$IFNDEF FPC}System.Generics.Collections,System.Generics.Defaults
   {$ELSE}Generics.Collections,Generics.Defaults{$ENDIF},
-  {$IFDEF USE_ABSTRACTMEM}UPCAbstractMem,{$ENDIF}
+  {$IFDEF USE_ABSTRACTMEM}UPCAbstractMem, UAbstractMemBlockchainStorage,{$ENDIF}
   UNetProtection;
 
 Const
@@ -2950,8 +2950,15 @@ procedure TNetConnection.DoProcess_GetBlocks_Response(HeaderData: TNetHeaderData
   DoDisconnect : Boolean;
   LBlocks : TList<TPCOperationsComp>;
   LSafeboxTransaction : TPCSafeBoxTransaction;
+  LPrevious : Boolean;
 begin
   DoDisconnect := true;
+  {$IFDEF USE_ABSTRACTMEM}
+  if (TNode.Node.Bank.Storage is TAbstractMemBlockchainStorage) then begin
+    LPrevious := TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).AutoFlushCache;
+    TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).AutoFlushCache := False;
+  end;
+  {$ENDIF}
   try
     if HeaderData.header_type<>ntp_response then begin
       errors := 'Not response';
@@ -3019,13 +3026,10 @@ begin
         end;
         sleep(1);
       end;
-      {$IFDEF USE_ABSTRACTMEM}
-      TNode.Node.Bank.SafeBox.PCAbstractMem.FlushCache;
-      {$ENDIF}
 
       FIsDownloadingBlocks := false;
       if ((LOpCount>0) And (FRemoteOperationBlock.block>=TNode.Node.Bank.BlocksCount)) then begin
-        Send_GetBlocks(TNode.Node.Bank.BlocksCount,100,c);
+        Send_GetBlocks(TNode.Node.Bank.BlocksCount,100+Random(300),c);
       end else begin
         // No more blocks to download, download Pending operations
         DoProcess_GetPendingOperations;
@@ -3041,6 +3045,15 @@ begin
     if DoDisconnect then begin
       DisconnectInvalidClient(false,errors+' > '+TNetData.HeaderDataToText(HeaderData)+' BuffSize: '+inttostr(DataBuffer.Size));
     end;
+    {$IFDEF USE_ABSTRACTMEM}
+    TNode.Node.Bank.SafeBox.PCAbstractMem.FlushCache;
+    if (TNode.Node.Bank.Storage is TAbstractMemBlockchainStorage) then begin
+      TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).AutoFlushCache := LPrevious;
+      if TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).PendingToSave = 0 then begin
+        TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).FileMem.FlushCache;
+      end;
+    end;
+    {$ENDIF}
   end;
 end;
 

+ 9 - 0
src/core/UPCAbstractMem.pas

@@ -613,6 +613,7 @@ begin
   end;
   Inc(FStats.FlushesCount);
   Inc(Fstats.FlushesMillis, TPlatform.GetElapsedMilliseconds(Ltc) );
+  TLog.NewLog(ltdebug,Self.ClassName,Format('AbstractMem Safebox flushed in %.2f seconds',[TPlatform.GetElapsedMilliseconds(Ltc)/1000]));
 end;
 
 Procedure DoCopyFile(const ASource, ADest : String);
@@ -795,6 +796,7 @@ end;
 
 procedure TPCAbstractMem.UpdateSafeboxFileName(const ANewSafeboxFileName: String);
 var LReadOnly, Ltmp : Boolean;
+  LCacheMem : TCacheMem;
 begin
   if SameFileName(FFileName,ANewSafeboxFileName) then Exit;
 
@@ -812,6 +814,13 @@ begin
   end;
   if FAbstractMem is TFileMem then begin
     TFileMem(FAbstractMem).SetCachePerformance(True,1024,FMaxMemUsage,200000);
+    LCacheMem := TFileMem(FAbstractMem).LockCache;
+    Try
+      LCacheMem.OnFlushedCache := OnCacheMemFlushedCache;
+      LCacheMem.OnLog := OnCacheMemLog;
+    Finally
+      TFileMem(FAbstractMem).UnlockCache;
+    End;
   end;
   DoInit(Ltmp);
 end;

+ 3 - 1
src/gui-classic/UFRMWallet.pas

@@ -393,7 +393,9 @@ begin
   FLastTC := 0;
   OnProgressNotify(Self,'Initializing databases',0,0);
   // Read Operations saved from disk
+  TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).AutoFlushCache := False;
   TNode.Node.InitSafeboxAndOperations($FFFFFFFF,OnProgressNotify); // New Build 2.1.4 to load pending operations buffer
+  TAbstractMemBlockchainStorage( TNode.Node.Bank.Storage ).AutoFlushCache := True;
   TNode.Node.AutoDiscoverNodes(CT_Discover_IPs);
   TNode.Node.NetServer.Active := true;
   FLastTC := 0;
@@ -436,6 +438,7 @@ begin
         Raise;
       end;
     End;
+    UpdateConfigChanged(Self);
     ips := TSettings.TryConnectOnlyWithThisFixedServers;
     TNode.DecodeIpStringToNodeServerAddressArray(ips,nsarr);
     TNetData.NetData.DiscoverFixedServersOnly(nsarr);
@@ -472,7 +475,6 @@ begin
     FThreadActivate := TThreadActivate.Create(true);
     TThreadActivate(FThreadActivate).FreeOnTerminate := true;
     TThreadActivate(FThreadActivate).Suspended := False;
-    UpdateConfigChanged(Self);
     UpdateNodeStatus;
     TPCTNetDataExtraMessages.InitNetDataExtraMessages(FNode,TNetData.NetData,FWalletKeys);
   Except