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

feat: add support for ravencoin #1627

wants to merge 4 commits into from

Conversation

jon4hz
Copy link
Contributor

@jon4hz jon4hz commented Feb 14, 2023

Hi, this PR adds support for ravencoin and lays the basis for other kawpow coins.

The code was tested on the ravencoin testnet.

[2023-02-14 22:57:54.7180] [I] [rvn1] Submitting block 936632 [00000003ca6b9e3312aa952d952a757705fe88e807b43b2f4cfa8a798d4da9ba] 
[2023-02-14 22:57:54.7426] [I] [rvn1] Daemon accepted block 936632 [00000003ca6b9e3312aa952d952a757705fe88e807b43b2f4cfa8a798d4da9ba] submitted by mu3CRvK5eMB3JiiNmQUwu2JLubobuhdfdb 
[2023-02-14 22:57:54.7441] [I] [rvn1] [0HMOEQPKV1L0Q] Share accepted: D=0.02 
[2023-02-14 22:57:54.7517] [I] [rvn1] Detected new block 936633 [BLOCK] 
[2023-02-14 22:57:54.7517] [I] [rvn1] Broadcasting jobs 
[2023-02-14 22:57:56.7884] [I] [rvn1] [0HMOEQPKV1L0Q] Share accepted: D=0.02 
[2023-02-14 22:58:04.2436] [I] [rvn1] [0HMOEQPKV1L0Q] Share accepted: D=0.02 
[2023-02-14 22:58:04.7487] [I] [rvn1] Broadcasting jobs 

Even though ravencoin is a fork of bitcoin, it has a different stratum protocol. This is why I added it as a custom family which extends the BitcoinJob and BitcoinJobManagerBase classes.

Payouts are handled by the BitcoinPayoutHandler without any modifications.

rel:
#1174
#876

stuff

wip

fix: native bindings

wip

fuck yeah

wip payout

fix payout

cleanup

raven -> ravencoin

more cleanup
@blackmennewstyle
Copy link

Nice :)
I was planning to give Kawpow a try but it looks like, you beat me to it :)

@MiningCryptoLive
Copy link

I would like to try raven coin. Is this merged into miningcore or do I need to submit a request from jon4hz?

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 23, 2023

no, this isn't merged yet. Hence the PR..

@MiningCryptoLive
Copy link

MiningCryptoLive commented Feb 23, 2023 via email

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 23, 2023

Probably, yes

@Konstantin35
Copy link
Contributor

