Skip to content

Commit

Permalink
Merge pull request #74 from PascalCoinDev/master
Browse files Browse the repository at this point in the history
Build 5.8
  • Loading branch information
PascalCoinDev committed Jan 24, 2024
2 parents aba8ab5 + 21db3ef commit 780934e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
37 changes: 36 additions & 1 deletion src/core/UAbstractMemBlockchainStorage.pas
Expand Up @@ -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;
Expand Down Expand Up @@ -1981,6 +1982,7 @@ constructor TAbstractMemBlockchainStorageSecondary.Create(AOwner: TComponent);
begin
inherited;
FAuxStorage := Nil;
FSaving := False;
end;

destructor TAbstractMemBlockchainStorageSecondary.Destroy;
Expand All @@ -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
Expand All @@ -2003,6 +2006,7 @@ procedure TAbstractMemBlockchainStorageSecondary.DoBlockNotFound(ABlock: Integer
end;
Finally
LOperationsComp.Free;
FSaving := False;
End;
end;
end;
Expand All @@ -2017,13 +2021,44 @@ 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
FAuxStorage := TFileStorage.Create(Self);
FAuxStorage.Bank := Self.Bank;
FAuxStorage.ReadOnly := Self.ReadOnly;
Result := FAuxStorage.Initialize;
// Try to fill secondary with newest blocks...
FillSecondary;
end;
end;

Expand All @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/core/UBlockChain.pas
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/UConst.pas
Expand Up @@ -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};
Expand Down
23 changes: 18 additions & 5 deletions src/core/UNetProtocol.pas
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions src/core/UPCAbstractMem.pas
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/gui-classic/UFRMWallet.pas
Expand Up @@ -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;
Expand Down Expand Up @@ -436,6 +438,7 @@ procedure TFRMWallet.Activate;
Raise;
end;
End;
UpdateConfigChanged(Self);
ips := TSettings.TryConnectOnlyWithThisFixedServers;
TNode.DecodeIpStringToNodeServerAddressArray(ips,nsarr);
TNetData.NetData.DiscoverFixedServersOnly(nsarr);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 780934e

Please sign in to comment.