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

feat: add support for ravencoin #1627

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,4 @@ fabric.properties
/*/*/*/*.a
/*/*/*/*/*/*/*/*.o
/*/*/*/*/*/*/*/*/*.o
/*/*/*/*/*/*/*/*/*/*.o
/*/*/*/*/*/*/*/*/*/*.o
/*/*/*/*/*/*/*/*/*/*.o
117 changes: 117 additions & 0 deletions examples/ravencoin_pool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"logging": {
"level": "info",
"enableConsoleLog": true,
"enableConsoleColors": true,
"logFile": "",
"apiLogFile": "",
"logBaseDirectory": "",
"perPoolLogFile": true
},
"banning": {
"manager": "Integrated",
"banOnJunkReceive": true,
"banOnInvalidShares": true,
"banOnLoginFailure": true
},
"notifications": {
"enabled": false,
"email": {
"host": "smtp.example.com",
"port": 465,
"user": "user",
"password": "password",
"fromAddress": "[email protected]",
"fromName": "pool support"
},
"admin": {
"enabled": true,
"emailAddress": "[email protected]",
"notifyBlockFound": false
}
},
"persistence": {
"postgres": {
"host": "localhost",
"port": 5432,
"user": "miningcore",
"password": "miningcore",
"database": "miningcore"
}
},
"paymentProcessing": {
"enabled": true,
"interval": 100
},
"shareRecoveryFile": "/app/recovered-shares.txt",
"api": {
"enabled": true,
"listenAddress": "0.0.0.0",
"port": 5000,
"metricsIpWhitelist": ["127.0.0.1"],
"adminIpWhitelist": ["127.0.0.1"],
"rateLimiting": {
"disabled": false,
"rules": [
{
"Endpoint": "*",
"Period": "1s",
"Limit": 500
}
],
"ipWhitelist": ["127.0.0.1"]
}
},
"nicehashClusterConfig": {
"enableAutoDiff": true
},
"clusterName": "devel_1",
"pools": [
{
"id": "rvn1",
"enabled": true,
"coin": "ravencoin",
"address": "mxR4ic4Q32giqfcYqQGxDteGhzkjgA2eX6",
"rewardRecipients": [
{
"type": "op",
"address": "mwQo1fhe1sAYtywSPEXEp7vGxFS46qzsnB",
"percentage": 1
}
],
"blockRefreshInterval": 120,
"clientConnectionTimeout": 600,
"banning": {
"enabled": true,
"time": 600,
"invalidPercent": 50,
"checkThreshold": 50
},
"ports": {
"4600": {
"name": "test",
"listenAddress": "*",
"difficulty": 1,
"varDiff": null
}
},
"daemons": [
{
"host": "127.0.0.1",
"port": 8766,
"user": "user",
"password": "passwd"
}
],
"paymentProcessing": {
"enabled": true,
"minimumPayment": 10000,
"payoutScheme": "PPLNS",
"payoutSchemeConfig": {
"factor": 0.5
}
}
}
]
}

4 changes: 3 additions & 1 deletion src/.idea/.idea.Miningcore/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Miningcore/AutofacModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Miningcore.Blockchain.Cryptonote;
using Miningcore.Blockchain.Equihash;
using Miningcore.Blockchain.Ethereum;
using Miningcore.Blockchain.Ravencoin;
using Miningcore.Configuration;
using Miningcore.Crypto;
using Miningcore.Crypto.Hashing.Equihash;
Expand Down Expand Up @@ -176,6 +177,11 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<EquihashJobManager>();
builder.RegisterType<ErgoJobManager>();

//////////////////////
// Ravencoin

builder.RegisterType<RavencoinJobManager>();

base.Load(builder);
}
}
14 changes: 7 additions & 7 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ protected virtual Transaction CreateOutputTransaction()
if(coin.HasMasterNodes)
rewardToPool = CreateMasternodeOutputs(tx, rewardToPool);

if (coin.HasFounderFee)
if(coin.HasFounderFee)
rewardToPool = CreateFounderOutputs(tx, rewardToPool);

if (coin.HasMinerFund)
if(coin.HasMinerFund)
rewardToPool = CreateMinerFundOutputs(tx, rewardToPool);

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

protected virtual Money CreateFounderOutputs(Transaction tx, Money reward)
{
if (founderParameters.Founder != null)
if(founderParameters.Founder != null)
{
Founder[] founders;
if (founderParameters.Founder.Type == JTokenType.Array)
if(founderParameters.Founder.Type == JTokenType.Array)
founders = founderParameters.Founder.ToObject<Founder[]>();
else
founders = new[] { founderParameters.Founder.ToObject<Founder>() };
Expand Down Expand Up @@ -529,7 +529,7 @@ protected virtual Money CreateMinerFundOutputs(Transaction tx, Money reward)
{
var payeeReward = minerFundParameters.MinimumValue;

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

if (coin.HasFounderFee)
if(coin.HasFounderFee)
founderParameters = BlockTemplate.Extra.SafeExtensionDataAs<FounderBlockTemplateExtra>();

if (coin.HasMinerFund)
if(coin.HasMinerFund)
minerFundParameters = BlockTemplate.Extra.SafeExtensionDataAs<MinerFundTemplateExtra>("coinbasetxn", "minerfund");

this.coinbaseHasher = coinbaseHasher;
Expand Down
16 changes: 8 additions & 8 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected async Task<SubmitResult> SubmitBlockAsync(Share share, string blockHex
? new RpcRequest(BitcoinCommands.SubmitBlock, new[] { blockHex })
: new RpcRequest(BitcoinCommands.GetBlockTemplate, new { mode = "submit", data = blockHex });

var batch = new []
var batch = new[]
{
submitBlockRequest,
new RpcRequest(BitcoinCommands.GetBlock, new[] { share.BlockHash })
Expand Down Expand Up @@ -466,17 +466,17 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
PostChainIdentifyConfigure();

// ensure pool owns wallet
if(validateAddressResponse is not {IsValid: true})
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} ||
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)
{
if(extraPoolConfig != null && extraPoolConfig.AddressType != BitcoinAddressType.Legacy)
logger.Info(()=> $"Interpreting pool address {poolConfig.Address} as type {extraPoolConfig?.AddressType.ToString()}");
logger.Info(() => $"Interpreting pool address {poolConfig.Address} as type {extraPoolConfig?.AddressType.ToString()}");

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

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

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

return result.Response is {IsValid: true};
return result.Response is { IsValid: true };
}

#endregion // API-Surface
Expand Down
14 changes: 7 additions & 7 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
using Miningcore.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Miningcore.Util.ActionUtils;
using Block = Miningcore.Persistence.Model.Block;
using Contract = Miningcore.Contracts.Contract;
using static Miningcore.Util.ActionUtils;

namespace Miningcore.Blockchain.Bitcoin;

[CoinFamily(CoinFamily.Bitcoin)]
[CoinFamily(CoinFamily.Bitcoin, CoinFamily.Ravencoin)]
public class BitcoinPayoutHandler : PayoutHandlerBase,
IPayoutHandler
{
Expand Down Expand Up @@ -250,8 +250,8 @@ public virtual async Task PayoutAsync(IMiningPool pool, Balance[] balances, Canc

var didUnlockWallet = false;

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

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

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

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

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

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

NotifyPayoutFailure(poolConfig.Id, failureBalances, error, null);
}
Expand Down
Loading