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 }
 
 
-  TPCOperationsComp = Class(TComponent)
+  TPCOperationsComp = Class
   private
   private
     FBank: TPCBank;
     FBank: TPCBank;
     FSafeBoxTransaction : TPCSafeBoxTransaction;
     FSafeBoxTransaction : TPCSafeBoxTransaction;
@@ -370,11 +370,10 @@ Type
     procedure SetBlockPayload(const Value: TRawBytes);
     procedure SetBlockPayload(const Value: TRawBytes);
     procedure OnOperationsHashTreeChanged(Sender : TObject);
     procedure OnOperationsHashTreeChanged(Sender : TObject);
   protected
   protected
-    procedure Notification(AComponent: TComponent; Operation: TOperation); Override;
     function SaveBlockToStreamExt(save_only_OperationBlock : Boolean; Stream: TStream; SaveToStorage : Boolean): Boolean;
     function SaveBlockToStreamExt(save_only_OperationBlock : Boolean; Stream: TStream; SaveToStorage : Boolean): Boolean;
     function LoadBlockFromStreamExt(Stream: TStream; LoadingFromStorage : Boolean; var errors: AnsiString): Boolean;
     function LoadBlockFromStreamExt(Stream: TStream; LoadingFromStorage : Boolean; var errors: AnsiString): Boolean;
   public
   public
-    Constructor Create(AOwner: TComponent); Override;
+    Constructor Create(ABank: TPCBank);
     Destructor Destroy; Override;
     Destructor Destroy; Override;
     Procedure CopyFromExceptAddressKey(Operations : TPCOperationsComp);
     Procedure CopyFromExceptAddressKey(Operations : TPCOperationsComp);
     Procedure CopyFrom(Operations : TPCOperationsComp);
     Procedure CopyFrom(Operations : TPCOperationsComp);
@@ -1351,9 +1350,8 @@ begin
   Result := FOperationsHashTree.OperationsCount;
   Result := FOperationsHashTree.OperationsCount;
 end;
 end;
 
 
-constructor TPCOperationsComp.Create(AOwner: TComponent);
+constructor TPCOperationsComp.Create(ABank: TPCBank);
 begin
 begin
-  inherited Create(AOwner);
   FOperationsLock := TPCCriticalSection.Create('TPCOperationsComp_OPERATIONSLOCK');
   FOperationsLock := TPCCriticalSection.Create('TPCOperationsComp_OPERATIONSLOCK');
   FDisableds := 0;
   FDisableds := 0;
   FStreamPoW := TMemoryStream.Create;
   FStreamPoW := TMemoryStream.Create;
@@ -1364,8 +1362,8 @@ begin
   FOperationBlock := GetFirstBlock;
   FOperationBlock := GetFirstBlock;
   FSafeBoxTransaction := Nil;
   FSafeBoxTransaction := Nil;
   FPreviousUpdatedBlocks := TAccountPreviousBlockInfo.Create;
   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 else Clear(true);
 end;
 end;
 
 
@@ -1580,18 +1578,6 @@ begin
   end;
   end;
 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;
 class function TPCOperationsComp.OperationBlockToText(const OperationBlock: TOperationBlock): AnsiString;
 begin
 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,
   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;
   end;
   FBank := value;
   FBank := value;
   if Assigned(value) then begin
   if Assigned(value) then begin
-    value.FreeNotification(Self);
     FSafeBoxTransaction := TPCSafeBoxTransaction.Create(FBank.SafeBox);
     FSafeBoxTransaction := TPCSafeBoxTransaction.Create(FBank.SafeBox);
   end;
   end;
   Clear(true);
   Clear(true);

+ 1 - 1
src/core/UNode.pas

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