Browse Source

Forced GUI update caused by abstractmem usage

PascalCoin 5 years ago
parent
commit
95ead7bd5f

+ 1 - 0
src/gui-classic/UFRMAccountSelect.pas

@@ -28,6 +28,7 @@ uses
 {$ELSE}
 {$ELSE}
   LCLIntf, LCLType, LMessages,
   LCLIntf, LCLType, LMessages,
 {$ENDIF}
 {$ENDIF}
+  UPCDataTypes,
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, UAccounts, Grids, StdCtrls, Buttons, ExtCtrls, UWallet, UNode,
   Dialogs, UAccounts, Grids, StdCtrls, Buttons, ExtCtrls, UWallet, UNode,
   UGridUtils, UConst, UThread, UPCOrderedLists, UBaseTypes;
   UGridUtils, UConst, UThread, UPCOrderedLists, UBaseTypes;

+ 2 - 2
src/gui-classic/UFRMOperation.pas

@@ -32,7 +32,7 @@ uses
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls, UNode, UWallet, UCrypto, Buttons, UBlockChain,
   Dialogs, StdCtrls, UNode, UWallet, UCrypto, Buttons, UBlockChain,
   UAccounts, UFRMAccountSelect, ActnList, ComCtrls, Types, UFRMMemoText,
   UAccounts, UFRMAccountSelect, ActnList, ComCtrls, Types, UFRMMemoText,
-  UPCEncryption, UBaseTypes, UPCOrderedLists;
+  UPCEncryption, UBaseTypes, UPCDataTypes, UPCOrderedLists;
 
 
 Const
 Const
   CM_PC_WalletKeysChanged = WM_USER + 1;
   CM_PC_WalletKeysChanged = WM_USER + 1;
@@ -192,7 +192,7 @@ implementation
 
 
 uses
 uses
   UConst, UOpTransaction, UFRMNewPrivateKeyType, UFRMWalletKeys, UFRMHashLock,
   UConst, UOpTransaction, UFRMNewPrivateKeyType, UFRMWalletKeys, UFRMHashLock,
-  UCommon, UPCDataTypes, ULog, UGUIUtils;
+  UCommon, ULog, UGUIUtils;
 
 
 {$IFnDEF FPC}
 {$IFnDEF FPC}
   {$R *.dfm}
   {$R *.dfm}

+ 1 - 1
src/gui-classic/UFRMOperationsExplorer.pas

@@ -132,7 +132,7 @@ Uses
 {$IFDEF TESTNET}
 {$IFDEF TESTNET}
    UFRMRandomOperations,
    UFRMRandomOperations,
 {$ENDIF}
 {$ENDIF}
-   UFRMRPCCalls, UFRMMemoText;
+   UPCDataTypes, UFRMRPCCalls, UFRMMemoText;
 
 
 
 
 { TFRMOperationsExplorer }
 { TFRMOperationsExplorer }

+ 2 - 0
src/gui-classic/UFRMRandomOperations.pas

@@ -129,6 +129,8 @@ implementation
   {$R *.lfm}
   {$R *.lfm}
 {$ENDIF}
 {$ENDIF}
 
 
+uses UPCDataTypes;
+
 { TRandomGeneratorThread }
 { TRandomGeneratorThread }
 
 
 procedure TRandomGeneratorThread.OnBankNewBlock(Sender: TObject);
 procedure TRandomGeneratorThread.OnBankNewBlock(Sender: TObject);

+ 7 - 2
src/gui-classic/UFRMWallet.pas

@@ -34,7 +34,7 @@ uses
   ExtCtrls, ComCtrls, UWallet, StdCtrls, ULog, Grids, UAppParams, UBlockChain,
   ExtCtrls, ComCtrls, UWallet, StdCtrls, ULog, Grids, UAppParams, UBlockChain,
   UNode, UGridUtils, UJSONFunctions, UAccounts, Menus, ImgList, UNetProtocol,
   UNode, UGridUtils, UJSONFunctions, UAccounts, Menus, ImgList, UNetProtocol,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
-  UAccountKeyStorage, UBaseTypes, UPCDataTypes,
+  UAccountKeyStorage, UBaseTypes, UPCDataTypes, UOrderedList,
   UFRMRPCCalls, UTxMultiOperation,
   UFRMRPCCalls, UTxMultiOperation,
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
 
@@ -338,6 +338,7 @@ Uses UFolderHelper,
   UPCTNetDataExtraMessages,
   UPCTNetDataExtraMessages,
   UFRMDiagnosticTool,
   UFRMDiagnosticTool,
   {$ENDIF}
   {$ENDIF}
