Sfoglia il codice sorgente

5.7 version with CT_AllowPropagate0feeOperations=False

Pascal Coin 3 anni fa
parent
commit
b21ff6485f
5 ha cambiato i file con 39 aggiunte e 32 eliminazioni
  1. 2 0
      CHANGELOG.md
  2. 25 5
      src/core/UBlockChain.pas
  3. 2 1
      src/core/UConst.pas
  4. 9 26
      src/core/UNetProtocol.pas
  5. 1 0
      src/core/USettings.pas

+ 2 - 0
CHANGELOG.md

@@ -1,6 +1,8 @@
 # Changelog
 
 ## Build 5.7 - PENDING
+- This version will not propagate 0-Fee operations, but will allow 0-Fee operations to the blockchain (CT_AllowPropagate0feeOperations=False)
+  - A wallet that wants to execute 0-Fee operations will need to connect to a miner/pool/node running a 5.6 version or solomine
 - Improvements on TMemPool save to file to protect continued saving process
 - Improvements on TStorage to allow usage of AbstractMem library
 - AbstractMem library v1.6 with improvements on speed and allowing 64bits offsets for files +4Gb

+ 25 - 5
src/core/UBlockChain.pas

@@ -350,7 +350,8 @@ Type
     Property TotalAmount : Int64 read FTotalAmount;
     Property TotalFee : Int64 read FTotalFee;
     function SaveOperationsHashTreeToStream(AStream: TStream; ASaveToStorage : Boolean): Boolean;
-    function LoadOperationsHashTreeFromStream(AStream: TStream; ALoadingFromStorage : Boolean; ASetOperationsToProtocolVersion : Word; ALoadFromStorageVersion : Word; APreviousUpdatedBlocks : TAccountPreviousBlockInfo; var AErrors : String): Boolean;
+    function LoadOperationsHashTreeFromStream(AStream: TStream; ALoadingFromStorage : Boolean; ASetOperationsToProtocolVersion : Word; ALoadFromStorageVersion : Word; APreviousUpdatedBlocks : TAccountPreviousBlockInfo; var AErrors : String): Boolean; overload;
+    function LoadOperationsHashTreeFromStream(AStream: TStream; ALoadingFromStorage : Boolean; ASetOperationsToProtocolVersion : Word; ALoadFromStorageVersion : Word; APreviousUpdatedBlocks : TAccountPreviousBlockInfo; AAllow0FeeOperations : Boolean; var AOperationsCount, AProcessedCount : Integer; var AErrors : String): Boolean; overload;
     function IndexOfOperation(op : TPCOperation) : Integer;
     function CountOperationsBySameSignerWithoutFee(account_number : Cardinal) : Integer;
     Procedure Delete(index : Integer);
@@ -3056,7 +3057,11 @@ begin
   Index := L;
 end;
 
-function TOperationsHashTree.LoadOperationsHashTreeFromStream(AStream: TStream; ALoadingFromStorage : Boolean; ASetOperationsToProtocolVersion : Word; ALoadFromStorageVersion : Word; APreviousUpdatedBlocks : TAccountPreviousBlockInfo; var AErrors : String): Boolean;
+function TOperationsHashTree.LoadOperationsHashTreeFromStream(AStream: TStream;
+  ALoadingFromStorage: Boolean; ASetOperationsToProtocolVersion,
+  ALoadFromStorageVersion: Word;
+  APreviousUpdatedBlocks: TAccountPreviousBlockInfo;
+  AAllow0FeeOperations: Boolean; var AOperationsCount, AProcessedCount : Integer; var AErrors: String): Boolean;
 Var c, i: Cardinal;
   LOpTypeWord : Word;
   LOpProtocolVersion : Word;
@@ -3065,7 +3070,10 @@ Var c, i: Cardinal;
   LOpClass: TPCOperationClass;
   LLastNE : TNotifyEvent;
 begin
-  Result := false;
+  Result := False;
+  AErrors := '';
+  AOperationsCount := 0;
+  AProcessedCount := 0;
   //
   If AStream.Read(c, 4)<4 then begin
     AErrors := 'Cannot read operations count';
@@ -3114,6 +3122,7 @@ begin
         AErrors := 'Invalid operation structure ' + inttostr(i) + '/' + inttostr(c) + ' optype not valid:' + InttoHex(LOpTypeWord, 2);
         Exit;
       end;
+      inc(AOperationsCount);
       LOperation := LOpClass.Create(LOpProtocolVersion);
       Try
         if ALoadingFromStorage then begin
@@ -3125,7 +3134,12 @@ begin
           AErrors := 'Invalid operation load from stream ' + inttostr(i) + '/' + inttostr(c)+' Class:'+LOpClass.ClassName;
           Exit;
         end;
-        AddOperationToHashTree(LOperation);
+        if (AAllow0FeeOperations) or (LOperation.OperationFee>0) then begin
+          AddOperationToHashTree(LOperation);
+          inc(AProcessedCount);
+        end else begin
+          {$IF HIGHLOG}TLog.NewLog(ltdebug,ClassName,Format('Not added a 0fee operation: %s',[LOperation.ToString]));{$ENDIF}
+        end;
       Finally
         FreeAndNil(LOperation);
       end;
@@ -3135,7 +3149,13 @@ begin
   end;
   If Assigned(FOnChanged) then FOnChanged(Self);
   AErrors := '';
-  Result := true;
+  Result := True;
+end;
+
+function TOperationsHashTree.LoadOperationsHashTreeFromStream(AStream: TStream; ALoadingFromStorage : Boolean; ASetOperationsToProtocolVersion : Word; ALoadFromStorageVersion : Word; APreviousUpdatedBlocks : TAccountPreviousBlockInfo; var AErrors : String): Boolean;
+var Lopc,Lprc : Integer;
+begin
+  Result := LoadOperationsHashTreeFromStream(AStream,ALoadingFromStorage,ASetOperationsToProtocolVersion,ALoadFromStorageVersion,APreviousUpdatedBlocks,True,Lopc,Lprc,AErrors);
 end;
 
 procedure TOperationsHashTree.MarkVerifiedECDSASignatures(operationsHashTreeToMark: TOperationsHashTree);

