Browse Source

Converting TPCOperationsComp to TObject

Does not need to be TComponent, converting to TObject. Also detected possible Notification problem on destroy caused by multithread race condition at Bank component
PascalCoin 6 years ago
parent
commit
92501337d2
2 changed files with 6 additions and 21 deletions
  1. 5 20
      src/core/UBlockChain.pas
  2. 1 1
      src/core/UNode.pas

+ 5 - 20
src/core/UBlockChain.pas

@@ -341,7 +341,7 @@ Type
 
   { TPCOperationsComp }
 
-  TPCOperationsComp = Class(TComponent)
+  TPCOperationsComp = Class
   private
     FBank: TPCBank;
     FSafeBoxTransaction : TPCSafeBoxTransaction;
@@ -370,11 +370,10 @@ Type
     procedure SetBlockPayload(const Value: TRawBytes);
     procedure OnOperationsHashTreeChanged(Sender : TObject);
   protected
-    procedure Notification(AComponent: TComponent; Operation: TOperation); Override;
     function SaveBlockToStreamExt(save_only_OperationBlock : Boolean; Stream: TStream; SaveToStorage : Boolean): Boolean;
     function LoadBlockFromStreamExt(Stream: TStream; LoadingFromStorage : Boolean; var errors: AnsiString): Boolean;
   public
-    Constructor Create(AOwner: TComponent); Override;
+    Constructor Create(ABank: TPCBank);
     Destructor Destroy; Override;
     Procedure CopyFromExceptAddressKey(Operations : TPCOperationsComp);
     Procedure CopyFrom(Operations : TPCOperationsComp);
@@ -1351,9 +1350,8 @@ begin
   Result := FOperationsHashTree.OperationsCount;
 end;
 
-constructor TPCOperationsComp.Create(AOwner: TComponent);
+constructor TPCOperationsComp.Create(ABank: TPCBank);
 begin
-  inherited Create(AOwner);
   FOperationsLock := TPCCriticalSection.Create('TPCOperationsComp_OPERATIONSLOCK');
   FDisableds := 0;
   FStreamPoW := TMemoryStream.Create;
@@ -1364,8 +1362,8 @@ begin
   FOperationBlock := GetFirstBlock;
   FSafeBoxTransaction := Nil;
   FPreviousUpdatedBlocks := TAccountPreviousBlockInfo.Create;
-  if Assigned(AOwner) And (AOwner is TPCBank) then begin
-    SetBank( TPCBank(AOwner) );
+  if Assigned(ABank) then begin
+    SetBank( TPCBank(ABank) );
   end else Clear(true);
 end;
 
@@ -1580,18 +1578,6 @@ begin
   end;
 end;
 
-procedure TPCOperationsComp.Notification(AComponent: TComponent;
-  Operation: TOperation);
-begin
-  inherited;
-  if (Operation = opRemove) then begin
-    if AComponent = FBank then begin
-      FBank := Nil;
-      FreeAndNil(FSafeBoxTransaction);
-    end;
-  end;
-end;
-
 class function TPCOperationsComp.OperationBlockToText(const OperationBlock: TOperationBlock): AnsiString;
 begin
   Result := Format('Block:%d Timestamp:%d Reward:%d Fee:%d Target:%d PoW:%s Payload:%s Nonce:%d OperationsHash:%s SBH:%s',[operationBlock.block,
@@ -1840,7 +1826,6 @@ begin
   end;
   FBank := value;
   if Assigned(value) then begin
-    value.FreeNotification(Self);
     FSafeBoxTransaction := TPCSafeBoxTransaction.Create(FBank.SafeBox);
   end;
   Clear(true);

+ 1 - 1
src/core/UNode.pas

@@ -559,7 +559,7 @@ begin
   FBCBankNotify.Bank := FBank;
   FBCBankNotify.OnNewBlock := OnBankNewBlock;
   FNetServer := TNetServer.Create;
-  FOperations := TPCOperationsComp.Create(Self);
+  FOperations := TPCOperationsComp.Create(Nil);
   FOperations.bank := FBank;
   FNotifyList := TList.Create;
   {$IFDEF BufferOfFutureOperations}