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

Commit fa4dea5

Browse files
committed
feat: add support for ravencoin
stuff wip fix: native bindings wip fuck yeah wip payout fix payout cleanup raven -> ravencoin more cleanup
1 parent bfabc54 commit fa4dea5

27 files changed

+2180
-995
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,4 @@ fabric.properties
210210
/*/*/*/*.a
211211
/*/*/*/*/*/*/*/*.o
212212
/*/*/*/*/*/*/*/*/*.o
213-
/*/*/*/*/*/*/*/*/*/*.o
214-
/*/*/*/*/*/*/*/*/*/*.o
213+
/*/*/*/*/*/*/*/*/*/*.o

examples/ravencoin_pool.json

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"logging": {
3+
"level": "info",
4+
"enableConsoleLog": true,
5+
"enableConsoleColors": true,
6+
"logFile": "",
7+
"apiLogFile": "",
8+
"logBaseDirectory": "",
9+
"perPoolLogFile": true
10+
},
11+
"banning": {
12+
"manager": "Integrated",
13+
"banOnJunkReceive": true,
14+
"banOnInvalidShares": true,
15+
"banOnLoginFailure": true
16+
},
17+
"notifications": {
18+
"enabled": false,
19+
"email": {
20+
"host": "smtp.example.com",
21+
"port": 465,
22+
"user": "user",
23+
"password": "password",
24+
"fromAddress": "info@yourpool.org",
25+
"fromName": "pool support"
26+
},
27+
"admin": {
28+
"enabled": true,
29+
"emailAddress": "admin@yourpool.org",
30+
"notifyBlockFound": false
31+
}
32+
},
33+
"persistence": {
34+
"postgres": {
35+
"host": "localhost",
36+
"port": 5432,
37+
"user": "miningcore",
38+
"password": "miningcore",
39+
"database": "miningcore"
40+
}
41+
},
42+
"paymentProcessing": {
43+
"enabled": true,
44+
"interval": 100
45+
},
46+
"shareRecoveryFile": "/app/recovered-shares.txt",
47+
"api": {
48+
"enabled": true,
49+
"listenAddress": "0.0.0.0",
50+
"port": 5000,
51+
"metricsIpWhitelist": ["127.0.0.1"],
52+
"adminIpWhitelist": ["127.0.0.1"],
53+
"rateLimiting": {
54+
"disabled": false,
55+
"rules": [
56+
{
57+
"Endpoint": "*",
58+
"Period": "1s",
59+
"Limit": 500
60+
}
61+
],
62+
"ipWhitelist": ["127.0.0.1"]
63+
}
64+
},
65+
"nicehashClusterConfig": {
66+
"enableAutoDiff": true
67+
},
68+
"clusterName": "devel_1",
69+
"pools": [
70+
{
71+
"id": "rvn1",
72+
"enabled": true,
73+
"coin": "ravencoin",
74+
"address": "mxR4ic4Q32giqfcYqQGxDteGhzkjgA2eX6",
75+
"rewardRecipients": [
76+
{
77+
"type": "op",
78+
"address": "mwQo1fhe1sAYtywSPEXEp7vGxFS46qzsnB",
79+
"percentage": 1
80+
}
81+
],
82+
"blockRefreshInterval": 120,
83+
"clientConnectionTimeout": 600,
84+
"banning": {
85+
"enabled": true,
86+
"time": 600,
87+
"invalidPercent": 50,
88+
"checkThreshold": 50
89+
},
90+
"ports": {
91+
"4600": {
92+
"name": "test",
93+
"listenAddress": "*",
94+
"difficulty": 1,
95+
"varDiff": null
96+
}
97+
},
98+
"daemons": [
99+
{
100+
"host": "127.0.0.1",
101+
"port": 8766,
102+
"user": "user",
103+
"password": "passwd"
104+
}
105+
],
106+
"paymentProcessing": {
107+
"enabled": true,
108+
"minimumPayment": 10000,
109+
"payoutScheme": "PPLNS",
110+
"payoutSchemeConfig": {
111+
"factor": 0.5
112+
}
113+
}
114+
}
115+
]
116+
}
117+

src/Miningcore/AutofacModule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Miningcore.Blockchain.Cryptonote;
88
using Miningcore.Blockchain.Equihash;
99
using Miningcore.Blockchain.Ethereum;
10+
using Miningcore.Blockchain.Ravencoin;
1011
using Miningcore.Configuration;
1112
using Miningcore.Crypto;
1213
using Miningcore.Crypto.Hashing.Equihash;
@@ -176,6 +177,11 @@ protected override void Load(ContainerBuilder builder)
176177
builder.RegisterType<EquihashJobManager>();
177178
builder.RegisterType<ErgoJobManager>();
178179

180+
//////////////////////
181+
// Ravencoin
182+
183+
builder.RegisterType<RavencoinJobManager>();
184+
179185
base.Load(builder);
180186
}
181187
}

src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ protected virtual Transaction CreateOutputTransaction()
243243
if(coin.HasMasterNodes)
244244
rewardToPool = CreateMasternodeOutputs(tx, rewardToPool);
245245

246-
if (coin.HasFounderFee)
246+
if(coin.HasFounderFee)
247247
rewardToPool = CreateFounderOutputs(tx, rewardToPool);
248248

249-
if (coin.HasMinerFund)
249+
if(coin.HasMinerFund)
250250
rewardToPool = CreateMinerFundOutputs(tx, rewardToPool);
251251

252252
// Remaining amount goes to pool
@@ -492,10 +492,10 @@ protected virtual Money CreateMasternodeOutputs(Transaction tx, Money reward)
492492

493493
protected virtual Money CreateFounderOutputs(Transaction tx, Money reward)
494494
{
495-
if (founderParameters.Founder != null)
495+
if(founderParameters.Founder != null)
496496
{
497497
Founder[] founders;
498-
if (founderParameters.Founder.Type == JTokenType.Array)
498+
if(founderParameters.Founder.Type == JTokenType.Array)
499499
founders = founderParameters.Founder.ToObject<Founder[]>();
500500
else
501501
founders = new[] { founderParameters.Founder.ToObject<Founder>() };
@@ -529,7 +529,7 @@ protected virtual Money CreateMinerFundOutputs(Transaction tx, Money reward)
529529
{
530530
var payeeReward = minerFundParameters.MinimumValue;
531531

532-
if (!string.IsNullOrEmpty(minerFundParameters.Addresses?.FirstOrDefault()))
532+
if(!string.IsNullOrEmpty(minerFundParameters.Addresses?.FirstOrDefault()))
533533
{
534534
var payeeAddress = BitcoinUtils.AddressToDestination(minerFundParameters.Addresses[0], network);
535535
tx.Outputs.Add(payeeReward, payeeAddress);
@@ -612,10 +612,10 @@ public void Init(BlockTemplate blockTemplate, string jobId,
612612
if(coin.HasPayee)
613613
payeeParameters = BlockTemplate.Extra.SafeExtensionDataAs<PayeeBlockTemplateExtra>();
614614

615-
if (coin.HasFounderFee)
615+
if(coin.HasFounderFee)
616616
founderParameters = BlockTemplate.Extra.SafeExtensionDataAs<FounderBlockTemplateExtra>();
617617

618-
if (coin.HasMinerFund)
618+
if(coin.HasMinerFund)
619619
minerFundParameters = BlockTemplate.Extra.SafeExtensionDataAs<MinerFundTemplateExtra>("coinbasetxn", "minerfund");
620620

621621
this.coinbaseHasher = coinbaseHasher;

src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected async Task<SubmitResult> SubmitBlockAsync(Share share, string blockHex
262262
? new RpcRequest(BitcoinCommands.SubmitBlock, new[] { blockHex })
263263
: new RpcRequest(BitcoinCommands.GetBlockTemplate, new { mode = "submit", data = blockHex });
264264

265-
var batch = new []
265+
var batch = new[]
266266
{
267267
submitBlockRequest,
268268
new RpcRequest(BitcoinCommands.GetBlock, new[] { share.BlockHash })
@@ -466,17 +466,17 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
466466
PostChainIdentifyConfigure();
467467

468468
// ensure pool owns wallet
469-
if(validateAddressResponse is not {IsValid: true})
469+
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} ||
472+
isPoS = poolConfig.Template is BitcoinTemplate { IsPseudoPoS: true } ||
473473
(difficultyResponse.Values().Any(x => x.Path == "proof-of-stake" && !difficultyResponse.Values().Any(x => x.Path == "proof-of-work")));
474474

475475
// Create pool address script from response
476476
if(!isPoS)
477477
{
478478
if(extraPoolConfig != null && extraPoolConfig.AddressType != BitcoinAddressType.Legacy)
479-
logger.Info(()=> $"Interpreting pool address {poolConfig.Address} as type {extraPoolConfig?.AddressType.ToString()}");
479+
logger.Info(() => $"Interpreting pool address {poolConfig.Address} as type {extraPoolConfig?.AddressType.ToString()}");
480480

481481
poolAddressDestination = AddressToDestination(poolConfig.Address, extraPoolConfig?.AddressType);
482482
}
@@ -488,8 +488,8 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
488488
if(clusterConfig.PaymentProcessing?.Enabled == true && poolConfig.PaymentProcessing?.Enabled == true)
489489
{
490490
// ensure pool owns wallet
491-
if(validateAddressResponse is {IsMine: false} && addressInfoResponse is {IsMine: false})
492-
logger.Warn(()=> $"Daemon does not own pool-address '{poolConfig.Address}'");
491+
if(validateAddressResponse is { IsMine: false } && addressInfoResponse is { IsMine: false })
492+
logger.Warn(() => $"Daemon does not own pool-address '{poolConfig.Address}'");
493493
}
494494

495495
// update stats
@@ -512,7 +512,7 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
512512
// Periodically update network stats
513513
Observable.Interval(TimeSpan.FromMinutes(10))
514514
.Select(_ => Observable.FromAsync(() =>
515-
Guard(()=> !hasLegacyDaemon ? UpdateNetworkStatsAsync(ct) : UpdateNetworkStatsLegacyAsync(ct),
515+
Guard(() => !hasLegacyDaemon ? UpdateNetworkStatsAsync(ct) : UpdateNetworkStatsLegacyAsync(ct),
516516
ex => logger.Error(ex))))
517517
.Concat()
518518
.Subscribe();
@@ -573,7 +573,7 @@ public virtual async Task<bool> ValidateAddressAsync(string address, Cancellatio
573573

574574
var result = await rpc.ExecuteAsync<ValidateAddressResponse>(logger, BitcoinCommands.ValidateAddress, ct, new[] { address });
575575

576-
return result.Response is {IsValid: true};
576+
return result.Response is { IsValid: true };
577577
}
578578

579579
#endregion // API-Surface

src/Miningcore/Blockchain/Bitcoin/BitcoinPayoutHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
using Miningcore.Util;
1616
using Newtonsoft.Json;
1717
using Newtonsoft.Json.Linq;
18+
using static Miningcore.Util.ActionUtils;
1819
using Block = Miningcore.Persistence.Model.Block;
1920
using Contract = Miningcore.Contracts.Contract;
20-
using static Miningcore.Util.ActionUtils;
2121

2222
namespace Miningcore.Blockchain.Bitcoin;
2323

24-
[CoinFamily(CoinFamily.Bitcoin)]
24+
[CoinFamily(CoinFamily.Bitcoin, CoinFamily.Ravencoin)]
2525
public class BitcoinPayoutHandler : PayoutHandlerBase,
2626
IPayoutHandler
2727
{
@@ -250,8 +250,8 @@ public virtual async Task PayoutAsync(IMiningPool pool, Balance[] balances, Canc
250250

251251
var didUnlockWallet = false;
252252

253-
// send command
254-
tryTransfer:
253+
// send command
254+
tryTransfer:
255255
var result = await rpcClient.ExecuteAsync<string>(logger, BitcoinCommands.SendMany, ct, args);
256256

257257
if(result.Error == null)
@@ -336,7 +336,7 @@ await Guard(async () =>
336336
// use a common id for all log entries related to this transfer
337337
var transferId = CorrelationIdGenerator.GetNextId();
338338

339-
logger.Info(()=> $"[{LogCategory}] [{transferId}] Sending {FormatAmount(amount)} to {address}");
339+
logger.Info(() => $"[{LogCategory}] [{transferId}] Sending {FormatAmount(amount)} to {address}");
340340

341341
var result = await rpcClient.ExecuteAsync<string>(logger, BitcoinCommands.SendToAddress, ct, new object[]
342342
{
@@ -376,10 +376,10 @@ await Guard(async () =>
376376

377377
if(txFailures.Any())
378378
{
379-
var failureBalances = txFailures.Select(x=> new Balance { Amount = x.Item1.Value }).ToArray();
379+
var failureBalances = txFailures.Select(x => new Balance { Amount = x.Item1.Value }).ToArray();
380380
var error = string.Join(", ", txFailures.Select(x => $"{x.Item1.Key} {FormatAmount(x.Item1.Value)}: {x.Item2.Message}"));
381381

382-
logger.Error(()=> $"[{LogCategory}] Failed to transfer the following balances: {error}");
382+
logger.Error(() => $"[{LogCategory}] Failed to transfer the following balances: {error}");
383383

384384
NotifyPayoutFailure(poolConfig.Id, failureBalances, error, null);
385385
}

0 commit comments

Comments
 (0)