Browse Source

Merge pull request #11 from PascalCoinDev/master

Improvements
Pascal Coin 5 years ago
parent
commit
75a623ee45
4 changed files with 49 additions and 7 deletions
  1. 11 0
      CHANGELOG.md
  2. 2 2
      src/core/UCrypto.pas
  3. 34 3
      src/core/UPoolMining.pas
  4. 2 2
      src/gui-classic/UFRMDiagnosticTool.pas

+ 11 - 0
CHANGELOG.md

@@ -31,6 +31,17 @@
   - Added "new_data" field allowing update Account.Data field (0..32 bytes)
   - Updated digest hash value adding "new_data" field  
 - Hardcoded RandomHash digest/hash values for quick speed safebox check on fresh installation
+- Pools or external miners: Added new JSON-RPC methods for Server mining support (TCP/IP, no HTTP protocol)
+  - New methods "rh" and "rh2" that will return a hash calculated using the RandomHash or RandomHash2 algo
+  - params must include a 1-length array with the digest in hexastring format
+  - Example:
+    - Call {"id":123,"method":"rh2","params":["a02f3a4b5c62102e1a9a983f"]}
+    - Response {"id":123,"error":null,
+      "result":
+        {"digest":"A02F3A4B5C62102E1A9A983F",
+         "hash":"5D825627E1E9865C17050E55B05D7D3A0C36C11D855261A511880C3CBF015AA9",
+         "algo":"rh2"}
+        }
 - JSON-RPC changes:  
   - Updated "listaccountforsale" method to allow ATOMIC SWAPS (PIP-0032)
     - Added "type" to discrimine between kind of listing. Available values are:

+ 2 - 2
src/core/UCrypto.pas

@@ -774,7 +774,7 @@ end;
 
 class function TCrypto.DoRandomHash2(const TheMessage: TRawBytes): TRawBytes;
 begin
-  Result := TRandomHash2.Compute(TheMessage);
+  Result := TRandomHash2Fast.Compute(TheMessage);
 end;
 
 class procedure TCrypto.DoRandomHash(p : PAnsiChar; plength : Cardinal; out AResult : TRawBytes);
@@ -797,7 +797,7 @@ begin
   if Length(AResult) <> 32 then SetLength(AResult, 32);
   SetLength(LInput, plength);
   Move(p^, LInput[0], plength);
-  LResult := TRandomHash2.Compute(LInput);
+  LResult := TRandomHash2Fast.Compute(LInput);
   Move(LResult[0], AResult[Low(AResult)], 32);
 end;
 

+ 34 - 3
src/core/UPoolMining.pas

@@ -38,6 +38,8 @@ Const
   CT_PoolMining_Method_STATUS = 'status';
   CT_PoolMining_Method_MINER_NOTIFY = 'miner-notify'; // Server message to clients to update miners PoW data
   CT_PoolMining_Method_MINER_SUBMIT = 'miner-submit'; // Client message to server to notify a PoW found
+  CT_PoolMining_Method_MINER_RANDOMHASH = 'rh'; // Client message to server to calculate a hash based on RandomHash algo
+  CT_PoolMining_Method_MINER_RANDOMHASH2 = 'rh2'; // Client message to server to calculate a hash based on RandomHash2 algo
 
   CT_PoolMining_Method_STRATUM_MINING_AUTHORIZE = 'mining.authorize';
   CT_PoolMining_Method_STRATUM_MINING_SUBSCRIBE = 'mining.subscribe';
@@ -415,8 +417,6 @@ begin
       stream.Write(b,1);
       b := 10;
       stream.Write(b,1);
-      b := 0;
-      stream.Write(b,1);
       stream.Position := 0;
       WriteBufferToSend(stream);
     finally
@@ -699,6 +699,7 @@ Var method : String;
     id_value : Variant;
     i : Integer;
   response_result : TPCJSONObject;
+  LDigest : TRawBytes;
 begin
   If ResponseMethod<>'' then begin
     method := ResponseMethod;
@@ -739,7 +740,37 @@ begin
   end else if method=CT_PoolMining_Method_MINER_SUBMIT then begin
     // Try to submit a PoW
     if params.Count=1 then MinerSubmit(Client,params.GetAsObject(0),id_value)
-    else TLog.NewLog(lterror,ClassName,'Invalid params array of method '+method);
+    else begin
+      Client.SendJSONRPCErrorResponse(id_value,'params must be 1-count JSON array');
+      TLog.NewLog(lterror,ClassName,'Invalid params array of method '+method);
+    end;
+  end else if (method=CT_PoolMining_Method_MINER_RANDOMHASH) or (method=CT_PoolMining_Method_MINER_RANDOMHASH2) then begin
+    //
+    if params.Count<>1 then begin
+      Client.SendJSONRPCErrorResponse(id_value,'params must be 1-count JSON array');
+    end else if (params.Items[0] is TPCJSONVariantValue) then begin
+      // Check the digest:
+      if Not TCrypto.HexaToRaw( params.GetAsVariant(0).AsString(''), LDigest ) then begin
+        Client.SendJSONRPCErrorResponse(id_value,'array does not contain an hexastring');
+      end else begin
+        response_result := TPCJSONObject.Create;
+        Try
+          response_result.GetAsVariant('digest').Value := LDigest.ToHexaString;
+          if (method=CT_PoolMining_Method_MINER_RANDOMHASH) then begin
+            // RandomHash 1 algo
+            response_result.GetAsVariant('hash').Value := TCrypto.DoRandomHash(LDigest).ToHexaString;
+            response_result.GetAsVariant('algo').Value := 'rh';
+          end else begin
+            // RandomHash 2 algo
+            response_result.GetAsVariant('hash').Value := TCrypto.DoRandomHash2(LDigest).ToHexaString;
+            response_result.GetAsVariant('algo').Value := 'rh2';
+          end;
+          Client.SendJSONRPCResponse(response_result,id_value);
+        Finally
+          response_result.Free;
+        End;
+      end;
+    end;
   end else begin
     // Invalid command
     if (not VarIsNull(id_value)) then begin

+ 2 - 2
src/gui-classic/UFRMDiagnosticTool.pas

@@ -175,13 +175,13 @@ var
  LTotalHashes, LNotifyHashes : UInt32;
 begin
   SetLength(LInput, 200);
-  while True do begin
+  while Not Terminated do begin
     LTotalHashes := 0;
     LNotifyHashes := 0;
     LStartTime := Now;
     LNotifyStartTime := LStartTime;
     LTC := TPlatform.GetTickCount;
-    while Not FExitLoop do begin
+    while (Not FExitLoop) And (Not Terminated) do begin
      if TryNextRound (RandomizeNonce(LInput), FLastHash) then begin
        inc(LTotalHashes);
        inc(LNotifyHashes);