Tested this project conditionally working there are many inaccuracies such as diff target
correctgey will be

    public static BigInteger BigMaxValue = BigInteger.Pow(2, 256);
    public static readonly BigInteger Diff1 = BigInteger.Parse("00000000ffff0000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
    public static double Mul = (double) BigInteger.Divide(BigMaxValue, Diff1);

var shareDiff = (double) BigInteger.Divide(RavencoinConstants.BigMaxValue, resultValueBig) / RavencoinConstants.Mul;

    public static string EncodeTarget(double difficulty)
    {

        BigInteger BaseTarget = BigInteger.Parse("00000000ffff0000000000000000000000000000000000000000000000000000", System.Globalization.NumberStyles.AllowHexSpecifier, null);

        difficulty = 1.0 / difficulty;

        BigInteger NewTarget;
        BigInteger DecimalDiff;
        BigInteger DecimalTarget;

        NewTarget = BigInteger.Multiply(BaseTarget, new BigInteger(difficulty));

        string StringDiff = difficulty.ToString(System.Globalization.CultureInfo.InvariantCulture);
        int DecimalOffset = StringDiff.IndexOf(".");
        if(DecimalOffset > -1)
        {
            int Precision = (StringDiff.Length - 1) - DecimalOffset;
            DecimalDiff = BigInteger.Parse(StringDiff.Substring(DecimalOffset + 1));
            DecimalTarget = BigInteger.Multiply(BaseTarget, DecimalDiff);

            string s = DecimalTarget.ToString();
            s = s.Substring(0, s.Length - Precision);

            DecimalTarget = BigInteger.Parse(s);
            NewTarget += DecimalTarget;
        }

        return string.Format("{0:x64}", NewTarget);
    }

and OnSubscribeAsync

        manager.PrepareWorker(connection);

        var data = new object[]
        {
           null,
           context.ExtraNonce1,
        }
        .ToArray();
    public void PrepareWorker(StratumConnection client)
    {
        var context = client.ContextAs<RavencoinWorkerContext>();
        context.ExtraNonce1 = extraNonceProvider.Next();
    }

I didn’t check the block on the test network, I didn’t catch the payout yet, but I’m going to do it and write it.

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 23, 2023

Hi @Konstantin35

Thanks a lot for taking a look at this!

Good hint with the target encoding. I was actually quite unsure if I handled that correctly but I kinda forgot about it since the code seemed to work. (It actually does work but I think I'm loosing some precision down the line.)

I ported the share validation from blinkhash's foundation pool and I never heard that they do it wrong.
https://github.com/blinkhash/foundation-v2-ravencoin/blob/4ed8f799ff6594926c48509c8f3292886d660932/stratum/main/manager.js#L167

What makes you think that Diff1 should be "00000000ffff0000000000000000000000000000000000000000000000000000"?

As for the subscribe params: wildrig accepts both variants. Is there a particular reason to only send null + extraNonce1?

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 24, 2023

No it does not.
d3dcec6

@furcalor
Copy link

furcalor commented Feb 24, 2023

No it does not. d3dcec6

Stand corrected, not sure if its because of old base for me, but I also needed to add:

   {
        KawpowHasher = new EthashLight();
    }
    #region Overrides of CoinTemplate

    public override string GetAlgorithmName()
    {
        return "KAWPOW";
    }

    #endregion

to clusterconfigextension so it would not use the headerhasher as displayed algo.

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 24, 2023

Good catch! Fixed in 1f3df14

@Konstantin35
Copy link
Contributor

As for the subscribe params: wildrig accepts both variants. Is there a particular reason to only send null + extraNonce1?

https://github.com/nicehash/Specifications/blob/master/KawPow_NiceHash_v1.0.txt

@Konstantin35
Copy link
Contributor

When testing the same problem as Ethash: Abstract and light cache jumping pings on Ethash tested with dag generation there is a stable ping difference with my pool of 1ms it turns out that with dag is much better. If you use light cache then you also need to generate cache files and test them.

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 25, 2023

When testing the same problem as Ethash: Abstract and light cache jumping pings on Ethash tested with dag generation there is a stable ping difference with my pool of 1ms it turns out that with dag is much better.

I'm no expert on ethash by all means but I think the performance difference can be explained, because the light cache has to calculate the required dag sequences on the fly, where as the dag has them already precalculated.

See: https://ethereum.org/en/developers/docs/consensus-mechanisms/pow/mining-algorithms/ethash/

  1. Mining involves grabbing random slices of the dataset and hashing them together. Verification can be done with low memory by using the cache to regenerate the specific pieces of the dataset that you need, so you only need to store the cache.

How big was the performance difference in your experience? If it's only a ms I dare to say the advantage of being able to scale overwhelms the disadvantages. But yeah, that all depends on how big the difference is.

If you use light cache then you also need to generate cache files and test them.

I though that was already handled by the c++ code but I'll take another look. Doesn't it store the light cache in-memory?

@papagruz
Copy link

Hello. I try kawpow algo on hivecoin. Have error with block submission: submission failed with: bad-cb-community-autonomous-amount
To coins.json i add "payFoundersReward": true,
Maybe we need to add something else. Or is the support for kawpow not finished yet?
Thanks.

@furcalor
Copy link

furcalor commented Feb 27, 2023

Hello. I try kawpow algo on hivecoin. Have error with block submission: submission failed with: bad-cb-community-autonomous-amount To coins.json i add "payFoundersReward": true, Maybe we need to add something else. Or is the support for kawpow not finished yet? Thanks.

You need to add support for "CommunityAutonomousAddress" and "CommunityAutonomousValue" as those are different to founder/payee/masternode/minerfund. Check the minerfund commit and follow that. Pretty easy to add.

I did lazy way and just added to getblocktemplate. Was going to do it properly with its own file and submit a pull request to jon4hz, but got distracted
In bitcoinjob:

        if (coin.HasCommunityAddress)
            rewardToPool = CreateCommunityAddressOutputs(tx, rewardToPool);
    #region CommunityAddress

    protected virtual Money CreateCommunityAddressOutputs(Transaction tx, Money reward)
    {
        if(BlockTemplate.CommunityAutonomousAddress != null && BlockTemplate.CommunityAutonomousValue > 0)
        {
        var payeeReward = BlockTemplate.CommunityAutonomousValue;
        reward -= payeeReward;
        var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.CommunityAutonomousAddress, network);
        tx.Outputs.Add(payeeReward, payeeAddress);
        }
        return reward;
    }
    #endregion // CommunityAddress

in getblocktemplate

        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string CommunityAutonomousAddress { get; set; }
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public long CommunityAutonomousValue { get; set; }

in clusterconfig

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

I think didn't miss anything, but might have.

@papagruz
Copy link

Hello. I try kawpow algo on hivecoin. Have error with block submission: submission failed with: bad-cb-community-autonomous-amount To coins.json i add "payFoundersReward": true, Maybe we need to add something else. Or is the support for kawpow not finished yet? Thanks.

You need to add support for "CommunityAutonomousAddress" and "CommunityAutonomousValue" as those are different to founder/payee/masternode/minerfund. Check the minerfund commit and follow that. Pretty easy to add.

I did lazy way and just added to getblocktemplate. Was going to do it properly with its own file and submit a pull request to jon4hz, but got distracted In bitcoinjob:

        if (coin.HasCommunityAddress)
            rewardToPool = CreateCommunityAddressOutputs(tx, rewardToPool);
    #region CommunityAddress

    protected virtual Money CreateCommunityAddressOutputs(Transaction tx, Money reward)
    {
        if(BlockTemplate.CommunityAutonomousAddress != null && BlockTemplate.CommunityAutonomousValue > 0)
        {
        var payeeReward = BlockTemplate.CommunityAutonomousValue;
        reward -= payeeReward;
        var payeeAddress = BitcoinUtils.AddressToDestination(BlockTemplate.CommunityAutonomousAddress, network);
        tx.Outputs.Add(payeeReward, payeeAddress);
        }
        return reward;
    }
    #endregion // CommunityAddress

in getblocktemplate

        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public string CommunityAutonomousAddress { get; set; }
        [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
        public long CommunityAutonomousValue { get; set; }

in clusterconfig

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

I think didn't miss anything, but might have.

I add all this code, recompile. But submission failed again.

@furcalor
Copy link

did you also add "hasCommunityAddress": true in to the coins.json for the coin?

@papagruz
Copy link

did you also add "hasCommunityAddress": true in to the coins.json for the coin?

No. just add code. Thank you, now try add to coins.json

@papagruz
Copy link

After add "hasCommunityAddress": true block submission done! Thank you.

@papagruz
Copy link

Find new issue. Payments work, but there are no records in the database about payments made. No records in "payments" in db.

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 28, 2023

Are you using the same wallet for the pool fee and mining?

@papagruz
Copy link

Are you using the same wallet for the pool fee and mining?

Yes 1 wallet for fee and mining. Now try change wallet

@jon4hz
Copy link
Contributor Author

jon4hz commented Feb 28, 2023

Miningcore doesn't store payments sent to the fee wallet. You'll have to use a different wallet for mining if you want to test payouts.

@papagruz
Copy link

Miningcore doesn't store payments sent to the fee wallet. You'll have to use a different wallet for mining if you want to test payouts.

Thank you. Understand. Now change wallet

@papagruz
Copy link

papagruz commented Mar 1, 2023

Have new problem :)
On Paprikacon wrong block reward. On cryptonote pool right reward 36 coin.
On miningcore reward 12 coins.
Think miningcore set wrong CommunityReward.
In code set % reward? or miningcore take info from network?

@furcalor
Copy link

furcalor commented Mar 1, 2023

Have new problem :) On Paprikacon wrong block reward. On cryptonote pool right reward 36 coin. On miningcore reward 12 coins. Think miningcore set wrong CommunityReward. In code set % reward? or miningcore take info from network?

