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

Commit 20c2690

Browse files
committed
fix: linter warnings and cleanup
1 parent 7b6f393 commit 20c2690

File tree

8 files changed

+66
-64
lines changed

8 files changed

+66
-64
lines changed

src/.idea/.idea.Miningcore/.idea/indexLayout.xml

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

src/Miningcore/Blockchain/Ravencoin/RavencoinJob.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ namespace Miningcore.Blockchain.Ravencoin;
1919

2020
public class RavencoinJobParams
2121
{
22-
public ulong Height { get; set; }
22+
public ulong Height { get; init; }
2323
public bool CleanJobs { get; set; }
2424
}
2525

2626
public class RavencoinJob : BitcoinJob
2727
{
28-
protected Cache kawpowHasher;
29-
protected new RavencoinJobParams jobParams;
28+
private Cache kawpowHasher;
29+
private new RavencoinJobParams jobParams;
3030

31-
protected byte[] SerializeHeader(Span<byte> coinbaseHash)
31+
private byte[] SerializeHeader(Span<byte> coinbaseHash)
3232
{
3333
// build merkle-root
3434
var merkleRoot = mt.WithFirst(coinbaseHash.ToArray());
@@ -51,7 +51,7 @@ protected byte[] SerializeHeader(Span<byte> coinbaseHash)
5151
return blockHeader.ToBytes();
5252
}
5353

54-
public virtual (Share Share, string BlockHex) ProcessShareInternal(ILogger logger,
54+
public (Share Share, string BlockHex) ProcessShareInternal(ILogger logger,
5555
StratumConnection worker, ulong nonce, string inputHeaderHash, string mixHash)
5656
{
5757
var context = worker.ContextAs<RavencoinWorkerContext>();
@@ -68,7 +68,6 @@ public virtual (Share Share, string BlockHex) ProcessShareInternal(ILogger logge
6868
headerHasher.Digest(headerBytes, headerHash);
6969
headerHash.Reverse();
7070

71-
var headerValue = new uint256(headerHash);
7271
var headerHashHex = headerHash.ToHexString();
7372

7473
if(headerHashHex != inputHeaderHash)
@@ -119,25 +118,25 @@ public virtual (Share Share, string BlockHex) ProcessShareInternal(ILogger logge
119118
Difficulty = stratumDifficulty / shareMultiplier,
120119
};
121120

122-
if(isBlockCandidate)
121+
if(!isBlockCandidate)
123122
{
124-
result.IsBlockCandidate = true;
125-
result.BlockHash = resultBytes.ReverseInPlace().ToHexString();
123+
return (result, null);
124+
}
126125

127-
var blockBytes = SerializeBlock(headerBytes, coinbase, nonce, mixHashOut);
128-
var blockHex = blockBytes.ToHexString();
126+
result.IsBlockCandidate = true;
127+
result.BlockHash = resultBytes.ReverseInPlace().ToHexString();
129128

130-
return (result, blockHex);
131-
}
129+
var blockBytes = SerializeBlock(headerBytes, coinbase, nonce, mixHashOut);
130+
var blockHex = blockBytes.ToHexString();
132131

133-
return (result, null);
132+
return (result, blockHex);
134133
}
135134

136-
protected virtual byte[] SerializeCoinbase(string extraNonce1)
135+
private byte[] SerializeCoinbase(string extraNonce1)
137136
{
138137
var extraNonce1Bytes = extraNonce1.HexToByteArray();
139138

140-
using(var stream = new MemoryStream())
139+
using var stream = new MemoryStream();
141140
{
142141
stream.Write(coinbaseInitial);
143142
stream.Write(extraNonce1Bytes);
@@ -147,12 +146,12 @@ protected virtual byte[] SerializeCoinbase(string extraNonce1)
147146
}
148147
}
149148

150-
protected virtual byte[] SerializeBlock(byte[] header, byte[] coinbase, ulong nonce, byte[] mixHash)
149+
private byte[] SerializeBlock(byte[] header, byte[] coinbase, ulong nonce, byte[] mixHash)
151150
{
152151
var rawTransactionBuffer = BuildRawTransactionBuffer();
153152
var transactionCount = (uint) BlockTemplate.Transactions.Length + 1; // +1 for prepended coinbase tx
154153

155-
using(var stream = new MemoryStream())
154+
using var stream = new MemoryStream();
156155
{
157156
var bs = new BitcoinStream(stream, true);
158157

@@ -198,7 +197,8 @@ public void Init(BlockTemplate blockTemplate, string jobId,
198197
var coinbaseString = !string.IsNullOrEmpty(cc.PaymentProcessing?.CoinbaseString) ?
199198
cc.PaymentProcessing?.CoinbaseString.Trim() : "Miningcore";
200199

201-
this.scriptSigFinalBytes = new Script(Op.GetPushOp(Encoding.UTF8.GetBytes(coinbaseString))).ToBytes();
200+
if(!string.IsNullOrEmpty(coinbaseString))
201+
this.scriptSigFinalBytes = new Script(Op.GetPushOp(Encoding.UTF8.GetBytes(coinbaseString))).ToBytes();
202202

203203
this.Difficulty = new Target(System.Numerics.BigInteger.Parse(BlockTemplate.Target, NumberStyles.HexNumber)).Difficulty;
204204

@@ -233,7 +233,7 @@ public void Init(BlockTemplate blockTemplate, string jobId,
233233
return jobParams;
234234
}
235235

236-
public virtual void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string headerHash)
236+
public void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string headerHash)
237237
{
238238
workerJob.Job = this;
239239
workerJob.Height = BlockTemplate.Height;
@@ -242,7 +242,7 @@ public virtual void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string he
242242
headerHash = CreateHeaderHash(workerJob);
243243
}
244244

245-
protected virtual string CreateHeaderHash(RavencoinWorkerJob workerJob)
245+
private string CreateHeaderHash(RavencoinWorkerJob workerJob)
246246
{
247247
var headerHasher = coin.HeaderHasherValue;
248248
var coinbaseHasher = coin.CoinbaseHasherValue;

src/Miningcore/Blockchain/Ravencoin/RavencoinJobManager.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,38 @@ public RavencoinJobManager(
2929

3030
private RavencoinTemplate coin;
3131

32-
protected async Task<RpcResponse<BlockTemplate>> GetBlockTemplateAsync(CancellationToken ct)
32+
private async Task<RpcResponse<BlockTemplate>> GetBlockTemplateAsync(CancellationToken ct)
3333
{
3434
var result = await rpc.ExecuteAsync<BlockTemplate>(logger,
3535
BitcoinCommands.GetBlockTemplate, ct, extraPoolConfig?.GBTArgs ?? (object) GetBlockTemplateParams());
3636

3737
return result;
3838
}
3939

40-
protected RpcResponse<BlockTemplate> GetBlockTemplateFromJson(string json)
40+
private RpcResponse<BlockTemplate> GetBlockTemplateFromJson(string json)
4141
{
4242
var result = JsonConvert.DeserializeObject<JsonRpcResponse>(json);
4343

4444
return new RpcResponse<BlockTemplate>(result!.ResultAs<BlockTemplate>());
4545
}
4646

47-
private RavencoinJob CreateJob()
47+
private static RavencoinJob CreateJob()
4848
{
49-
return new();
49+
return new RavencoinJob();
5050
}
5151

52-
public double ShareMultiplier => coin.ShareMultiplier;
52+
private double ShareMultiplier => coin.ShareMultiplier;
5353

5454

5555
protected override void PostChainIdentifyConfigure()
5656
{
5757
base.PostChainIdentifyConfigure();
5858

59-
if(poolConfig.EnableInternalStratum == true && coin.HeaderHasherValue is IHashAlgorithmInit hashInit)
60-
{
61-
if(!hashInit.DigestInit(poolConfig))
62-
logger.Error(() => $"{hashInit.GetType().Name} initialization failed");
63-
}
59+
if(poolConfig.EnableInternalStratum == false || coin.HeaderHasherValue is not IHashAlgorithmInit hashInit)
60+
return;
61+
62+
if(!hashInit.DigestInit(poolConfig))
63+
logger.Error(() => $"{hashInit.GetType().Name} initialization failed");
6464
}
6565

6666
protected override async Task PostStartInitAsync(CancellationToken ct)
@@ -74,7 +74,7 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
7474
{
7575
var blockTemplate = await GetBlockTemplateAsync(ct);
7676

77-
if(blockTemplate != null || blockTemplate.Response != null)
77+
if(blockTemplate?.Response != null)
7878
{
7979
logger.Info(() => "Loading current light cache ...");
8080

@@ -123,7 +123,9 @@ await GetBlockTemplateAsync(ct) :
123123
{
124124
job = CreateJob();
125125

126-
var kawpowHasher = await coin.KawpowHasher.GetCacheAsync(logger, (int) blockTemplate.Height);
126+
var blockHeight = forceUpdate ? job.BlockTemplate.Height : blockTemplate.Height;
127+
128+
var kawpowHasher = await coin.KawpowHasher.GetCacheAsync(logger, (int) blockHeight);
127129

128130
job.Init(blockTemplate, NextJobId(),
129131
poolConfig, extraPoolConfig, clusterConfig, clock, poolAddressDestination, network, isPoS,
@@ -198,7 +200,7 @@ public override void Configure(PoolConfig pc, ClusterConfig cc)
198200
base.Configure(pc, cc);
199201
}
200202

201-
public virtual object[] GetSubscriberData(StratumConnection worker)
203+
public object[] GetSubscriberData(StratumConnection worker)
202204
{
203205
Contract.RequiresNonNull(worker);
204206

@@ -216,7 +218,7 @@ public virtual object[] GetSubscriberData(StratumConnection worker)
216218
return responseData;
217219
}
218220

219-
public virtual void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string headerHash)
221+
public void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string headerHash)
220222
{
221223
headerHash = null;
222224

@@ -231,7 +233,7 @@ public virtual void PrepareWorkerJob(RavencoinWorkerJob workerJob, out string he
231233
}
232234
}
233235

234-
public virtual async ValueTask<Share> SubmitShareAsync(StratumConnection worker, object submission,
236+
public async ValueTask<Share> SubmitShareAsync(StratumConnection worker, object submission,
235237
CancellationToken ct)
236238
{
237239
Contract.RequiresNonNull(worker);
@@ -245,9 +247,9 @@ public virtual async ValueTask<Share> SubmitShareAsync(StratumConnection worker,
245247
// extract params
246248
var workerValue = (submitParams[0] as string)?.Trim();
247249
var jobId = submitParams[1] as string;
248-
var nonce = (submitParams[2] as string).Substring(2);
249-
var headerHash = (submitParams[3] as string).Substring(2);
250-
var mixHash = (submitParams[4] as string).Substring(2);
250+
var nonce = (submitParams[2] as string)?.Substring(2);
251+
var headerHash = (submitParams[3] as string)?.Substring(2);
252+
var mixHash = (submitParams[4] as string)?.Substring(2);
251253

252254
if(string.IsNullOrEmpty(workerValue))
253255
throw new StratumException(StratumError.Other, "missing or invalid workername");
@@ -308,4 +310,4 @@ public virtual async ValueTask<Share> SubmitShareAsync(StratumConnection worker,
308310
}
309311

310312
#endregion // API-Surface
311-
}
313+
}

src/Miningcore/Blockchain/Ravencoin/RavencoinPool.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public RavencoinPool(IComponentContext ctx,
3737
{
3838
}
3939

40-
protected RavencoinJobParams currentJobParams;
40+
private RavencoinJobParams currentJobParams;
4141
private long currentJobId;
42-
protected RavencoinJobManager manager;
42+
private RavencoinJobManager manager;
4343
private RavencoinTemplate coin;
4444

4545
protected virtual async Task OnSubscribeAsync(StratumConnection connection, Timestamped<JsonRpcRequest> tsRequest)
@@ -80,7 +80,7 @@ protected virtual async Task OnSubscribeAsync(StratumConnection connection, Time
8080
context.SetDifficulty(nicehashDiff.Value);
8181
}
8282

83-
var minerJobParams = CreateWorkerJob(connection, (int) currentJobParams.Height, currentJobParams.CleanJobs);
83+
var minerJobParams = CreateWorkerJob(connection, currentJobParams.CleanJobs);
8484
// send intial update
8585
await connection.NotifyAsync(RavencoinStratumMethods.SetDifficulty, new object[] { RavencoinUtils.EncodeTarget(context.Difficulty) });
8686
await connection.NotifyAsync(RavencoinStratumMethods.MiningNotify, minerJobParams);
@@ -150,7 +150,7 @@ protected virtual async Task OnAuthorizeAsync(StratumConnection connection, Time
150150
}
151151
}
152152

153-
private object CreateWorkerJob(StratumConnection connection, int block, bool update)
153+
private object CreateWorkerJob(StratumConnection connection, bool update)
154154
{
155155
var context = connection.ContextAs<RavencoinWorkerContext>();
156156
var job = new RavencoinWorkerJob(NextJobId(), context.ExtraNonce1);
@@ -256,11 +256,11 @@ protected virtual async Task OnNewJobAsync(object job)
256256

257257
currentJobParams = job as RavencoinJobParams;
258258

259-
await Guard(() => ForEachMinerAsync(async (connection, ct) =>
259+
await Guard(() => ForEachMinerAsync(async (connection, _) =>
260260
{
261261
var context = connection.ContextAs<RavencoinWorkerContext>();
262262

263-
var minerJobParams = CreateWorkerJob(connection, (int) currentJobParams.Height, currentJobParams.CleanJobs);
263+
var minerJobParams = CreateWorkerJob(connection, currentJobParams.CleanJobs);
264264

265265
if(context.ApplyPendingDifficulty())
266266
await connection.NotifyAsync(RavencoinStratumMethods.SetDifficulty, new object[] { RavencoinUtils.EncodeTarget(context.Difficulty) });
@@ -385,13 +385,11 @@ protected override async Task OnVarDiffUpdateAsync(StratumConnection connection,
385385

386386
if(connection.Context.ApplyPendingDifficulty())
387387
{
388-
var context = connection.ContextAs<RavencoinWorkerContext>();
389-
var minerJobParams = CreateWorkerJob(connection, (int) currentJobParams.Height, currentJobParams.CleanJobs);
390-
388+
var minerJobParams = CreateWorkerJob(connection, currentJobParams.CleanJobs);
391389
await connection.NotifyAsync(RavencoinStratumMethods.SetDifficulty, new object[] { RavencoinUtils.EncodeTarget(connection.Context.Difficulty) });
392390
await connection.NotifyAsync(RavencoinStratumMethods.MiningNotify, minerJobParams);
393391
}
394392
}
395393

396394
#endregion // Overrides
397-
}
395+
}

src/Miningcore/Blockchain/Ravencoin/RavencoinWorkerContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ public class RavencoinWorkerContext : WorkerContextBase
1919
/// </summary>
2020
public string ExtraNonce1 { get; set; }
2121

22-
private List<RavencoinWorkerJob> validJobs { get; } = new();
22+
private List<RavencoinWorkerJob> ValidJobs { get; } = new();
2323

2424
public void AddJob(RavencoinWorkerJob job)
2525
{
26-
validJobs.Insert(0, job);
26+
ValidJobs.Insert(0, job);
2727

28-
while(validJobs.Count > 4)
29-
validJobs.RemoveAt(validJobs.Count - 1);
28+
while(ValidJobs.Count > 4)
29+
ValidJobs.RemoveAt(ValidJobs.Count - 1);
3030
}
3131

3232
public RavencoinWorkerJob FindJob(string jobId)
3333
{
34-
return validJobs.FirstOrDefault(x => x.Id == jobId);
34+
return ValidJobs.FirstOrDefault(x => x.Id == jobId);
3535
}
3636
}

src/Miningcore/Blockchain/Ravencoin/RavencoinWorkerJob.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public RavencoinWorkerJob(string jobId, string extraNonce1)
2222
public string Bits { get; set; }
2323
public string SeedHash { get; set; }
2424

25-
public readonly ConcurrentDictionary<string, bool> Submissions = new(StringComparer.OrdinalIgnoreCase);
25+
private readonly ConcurrentDictionary<string, bool> submissions = new(StringComparer.OrdinalIgnoreCase);
2626

2727
private bool RegisterSubmit(string nonce, string headerHash, string mixHash)
2828
{
@@ -32,10 +32,10 @@ private bool RegisterSubmit(string nonce, string headerHash, string mixHash)
3232
.Append(mixHash)
3333
.ToString();
3434

35-
return Submissions.TryAdd(key, true);
35+
return submissions.TryAdd(key, true);
3636
}
3737

38-
public virtual (Share Share, string BlockHex) ProcessShare(ILogger logger, StratumConnection worker, string nonce, string headerHash, string mixHash)
38+
public (Share Share, string BlockHex) ProcessShare(ILogger logger, StratumConnection worker, string nonce, string headerHash, string mixHash)
3939
{
4040
Contract.RequiresNonNull(worker);
4141
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(nonce));
@@ -51,7 +51,7 @@ public virtual (Share Share, string BlockHex) ProcessShare(ILogger logger, Strat
5151
throw new StratumException(StratumError.Other, $"incorrect size of nonce: {nonce}");
5252

5353
// check if nonce is within range
54-
if(nonce.IndexOf(context.ExtraNonce1.Substring(0, 4)) != 0)
54+
if(nonce.IndexOf(context.ExtraNonce1[0..4], StringComparison.OrdinalIgnoreCase) != 0)
5555
throw new StratumException(StratumError.Other, $"nonce out of range: {nonce}");
5656

5757
// dupe check
@@ -62,4 +62,4 @@ public virtual (Share Share, string BlockHex) ProcessShare(ILogger logger, Strat
6262

6363
return Job.ProcessShareInternal(logger, worker, nonceLong, headerHash, mixHash);
6464
}
65-
}
65+
}

src/Miningcore/Crypto/Hashing/Algorithms/Sha256DT.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public void Digest(ReadOnlySpan<byte> data, Span<byte> result, params object[] e
1010
{
1111
Contract.Requires<ArgumentException>(result.Length >= 32);
1212

13-
fixed (byte* input = data)
13+
fixed(byte* input = data)
1414
{
15-
fixed (byte* output = result)
15+
fixed(byte* output = result)
1616
{
1717
Multihash.sha256dt(input, output);
1818
}

src/Miningcore/coins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"telegram": "https://t.me/VGC_5GCASH",
1010
"discord": "https://discord.gg/uXHvyBT",
1111
"coinbaseHasher": {
12-
"hash": "sha256d"
12+
"hash": "sha256d",
1313
},
1414
"headerHasher": {
1515
"hash": "x16r-v2"

0 commit comments

Comments
 (0)