+  UAbstractBTree,
   UFRMAbout, UFRMOperation, UFRMWalletKeys, UFRMPayloadDecoder, UFRMNodesIp, UFRMMemoText,
   UFRMAbout, UFRMOperation, UFRMWalletKeys, UFRMPayloadDecoder, UFRMNodesIp, UFRMMemoText,
   USettings, UCommon, UPCOrderedLists;
   USettings, UCommon, UPCOrderedLists;
 
 
@@ -393,6 +394,8 @@ begin
     ExtractFileDir(Application.ExeName)+PathDelim+CT_Hardcoded_RandomHash_Table_Filename,
     ExtractFileDir(Application.ExeName)+PathDelim+CT_Hardcoded_RandomHash_Table_Filename,
     LRaw );
     LRaw );
   {$ENDIF}
   {$ENDIF}
+  FLastTC := 0;
+  OnProgressNotify(Self,'Initializing databases',0,0);
   // Read Operations saved from disk
   // Read Operations saved from disk
   TNode.Node.InitSafeboxAndOperations($FFFFFFFF,OnProgressNotify); // New Build 2.1.4 to load pending operations buffer
   TNode.Node.InitSafeboxAndOperations($FFFFFFFF,OnProgressNotify); // New Build 2.1.4 to load pending operations buffer
   TNode.Node.AutoDiscoverNodes(CT_Discover_IPs);
   TNode.Node.AutoDiscoverNodes(CT_Discover_IPs);
@@ -1207,6 +1210,7 @@ begin
           TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(acc.accountInfo.new_publicKey))]));
           TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(acc.accountInfo.new_publicKey))]));
       end;
       end;
     end;
     end;
+    {$IFnDEF USE_ABSTRACTMEM}
     l := TAccountKeyStorage.KS.LockList;
     l := TAccountKeyStorage.KS.LockList;
     try
     try
       sl.Add(Format('%d public keys in TAccountKeyStorage data',[l.count]));
       sl.Add(Format('%d public keys in TAccountKeyStorage data',[l.count]));
@@ -1240,6 +1244,7 @@ begin
         ak.EC_OpenSSL_NID,
         ak.EC_OpenSSL_NID,
         TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(ak)) ]));
         TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(ak)) ]));
     end;
     end;
+    {$ENDIF}
     F := TFRMMemoText.Create(Self);
     F := TFRMMemoText.Create(Self);
     try
     try
       F.InitData('Keys in safebox',sl.Text);
       F.InitData('Keys in safebox',sl.Text);
@@ -2558,7 +2563,7 @@ begin
     FLog.OnNewLog := Nil;
     FLog.OnNewLog := Nil;
     if PageControl.ActivePage = tsLogs then PageControl.ActivePage := tsMyAccounts;
     if PageControl.ActivePage = tsLogs then PageControl.ActivePage := tsMyAccounts;
   end else FLog.OnNewLog := OnNewLog;
   end else FLog.OnNewLog := OnNewLog;
-  if FAppParams.ParamByName[CT_PARAM_SaveLogFiles].GetAsBoolean(false) then begin
+  if (FAppParams.ParamByName[CT_PARAM_SaveLogFiles].GetAsBoolean(false)) then begin
     if FAppParams.ParamByName[CT_PARAM_SaveDebugLogs].GetAsBoolean(false) then FLog.SaveTypes := CT_TLogTypes_ALL
     if FAppParams.ParamByName[CT_PARAM_SaveDebugLogs].GetAsBoolean(false) then FLog.SaveTypes := CT_TLogTypes_ALL
     else FLog.SaveTypes := CT_TLogTypes_DEFAULT;
     else FLog.SaveTypes := CT_TLogTypes_DEFAULT;
     FLog.FileName := TNode.GetPascalCoinDataFolder+PathDelim+'PascalCointWallet.log';
     FLog.FileName := TNode.GetPascalCoinDataFolder+PathDelim+'PascalCointWallet.log';

+ 6 - 2
src/gui-classic/UFRMWalletKeys.pas

@@ -96,7 +96,7 @@ uses
   LCLIntf, LCLType,
   LCLIntf, LCLType,
 {$ENDIF}
 {$ENDIF}
   UCrypto, UAccounts, UFRMNewPrivateKeyType, UBaseTypes, UPCEncryption,
   UCrypto, UAccounts, UFRMNewPrivateKeyType, UBaseTypes, UPCEncryption,