Getting OT on kawpow, but paprikacoin has incorrect coinbasevalue on getblocktemplate, I submitted a pull request to fix it. In the meanwhile, check the pull request in paprikacoin git, apply it and build from source.

@jon4hz
Copy link
Contributor Author

jon4hz commented Mar 1, 2023

@papagruz This PR is about ravencoin and not some random other coin. Please keep this thread on topic and open another issue if you have issues with paprikacoin...

@papagruz
Copy link

papagruz commented Mar 1, 2023

Ok. Thanks

@MiningCryptoLive
Copy link

Read the comments! This PR is for Ravencoin. Not other coins based on kawpow. Open a new discussion for the coin you are trying to work with

@blackmennewstyle
Copy link

Sorry i'm a little bit late to the party.

I tried to mine RVN testnet using that PR, and both T-Rex Miner and SRBMiner-Multi are sending this method to the pool:

[2023-06-06 04:14:36.6697] [D] [rvn1] [0HMR68ARULC2F] [NET] Received data: {"jsonrpc":"2.0","method":"eth_submitHashrate","params":["0x00000000000000000000000000000000000000000000000000000000002c80d8", "0xd0cadda1c061988bd7a4b83d3ca08fb04d6c4dad4c4ddd6bbdb12e89662ea60d"],"id":7}

