Browse Source

New V3 target calculation proposal

PascalCoin 7 years ago
parent
commit
1696dec6f1
3 changed files with 13 additions and 10 deletions
  1. 2 2
      README.md
  2. 9 5
      src/core/UAccounts.pas
  3. 2 3
      src/core/UConst.pas

+ 2 - 2
README.md

@@ -37,8 +37,8 @@ Also, consider a donation at PascalCoin development account: "0-10"
 ### DEVELOPMENT STATUS
 ### DEVELOPMENT STATUS
 - TODO: PIP - 0010
 - TODO: PIP - 0010
 - TODO: Add new network operations
 - TODO: Add new network operations
-- TODO: New target calc on protocol V3 in order to reduce the sinusoidal effect
-  - TODO: (on testing...) On V3 will look last 5 blocks instead of last 10 in order to decide if continue increasing/decreasing target
+- New target calc on protocol V3 in order to reduce the sinusoidal effect
+  - Harmonization of the sinusoidal effect modifying the rise / fall by 50% calculating over the last 10 blocks only when increase/decrease is high
 - New Safebox Snapshoting
 - New Safebox Snapshoting
   - This allow quickly rollback/commit directly to Safebox instead of create a separate Safebox on memory (read from disk... use more ram...)
   - This allow quickly rollback/commit directly to Safebox instead of create a separate Safebox on memory (read from disk... use more ram...)
   - Is usefull when detecting posible orphan blocks in order to check which chain is the highest chain without duplicating a safebox to compare
   - Is usefull when detecting posible orphan blocks in order to check which chain is the highest chain without duplicating a safebox to compare

+ 9 - 5
src/core/UAccounts.pas

@@ -3268,9 +3268,7 @@ begin
     If (protocolVersion=CT_PROTOCOL_1) then begin
     If (protocolVersion=CT_PROTOCOL_1) then begin
       Result := TPascalCoinProtocol.GetNewTarget(tsTeorical, tsReal,TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target));
       Result := TPascalCoinProtocol.GetNewTarget(tsTeorical, tsReal,TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target));
     end else if (protocolVersion<=CT_PROTOCOL_3) then begin
     end else if (protocolVersion<=CT_PROTOCOL_3) then begin
-      If (protocolVersion=CT_PROTOCOL_2) then
-        CalcBack := CalcBack DIV CT_CalcNewTargetLimitChange_SPLIT_v2
-      else CalcBack := CalcBack DIV CT_CalcNewTargetLimitChange_SPLIT_v3;
+      CalcBack := CalcBack DIV CT_CalcNewTargetLimitChange_SPLIT;
       If CalcBack=0 then CalcBack := 1;
       If CalcBack=0 then CalcBack := 1;
       ts2 := Block(BlocksCount-CalcBack-1).blockchainInfo.timestamp;
       ts2 := Block(BlocksCount-CalcBack-1).blockchainInfo.timestamp;
       tsTeoricalStop := (CalcBack * CT_NewLineSecondsAvg);
       tsTeoricalStop := (CalcBack * CT_NewLineSecondsAvg);
@@ -3284,8 +3282,14 @@ begin
          ((tsTeorical<tsReal) and (tsTeoricalStop<tsRealStop)) then begin
          ((tsTeorical<tsReal) and (tsTeoricalStop<tsRealStop)) then begin
         Result := TPascalCoinProtocol.GetNewTarget(tsTeorical, tsReal,TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target));
         Result := TPascalCoinProtocol.GetNewTarget(tsTeorical, tsReal,TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target));
       end else begin
       end else begin
-        // Nothing to do!
-        Result:=TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target);
+        if (protocolVersion=CT_PROTOCOL_2) then begin
+          // Nothing to do!
+          Result:=TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target);
+        end else begin
+          // New on V3 protocol:
+          // Harmonization of the sinusoidal effect modifying the rise / fall by 50% calculating over the "stop" area
+          Result := TPascalCoinProtocol.GetNewTarget(tsTeoricalStop, (tsTeoricalStop + tsRealStop) DIV 2,TPascalCoinProtocol.TargetFromCompact(lastBlock.compact_target));
+        end;
       end;
       end;
     end else begin
     end else begin
       Raise Exception.Create('ERROR DEV 20180306-1 Protocol not valid');
       Raise Exception.Create('ERROR DEV 20180306-1 Protocol not valid');

+ 2 - 3
src/core/UConst.pas

@@ -65,8 +65,7 @@ Const
   CT_MinCompactTarget: Cardinal = {$IFDEF PRODUCTION}$19000000{$ELSE}{$IFDEF TESTNET}$17000000{$ELSE}{$ENDIF}{$ENDIF}; // First compact target of block 0
   CT_MinCompactTarget: Cardinal = {$IFDEF PRODUCTION}$19000000{$ELSE}{$IFDEF TESTNET}$17000000{$ELSE}{$ENDIF}{$ENDIF}; // First compact target of block 0
 
 
   CT_CalcNewTargetBlocksAverage: Cardinal = 100;
   CT_CalcNewTargetBlocksAverage: Cardinal = 100;
-  CT_CalcNewTargetLimitChange_SPLIT_v2 = 10;
-  CT_CalcNewTargetLimitChange_SPLIT_v3 = 20;
+  CT_CalcNewTargetLimitChange_SPLIT = 10;
 
 
   CT_MaxAccount : Cardinal = $FFFFFFFF;
   CT_MaxAccount : Cardinal = $FFFFFFFF;
   CT_MaxBlock : Cardinal = $FFFFFFFF;
   CT_MaxBlock : Cardinal = $FFFFFFFF;
@@ -101,7 +100,7 @@ Const
   CT_Protocol_Upgrade_v3_MinBlock = {$IFDEF PRODUCTION}210000{$ELSE}250{$ENDIF};
   CT_Protocol_Upgrade_v3_MinBlock = {$IFDEF PRODUCTION}210000{$ELSE}250{$ENDIF};
 
 
 
 
-  CT_MagicNetIdentification = {$IFDEF PRODUCTION}$0A043580{$ELSE}$03000020{$ENDIF}; // Unix timestamp 168048000 ... It's Albert birthdate!
+  CT_MagicNetIdentification = {$IFDEF PRODUCTION}$0A043580{$ELSE}$03000030{$ENDIF}; // Unix timestamp 168048000 ... It's Albert birthdate!
 
 
   CT_NetProtocol_Version: Word = $0006; // Version 2.1.2 only allows net protocol 6 (Introduced on 2.0.0)
   CT_NetProtocol_Version: Word = $0006; // Version 2.1.2 only allows net protocol 6 (Introduced on 2.0.0)
   // IMPORTANT NOTE!!!
   // IMPORTANT NOTE!!!