Skip to content

Commit

Permalink
Pool stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jianmingyong committed May 16, 2023
1 parent f9b4056 commit 612bb7f
Show file tree
Hide file tree
Showing 32 changed files with 295 additions and 171 deletions.
6 changes: 0 additions & 6 deletions Xeno.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xenopool.Server", "Xenopool
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xenopool.Client", "Xenopool\Client\Xenopool.Client.csproj", "{F995DC5A-D77F-4371-9C9C-0A3C301A6E48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xenopool.Shared", "Xenopool\Shared\Xenopool.Shared.csproj", "{DD97147E-84C1-44D3-94DE-E6708485B0E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xenolib", "Xenolib\Xenolib.csproj", "{5E48710D-46E3-406A-90A1-FD0791CF8504}"
EndProject
Global
Expand All @@ -33,10 +31,6 @@ Global
{F995DC5A-D77F-4371-9C9C-0A3C301A6E48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F995DC5A-D77F-4371-9C9C-0A3C301A6E48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F995DC5A-D77F-4371-9C9C-0A3C301A6E48}.Release|Any CPU.Build.0 = Release|Any CPU
{DD97147E-84C1-44D3-94DE-E6708485B0E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD97147E-84C1-44D3-94DE-E6708485B0E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD97147E-84C1-44D3-94DE-E6708485B0E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD97147E-84C1-44D3-94DE-E6708485B0E2}.Release|Any CPU.Build.0 = Release|Any CPU
{5E48710D-46E3-406A-90A1-FD0791CF8504}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E48710D-46E3-406A-90A1-FD0791CF8504}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E48710D-46E3-406A-90A1-FD0791CF8504}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "google/api/annotations.proto";
package Xenolib.Algorithms.Xenophyte.Centralized.Networking.Pool;