Command lines for both miners:

/home/ceedii/SRBMiner-Multi-2-2-8/SRBMiner-MULTI --api-enable --api-port 4448 --api-rig-name ganymede --algorithm kawpow --pool stratum+ssl://callisto.cedric-crispin.com:4055 --wallet mzASNqJJPTKcASFcFjNiA1j4jYxD5VFZee.ganymede --password x --gpu-id GPU0 --disable-cpu
/home/ceedii/t-rex-0.26.8-linux/t-rex -a kawpow -o stratum+ssl://callisto.cedric-crispin.com:4055 -u mzASNqJJPTKcASFcFjNiA1j4jYxD5VFZee.ganymede -p x --no-strict-ssl -d 0 --api-bind-http 192.168.1.5:4448 --no-watchdog

Am i the only one having that issue?

@jon4hz
Copy link
Contributor Author

jon4hz commented Jun 6, 2023

@blackmennewstyle that isn't an issue, just the miner reporting its hashrate to the pool. Miningcore doesn't support that though, so the message gets ignored.

@blackmennewstyle
Copy link

@blackmennewstyle that isn't an issue, just the miner reporting its hashrate to the pool. Miningcore doesn't support that though, so the message gets ignored.

Hi, sorry for the confusion i wanted to write behavior not issue, another brain glitch i guess. Everything is working fine, i had to decrease my minDiff though because my GPU for testing isn't really great at KAWPOW lol

Nice job mate 👍

@blackmennewstyle
Copy link

blackmennewstyle commented Jun 26, 2023

Did anyone manage to successfully catch a block on Ravencoin mainnet?

@MiningCryptoLive
Copy link

MiningCryptoLive commented Jun 26, 2023 via email

@blackmennewstyle
Copy link

Yes. How long have you been mining and what is your hashrate on the pool?
On Mon, Jun 26, 2023 at 1:42 AM Cédric CRISPIN @.> wrote: Have anyone managed to successfully catch a block on Ravencoin mainnet? — Reply to this email directly, view it on GitHub <#1627 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIAKRUSN4WWHD2O4EK5GLTXNEONRANCNFSM6AAAAAAU4DJW24 . You are receiving this because you commented.Message ID: @.>
-- Randy Hasson 199 East Markison Avenue Columbus, Ohio 43207

Almost 4 days with just 130 MH/s lol

Did you implement @Konstantin35 suggestions with the target encoding and also the shareDiff calculation?

@MiningCryptoLive
Copy link

MiningCryptoLive commented Jun 26, 2023 via email

@blackmennewstyle
Copy link

blackmennewstyle commented Jun 26, 2023

With 130 mh/s it will take weeks if not months to find a block On Mon, Jun 26, 2023 at 10:26 AM Cédric CRISPIN @.> wrote:
Yes. How long have you been mining and what is your hashrate on the pool? On Mon, Jun 26, 2023 at 1:42 AM Cédric CRISPIN @.
> wrote: Have anyone managed to successfully catch a block on Ravencoin mainnet? — Reply to this email directly, view it on GitHub <#1627 (comment) <#1627 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIAKRUSN4WWHD2O4EK5GLTXNEONRANCNFSM6AAAAAAU4DJW24 https://github.com/notifications/unsubscribe-auth/AAIAKRUSN4WWHD2O4EK5GLTXNEONRANCNFSM6AAAAAAU4DJW24 . You are receiving this because you commented.Message ID: @.
> -- Randy Hasson 199 East Markison Avenue Columbus, Ohio 43207 https://www.google.com/maps/search/199+East+Markison+Avenue+Columbus,+Ohio+43207?entry=gmail&source=g Almost 4 days with just 130 MH/s lol Did you implement @Konstantin35 https://github.com/Konstantin35 suggestions with the target encoding and also the shareDiff calculation? — Reply to this email directly, view it on GitHub <#1627 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIAKRWKRVYN5RZF3OBLUMTXNGLY5ANCNFSM6AAAAAAU4DJW24 . You are receiving this because you commented.Message ID: @.
**>
-- Randy Hasson 199 East Markison Avenue Columbus, Ohio 43207

I know lol But i think there is an issue with target encoding and shareDiff calculation because i'm getting from time to time, few low difficulty rejected shares and i think the modifications suggested by @Konstantin35 would fix them. So i imagine you didn't implement them into your pool then since you did not answer lol

