Skip to content

Commit

Permalink
Improved blockchain download on NetProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalCoinDev committed Jan 15, 2024
1 parent bc6f2b0 commit 5aecb2e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/core/UNetProtocol.pas
Original file line number Diff line number Diff line change
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,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;

Expand Down

0 comments on commit 5aecb2e

Please sign in to comment.