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

Commit

Permalink
Merge pull request #1303 from oliverw/dev
Browse files Browse the repository at this point in the history
dev v70
  • Loading branch information
Oliver Weichhold authored Jul 8, 2022
2 parents f42b9f9 + f014d06 commit 2e3a0f1
Show file tree
Hide file tree
Showing 60 changed files with 9,811 additions and 8,342 deletions.
Binary file modified libs/runtimes/win-x64/libethhash.dll
Binary file not shown.
Binary file modified libs/runtimes/win-x64/libmultihash.dll
Binary file not shown.
49 changes: 49 additions & 0 deletions src/Miningcore.Tests/Crypto/HashingTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Text;
using Miningcore.Crypto.Hashing.Algorithms;
using Miningcore.Crypto.Hashing.Equihash;
using Miningcore.Extensions;
Expand Down Expand Up @@ -307,6 +308,54 @@ public void Sha256Csm_Hash()
Assert.Equal("e537f42caaeadfc2f022eff26f6e4b16c78ce86f5eda63b347d4466806e07821", result);
}

[Fact]
public void Sha3_256_Hash()
{
var hasher = new Sha3_256();
var hash = new byte[32];

hasher.Digest(Encoding.UTF8.GetBytes("tests"), hash);
var result = hash.ToHexString();

Assert.Equal("a44f0ac069e85531cdeee61fe8eb6090b649c6a685d682d3ce0e9d096911a217", result);
}

[Fact]
public void Sha3_512_Hash()
{
var hasher = new Sha3_512();
var hash = new byte[64];

hasher.Digest(Encoding.UTF8.GetBytes("tests"), hash);
var result = hash.ToHexString();

Assert.Equal("7bd9b04be8de4f7cd3364e37b23bc8bcf1c16c0e10efb0b16fb4b4d59d0d1456f0412ee83c6f626b2bf4d1f409e6a80e5c2386226b0d82585d9717c7a914ce9b", result);
}

[Fact]
public void Sha3_256d_Hash()
{
var hasher = new Sha3_256d();
var hash = new byte[32];

hasher.Digest(testValue2, hash);
var result = hash.ToHexString();

Assert.Equal("2881d07e59a0b90d782e350584c56af32ad430aba35acdddcfa9d5e612f4e503", result);
}

[Fact]
public void Sha3_512d_Hash()
{
var hasher = new Sha3_512d();
var hash = new byte[64];

hasher.Digest(testValue2, hash);
var result = hash.ToHexString();

Assert.Equal("c83f31ebd447e3c098031f24e2ff10ec36642632cca0a19249d207253466683041ca49e2f54a827f84e857af8bc82645c67191da99917d492df11c4f06670695", result);
}

[Fact]
public void Hmq17_Hash()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Miningcore.Tests/Miningcore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="5.0.0" />
<PackageReference Include="NLog" Version="4.7.14" />
<PackageReference Include="Npgsql" Version="6.0.3" />
<PackageReference Include="NLog" Version="5.0.1" />
<PackageReference Include="Npgsql" Version="6.0.5" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
46 changes: 46 additions & 0 deletions src/Miningcore/Api/Middlewares/ApiRequestMetricsMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using Miningcore.Extensions;
using Miningcore.Messaging;
using Miningcore.Notifications.Messages;

namespace Miningcore.Api.Middlewares;

/// <summary>
/// Publishes telemetry data of API request execution times
/// </summary>
public class ApiRequestMetricsMiddleware
{
public ApiRequestMetricsMiddleware(RequestDelegate next, IMessageBus messageBus)
{
this.next = next;
this.messageBus = messageBus;
}

private readonly RequestDelegate next;
private readonly IMessageBus messageBus;

public async Task Invoke(HttpContext context)
{
if(context.Request?.Path.StartsWithSegments("/api") == true)
{
var sw = Stopwatch.StartNew();

try
{
await next.Invoke(context);

messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, true);
}

catch
{
messageBus.SendTelemetry(context.Request.Path, TelemetryCategory.ApiRequest, null, sw.Elapsed, false);
throw;
}
}

else
await next.Invoke(context);
}
}
3 changes: 2 additions & 1 deletion src/Miningcore/Blockchain/Bitcoin/BitcoinConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class BitcoinConstants
{
public const int ExtranoncePlaceHolderLength = 8;
public const decimal SatoshisPerBitcoin = 100000000;
public static double Pow2x32 = Math.Pow(2, 32);
public static readonly double Pow2x32 = Math.Pow(2, 32);
public static readonly BigInteger Diff1 = BigInteger.Parse("00ffff0000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
public const int CoinbaseMinConfimations = 102;

Expand Down Expand Up @@ -147,6 +147,7 @@ public static class BitcoinCommands
public const string GetBlock = "getblock";
public const string GetTransaction = "gettransaction";
public const string SendMany = "sendmany";
public const string SendToAddress = "sendtoaddress";
public const string WalletPassphrase = "walletpassphrase";
public const string WalletLock = "walletlock";

Expand Down
3 changes: 2 additions & 1 deletion src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
if(validateAddressResponse is not {IsValid: true})
throw new PoolStartupException($"Daemon reports pool-address '{poolConfig.Address}' as invalid", poolConfig.Id);

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

// Create pool address script from response
if(!isPoS)
Expand Down
Loading

0 comments on commit 2e3a0f1

Please sign in to comment.