Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #9

Merged
merged 5 commits into from
Sep 4, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public class EthereumPoolConfigExtra
/// Useful to specify the real chain type when running geth
/// </summary>
public string ChainTypeOverride { get; set; }

/// <summary>
/// There are several reports of bad actors taking advantage of the old "Ethash Stratum V1" protocol in order to perform multiple dangerous attacks like man-in-the-middle (MITM) attacks
/// https://braiins.com/blog/hashrate-robbery-stratum-v2-fixes-this-and-more
/// https://eips.ethereum.org/EIPS/eip-1571
/// https://github.com/AndreaLanfranchi/EthereumStratum-2.0.0/issues/10#issuecomment-595053258
/// Based on that critical fact, mining pool should be cautious of the risks of using a such deprecated and broken stratum protocol. Used it at your own risks.
/// "Ethash Stratum V1" protocol is disabled by default
/// </summary>
public bool enableEthashStratumV1 { get; set; } = false;

/// <summary>
/// getWork stream published via ZMQ
Expand Down
31 changes: 30 additions & 1 deletion src/Miningcore/Blockchain/Ethereum/EthereumConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class EthereumConstants
public class RethereumConstants
{
public const ulong EpochLength = 32000;
public const ulong LondonHeight = 15787969;
public const ulong LondonHeight = 13524557;
public const decimal LondonBlockReward = 3.0m;
public const ulong ArrowGlacierHeight = 27200177;
public const decimal ArrowGlacierBlockReward = 2.0m;
Expand All @@ -62,6 +62,33 @@ public class EthereumClassicConstants
public const decimal BaseRewardInitial = 5.0m;
}

// OCTA block reward distribution -
// https://docs.octa.space/cryptocurrency/monetary-policy
public class OctaSpaceConstants
{
public const ulong TriangulumHardForkHeight = 10000000;
public const decimal TriangulumBlockReward = 1.0m;
public const ulong VegaHardForkHeight = 8000000;
public const decimal VegaBlockReward = 1.1m;
public const ulong BlackeyeHardForkHeight = 6000000;
public const decimal BlackeyeBlockReward = 1.2m;
public const ulong DneprHardForkHeight = 4000000;
public const decimal DneprBlockReward = 1.85m;
public const ulong MahasimHardForkHeight = 3000000;
public const decimal MahasimBlockReward = 2.3m;
public const ulong PolarisHardForkHeight = 2500000;
public const decimal PolarisBlockReward = 2.8m;
public const ulong SpringwaterHardForkHeight = 2000000;
public const decimal SpringwaterBlockReward = 3.0m;
public const ulong ZagamiHardForkHeight = 1500000;
public const decimal ZagamiBlockReward = 3.5m;
public const ulong OldenburgHardForkHeight = 1000000;
public const decimal OldenburgBlockReward = 4.0m;
public const ulong ArcturusHardForkHeight = 650000;
public const decimal ArcturusBlockReward = 5.0m;
public const decimal BaseRewardInitial = 6.5m;
}

// Callisto Monetary Policy
// https://github.com/EthereumCommonwealth/Roadmap/issues/56
public class CallistoConstants
Expand Down Expand Up @@ -147,6 +174,7 @@ public enum EthereumNetworkType
Canxium = 3003,
Rethereum = 622277,
Bitnet = 210,
OctaSpace = 800001,

Unknown = -1,
}
Expand All @@ -169,6 +197,7 @@ public enum GethChainType
Canxium = 3003,
Rethereum = 622277,
Bitnet = 210,
OctaSpace = 800001,

