Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 2e3a0f1

Browse files
author
Oliver Weichhold
authored
Merge pull request #1303 from oliverw/dev
dev v70
2 parents f42b9f9 + f014d06 commit 2e3a0f1

60 files changed

Lines changed: 9811 additions & 8342 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
-512 Bytes
Binary file not shown.
-2.5 KB
Binary file not shown.

src/Miningcore.Tests/Crypto/HashingTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Text;
34
using Miningcore.Crypto.Hashing.Algorithms;
45
using Miningcore.Crypto.Hashing.Equihash;
56
using Miningcore.Extensions;
@@ -307,6 +308,54 @@ public void Sha256Csm_Hash()
307308
Assert.Equal("e537f42caaeadfc2f022eff26f6e4b16c78ce86f5eda63b347d4466806e07821", result);
308309
}
309310

311+
[Fact]
312+
public void Sha3_256_Hash()
313+
{
314+
var hasher = new Sha3_256();
315+
var hash = new byte[32];
316+
317+
hasher.Digest(Encoding.UTF8.GetBytes("tests"), hash);
318+
var result = hash.ToHexString();
319+
320+
Assert.Equal("a44f0ac069e85531cdeee61fe8eb6090b649c6a685d682d3ce0e9d096911a217", result);
321+
}
322+
323+
[Fact]
324+
public void Sha3_512_Hash()
325+
{
326+
var hasher = new Sha3_512();
327+
var hash = new byte[64];
328+
329+
hasher.Digest(Encoding.UTF8.GetBytes("tests"), hash);
330+
var result = hash.ToHexString();
331+
332+
Assert.Equal("7bd9b04be8de4f7cd3364e37b23bc8bcf1c16c0e10efb0b16fb4b4d59d0d1456f0412ee83c6f626b2bf4d1f409e6a80e5c2386226b0d82585d9717c7a914ce9b", result);
333+
}
334+
335+
[Fact]
336+
public void Sha3_256d_Hash()
337+
{
338+
var hasher = new Sha3_256d();
339+
var hash = new byte[32];
340+
341+
hasher.Digest(testValue2, hash);
342+
var result = hash.ToHexString();
343+
344+
Assert.Equal("2881d07e59a0b90d782e350584c56af32ad430aba35acdddcfa9d5e612f4e503", result);
345+
}
346+
347+
[Fact]
348+
public void Sha3_512d_Hash()
349+
{
350+
var hasher = new Sha3_512d();
351+
var hash = new byte[64];
352+
353+
hasher.Digest(testValue2, hash);
354+
var result = hash.ToHexString();
355+
356+
Assert.Equal("c83f31ebd447e3c098031f24e2ff10ec36642632cca0a19249d207253466683041ca49e2f54a827f84e857af8bc82645c67191da99917d492df11c4f06670695", result);
357+
}
358+
310359
[Fact]
311360
public void Hmq17_Hash()
312361
{

src/Miningcore.Tests/Miningcore.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
</ItemGroup>
3434

3535
<ItemGroup>
36-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
36+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
3737
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
38-
<PackageReference Include="NLog" Version="4.7.14" />
39-
<PackageReference Include="Npgsql" Version="6.0.3" />
38+
<PackageReference Include="NLog" Version="5.0.1" />
39+
<PackageReference Include="Npgsql" Version="6.0.5" />
4040
<PackageReference Include="xunit" Version="2.4.1" />
41-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
41+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
4242
<PrivateAssets>all</PrivateAssets>
4343
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4444
</PackageReference>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Http;
3+
using Miningcore.Extensions;
4+
using Miningcore.Messaging;
5+
using Miningcore.Notifications.Messages;
6+
7+
namespace Miningcore.Api.Middlewares;
8+
9+
/// <summary>
10+
/// Publishes telemetry data of API request execution times
11+
/// </summary>
12+
public class ApiRequestMetricsMiddleware
13+
{
14+
public ApiRequestMetricsMiddleware(RequestDelegate next, IMessageBus messageBus)
15+
{
16+
this.next = next;
17+
this.messageBus = messageBus;
18+
}
19+
20+
private readonly RequestDelegate next;
21+
private readonly IMessageBus messageBus;
22+
23+
public async Task Invoke(HttpContext context)
24+
{
25+
if(context.Request?.Path.StartsWithSegments("/api") == true)
26+
{
27+
var sw = Stopwatch.StartNew();
28+
29+
try
30+
{
31+
await next.Invoke(context);
32+
33+
messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, true);
34+
}
35+
36+
catch
37+
{
38+
messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, false);
39+
throw;
40+
}
41+
}
42+
43+
else
44+
await next.Invoke(context);
45+
}
46+
}

src/Miningcore/Blockchain/Bitcoin/BitcoinConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class BitcoinConstants
5353
{
5454
public const int ExtranoncePlaceHolderLength = 8;
5555
public const decimal SatoshisPerBitcoin = 100000000;
56-
public static double Pow2x32 = Math.Pow(2, 32);
56+
public static readonly double Pow2x32 = Math.Pow(2, 32);
5757
public static readonly BigInteger Diff1 = BigInteger.Parse("00ffff0000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
5858
public const int CoinbaseMinConfimations = 102;
5959

@@ -147,6 +147,7 @@ public static class BitcoinCommands
147147
public const string GetBlock = "getblock";
148148
public const string GetTransaction = "gettransaction";
149149
public const string SendMany = "sendmany";
150+
public const string SendToAddress = "sendtoaddress";
150151
public const string WalletPassphrase = "walletpassphrase";
151152
public const string WalletLock = "walletlock";
152153

src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
469469
if(validateAddressResponse is not {IsValid: true})
470470
throw new PoolStartupException($"Daemon reports pool-address '{poolConfig.Address}' as invalid", poolConfig.Id);
471471

472-
isPoS = poolConfig.Template is BitcoinTemplate {IsPseudoPoS: true} || difficultyResponse.Values().Any(x => x.Path == "proof-of-stake");
472+
isPoS = poolConfig.Template is BitcoinTemplate {IsPseudoPoS: true} ||
473+
(difficultyResponse.Values().Any(x => x.Path == "proof-of-stake" && !difficultyResponse.Values().Any(x => x.Path == "proof-of-work")));
473474

474475
// Create pool address script from response
475476
if(!isPoS)

0 commit comments

Comments
 (0)