-  UCommon, UGUIUtils;
+  UPCDataTypes, UCommon, UGUIUtils;
 
 
 {$IFnDEF FPC}
 {$IFnDEF FPC}
   {$R *.dfm}
   {$R *.dfm}
@@ -580,6 +580,7 @@ procedure TFRMWalletKeys.UpdateWalletKeys;
 Var lasti,i,j : Integer;
 Var lasti,i,j : Integer;
   selected_wk,wk : TWalletKey;
   selected_wk,wk : TWalletKey;
   s : AnsiString;
   s : AnsiString;
+  Lanl : TAccountsNumbersList;
 begin
 begin
   GetSelectedWalletKeyAndIndex(wk,lasti);
   GetSelectedWalletKeyAndIndex(wk,lasti);
   lbWalletKeys.Items.BeginUpdate;
   lbWalletKeys.Items.BeginUpdate;
@@ -608,7 +609,10 @@ begin
       if (WalletKeys is TWalletKeysExt) then begin
       if (WalletKeys is TWalletKeysExt) then begin
         j := TWalletKeysExt(WalletKeys).AccountsKeyList.IndexOfAccountKey(wk.AccountKey);
         j := TWalletKeysExt(WalletKeys).AccountsKeyList.IndexOfAccountKey(wk.AccountKey);
         if (j>=0) then begin
         if (j>=0) then begin
-          s := s+' ('+IntToStr(TWalletKeysExt(WalletKeys).AccountsKeyList.AccountKeyList[j].Count)+' Accounts)';
+          Lanl := TWalletKeysExt(WalletKeys).AccountsKeyList.AccountKeyList[j];
+          if Assigned(Lanl) then begin
+            s := s+' ('+IntToStr(Lanl.Count)+' Accounts)';
+          end else s := s+' (No Accounts)';
         end;
         end;
       end;
       end;
       if Not Assigned(wk.PrivateKey) then begin
       if Not Assigned(wk.PrivateKey) then begin

+ 36 - 14
src/gui-classic/UGridUtils.pas

@@ -30,7 +30,7 @@ uses
 {$ELSE}
 {$ELSE}
   LCLIntf, LCLType, LMessages,
   LCLIntf, LCLType, LMessages,
 {$ENDIF}
 {$ENDIF}
-  Classes, Grids, UNode, UAccounts, UBlockChain, UAppParams, UThread,
+  Classes, Grids, UNode, UAccounts, UBlockChain, UAppParams, UThread, UPCDataTypes,
   UWallet, UCrypto, UPoolMining, URPC, UBaseTypes, UPCOrderedLists,
   UWallet, UCrypto, UPoolMining, URPC, UBaseTypes, UPCOrderedLists,
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
 
@@ -289,8 +289,8 @@ uses
 
 
 procedure TAccountsGridUpdateThread.BCExecute;
 procedure TAccountsGridUpdateThread.BCExecute;
 Var
 Var
-  l : TOrderedCardinalList;
-  i,j : Integer;
+  l : TAccountsNumbersList;
+  i,j, j_min, j_max : Integer;
   c  : Cardinal;
   c  : Cardinal;
   LApplyfilter : Boolean;
   LApplyfilter : Boolean;
   LAccount : TAccount;
   LAccount : TAccount;
@@ -307,26 +307,44 @@ begin
         while (Not Terminated) and (i<FAccountsGridFilter.OrderedAccountsKeyList.Count)
         while (Not Terminated) and (i<FAccountsGridFilter.OrderedAccountsKeyList.Count)
           and ((FAccountsGridFilter.indexAccountsKeyList<0) or (FAccountsGridFilter.indexAccountsKeyList=i)) do begin
           and ((FAccountsGridFilter.indexAccountsKeyList<0) or (FAccountsGridFilter.indexAccountsKeyList=i)) do begin
 
 
+          j_min := 0;
+
+          while (j_min>=0) do begin
+
           LNode.bank.SafeBox.StartThreadSafe;
           LNode.bank.SafeBox.StartThreadSafe;
           FAccountsGridFilter.OrderedAccountsKeyList.Lock; // Protection v4
           FAccountsGridFilter.OrderedAccountsKeyList.Lock; // Protection v4
           Try
           Try
             l := FAccountsGridFilter.OrderedAccountsKeyList.AccountKeyList[i];
             l := FAccountsGridFilter.OrderedAccountsKeyList.AccountKeyList[i];