@blackmennewstyle
Copy link

blackmennewstyle commented Jun 27, 2023

I implemented what is suggested here #1627 (comment)

After restart, all my low difficulty rejected shares are gone. That GPUs rig was mining on flypool before and it never got the amount of rejected shares i was seeing, maximum one per 24h.

[2023-06-27 02:22:24] Stats Uptime: 0 days, 09:22:09
[2023-06-27 02:22:24] ----------------------------------------- GPU Status -------------------------------------------
[2023-06-27 02:22:24] GPU  0 [57C, fan 76%]      kawpow: 16.76Mh/s, avg 16.66Mh/s, pool 16.85Mh/s a:414 r:0 hw:0
[2023-06-27 02:22:24] GPU  1 [59C, fan 80%]      kawpow: 16.76Mh/s, avg 16.66Mh/s, pool 15.52Mh/s a:385 r:0 hw:0
[2023-06-27 02:22:24] GPU  2 [59C, fan 78%]      kawpow: 16.78Mh/s, avg 16.68Mh/s, pool 15.68Mh/s a:387 r:0 hw:0
[2023-06-27 02:22:24] GPU  3 [59C, fan 78%]      kawpow: 16.62Mh/s, avg 16.51Mh/s, pool 17.30Mh/s a:421 r:0 hw:0
[2023-06-27 02:22:24] GPU  4 [49C, fan 68%]      kawpow: 16.77Mh/s, avg 16.67Mh/s, pool 16.90Mh/s a:407 r:0 hw:0
[2023-06-27 02:22:24] GPU  5 [59C, fan 78%]      kawpow: 16.76Mh/s, avg 16.66Mh/s, pool 16.26Mh/s a:405 r:0 hw:0
[2023-06-27 02:22:24] Total                      kawpow: 100.5Mh/s, avg 99.84Mh/s, pool 98.51Mh/s a:2419 r:0
[2023-06-27 02:22:24] ----------------------------------------- Pool Status ------------------------------------------
[2023-06-27 02:22:24] stratum.cedric-crispin.com kawpow: 96.59Mh/s, avg 97.84Mh/s, pool 98.51Mh/s a:2419 r:0
[2023-06-27 02:22:24] ------------------------------------------------------------------------------------------------
using System.Globalization;
using System.Numerics;
using Miningcore.Util;

namespace Miningcore.Blockchain.Ravencoin;

public class RavencoinConstants
{
    public const int EpochLength = 7500;
    public static BigInteger BigMaxValue = BigInteger.Pow(2, 256);
    public static readonly BigInteger Diff1B = BigInteger.Parse("00000000ff000000000000000000000000000000000000000000000000000000", NumberStyles.AllowHexSpecifier, null);
    public static readonly BigInteger Diff1 = BigInteger.Parse("00000000ff000000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
    public const int ExtranoncePlaceHolderLength = 2;
    public static double Multiplier = (double) new BigRational(BigMaxValue, Diff1);
}
// calc share-diff
var shareDiff = (double) new BigRational(RavencoinConstants.BigMaxValue, resultValueBig) / RavencoinConstants.Multiplier;
using System.Globalization;
using System.Numerics;

namespace Miningcore.Blockchain.Ravencoin;

public static class RavencoinUtils
{
    public static string RavencoinEncodeTarget(double difficulty)
    {
        difficulty = 1.0 / difficulty;

        BigInteger NewTarget;
        BigInteger DecimalDiff;
        BigInteger DecimalTarget;

        NewTarget = BigInteger.Multiply(RavencoinConstants.Diff1B, new BigInteger(difficulty));

        string StringDiff = difficulty.ToString(CultureInfo.InvariantCulture);
        int DecimalOffset = StringDiff.IndexOf(".");
        if(DecimalOffset > -1)
        {
            int Precision = (StringDiff.Length - 1) - DecimalOffset;
            DecimalDiff = BigInteger.Parse(StringDiff.Substring(DecimalOffset + 1));
            DecimalTarget = BigInteger.Multiply(RavencoinConstants.Diff1B, DecimalDiff);

            string s = DecimalTarget.ToString();
            s = s.Substring(0, s.Length - Precision);

            DecimalTarget = BigInteger.Parse(s);
            NewTarget += DecimalTarget;
        }

        return string.Format("{0:x64}", NewTarget);
    }
}

I use Ravencoin diff 00000000ff000000000000000000000000000000000000000000000000000000 instead of 00000000ffff0000000000000000000000000000000000000000000000000000, the later is FIRO diff if i am not mistaken.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants