Esempio n. 1
0
        public MoneroJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId, string jobId,
                         PoolConfig poolConfig, ClusterConfig clusterConfig)
        {
            Contract.RequiresNonNull(blockTemplate, nameof(blockTemplate));
            Contract.RequiresNonNull(poolConfig, nameof(poolConfig));
            Contract.RequiresNonNull(clusterConfig, nameof(clusterConfig));
            Contract.RequiresNonNull(instanceId, nameof(instanceId));
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(jobId), $"{nameof(jobId)} must not be empty");

            switch (poolConfig.Coin.Type)
            {
            case CoinType.AEON:
                hashSlow = LibCryptonote.CryptonightHashSlowLite;
                break;

            case CoinType.XMR:
                hashSlow = buf =>
                {
                    // PoW variant
                    var variant = buf[0] >= 7 ? buf[0] - 6 : 0;

                    return(LibCryptonote.CryptonightHashSlow(buf, variant));
                };
                break;

            default:
                hashSlow = buf => LibCryptonote.CryptonightHashSlow(buf, 0);
                break;
            }

            BlockTemplate = blockTemplate;
            PrepareBlobTemplate(instanceId);
        }
Esempio n. 2
0
        public CryptonoteJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId, string jobId,
                             PoolConfig poolConfig, ClusterConfig clusterConfig, string prevHash)
        {
            Contract.RequiresNonNull(blockTemplate, nameof(blockTemplate));
            Contract.RequiresNonNull(poolConfig, nameof(poolConfig));
            Contract.RequiresNonNull(clusterConfig, nameof(clusterConfig));
            Contract.RequiresNonNull(instanceId, nameof(instanceId));
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(jobId), $"{nameof(jobId)} must not be empty");

            coin          = poolConfig.Template.As <CryptonoteCoinTemplate>();
            BlockTemplate = blockTemplate;
            PrepareBlobTemplate(instanceId);
            PrevHash = prevHash;

            switch (coin.Hash)
            {
            case CryptonightHashType.Normal:
                hashFunc = LibCryptonight.Cryptonight;
                break;

            case CryptonightHashType.Lite:
                hashFunc = LibCryptonight.CryptonightLight;
                break;

            case CryptonightHashType.Heavy:
                hashFunc = LibCryptonight.CryptonightHeavy;
                break;
            }
        }
Esempio n. 3
0
        public MoneroJob(int id, GetBlockTemplateResponse blockTemplate, byte[] instanceId)
        {
            Id            = id;
            BlockTemplate = blockTemplate;

            _workerJobCounter = new JobCounter();
            PrepareBlobTemplate(instanceId);
        }
Esempio n. 4
0
        public MoneroJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId, string jobId,
                         PoolConfig poolConfig, ClusterConfig clusterConfig)
        {
            Contract.RequiresNonNull(blockTemplate, nameof(blockTemplate));
            Contract.RequiresNonNull(poolConfig, nameof(poolConfig));
            Contract.RequiresNonNull(clusterConfig, nameof(clusterConfig));
            Contract.RequiresNonNull(instanceId, nameof(instanceId));
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(jobId), $"{nameof(jobId)} must not be empty");

            BlockTemplate = blockTemplate;
            PrepareBlobTemplate(instanceId);
        }
Esempio n. 5
0
    public CryptonoteJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId, string jobId,
                         CryptonoteCoinTemplate coin, PoolConfig poolConfig, ClusterConfig clusterConfig, string prevHash, string randomXRealm)
    {
        Contract.RequiresNonNull(blockTemplate);
        Contract.RequiresNonNull(poolConfig);
        Contract.RequiresNonNull(clusterConfig);
        Contract.RequiresNonNull(instanceId);
        Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(jobId));

        BlockTemplate = blockTemplate;
        PrepareBlobTemplate(instanceId);
        PrevHash     = prevHash;
        RandomXRealm = randomXRealm;

        hashFunc = hashFuncs[coin.Hash];
    }
Esempio n. 6
0
        public CryptonoteJob(GetBlockTemplateResponse blockTemplate, byte[] instanceId, string jobId,
                             CryptonoteCoinTemplate coin, PoolConfig poolConfig, ClusterConfig clusterConfig, string prevHash, string randomXRealm)
        {
            Contract.RequiresNonNull(blockTemplate, nameof(blockTemplate));
            Contract.RequiresNonNull(poolConfig, nameof(poolConfig));
            Contract.RequiresNonNull(clusterConfig, nameof(clusterConfig));
            Contract.RequiresNonNull(instanceId, nameof(instanceId));
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(jobId), $"{nameof(jobId)} must not be empty");

            BlockTemplate = blockTemplate;
            PrepareBlobTemplate(instanceId);
            PrevHash = prevHash;

            switch (coin.Hash)
            {
            case CryptonightHashType.RandomX:
                hashFunc = ((seedHex, data, result, height) =>
                {
                    LibRandomX.CalculateHash(randomXRealm, seedHex, data, result);
                });
                break;
            }
        }
    private void UpdateHashParams(GetBlockTemplateResponse blockTemplate)
    {
        switch (coin.Hash)
        {
        case CryptonightHashType.RandomX:
        {
            // detect seed hash change
            if (currentSeedHash != blockTemplate.SeedHash)
            {
                logger.Info(() => $"Detected new seed hash {blockTemplate.SeedHash} starting @ height {blockTemplate.Height}");

                if (poolConfig.EnableInternalStratum == true)
                {
                    RandomX.WithLock(() =>
                        {
                            // delete old seed
                            if (currentSeedHash != null)
                            {
                                RandomX.DeleteSeed(randomXRealm, currentSeedHash);
                            }

                            // activate new one
                            currentSeedHash = blockTemplate.SeedHash;
                            RandomX.CreateSeed(randomXRealm, currentSeedHash, randomXFlagsOverride, randomXFlagsAdd, extraPoolConfig.RandomXVMCount);
                        });
                }

                else
                {
                    currentSeedHash = blockTemplate.SeedHash;
                }
            }

            break;
        }

        case CryptonightHashType.RandomARQ:
        {
            // detect seed hash change
            if (currentSeedHash != blockTemplate.SeedHash)
            {
                logger.Info(() => $"Detected new seed hash {blockTemplate.SeedHash} starting @ height {blockTemplate.Height}");

                if (poolConfig.EnableInternalStratum == true)
                {
                    RandomARQ.WithLock(() =>
                        {
                            // delete old seed
                            if (currentSeedHash != null)
                            {
                                RandomARQ.DeleteSeed(randomXRealm, currentSeedHash);
                            }

                            // activate new one
                            currentSeedHash = blockTemplate.SeedHash;
                            RandomARQ.CreateSeed(randomXRealm, currentSeedHash, randomXFlagsOverride, randomXFlagsAdd, extraPoolConfig.RandomXVMCount);
                        });
                }

                else
                {
                    currentSeedHash = blockTemplate.SeedHash;
                }
            }

            break;
        }
        }
    }