-            for j := 0 to l.Count - 1 do begin
-              LAccount := LNode.Bank.SafeBox.Account(l.Get(j));
-              if LApplyfilter then begin
-                if (LAccount.balance>=FAccountsGridFilter.MinBalance) And ((FAccountsGridFilter.MaxBalance<0) Or (LAccount.balance<=FAccountsGridFilter.MaxBalance)) then begin
+            if Assigned(l) then begin
+
+              j_max := (j_min + 500);
+              if j_max>=l.Count then j_max := l.Count-1;
+
+              for j := j_min to j_max do begin
+                LAccount := LNode.Bank.SafeBox.Account(l.Get(j));
+                if LApplyfilter then begin
+                  if (LAccount.balance>=FAccountsGridFilter.MinBalance) And ((FAccountsGridFilter.MaxBalance<0) Or (LAccount.balance<=FAccountsGridFilter.MaxBalance)) then begin
+                    FProcessedList.Add(LAccount.account);
+                    FBalance := FBalance + LAccount.balance;
+                  end;
+                end else begin
                   FProcessedList.Add(LAccount.account);
                   FProcessedList.Add(LAccount.account);
                   FBalance := FBalance + LAccount.balance;
                   FBalance := FBalance + LAccount.balance;
                 end;
                 end;
-              end else begin
-                FProcessedList.Add(LAccount.account);
-                FBalance := FBalance + LAccount.balance;
+                if Terminated then Exit;
+              end;
+              j_min := j_max+1;
+              if (j_max>=(l.Count-1)) then begin
+                j_min := -1;
+                break;
               end;
               end;
-              if Terminated then Exit;
             end;
             end;
           finally
           finally
             FAccountsGridFilter.OrderedAccountsKeyList.Unlock;
             FAccountsGridFilter.OrderedAccountsKeyList.Unlock;
             LNode.Bank.SafeBox.EndThreadSave;
             LNode.Bank.SafeBox.EndThreadSave;
+          end;
+            if j_max>=0 then Sleep(0);
+
           end;
           end;
           inc(i);
           inc(i);
         end;
         end;
@@ -342,10 +360,10 @@ begin
         end;
         end;
       end;
       end;
   Finally
   Finally
-    FisProcessing := False;
     if Not Terminated then begin
     if Not Terminated then begin
       Synchronize(SynchronizedOnTerminated);
       Synchronize(SynchronizedOnTerminated);
     end;
     end;
+    FisProcessing := False;
   End;
   End;
 end;
 end;
 
 
@@ -377,6 +395,7 @@ begin
     finally
     finally
       FAccountsGrid.UnlockAccountsList;
       FAccountsGrid.UnlockAccountsList;
     end;
     end;
+    FisProcessing := False;
     if Assigned(FAccountsGrid.FOnAccountsGridUpdatedData) then  FAccountsGrid.FOnAccountsGridUpdatedData(FAccountsGrid);
     if Assigned(FAccountsGrid.FOnAccountsGridUpdatedData) then  FAccountsGrid.FOnAccountsGridUpdatedData(FAccountsGrid);
   end;
   end;
 end;
 end;
@@ -860,7 +879,10 @@ begin
   LTmp := FAccountsGridUpdateThread;
   LTmp := FAccountsGridUpdateThread;
   FAccountsGridUpdateThread := Nil;
   FAccountsGridUpdateThread := Nil;
   if Assigned(Ltmp) then begin
   if Assigned(Ltmp) then begin
-    if Not AWaitUntilTerminated then LTmp.FreeOnTerminate := True;
+    if Not LTmp.IsProcessing then AWaitUntilTerminated := True;
+    if Not AWaitUntilTerminated then begin
+      LTmp.FreeOnTerminate := True;
+    end;
     LTmp.Terminate;
     LTmp.Terminate;
     if AWaitUntilTerminated then begin
     if AWaitUntilTerminated then begin
       LTmp.WaitFor;
       LTmp.WaitFor;
@@ -896,10 +918,10 @@ end;
 procedure TAccountsGrid.UpdateData;
 procedure TAccountsGrid.UpdateData;
 begin
 begin
   UpdateAccountsBalance;
   UpdateAccountsBalance;
+  TerminateAccountGridUpdateThread(False);
   if Assigned(Node) then begin
   if Assigned(Node) then begin
     case FAccountsGridDatasource of
     case FAccountsGridDatasource of
       acds_NodeFiltered: begin
       acds_NodeFiltered: begin
-        TerminateAccountGridUpdateThread(False);
         FAccountsBalance := 0;
         FAccountsBalance := 0;
         FAccountsGridUpdateThread := TAccountsGridUpdateThread.Create(Self,AccountsGridFilter);
         FAccountsGridUpdateThread := TAccountsGridUpdateThread.Create(Self,AccountsGridFilter);
       end;
       end;