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

Commit 05b7810

Browse files
author
Oliver Weichhold
authored
Merge pull request #1130 from oliverw/oliverw
- Implement support for Postgres TLS - Don't expose Ergo Wallet Password through API - Don't expose confidential Tls information through API - Fixed a bug that would delay job updates to all miners if the previous update was delayed due to a dead connection - Remove artificial outbound stratum message length and optimize memory usage - Re-introduce Ethereum Job backlog - Build script fixes (@warren-ru)
2 parents fb0f2f7 + c7a59d3 commit 05b7810

File tree

81 files changed

+1114
-1197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1114
-1197
lines changed

src/.idea/.idea.Miningcore/.idea/dataSources.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.Miningcore/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.Miningcore/.idea/sqldialects.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Miningcore/Api/Controllers/AdminApiController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async Task<decimal> GetMinerBalanceAsync(string poolId, string address)
6666
if(string.IsNullOrEmpty(address))
6767
throw new ApiException("Invalid or missing miner address", HttpStatusCode.NotFound);
6868

69-
var result = await cf.Run(con=> minerRepo.GetSettings(con, null, pool.Id, address));
69+
var result = await cf.Run(con=> minerRepo.GetSettingsAsync(con, null, pool.Id, address));
7070

7171
if(result == null)
7272
throw new ApiException("No settings found", HttpStatusCode.NotFound);
@@ -98,9 +98,9 @@ public async Task<decimal> GetMinerBalanceAsync(string poolId, string address)
9898

9999
var result = await cf.RunTx(async (con, tx) =>
100100
{
101-
await minerRepo.UpdateSettings(con, tx, mapped);
101+
await minerRepo.UpdateSettingsAsync(con, tx, mapped);
102102

103-
return await minerRepo.GetSettings(con, tx, mapped.PoolId, mapped.Address);
103+
return await minerRepo.GetSettingsAsync(con, tx, mapped.PoolId, mapped.Address);
104104
});
105105

106106
logger.Info(()=> $"Updated settings for pool {pool.Id}, miner {address}");

src/Miningcore/Api/Controllers/ClusterApiController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ public ClusterApiController(IComponentContext ctx) : base(ctx)
3838
public async Task<Responses.Block[]> PageBlocksPagedAsync(
3939
[FromQuery] int page, [FromQuery] int pageSize = 15, [FromQuery] BlockStatus[] state = null)
4040
{
41-
var blockStates = state != null && state.Length > 0 ?
41+
var ct = HttpContext.RequestAborted;
42+
var blockStates = state is { Length: > 0 } ?
4243
state :
4344
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned };
4445

45-
var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, blockStates, page, pageSize)))
46+
var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, blockStates, page, pageSize, ct)))
4647
.Select(mapper.Map<Responses.Block>)
4748
.Where(x => enabledPools.Contains(x.PoolId))
4849
.ToArray();

src/Miningcore/Api/Controllers/PoolApiController.cs

Lines changed: 53 additions & 42 deletions
Large diffs are not rendered by default.

src/Miningcore/Api/Extensions/MiningPoolExtensions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using AutoMapper;
22
using Miningcore.Api.Responses;
33
using Miningcore.Blockchain;
4+
using Miningcore.Blockchain.Ergo.Configuration;
45
using Miningcore.Configuration;
6+
using Miningcore.Extensions;
57
using Miningcore.Mining;
68

79
namespace Miningcore.Api.Extensions;
@@ -28,9 +30,19 @@ public static PoolInfo ToPoolInfo(this PoolConfig poolConfig, IMapper mapper, Pe
2830
{
2931
var extra = poolInfo.PaymentProcessing.Extra;
3032

31-
//extra.StripValue(nameof(EthereumPoolPaymentProcessingConfigExtra.CoinbasePassword));
33+
extra.StripValue(nameof(ErgoPaymentProcessingConfigExtra.WalletPassword));
3234
}
3335

36+
if(poolInfo.Ports != null)
37+
{
38+
foreach(var port in poolInfo.Ports.Keys)
39+
{
40+
var portInfo = poolInfo.Ports[port];
41+
42+
portInfo.TlsPfxFile = null;
43+
portInfo.TlsPfxPassword = null;
44+
}
45+
}
3446
return poolInfo;
3547
}
3648
}

