Skip to content

Commit

Permalink
Added support for FortuneBlock.
Browse files Browse the repository at this point in the history
Mike Algo
Fortune Reward
  • Loading branch information
accarto committed Nov 7, 2024
1 parent a108897 commit e223c97
Show file tree
Hide file tree
Showing 18 changed files with 2,343 additions and 414 deletions.
42 changes: 42 additions & 0 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ protected virtual Transaction CreateOutputTransaction()
if(coin.HasFounderFee)
rewardToPool = CreateFounderOutputs(tx, rewardToPool);

if(coin.HasFortuneReward)
rewardToPool = CreateFortuneOutputs(tx, rewardToPool);

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

Expand Down Expand Up @@ -532,6 +535,42 @@ protected virtual Money CreateMasternodeOutputs(Transaction tx, Money reward)

#endregion // Masternodes


#region Fortune

protected FortuneBlockTemplateExtra fortuneParameters;

protected virtual Money CreateFortuneOutputs(Transaction tx, Money reward)
{
if(fortuneParameters.Fortune != null)
{
Fortune[] fortunes;
if(fortuneParameters.Fortune.Type == JTokenType.Array)
fortunes = fortuneParameters.Fortune.ToObject<Fortune[]>();
else
fortunes = new[] { fortuneParameters.Fortune.ToObject<Fortune>() };

if(fortunes != null)
{
foreach(var Fortune in fortunes)
{
if(!string.IsNullOrEmpty(Fortune.Payee))
{
var payeeAddress = BitcoinUtils.AddressToDestination(Fortune.Payee, network);
var payeeReward = Fortune.Amount;

tx.Outputs.Add(payeeReward, payeeAddress);
reward -= payeeReward;
}
}
}
}

return reward;
}

#endregion // Fortune

#region Founder

protected FounderBlockTemplateExtra founderParameters;
Expand Down Expand Up @@ -824,6 +863,9 @@ public void Init(BlockTemplate blockTemplate, string jobId,
if(coin.HasFounderFee)
founderParameters = BlockTemplate.Extra.SafeExtensionDataAs<FounderBlockTemplateExtra>();

if(coin.HasFortuneReward)
fortuneParameters = BlockTemplate.Extra.SafeExtensionDataAs<FortuneBlockTemplateExtra>();

if(coin.HasFounderReward)
founderrewardParameters = BlockTemplate.Extra.SafeExtensionDataAs<FounderRewardBlockTemplateExtra>();

Expand Down
20 changes: 20 additions & 0 deletions src/Miningcore/Blockchain/Bitcoin/DaemonResponses/Fortune.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Miningcore.Blockchain.Bitcoin.DaemonResponses
{
public class Fortune
{
public string Payee { get; set; }
public string Script { get; set; }
public long Amount { get; set; }
}

public class FortuneBlockTemplateExtra
{
public JToken Fortune { get; set; }

[JsonProperty("fortune_payments_started")]
public bool FortunePaymentsStarted { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Miningcore/Blockchain/Cryptonote/CryptonoteJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public CryptonoteJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId,
{ CryptonightHashType.CryptonightFast, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, CN_FAST, height) },
{ CryptonightHashType.CryptonightXAO, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, CN_XAO, height) },
{ CryptonightHashType.Ghostrider, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, GHOSTRIDER_RTM, height) },
{ CryptonightHashType.Mike, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, GHOSTRIDER_MIKE, height) },
{ CryptonightHashType.CryptonightLite0, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, CN_LITE_0, height) },
{ CryptonightHashType.CryptonightLite1, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, CN_LITE_1, height) },
{ CryptonightHashType.CryptonightHeavy, (_, _, data, result, height) => Cryptonight.CryptonightHash(data, result, CN_HEAVY_0, height) },
Expand Down
6 changes: 6 additions & 0 deletions src/Miningcore/Configuration/ClusterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public class BitcoinNetworkParams
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasFounderFee { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasFortuneReward { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool HasFounderReward { get; set; }

Expand Down Expand Up @@ -425,6 +428,9 @@ public enum CryptonightHashType
[EnumMember(Value = "gr")]
Ghostrider,

[EnumMember(Value = "mike")]
Mike,

[EnumMember(Value = "cn_lite0")]
CryptonightLite0,

Expand Down
13 changes: 13 additions & 0 deletions src/Miningcore/Crypto/Hashing/Algorithms/Mike.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Miningcore.Native;
using static Miningcore.Native.Cryptonight.Algorithm;

namespace Miningcore.Crypto.Hashing.Algorithms;

[Identifier("mike")]
public class Mike : IHashAlgorithm
{
public void Digest(ReadOnlySpan<byte> data, Span<byte> result, params object[] extra)
{
Cryptonight.CryptonightHash(data, result, GHOSTRIDER_MIKE, 0);
}
}
2 changes: 2 additions & 0 deletions src/Miningcore/Native/Cryptonight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum Algorithm
CN_GR_4 = 0x63120104, // "cn/turtle" GhostRider
CN_GR_5 = 0x63120105, // "cn/turtle-lite" GhostRider
GHOSTRIDER_RTM = 0x6c150000, // "ghostrider" GhostRider
GHOSTRIDER_MIKE = 0x6c15006d, // "mike" Mike
// RX_0 = 0x72151200, // "rx/0" RandomX (reference configuration).
// RX_WOW = 0x72141177, // "rx/wow" RandomWOW (Wownero).
// RX_ARQ = 0x72121061, // "rx/arq" RandomARQ (Arqma).
Expand Down Expand Up @@ -97,6 +98,7 @@ public enum Algorithm
Algorithm.CN_DOUBLE,
Algorithm.CN_CCX,
Algorithm.GHOSTRIDER_RTM,
Algorithm.GHOSTRIDER_MIKE,
};

private static readonly HashSet<Algorithm> validCryptonightLiteAlgos = new()
Expand Down
Loading

0 comments on commit e223c97

Please sign in to comment.