Bläddra i källkod

Handeled pascalcoin comments

- Fixed memory leak
- Better while condition and break when !canrecover
kapytanhook 3 år sedan
förälder
incheckning
8f3865eba2
2 ändrade filer med 21 tillägg och 11 borttagningar
  1. 15 9
      src/core/UBlockChain.pas
  2. 6 2
      src/core/UPoolMining.pas

+ 15 - 9
src/core/UBlockChain.pas

@@ -2120,6 +2120,7 @@ end;
 function TPCOperationsComp.AddMinerRecover(LRecoverAccounts: TAccountList): Boolean;
 var
   LAccount: TAccount;
+  LOpRecoverFounds: TOpRecoverFounds;
   i: Integer;
   errors: string;
 begin
@@ -2129,15 +2130,20 @@ begin
   try
     for i:=0 to LRecoverAccounts.Count-1 do begin
       LAccount := LRecoverAccounts[i];
-      if not(
-        Self.AddOperation(
-          True,
-          TOpRecoverFounds.Create(Self.OperationBlock.protocol_version, LAccount.account, LAccount.n_operation+1, 0, Self.AccountKey),
-          errors
-        )
-      ) then begin
-        // if it fails then it number of operations could be maxed out, not a problem
-        Break;
+      LOpRecoverFounds := TOpRecoverFounds.Create(Self.OperationBlock.protocol_version, LAccount.account, LAccount.n_operation+1, 0, Self.AccountKey);
+      try
+        if not(
+          Self.AddOperation(
+            True,
+            LOpRecoverFounds,
+            errors
+          )
+        ) then begin
+          // if it fails then it number of operations could be maxed out, not a problem
+          Break;
+        end;
+      finally
+        LOpRecoverFounds.Free;
       end;
     end;
   finally

+ 6 - 2
src/core/UPoolMining.pas

@@ -953,9 +953,10 @@ var
   LAccOrd: TAccountsOrderedByUpdatedBlock;
   LAccount: TAccount;
   LRecoverAccounts: TList<TAccount>;
-  LIndexKey, LRecIndex: Integer;
+  LIndexKey, LRecIndex, LRecoverAccountsCount: Integer;
 begin
   LIndexKey := 0;
+  LRecoverAccountsCount := 0;
   LRecoverAccounts := TList<TAccount>.Create(); // make a list of RecoverAccounts
   nbOperations.Lock;
   try
@@ -964,10 +965,13 @@ begin
       LAccount := CT_Account_NUL;
       if LAccOrd.First(LIndexKey) then begin
         LRecIndex := 0;
-        while (LRecIndex < 500) do begin // Will recover at most 500 accounts per mined block (unrealistic to have more, fewer TAccountComp.AccountCanRecover checks required)
+        LRecoverAccountsCount := LAccOrd.Count;
+        while ((LRecIndex < LRecoverAccountsCount) and (LRecIndex < CT_MAX_0_fee_operations_per_block_by_miner)) do begin
           LAccount := FNodeNotifyEvents.Node.GetMempoolAccount(LIndexKey);
           if(TAccountComp.AccountCanRecover(LAccount, nbOperations.OperationBlock.block)) then begin // does the AccountCanRecover check, !locked, old enough, etc
             LRecoverAccounts.Add(LAccount);
+          end else begin
+            Break; // we could not recover this account, then we can never recover move recent accounts
           end;
           if Not LAccOrd.Next(LIndexKey) then Break;
           Inc(LRecIndex);