Unknown = -1,
}
Expand Down
28 changes: 26 additions & 2 deletions src/Miningcore/Blockchain/Ethereum/EthereumPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async Task<Block[]> ClassifyBlocksAsync(IMiningPool pool, Block[] blocks,
var gasUsed = blockHashResponse.Response.GasUsed;

var burnedFee = (decimal) 0;
if(extraPoolConfig?.ChainTypeOverride == "Ethereum" || extraPoolConfig?.ChainTypeOverride == "Main" || extraPoolConfig?.ChainTypeOverride == "MainPow" || extraPoolConfig?.ChainTypeOverride == "Ubiq" || extraPoolConfig?.ChainTypeOverride == "EtherOne" || extraPoolConfig?.ChainTypeOverride == "Pink" || extraPoolConfig?.ChainTypeOverride == "JibChain" || extraPoolConfig?.ChainTypeOverride == "Altcoin" || extraPoolConfig?.ChainTypeOverride == "Pom" || extraPoolConfig?.ChainTypeOverride == "MaxxChain" || extraPoolConfig?.ChainTypeOverride == "Canxium" || extraPoolConfig?.ChainTypeOverride == "Rethereum" || extraPoolConfig?.ChainTypeOverride == "Bitnet")
if(extraPoolConfig?.ChainTypeOverride == "Ethereum" || extraPoolConfig?.ChainTypeOverride == "Main" || extraPoolConfig?.ChainTypeOverride == "MainPow" || extraPoolConfig?.ChainTypeOverride == "Ubiq" || extraPoolConfig?.ChainTypeOverride == "EtherOne" || extraPoolConfig?.ChainTypeOverride == "Pink" || extraPoolConfig?.ChainTypeOverride == "JibChain" || extraPoolConfig?.ChainTypeOverride == "Altcoin" || extraPoolConfig?.ChainTypeOverride == "Pom" || extraPoolConfig?.ChainTypeOverride == "MaxxChain" || extraPoolConfig?.ChainTypeOverride == "Canxium" || extraPoolConfig?.ChainTypeOverride == "Rethereum" || extraPoolConfig?.ChainTypeOverride == "Bitnet" || extraPoolConfig?.ChainTypeOverride == "OctaSpace")
burnedFee = (baseGas * gasUsed / EthereumConstants.Wei);

block.Hash = blockHash;
Expand Down Expand Up @@ -291,7 +291,7 @@ public async Task PayoutAsync(IMiningPool pool, Balance[] balances, Cancellation
// ensure we have peers
var infoResponse = await rpcClient.ExecuteAsync<string>(logger, EC.GetPeerCount, ct);

if((networkType == EthereumNetworkType.Main || extraPoolConfig?.ChainTypeOverride == "Classic" || extraPoolConfig?.ChainTypeOverride == "Mordor" || networkType == EthereumNetworkType.MainPow || extraPoolConfig?.ChainTypeOverride == "Ubiq" || extraPoolConfig?.ChainTypeOverride == "EtherOne" || extraPoolConfig?.ChainTypeOverride == "Pink" || extraPoolConfig?.ChainTypeOverride == "JibChain" || extraPoolConfig?.ChainTypeOverride == "Altcoin" || extraPoolConfig?.ChainTypeOverride == "Pom" || extraPoolConfig?.ChainTypeOverride == "MaxxChain" || extraPoolConfig?.ChainTypeOverride == "Canxium" || extraPoolConfig?.ChainTypeOverride == "Rethereum" || extraPoolConfig?.ChainTypeOverride == "Bitnet") &&
if((networkType == EthereumNetworkType.Main || extraPoolConfig?.ChainTypeOverride == "Classic" || extraPoolConfig?.ChainTypeOverride == "Mordor" || networkType == EthereumNetworkType.MainPow || extraPoolConfig?.ChainTypeOverride == "Ubiq" || extraPoolConfig?.ChainTypeOverride == "EtherOne" || extraPoolConfig?.ChainTypeOverride == "Pink" || extraPoolConfig?.ChainTypeOverride == "JibChain" || extraPoolConfig?.ChainTypeOverride == "Altcoin" || extraPoolConfig?.ChainTypeOverride == "Pom" || extraPoolConfig?.ChainTypeOverride == "MaxxChain" || extraPoolConfig?.ChainTypeOverride == "Canxium" || extraPoolConfig?.ChainTypeOverride == "Rethereum" || extraPoolConfig?.ChainTypeOverride == "Bitnet" || extraPoolConfig?.ChainTypeOverride == "OctaSpace") &&
(infoResponse.Error != null || string.IsNullOrEmpty(infoResponse.Response) ||
infoResponse.Response.IntegralFromHex<int>() < EthereumConstants.MinPayoutPeerCount))
{
Expand Down Expand Up @@ -431,6 +431,30 @@ internal static decimal GetBaseBlockReward(GethChainType chainType, ulong height

case GethChainType.Bitnet:
return BitnetConstants.BaseRewardInitial;

case GethChainType.OctaSpace:
if(height >= OctaSpaceConstants.TriangulumHardForkHeight)
return OctaSpaceConstants.TriangulumBlockReward;
if(height >= OctaSpaceConstants.VegaHardForkHeight)
return OctaSpaceConstants.VegaBlockReward;
if(height >= OctaSpaceConstants.BlackeyeHardForkHeight)
return OctaSpaceConstants.BlackeyeBlockReward;
if(height >= OctaSpaceConstants.DneprHardForkHeight)
return OctaSpaceConstants.DneprBlockReward;
if(height >= OctaSpaceConstants.MahasimHardForkHeight)
return OctaSpaceConstants.MahasimBlockReward;
if(height >= OctaSpaceConstants.PolarisHardForkHeight)
return OctaSpaceConstants.PolarisBlockReward;
if(height >= OctaSpaceConstants.SpringwaterHardForkHeight)
return OctaSpaceConstants.SpringwaterBlockReward;
if(height >= OctaSpaceConstants.ZagamiHardForkHeight)
return OctaSpaceConstants.ZagamiBlockReward;
if(height >= OctaSpaceConstants.OldenburgHardForkHeight)
return OctaSpaceConstants.OldenburgBlockReward;
if(height >= OctaSpaceConstants.ArcturusHardForkHeight)
return OctaSpaceConstants.ArcturusBlockReward;

return OctaSpaceConstants.BaseRewardInitial;

default:
throw new Exception("Unable to determine block reward: Unsupported chain type");
Expand Down
41 changes: 35 additions & 6 deletions src/Miningcore/Blockchain/Ethereum/EthereumPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using Autofac;
using AutoMapper;
using Microsoft.IO;
using Miningcore.Blockchain.Ethereum.Configuration;
using Miningcore.Configuration;
using Miningcore.Extensions;
using Miningcore.JsonRpc;
using Miningcore.Messaging;
using Miningcore.Mining;
Expand Down Expand Up @@ -37,6 +39,7 @@ public EthereumPool(IComponentContext ctx,

private EthereumJobManager manager;
private EthereumCoinTemplate coin;
private EthereumPoolConfigExtra extraPoolConfig;

#region // Protocol V2 handlers - https://github.com/nicehash/Specifications/blob/master/EthereumStratum_NiceHash_v1.0.0.txt

Expand Down Expand Up @@ -361,6 +364,7 @@ private async Task SendWork(EthereumWorkerContext context, StratumConnection con
public override void Configure(PoolConfig pc, ClusterConfig cc)
{
coin = pc.Template.As<EthereumCoinTemplate>();
extraPoolConfig = pc.Extra.SafeExtensionDataAs<EthereumPoolConfigExtra>();

base.Configure(pc, cc);
}
Expand Down Expand Up @@ -483,22 +487,47 @@ protected override async Task OnRequestAsync(StratumConnection connection,
break;

// V1 Stratum methods
// There are several reports of bad actors taking advantage of the old "Ethash Stratum V1" protocol in order to perform multiple dangerous attacks like man-in-the-middle (MITM) attacks
// https://braiins.com/blog/hashrate-robbery-stratum-v2-fixes-this-and-more
// https://eips.ethereum.org/EIPS/eip-1571
// https://github.com/AndreaLanfranchi/EthereumStratum-2.0.0/issues/10#issuecomment-595053258
// Based on that critical fact, mining pool should be cautious of the risks of using a such deprecated and broken stratum protocol. Used it at your own risks.
case EthereumStratumMethods.SubmitLogin:
context.ProtocolVersion = 1; // lock in protocol version

await OnSubmitLoginAsync(connection, tsRequest);
break;

case EthereumStratumMethods.GetWork:
EnsureProtocolVersion(context, 1);

await OnGetWorkAsync(connection, tsRequest);
if(!extraPoolConfig.enableEthashStratumV1)
{
logger.Info(() => $"[{connection.ConnectionId}] Unsupported RPC request: {JsonConvert.SerializeObject(request, serializerSettings)}");

await connection.RespondErrorAsync(StratumError.Other, $"Unsupported request {request.Method}", request.Id);
}
else
{
EnsureProtocolVersion(context, 1);

logger.Warn(() => $"Use of Ethash Stratum V1 method: {request.Method}");
await OnGetWorkAsync(connection, tsRequest);
}
break;

case EthereumStratumMethods.SubmitWork:
EnsureProtocolVersion(context, 1);

await OnSubmitAsync(connection, tsRequest, ct, true);
if(!extraPoolConfig.enableEthashStratumV1)
{
logger.Info(() => $"[{connection.ConnectionId}] Unsupported RPC request: {JsonConvert.SerializeObject(request, serializerSettings)}");

await connection.RespondErrorAsync(StratumError.Other, $"Unsupported request {request.Method}", request.Id);
}
else
{
EnsureProtocolVersion(context, 1);

logger.Warn(() => $"Use of Ethash Stratum V1 method: {request.Method}");
await OnSubmitAsync(connection, tsRequest, ct, true);
}
break;

case EthereumStratumMethods.SubmitHashrate:
Expand Down
2 changes: 1 addition & 1 deletion src/Miningcore/Miningcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<PackageReference Include="NBitcoin" Version="7.0.17" />
<PackageReference Include="NBitcoin.Altcoins" Version="3.0.17" />
<PackageReference Include="NBitcoin.Zcash" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="NLog" Version="5.0.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
<PackageReference Include="Polly" Version="7.2.3" />
Expand Down
78 changes: 78 additions & 0 deletions src/Miningcore/coins.json
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,66 @@
"explorerTxLink": "https://explorer.fulminareproject.com/transaction/{0}",
"explorerAccountLink": "https://explorer.fulminareproject.com/address/{0}"
},
"clore": {
"name": "Clore",
"symbol": "CLORE",
"family": "progpow",
"progpower": "kawpow",
"website": "",
"market": "",
"twitter": "",
"telegram": "",
"discord": "",
"coinbaseHasher": {
"hash": "sha256d"
},
"headerHasher": {
"hash": "sha256d"
},
"blockHasher": {
"hash": "reverse",
"args": [
{
"hash": "sha256d"
}
]
},
"hasCommunityAddress": true,
"shareMultiplier": 1,
"explorerBlockLink": "https://exploreblockchain.clore.ai/block/$hash$",
"explorerTxLink": "https://exploreblockchain.clore.ai/tx/{0}",
"explorerAccountLink": "https://exploreblockchain.clore.ai/address/{0}"
},
"meowcoin": {
"name": "Meowcoin",
"symbol": "MEWC",
"family": "progpow",
"progpower": "kawpow",
"website": "",
"market": "",
"twitter": "",
"telegram": "",
"discord": "",
"coinbaseHasher": {
"hash": "sha256d"
},
"headerHasher": {
"hash": "sha256d"
},
"blockHasher": {
"hash": "reverse",
"args": [
{
"hash": "sha256d"
}
]
},
"hasCommunityAddress": true,
"shareMultiplier": 1,
"explorerBlockLink": "https://explorer.mewccrypto.com/block/$hash$",
"explorerTxLink": "https://explorer.mewccrypto.com/tx/{0}",
"explorerAccountLink": "https://explorer.mewccrypto.com/address/{0}"
},
"garlicoin": {
"name": "Garlicoin",
"symbol": "GRLC",
Expand Down Expand Up @@ -5115,6 +5175,24 @@
},
"explorerTxLink": "https://btnscan.com/tx/{0}?network=Bitnet",
"explorerAccountLink": "https://btnscan.com/address/{0}"
},
"octaspace": {
"name": "OctaSpace",
"canonicalName": "Octa.Space",
"symbol": "OCTA",
"family": "ethereum",
"ethasher": "ethash",
"website": "https://octa.space/",
"market": "https://coinmarketcap.com/currencies/octaspace/",
"twitter": "https://twitter.com/octa_space",
"telegram": "https://t.me/octa_space",
"discord": "https://discord.gg/octaspace",
"explorerBlockLinks": {
"block": "https://explorer.octa.space/block/$height$",
"uncle": "https://explorer.octa.space/block/$height$"
},
"explorerTxLink": "https://explorer.octa.space/tx/{0}",
"explorerAccountLink": "https://explorer.octa.space/address/{0}",
},
"ergo": {
"name": "Ergo",
Expand Down
Loading