From 5aecb2edbc32d34b9b196a69a4f3ef40c5326010 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Mon, 15 Jan 2024 15:04:34 +0100 Subject: [PATCH 1/7] Improved blockchain download on NetProtocol --- src/core/UNetProtocol.pas | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/core/UNetProtocol.pas b/src/core/UNetProtocol.pas index 436ba2b5..64a2756d 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,12 @@ 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; + end; + {$ENDIF} end; end; From 0015024f8ddf6b87f912e43440638e3a8e1b1d27 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Mon, 15 Jan 2024 15:08:43 +0100 Subject: [PATCH 2/7] Minor improvements --- src/core/UBlockChain.pas | 10 ---------- src/core/UPCAbstractMem.pas | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) 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/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; From c052738b59470dbb8ad85e5902025e79b5f6ae6b Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Wed, 17 Jan 2024 09:17:33 +0100 Subject: [PATCH 3/7] Flushing blockchain cache once downloaded blocks --- src/core/UNetProtocol.pas | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/UNetProtocol.pas b/src/core/UNetProtocol.pas index 64a2756d..4822edef 100644 --- a/src/core/UNetProtocol.pas +++ b/src/core/UNetProtocol.pas @@ -3049,6 +3049,9 @@ procedure TNetConnection.DoProcess_GetBlocks_Response(HeaderData: TNetHeaderData 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; From e15d2c82ab4225450924a29a27c716c2e4ab1a22 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Wed, 17 Jan 2024 14:36:42 +0100 Subject: [PATCH 4/7] Update UAbstractMemBlockchainStorage.pas --- src/core/UAbstractMemBlockchainStorage.pas | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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; From ebd4836768251669e0a1b760ba61b3b0e01301e1 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Wed, 17 Jan 2024 14:47:30 +0100 Subject: [PATCH 5/7] Update UFRMWallet.pas --- src/gui-classic/UFRMWallet.pas | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From f5e08f84be0d2e64a389001c2066fb979be3ece2 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Wed, 17 Jan 2024 14:55:11 +0100 Subject: [PATCH 6/7] Build 5.8 ## 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 --- CHANGELOG.md | 6 ++++++ src/core/UConst.pas | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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/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}; From 20debdadad53106fcc1eb33f7cf979518271e950 Mon Sep 17 00:00:00 2001 From: PascalCoin Date: Wed, 17 Jan 2024 14:56:10 +0100 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ea2c47e..997b2136 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ ``` -Copyright (c) 2016-2022 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.