+ 2 - 1
src/core/UConst.pas

@@ -138,6 +138,7 @@ Const
   CT_NetProtocol_Available: Word = {$IFDEF PRODUCTION}14{$ELSE}14{$ENDIF};
 
   CT_MaxAccountOperationsPerBlockWithoutFee = 1;
+  CT_AllowPropagate0feeOperations = False;
 
   CT_SafeBoxBankVersion : Word = 3; // Protocol 2 upgraded safebox version from 2 to 3
 
@@ -198,7 +199,7 @@ Const
   CT_OpSubtype_Data_Signer                = 103;
   CT_OpSubtype_Data_Receiver              = 104;
 
-  CT_ClientAppVersion : String = {$IFDEF PRODUCTION}'5.6'{$ELSE}{$IFDEF TESTNET}'TESTNET 5.6'{$ELSE}{$ENDIF}{$ENDIF};
+  CT_ClientAppVersion : String = {$IFDEF PRODUCTION}'5.7'{$ELSE}{$IFDEF TESTNET}'TESTNET 5.7'{$ELSE}{$ENDIF}{$ENDIF};
 
   CT_Discover_IPs = {$IFDEF PRODUCTION}'bpascal1.dynamic-dns.net;bpascal2.dynamic-dns.net;pascalcoin1.dynamic-dns.net;pascalcoin2.dynamic-dns.net;pascalcoin1.dns1.us;pascalcoin2.dns1.us;pascalcoin1.dns2.us;pascalcoin2.dns2.us'
                     {$ELSE}'pascaltestnet1.dynamic-dns.net;pascaltestnet2.dynamic-dns.net;pascaltestnet1.dns1.us;pascaltestnet2.dns1.us'{$ENDIF};

+ 9 - 26
src/core/UNetProtocol.pas

@@ -2719,6 +2719,7 @@ var c,i : Integer;
     operations : TOperationsHashTree;
     errors : String;
   DoDisconnect : Boolean;
+  Lopc,Lprc : Integer;
 begin
   DoDisconnect := true;
   operations := TOperationsHashTree.Create;
@@ -2727,30 +2728,9 @@ begin
       errors := 'Not autosend';
       exit;
     end;
-    if (NetProtocolVersion.protocol_available>=10) then begin
-      if Not operations.LoadOperationsHashTreeFromStream(DataBuffer,False,TNode.Node.Bank.SafeBox.CurrentProtocol,TNode.Node.Bank.SafeBox.CurrentProtocol,Nil,errors) then Exit;
-    end else begin
-      // TODO:
-      // After V5 Activation all this code can be deleted, not used anymore
-      if DataBuffer.Size<4 then begin
-        errors := 'Invalid databuffer size';
-        exit;
-      end;
-      DataBuffer.Read(c,4);
-      for i := 1 to c do begin
-        errors := 'Invalid operation '+inttostr(i)+'/'+inttostr(c);
-        if not DataBuffer.Read(optype,1)=1 then exit;
-        opclass := TPCOperationsComp.GetOperationClassByOpType(optype);
-        if Not Assigned(opclass) then exit;
-        op := opclass.Create(TNode.Node.Bank.SafeBox.CurrentProtocol);
-        Try
-          op.LoadFromNettransfer(DataBuffer);
-          operations.AddOperationToHashTree(op);
-        Finally
-          op.Free;
-        End;
-      end;
-    end;
+    if Not operations.LoadOperationsHashTreeFromStream(DataBuffer,False,
+      TNode.Node.Bank.SafeBox.CurrentProtocol,TNode.Node.Bank.SafeBox.CurrentProtocol,Nil,
+      CT_AllowPropagate0feeOperations,Lopc,Lprc,errors) then Exit;
     DoDisconnect := false;
   finally
     try
@@ -3333,7 +3313,7 @@ Var dataSend, dataReceived : TMemoryStream;
   headerData : TNetHeaderData;
   opht : TOperationsHashTree;
   errors : String;
-  i : Integer;
+  i,Lopc,Lprc : Integer;
 begin
   {$IFDEF PRODUCTION}
   If FNetProtocolVersion.protocol_available<=6 then Exit; // Note: GetPendingOperations started on protocol_available=7
@@ -3380,7 +3360,10 @@ begin
       //
       opht := TOperationsHashTree.Create;
       try
-        If Not opht.LoadOperationsHashTreeFromStream(dataReceived,False,FRemoteOperationBlock.protocol_version,FRemoteOperationBlock.protocol_version,Nil,errors) then begin
+        If Not opht.LoadOperationsHashTreeFromStream(dataReceived,False,
+          FRemoteOperationBlock.protocol_version,FRemoteOperationBlock.protocol_version,Nil,
+          CT_AllowPropagate0feeOperations,Lopc,Lprc,errors)
+        then begin
           DisconnectInvalidClient(False,'Invalid operations hash tree stream: '+errors);
           Exit;
         end;

+ 1 - 0
src/core/USettings.pas

@@ -264,6 +264,7 @@ class function TSettings.GetDefaultFee : Int64;
 begin
   CheckLoaded;
   Result := FAppParams.ParamByName[CT_PARAM_DefaultFee].GetAsInt64(0);
+  if (Not CT_AllowPropagate0feeOperations) and (Result<=0) then Result := 1;
 end;
 
 class procedure TSettings.SetDefaultFee(AInt64: Int64);