diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c5fdf66..ae910827 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/README.md b/README.md index f0deef80..997b2136 100644 --- a/README.md +++ b/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. diff --git a/src/core/UAbstractMemBlockchainStorage.pas b/src/core/UAbstractMemBlockchainStorage.pas index d1221c70..bbb1850a 100644 --- a/src/core/UAbstractMemBlockchainStorage.pas +++ b/src/core/UAbstractMemBlockchainStorage.pas @@ -265,6 +265,7 @@ TPendingData = record 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 @@ procedure TAbstractMemBlockchainStorageSecondary.DoBlockNotFound(ABlock: Integer 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 @@ procedure TAbstractMemBlockchainStorageSecondary.DoBlockNotFound(ABlock: Integer end; Finally LOperationsComp.Free; + FSaving := False; End; end; end; @@ -2017,6 +2021,35 @@ procedure TAbstractMemBlockchainStorageSecondary.DoDeleteBlockChainBlocks( 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 @@ function TAbstractMemBlockchainStorageSecondary.DoInitialize: Boolean; 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; diff --git a/src/core/UBlockChain.pas b/src/core/UBlockChain.pas index 2ac3b37f..65da5bd7 100644 --- a/src/core/UBlockChain.pas +++ b/src/core/UBlockChain.pas @@ -1097,7 +1097,6 @@ function TPCBank.DoSaveBank: Boolean; LBankfilename,Laux_newfilename: AnsiString; ms : TMemoryStream; LTC : TTickCount; - LOldB : Boolean; begin Result := true; LBankfilename := GetSafeboxCheckpointingFileName(GetStorageFolder(Orphan),BlocksCount); @@ -1142,16 +1141,7 @@ function TPCBank.DoSaveBank: Boolean; 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; diff --git a/src/core/UConst.pas b/src/core/UConst.pas index ff7d5094..b69e25ca 100644 --- a/src/core/UConst.pas +++ b/src/core/UConst.pas @@ -199,7 +199,7 @@ interface 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}; diff --git a/src/core/UNetProtocol.pas b/src/core/UNetProtocol.pas index 436ba2b5..4822edef 100644 --- a/src/core/UNetProtocol.pas +++ b/src/core/UNetProtocol.pas @@ -36,7 +36,7 @@ interface 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; 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 @@ procedure TNetConnection.DoProcess_GetBlocks_Response(HeaderData: TNetHeaderData 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 @@ procedure TNetConnection.DoProcess_GetBlocks_Response(HeaderData: TNetHeaderData 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; diff --git a/src/core/UPCAbstractMem.pas b/src/core/UPCAbstractMem.pas index abbfc2b1..54767539 100644 --- a/src/core/UPCAbstractMem.pas +++ b/src/core/UPCAbstractMem.pas @@ -613,6 +613,7 @@ procedure TPCAbstractMem.FlushCache; 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 @@ procedure TPCAbstractMem.SetUseCacheOnAbstractMemLists(const Value: Boolean); procedure TPCAbstractMem.UpdateSafeboxFileName(const ANewSafeboxFileName: String); var LReadOnly, Ltmp : Boolean; + LCacheMem : TCacheMem; begin if SameFileName(FFileName,ANewSafeboxFileName) then Exit; @@ -812,6 +814,13 @@ procedure TPCAbstractMem.UpdateSafeboxFileName(const ANewSafeboxFileName: String 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; diff --git a/src/gui-classic/UFRMWallet.pas b/src/gui-classic/UFRMWallet.pas index a9640884..a66bcbda 100644 --- a/src/gui-classic/UFRMWallet.pas +++ b/src/gui-classic/UFRMWallet.pas @@ -393,7 +393,9 @@ procedure TThreadActivate.BCExecute; 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 @@ procedure TFRMWallet.Activate; Raise; end; End; + UpdateConfigChanged(Self); ips := TSettings.TryConnectOnlyWithThisFixedServers; TNode.DecodeIpStringToNodeServerAddressArray(ips,nsarr); TNetData.NetData.DiscoverFixedServersOnly(nsarr); @@ -472,7 +475,6 @@ procedure TFRMWallet.Activate; FThreadActivate := TThreadActivate.Create(true); TThreadActivate(FThreadActivate).FreeOnTerminate := true; TThreadActivate(FThreadActivate).Suspended := False; - UpdateConfigChanged(Self); UpdateNodeStatus; TPCTNetDataExtraMessages.InitNetDataExtraMessages(FNode,TNetData.NetData,FWalletKeys); Except