src/Miningcore/Api/Responses/GetPoolsResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Miningcore.Blockchain;
33
using Miningcore.Configuration;
44
using Miningcore.Mining;
5-
using Newtonsoft.Json;
65
using Newtonsoft.Json.Linq;
76

87
namespace Miningcore.Api.Responses;

src/Miningcore/AutoMapperProfile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Miningcore.Configuration;
44
using Miningcore.Persistence.Model;
55
using Miningcore.Persistence.Model.Projections;
6+
using Newtonsoft.Json.Linq;
67
using MinerStats = Miningcore.Persistence.Model.Projections.MinerStats;
78

89
namespace Miningcore;
@@ -13,6 +14,9 @@ public class AutoMapperProfile : Profile
1314

1415
public AutoMapperProfile()
1516
{
17+
// Fix for Automapper 11 which chokes on recursive objects such as JToken
18+
CreateMap<JToken, JToken>().ConvertUsing(x=> x);
19+
1620
//////////////////////
1721
// outgoing mappings
1822

src/Miningcore/AutofacMetadata.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using JetBrains.Annotations;
21
using Miningcore.Configuration;
32

43
namespace Miningcore;
54

65
public class CoinFamilyAttribute : Attribute
76
{
8-
[UsedImplicitly]
9-
public CoinFamilyAttribute(IDictionary<string, object> values)
7+
public CoinFamilyAttribute(IDictionary<string, object> values)
108
{
119
if(values.ContainsKey(nameof(SupportedFamilies)))
1210
SupportedFamilies = (CoinFamily[]) values[nameof(SupportedFamilies)];

src/Miningcore/AutofacModule.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Newtonsoft.Json.Serialization;
2020
using Module = Autofac.Module;
2121
using Microsoft.AspNetCore.Mvc;
22+
using Microsoft.IO;
2223
using Miningcore.Blockchain.Ergo;
2324
using Miningcore.Nicehash;
2425
using Miningcore.Pushover;
@@ -51,6 +52,13 @@ protected override void Load(ContainerBuilder builder)
5152
.AsImplementedInterfaces()
5253
.SingleInstance();
5354

55+
builder.RegisterInstance(new RecyclableMemoryStreamManager
56+
{
57+
MaximumFreeSmallPoolBytes = 0x100000, // 1 MB
58+
MaximumFreeLargePoolBytes = 0x1000000, // 16 MB
59+
ThrowExceptionOnToArray = true
60+
});
61+
5462
builder.RegisterType<StandardClock>()
5563
.AsImplementedInterfaces()
5664
.SingleInstance();

src/Miningcore/Blockchain/Bitcoin/BitcoinJobManager.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ protected override object[] GetBlockTemplateParams()
4646

4747
protected async Task<RpcResponse<BlockTemplate>> GetBlockTemplateAsync(CancellationToken ct)
4848
{
49-
logger.LogInvoke();
50-
5149
var result = await rpc.ExecuteAsync<BlockTemplate>(logger,
5250
BitcoinCommands.GetBlockTemplate, ct, extraPoolConfig?.GBTArgs ?? (object) GetBlockTemplateParams());
5351

@@ -56,8 +54,6 @@ protected async Task<RpcResponse<BlockTemplate>> GetBlockTemplateAsync(Cancellat
5654

5755
protected RpcResponse<BlockTemplate> GetBlockTemplateFromJson(string json)
5856
{
59-
logger.LogInvoke();
60-
6157
var result = JsonConvert.DeserializeObject<JsonRpcResponse>(json);
6258

6359
return new RpcResponse<BlockTemplate>(result!.ResultAs<BlockTemplate>());
@@ -81,8 +77,6 @@ protected override void PostChainIdentifyConfigure()
8177

8278
protected override async Task<(bool IsNew, bool Force)> UpdateJob(CancellationToken ct, bool forceUpdate, string via = null, string json = null)
8379
{
84-
logger.LogInvoke();
85-
8680
try
8781
{
8882
if(forceUpdate)
@@ -212,8 +206,6 @@ public virtual async ValueTask<Share> SubmitShareAsync(StratumConnection worker,
212206
Contract.RequiresNonNull(worker, nameof(worker));
213207
Contract.RequiresNonNull(submission, nameof(submission));
214208

215-
logger.LogInvoke(new object[] { worker.ConnectionId });
216-
217209
if(submission is not object[] submitParams)
218210
throw new StratumException(StratumError.Other, "invalid params");
219211

src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Miningcore.Configuration;
88
using Miningcore.Contracts;
99
using Miningcore.Extensions;
10-
using Miningcore.JsonRpc;
1110
using Miningcore.Messaging;
1211
using Miningcore.Mining;
1312
using Miningcore.Notifications.Messages;
@@ -222,8 +221,6 @@ protected virtual async Task ShowDaemonSyncProgressAsync(CancellationToken ct)
222221

223222
private async Task UpdateNetworkStatsAsync(CancellationToken ct)
224223
{
225-
logger.LogInvoke();
226-
227224
try
228225
{
229226
var results = await rpc.ExecuteBatchAsync(logger, ct,
@@ -340,8 +337,6 @@ protected async Task ShowDaemonSyncProgressLegacyAsync(CancellationToken ct)
340337

341338
private async Task UpdateNetworkStatsLegacyAsync(CancellationToken ct)
342339
{
343-
logger.LogInvoke();
344-
345340
try
346341
{
347342
var results = await rpc.ExecuteBatchAsync(logger, ct,

src/Miningcore/Blockchain/Bitcoin/BitcoinPayoutHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Miningcore.Blockchain.Bitcoin.DaemonResponses;
55
using Miningcore.Configuration;
66
using Miningcore.Extensions;
7-
using Miningcore.JsonRpc;
87
using Miningcore.Messaging;
98
using Miningcore.Mining;
109
using Miningcore.Payments;

src/Miningcore/Blockchain/Bitcoin/BitcoinPool.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Reactive.Threading.Tasks;
55
using Autofac;
66
using AutoMapper;
7-
using JetBrains.Annotations;
7+
using Microsoft.IO;
88
using Miningcore.Configuration;
99
using Miningcore.Extensions;
1010
using Miningcore.JsonRpc;
@@ -24,7 +24,6 @@
2424
namespace Miningcore.Blockchain.Bitcoin;
2525

2626
[CoinFamily(CoinFamily.Bitcoin)]
27-
[UsedImplicitly]
2827
public class BitcoinPool : PoolBase
2928
{
3029
public BitcoinPool(IComponentContext ctx,
@@ -34,8 +33,9 @@ public BitcoinPool(IComponentContext ctx,
3433
IMapper mapper,
3534
IMasterClock clock,
3635
IMessageBus messageBus,
36+
RecyclableMemoryStreamManager rmsm,
3737
NicehashService nicehashService) :
38-
base(ctx, serializerSettings, cf, statsRepo, mapper, clock, messageBus, nicehashService)
38+
base(ctx, serializerSettings, cf, statsRepo, mapper, clock, messageBus, rmsm, nicehashService)
3939
{
4040
}
4141

@@ -321,11 +321,8 @@ protected virtual Task OnNewJobAsync(object jobParams)
321321

322322
logger.Info(() => "Broadcasting job");
323323

324-
return Guard(()=> Task.WhenAll(ForEachConnection(async connection =>
324+
return Guard(Task.WhenAll(TaskForEach(async connection =>
325325
{
326-
if(!connection.IsAlive)
327-
return;
328-
329326
var context = connection.ContextAs<BitcoinWorkerContext>();
330327

331328
if(!context.IsSubscribed || !context.IsAuthorized || CloseIfDead(connection, context))
@@ -393,9 +390,9 @@ protected override async Task SetupJobManager(CancellationToken ct)
393390
}
394391
}
395392

396-
protected override async Task InitStatsAsync()
393+
protected override async Task InitStatsAsync(CancellationToken ct)
397394
{
398-
await base.InitStatsAsync();
395+
await base.InitStatsAsync(ct);
399396

400397
blockchainStats = manager.BlockchainStats;
401398
}

src/Miningcore/Blockchain/Bitcoin/Configuration/BitcoinPoolConfigExtra.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using JetBrains.Annotations;
21
using Miningcore.Configuration;
32
using Newtonsoft.Json.Linq;
43

54
namespace Miningcore.Blockchain.Bitcoin.Configuration;
65

7-
[UsedImplicitly]
86
public class BitcoinPoolConfigExtra
97
{
108
public BitcoinAddressType AddressType { get; set; } = BitcoinAddressType.Legacy;

src/Miningcore/Blockchain/Bitcoin/DaemonResponses/Masternode.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using JetBrains.Annotations;
21
using Newtonsoft.Json;
32
using Newtonsoft.Json.Linq;
43

@@ -11,7 +10,6 @@ public class Masternode
1110
public long Amount { get; set; }
1211
}
1312

14-
[UsedImplicitly]
1513
public class SuperBlock
1614
{
1715
public string Payee { get; set; }

src/Miningcore/Blockchain/Bitcoin/DaemonResponses/Utxo.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using JetBrains.Annotations;
2-
31
namespace Miningcore.Blockchain.Bitcoin.DaemonResponses;
42

5-
[UsedImplicitly]
63
public class Utxo
74
{
85
public string TxId { get; set; }

src/Miningcore/Blockchain/Cryptonote/CryptonoteJobManager.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public CryptonoteJobManager(
6060

6161
protected async Task<bool> UpdateJob(CancellationToken ct, string via = null, string json = null)
6262
{
63-
logger.LogInvoke();
64-
6563
try
6664
{
6765
var response = string.IsNullOrEmpty(json) ? await GetBlockTemplateAsync(ct) : GetBlockTemplateFromJson(json);
@@ -144,8 +142,6 @@ protected async Task<bool> UpdateJob(CancellationToken ct, string via = null, st
144142

145143
private async Task<RpcResponse<GetBlockTemplateResponse>> GetBlockTemplateAsync(CancellationToken ct)
146144
{
147-
logger.LogInvoke();
148-
149145
var request = new GetBlockTemplateRequest
150146
{
151147
WalletAddress = poolConfig.Address,
@@ -157,8 +153,6 @@ private async Task<RpcResponse<GetBlockTemplateResponse>> GetBlockTemplateAsync(
157153

158154
private RpcResponse<GetBlockTemplateResponse> GetBlockTemplateFromJson(string json)
159155
{
160-
logger.LogInvoke();
161-
162156
var result = JsonConvert.DeserializeObject<JsonRpcResponse>(json);
163157

164158
return new RpcResponse<GetBlockTemplateResponse>(result.ResultAs<GetBlockTemplateResponse>());
@@ -182,8 +176,6 @@ private async Task ShowDaemonSyncProgressAsync(CancellationToken ct)
182176

183177
private async Task UpdateNetworkStatsAsync(CancellationToken ct)
184178
{
185-
logger.LogInvoke();
186-
187179
try
188180
{
189181
var response = await rpc.ExecuteAsync(logger, CryptonoteCommands.GetInfo, ct);
@@ -336,7 +328,6 @@ public async ValueTask<Share> SubmitShareAsync(StratumConnection worker,
336328
Contract.RequiresNonNull(worker, nameof(worker));
337329
Contract.RequiresNonNull(request, nameof(request));
338330

339-
logger.LogInvoke(new object[] { worker.ConnectionId });
340331
var context = worker.ContextAs<CryptonoteWorkerContext>();
341332

342333
var job = currentJob;

src/Miningcore/Blockchain/Cryptonote/CryptonotePayoutHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Miningcore.Blockchain.Cryptonote.DaemonResponses;
77
using Miningcore.Configuration;
88
using Miningcore.Extensions;
9-
using Miningcore.JsonRpc;
109
using Miningcore.Messaging;
1110
using Miningcore.Mining;
1211
using Miningcore.Native;

0 commit comments

Comments
 (0)