// Mining Pool Service
service Pool {
service PoolService {
// Authenticate miner by providing wallet address and worker id.
rpc Login (LoginRequest) returns (LoginResponse) {
option (google.api.http) = {
Expand Down Expand Up @@ -104,8 +104,8 @@ message JobSubmitRequest {
int64 second_number = 4;
string operator = 5;
int64 solution = 6;
string user_agent = 7;
bytes raw_data = 8;
bytes encrypted_share = 7;
bytes encrypted_share_hash = 8;
}

message JobSubmitResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Xenolib.Algorithms.Xenophyte.Centralized.Networking.Solo;

public sealed partial class BlockHeader
{
public int BlockHeight { get; private set; }
public long BlockHeight { get; private set; }

public long BlockTimestampCreate { get; private set; }

Expand Down Expand Up @@ -76,7 +76,7 @@ public bool UpdateBlockHeader(ReadOnlySpan<byte> packet)
switch (match.Groups["key"].Value)
{
case "ID":
BlockHeight = int.Parse(match.Groups["value"].Value);
BlockHeight = long.Parse(match.Groups["value"].Value);
break;

case "TIMESTAMP":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private async Task<bool> TryExecuteReadAsync(NetworkStream networkStream, Memory

public void Dispose()
{
_packetArrayPoolOwner.Dispose();
GC.SuppressFinalize(this);
_packetArrayPoolOwner.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Xenolib.Algorithms.Xenophyte.Centralized.Utilities;

public static partial class CpuMinerUtility
{
[UnsupportedOSPlatform("browser")]
private static partial class Native
{
[LibraryImport(Program.XenoNativeLibrary)]
Expand All @@ -17,23 +19,22 @@ private static partial class Native
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool XenophyteCentralizedAlgorithm_MakeEncryptedShare(ReadOnlySpan<byte> input, int inputLength, Span<byte> encryptedShare, Span<byte> hashEncryptedShare, ReadOnlySpan<byte> xorKey, int xorKeyLength, int aesKeySize, ReadOnlySpan<byte> aesKey, ReadOnlySpan<byte> aesIv, int aesRound);
}

public const string JobTypeEasy = "Easy Block";
public const string JobTypeSemiRandom = "Semi Random";
public const string JobTypeRandom = "Random";

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GenerateEasyBlockNumbers(long minValue, long maxValue, Span<long> output)
{
return Native.XenophyteCentralizedAlgorithm_GenerateEasyBlockNumbers(minValue, maxValue, output);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GenerateNonEasyBlockNumbers(long minValue, long maxValue, Span<long> output)
{
return Native.XenophyteCentralizedAlgorithm_GenerateNonEasyBlockNumbers(minValue, maxValue, output);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool MakeEncryptedShare(ReadOnlySpan<byte> input, Span<byte> encryptedShare, Span<byte> hashEncryptedShare, ReadOnlySpan<byte> xorKey, ReadOnlySpan<byte> aesKey, ReadOnlySpan<byte> aesIv, int aesRound)
{
Expand Down
6 changes: 6 additions & 0 deletions Xenolib/Utilities/Base64Utility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Xenolib.Utilities;

public static partial class Base64Utility
{
[UnsupportedOSPlatform("browser")]
private static partial class Native
{
[LibraryImport(Program.XenoNativeLibrary)]
Expand All @@ -20,24 +22,28 @@ private static partial class Native
public static partial int Base64Utility_Decode(ReadOnlySpan<byte> input, int inputLength, Span<byte> output);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int EncodeLength(ReadOnlySpan<byte> value)
{
return Native.Base64Utility_EncodeLength(value.Length);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int DecodeLength(ReadOnlySpan<byte> value)
{
return Native.Base64Utility_DecodeLength(value, value.Length);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Encode(ReadOnlySpan<byte> input, Span<byte> output)
{
return Native.Base64Utility_Encode(input, input.Length, output);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Decode(ReadOnlySpan<byte> input, Span<byte> output)
{
Expand Down
5 changes: 5 additions & 0 deletions Xenolib/Utilities/BufferUtility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Xenolib.Utilities;

public static partial class BufferUtility
{
[UnsupportedOSPlatform("browser")]
private static partial class Native
{
[LibraryImport(Program.XenoNativeLibrary)]
Expand All @@ -17,18 +19,21 @@ private static partial class Native
public static partial void BufferUtility_MemoryCopy_Long(Span<long> destination, ReadOnlySpan<long> source, int length);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemoryCopy(ReadOnlySpan<byte> source, Span<byte> destination, int length)
{
Native.BufferUtility_MemoryCopy_Byte(destination, source, length);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemoryCopy(ReadOnlySpan<int> source, Span<int> destination, int length)
{
Native.BufferUtility_MemoryCopy_Int(destination, source, length);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemoryCopy(ReadOnlySpan<long> source, Span<long> destination, int length)
{
Expand Down
2 changes: 2 additions & 0 deletions Xenolib/Utilities/CpuInformationUtility.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Versioning;

namespace Xenolib.Utilities;

[UnsupportedOSPlatform("browser")]
public static partial class CpuInformationUtility
{
private static partial class Native
Expand Down
5 changes: 5 additions & 0 deletions Xenolib/Utilities/MessageDigestUtility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Xenolib.Utilities;

public static partial class MessageDigestUtility
{
[UnsupportedOSPlatform("browser")]
private static partial class Native
{
[LibraryImport(Program.XenoNativeLibrary)]
Expand All @@ -17,18 +19,21 @@ private static partial class Native
public static partial int MessageDigestUtility_ComputeSha3_512Hash(ReadOnlySpan<byte> source, int length, Span<byte> destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ComputeSha2_256Hash(ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.MessageDigestUtility_ComputeSha2_256Hash(source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ComputeSha2_512Hash(ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.MessageDigestUtility_ComputeSha2_512Hash(source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ComputeSha3_512Hash(ReadOnlySpan<byte> source, Span<byte> destination)
{
Expand Down
7 changes: 7 additions & 0 deletions Xenolib/Utilities/SymmetricAlgorithmUtility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Xenolib.Utilities;

public static partial class SymmetricAlgorithmUtility
{
[UnsupportedOSPlatform("browser")]
private static partial class Native
{
[LibraryImport(Program.XenoNativeLibrary)]
Expand All @@ -23,30 +25,35 @@ private static partial class Native
public static partial int SymmetricAlgorithmUtility_Decrypt_AES_256_CFB_8(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, int sourceLength, Span<byte> destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Encrypt_AES_128_CBC(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.SymmetricAlgorithmUtility_Encrypt_AES_128_CBC(key, iv, source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Encrypt_AES_192_CBC(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.SymmetricAlgorithmUtility_Encrypt_AES_192_CBC(key, iv, source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Encrypt_AES_256_CBC(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.SymmetricAlgorithmUtility_Encrypt_AES_256_CBC(key, iv, source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Encrypt_AES_256_CFB_8(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, Span<byte> destination)
{
return Native.SymmetricAlgorithmUtility_Encrypt_AES_256_CFB_8(key, iv, source, source.Length, destination);
}

[UnsupportedOSPlatform("browser")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Decrypt_AES_256_CFB_8(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> source, Span<byte> destination)
{
Expand Down
6 changes: 5 additions & 1 deletion Xenolib/Xenolib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>none</DebugType>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.52.0" />
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.5" />
</ItemGroup>

<ItemGroup>
<Protobuf Include="Algorithms\Xenophyte\Centralized\Networking\Pool\Pool.proto" />
<Protobuf Include="Algorithms\Xenophyte\Centralized\Networking\Pool\Service.proto" />
</ItemGroup>

</Project>
10 changes: 3 additions & 7 deletions Xenopool/Client/Xenopool.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Xenopool.Shared.csproj"/>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions Xenopool/Server/ConsoleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
Logger.PrintCpuCont(_logger, string.Empty, CpuInformationUtility.ProcessorL2Cache / 1024.0 / 1024.0, CpuInformationUtility.ProcessorL3Cache / 1024.0 / 1024.0, CpuInformationUtility.ProcessorCoreCount, CpuInformationUtility.ProcessorThreadCount);
Logger.PrintEmpty(_logger);

await using var sqliteDatabaseContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
await sqliteDatabaseContext.Database.MigrateAsync(cancellationToken);
await using (var sqliteDatabaseContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken))
{
await sqliteDatabaseContext.Database.MigrateAsync(cancellationToken);
}

if (!await _rpcWalletNetwork.CheckIfWalletAddressExistAsync(cancellationToken))
{
Expand Down
8 changes: 1 addition & 7 deletions Xenopool/Server/Database/Repository/PoolAccountRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Xenopool.Server.Database.Tables;
using Xenopool.Server.Database.Tables;

namespace Xenopool.Server.Database.Repository;

Expand All @@ -23,11 +22,6 @@ public PoolAccount CreateAccount(string walletAddress)
{
return _context.PoolAccounts.SingleOrDefault(account => account.WalletAddress == walletAddress);
}

public Task<PoolAccount?> GetAccountAsync(string walletAddress, CancellationToken cancellationToken)
{
return _context.PoolAccounts.SingleOrDefaultAsync(account => account.WalletAddress == walletAddress, cancellationToken);
}

public Task SaveChangesAsync(CancellationToken cancellationToken)
{
Expand Down
1 change: 1 addition & 0 deletions Xenopool/Server/Database/SqliteDatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable IL2026

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Xenopool.Server.Database.Tables;

namespace Xenopool.Server.Database;
Expand Down
1 change: 1 addition & 0 deletions Xenopool/Server/ILLink.Descriptors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<assembly fullname="Xenopool">
<type fullname="Xenopool.Options.*" preserve="all"/>
<type fullname="Xenopool.Server.Database.Tables.*" preserve="all"/>
<type fullname="Xenopool.Server.Migrations.*" preserve="all"/>
</assembly>
</linker>
2 changes: 1 addition & 1 deletion Xenopool/Server/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static partial class Logger
public static partial void PrintConnected(ILogger logger, string mode, string host);

[LoggerMessage(EventId = 12, Level = LogLevel.Information, Message = $"{MagentaForegroundColor}{{job}}{Reset} from {WhiteForegroundColor}{{host}}{Reset} diff {WhiteForegroundColor}{{difficulty}}{Reset} algo {WhiteForegroundColor}{{algorithm}}{Reset} height {WhiteForegroundColor}{{height}}{Reset}")]
public static partial void PrintJob(ILogger logger, string job, string host, long difficulty, string algorithm, int height);
public static partial void PrintJob(ILogger logger, string job, string host, long difficulty, string algorithm, long height);

[LoggerMessage(EventId = 15, Level = LogLevel.Information, Message = $"{GreenForegroundColor}Job Type: {{jobType}} | Block found: {{firstNumber}} {{operatorSymbol}} {{secondNumber}} = {{result}}{Reset}")]
public static partial void PrintBlockFound(ILogger logger, string jobType, long firstNumber, char operatorSymbol, long secondNumber, long result);
Expand Down
Loading

0 comments on commit 612bb7f

Please sign in to comment.