miningcore icon indicating copy to clipboard operation
miningcore copied to clipboard

feat: add support for ravencoin

Open jon4hz opened this issue 2 years ago • 38 comments

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: https://github.com/oliverw/miningcore/issues/1174 https://github.com/oliverw/miningcore/discussions/876

jon4hz avatar Feb 14 '23 22:02 jon4hz

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

blackmennewstyle avatar Feb 17 '23 14:02 blackmennewstyle

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

MiningCryptoLive avatar Feb 22 '23 18:02 MiningCryptoLive

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

jon4hz avatar Feb 23 '23 00:02 jon4hz

Cool. Hopefully oliverw will merge the pr soon. If I clone your repo will it work? If I checkout the branch ravencoin?

On Wed, Feb 22, 2023, 7:05 PM jon4hz @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/oliverw/miningcore/pull/1627#issuecomment-1441026231, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIAKRQHBKXZEEFDLTXHZK3WY2SURANCNFSM6AAAAAAU4DJW24 . You are receiving this because you commented.Message ID: @.***>

MiningCryptoLive avatar Feb 23 '23 00:02 MiningCryptoLive

Probably, yes

jon4hz avatar Feb 23 '23 00:02 jon4hz

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.

Konstantin35 avatar Feb 23 '23 11:02 Konstantin35

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 avatar Feb 23 '23 22:02 jon4hz

No it does not. https://github.com/oliverw/miningcore/commit/d3dcec6aba63962bf1a953037d3e4ca85cda6edf

jon4hz avatar Feb 24 '23 15:02 jon4hz

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.

furcalor avatar Feb 24 '23 15:02 furcalor

Good catch! Fixed in https://github.com/oliverw/miningcore/pull/1627/commits/1f3df143b31797c68456d2dce0eee04e88c223bd

jon4hz avatar Feb 24 '23 15:02 jon4hz

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 avatar Feb 25 '23 07:02 Konstantin35

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.

Konstantin35 avatar Feb 25 '23 08:02 Konstantin35

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?

jon4hz avatar Feb 25 '23 16:02 jon4hz

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.

papagruz avatar Feb 27 '23 15:02 papagruz

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.

furcalor avatar Feb 27 '23 20:02 furcalor

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.

papagruz avatar Feb 28 '23 06:02 papagruz

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

furcalor avatar Feb 28 '23 12:02 furcalor

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 avatar Feb 28 '23 14:02 papagruz

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

papagruz avatar Feb 28 '23 15:02 papagruz

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

papagruz avatar Feb 28 '23 17:02 papagruz

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

jon4hz avatar Feb 28 '23 18:02 jon4hz

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

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

papagruz avatar Feb 28 '23 18:02 papagruz

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.

jon4hz avatar Feb 28 '23 18:02 jon4hz

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 avatar Feb 28 '23 18:02 papagruz

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?

papagruz avatar Mar 01 '23 09:03 papagruz

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.

furcalor avatar Mar 01 '23 12:03 furcalor

@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...

jon4hz avatar Mar 01 '23 12:03 jon4hz

Ok. Thanks

papagruz avatar Mar 01 '23 13:03 papagruz

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

MiningCryptoLive avatar Mar 01 '23 18:03 MiningCryptoLive

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?

blackmennewstyle avatar Jun 06 '23 04:06 blackmennewstyle