Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Dev (#271)
Browse files Browse the repository at this point in the history
* Fix ethereum explorer links
* Refactored-out chain specific share DTOs
* Moved ShareRecorder and ShareRelay to more fitting namespace
* Greatly reduce the number of threads for external stratum monitoring
* Add payload-type-flag-frame to share publisher/subscriber
* ProtoBuf Share Relay & Recorder
* Do not require monero wallet daemon config if payment processing is disabled
* Reconnect to share relay on receive timeout
* Cryptonote Tests
* Monero v7
  • Loading branch information
Oliver Weichhold authored Mar 16, 2018
1 parent df5ecf2 commit f511dd6
Show file tree
Hide file tree
Showing 158 changed files with 5,612 additions and 1,715 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ recovered-shares.json


src/MiningCore/config\.json
/src/MiningCore/config2.json
10 changes: 5 additions & 5 deletions src/MiningCore.Tests/Blockchain/Bitcoin/BitcoinJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public void BitcoinJob_Should_Accept_Valid_Share()
// set clock to submission time
clock.CurrentTime = DateTimeOffset.FromUnixTimeSeconds(1508869907).UtcDateTime;

var share = job.ProcessShare(worker, "01000000", "59ef86f2", "8d84ae6a");
var (share, blockHex) = job.ProcessShare(worker, "01000000", "59ef86f2", "8d84ae6a");

Assert.NotNull(share);
Assert.True(share.IsBlockCandidate);
Assert.Equal(share.BlockHash, "000000000fccf11cd0b7d9057441e430c320384b95b034bd28092c4553594b4a");
Assert.Equal(share.BlockHex, "00000020bb76da6422b707a90831c421798123293bc5fd377bbeb51985570909000000008677145722cbe6f1ebec19fecc724cab5487f3292a69f6908bd512f645bb0635f286ef59ffff7f206aae848d0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff295e0c0b2f454231362f414431322f04f286ef590801000058010000000c2f4d696e696e67436f72652f000000000100f2052a010000001976a9142ebb5cccf9a6bb927661d2953655c43c04accc3788ac00000000");
Assert.Equal(share.BlockHash, "601ed85039804bcecbbdb53e0ca358aeb8dabef2366fb64c216aac3aba02b716");
Assert.Equal(blockHex, "00000020bb76da6422b707a90831c421798123293bc5fd377bbeb5198557090900000000fd5418fe788ef961678e4bacdd1fe3903185b9ec63865bb3d2d279bb0eb48c0bf286ef59ffff7f206aae848d0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff295e0c0b2f454231362f414431322f04f286ef590001000058010000000c2f4d696e696e67436f72652f000000000100f2052a010000001976a9142ebb5cccf9a6bb927661d2953655c43c04accc3788ac00000000");
Assert.Equal(share.BlockHeight, 14);
Assert.Equal(share.BlockReward, 50);
Assert.Equal(share.Difficulty, 0.5);
Expand Down Expand Up @@ -87,14 +87,14 @@ public void BitcoinJob_Should_Not_Accept_Invalid_Share()
Assert.Throws<StratumException>(() => job.ProcessShare(worker, "02000000", "59ef86f2", "8d84ae6a"));

// make sure we don't accept case-sensitive duplicate shares as basically 0xdeadbeaf = 0xDEADBEAF.
var share = job.ProcessShare(worker, "01000000", "59ef86f2", "8d84ae6a");
var (share, blockHex) = job.ProcessShare(worker, "01000000", "59ef86f2", "8d84ae6a");
Assert.Throws<StratumException>(() => job.ProcessShare(worker, "01000000", "59ef86f2", "8D84AE6A"));

// invalid time
Assert.Throws<StratumException>(() => job.ProcessShare(worker, "01000000", "69ef86f2", "8d84ae6a"));

// invalid nonce
Assert.Throws<StratumException>(() => job.ProcessShare(worker, "01000000", "59ef86f2", "ad84be6a"));
Assert.Throws<StratumException>(() => job.ProcessShare(worker, "01000000", "59ef86f2", "4a84be6a"));

// valid share data but invalid submission time
clock.CurrentTime = DateTimeOffset.FromUnixTimeSeconds(1408869907).UtcDateTime;
Expand Down
6 changes: 3 additions & 3 deletions src/MiningCore.Tests/Blockchain/Monero/MoneroJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public void MoneroJob_Should_Accept_Valid_Share()
"{\"blocktemplate_blob\":\"0106e7eabdcf058234351e2e6ea901a56b33bb531587424321873072d80a9e97295b6c43152b9d00000000019c0201ffe00106e3a1a0cc010275d92c0a057aa5f073079694a153d426f837f49fdb9654da10a5364e79a2086280a0d9e61d028b46dca0d04998500b40b046fd6f8bb33229e6380fd465dbb1327aa6f813d8bd80c0fc82aa0202372f076459e769116d604d30aabff7160782acc0d20e0c5cdc8963ed4e16372f8090cad2c60e02f009504ce65538bbb684b466b21be3a90e3740f185d7089d37b75f0cf62b6e7680e08d84ddcb0102cf01b85c0b592bb6e508e20b5d317052b75de121908390363201abff3476ef0180c0caf384a302024b81076c8ad0cfe84cc32fe0813d63cdd0f7d8d0e56d82aa3f58cbbe49d4c61e2b017aaf3074be7ecb30a769595758e4da7c7c87ead864baf89b679b73153dfa352c0208000000000000000000\",\"Difficulty\":2,\"Height\":224,\"prev_hash\":\"8234351e2e6ea901a56b33bb531587424321873072d80a9e97295b6c43152b9d\",\"reserved_offset\":322,\"Status\":\"OK\"}");

var job = new MoneroJob(bt, "d150da".HexToByteArray(), "1", poolConfig, clusterConfig);
var share = job.ProcessShare("040100a4", 1, "f29c7fbf57d97eeedb61555857d7a34314250da20742b8157f96e0be89530a00", worker);
var (share, blobHex, blobHash) = job.ProcessShare("040100a4", 1, "f29c7fbf57d97eeedb61555857d7a34314250da20742b8157f96e0be89530a00", worker);

Assert.NotNull(share);
Assert.True(share.IsBlockCandidate);
Assert.Equal(share.BlobHash, "9258faf2dff5daf026681b5fa5d94a34dbb5bade1d9e2070865ba8c68f8f0454");
Assert.Equal(share.BlobHex, "0106e7eabdcf058234351e2e6ea901a56b33bb531587424321873072d80a9e97295b6c43152b9d040100a4019c0201ffe00106e3a1a0cc010275d92c0a057aa5f073079694a153d426f837f49fdb9654da10a5364e79a2086280a0d9e61d028b46dca0d04998500b40b046fd6f8bb33229e6380fd465dbb1327aa6f813d8bd80c0fc82aa0202372f076459e769116d604d30aabff7160782acc0d20e0c5cdc8963ed4e16372f8090cad2c60e02f009504ce65538bbb684b466b21be3a90e3740f185d7089d37b75f0cf62b6e7680e08d84ddcb0102cf01b85c0b592bb6e508e20b5d317052b75de121908390363201abff3476ef0180c0caf384a302024b81076c8ad0cfe84cc32fe0813d63cdd0f7d8d0e56d82aa3f58cbbe49d4c61e2b017aaf3074be7ecb30a769595758e4da7c7c87ead864baf89b679b73153dfa352c02080000000001d150da00");
Assert.Equal(blobHash, "9258faf2dff5daf026681b5fa5d94a34dbb5bade1d9e2070865ba8c68f8f0454");
Assert.Equal(blobHex, "0106e7eabdcf058234351e2e6ea901a56b33bb531587424321873072d80a9e97295b6c43152b9d040100a4019c0201ffe00106e3a1a0cc010275d92c0a057aa5f073079694a153d426f837f49fdb9654da10a5364e79a2086280a0d9e61d028b46dca0d04998500b40b046fd6f8bb33229e6380fd465dbb1327aa6f813d8bd80c0fc82aa0202372f076459e769116d604d30aabff7160782acc0d20e0c5cdc8963ed4e16372f8090cad2c60e02f009504ce65538bbb684b466b21be3a90e3740f185d7089d37b75f0cf62b6e7680e08d84ddcb0102cf01b85c0b592bb6e508e20b5d317052b75de121908390363201abff3476ef0180c0caf384a302024b81076c8ad0cfe84cc32fe0813d63cdd0f7d8d0e56d82aa3f58cbbe49d4c61e2b017aaf3074be7ecb30a769595758e4da7c7c87ead864baf89b679b73153dfa352c02080000000001d150da00");
Assert.Equal(share.BlockHeight, 224);
Assert.Equal(share.Difficulty, 1000);
}
Expand Down
89 changes: 89 additions & 0 deletions src/MiningCore.Tests/Crypto/CrytonoteTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using MiningCore.Extensions;
using MiningCore.Native;
using Xunit;

namespace MiningCore.Tests.Crypto
{
public class CrytonoteTests : TestBase
{
[Fact]
public void Crytonote_Hash_Slow()
{
var blobConverted = "0106a2aaafd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b42580100a4b1e2f4baf6ab7109071ab59bc52dba740d1de99fa0ae0c4afd6ea9f40c5d87ec01".HexToByteArray();
var result = LibCryptonote.CryptonightHashSlow(blobConverted, 0).ToHexString();

Assert.Equal("a845ffbdf83ae9a8ffa504a1011efbd5ed2294bb9da591d3b583740568402c00", result);
}

[Fact]
public void Cryptonote_SlowHash_Should_Throw_On_Null_Argument()
{
Assert.Throws<ArgumentNullException>(() => LibCryptonote.CryptonightHashSlow(null, 0));
}

[Fact]
public void Crytonote_Hash_Fast()
{
var blobConverted = "0106a2aaafd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b42580100a4b1e2f4baf6ab7109071ab59bc52dba740d1de99fa0ae0c4afd6ea9f40c5d87ec01".HexToByteArray();
var result = LibCryptonote.CryptonightHashFast(blobConverted).ToHexString();

Assert.Equal("ddc0e3a33b605ce39fa2d16a98d7634e33399ab1e4b56b3bdd3414b655fe9a98", result);
}

[Fact]
public void Cryptonote_FastHash_Should_Throw_On_Null_Argument()
{
Assert.Throws<ArgumentNullException>(() => LibCryptonote.CryptonightHashFast(null));
}

[Fact]
public void Crytonote_Hash_Slow_Lite()
{
var blobConverted = "0106f1adafd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b42597710c48c6d885e2622f40f82ecd9b9fd538f28df9b0557e07cd3237a31c76569ada98001".HexToByteArray();
var result = LibCryptonote.CryptonightHashSlowLite(blobConverted).ToHexString();

Assert.Equal("0769caee428a232cffb76fa200f174ff962734f24e7b3bf8d1b0d4e8ba6ceebf", result);
}

[Fact]
public void Crytonote_ConvertBlob()
{
var blob = "0106e5b3afd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b421c0300a401d90101ff9d0106d6d6a88702023c62e43372a58cb588147e20be53a27083f5c522f33c722b082ab7518c48cda280b4c4c32102609ec96e2499ee267d70efefc49f26e330526d3ef455314b7b5ba268a6045f8c80c0fc82aa0202fe5cc0fa56c4277d1a47827edce4725571529d57f33c73ada481ef84c323f30a8090cad2c60e02d88bf5e72a611c8b8464ce29e3b1adbfe1ae163886d9150fe511171cada98fcb80e08d84ddcb0102441915aaf9fbaf70ff454c701a6ae2bd59bb94dc0b888bf7e5d06274ee9238ca80c0caf384a302024078526e2132def44bde2806242652f5944e632f7d94290dd6ee5dda1929f5ee2b016e29f25f07ec2a8df59f0e118a6c9a4b769b745dc0c729071f6e0399d2585745020800000000012e7f76000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".HexToByteArray();
var result = LibCryptonote.ConvertBlob(blob, 330).ToHexString();

Assert.Equal("0106e5b3afd505583cf50bcc743d04d831d2b119dc94ad88679e359076ee3f18d258ee138b3b421c0300a4487286e262e95b8d2163a0c8b73527e8c9425adbdc4e532cf0ef4241f9ffbe9e01", result);
}

[Fact]
public void Cryptonote_ConvertBlob_Should_Throw_On_Null_Argument()
{
Assert.Throws<ArgumentNullException>(() => LibCryptonote.ConvertBlob(null, 0));
}

[Fact]
public void Crytonote_DecodeAddress()
{
var address = "48nhyWcSey31ngSEhV8j8NPm6B8PistCQJBjjDjmTvRSTWYg6iocAw131vE2JPh3ps33vgQDKLrUx3fcErusYWcMJBxpm1d";
var result = LibCryptonote.DecodeAddress(address);

Assert.Equal(18ul, result);
}

[Fact]
public void Cryptonote_DecodeAddress_Should_Throw_On_Null_Or_Empty_Argument()
{
Assert.Throws<ArgumentException>(() => LibCryptonote.DecodeAddress(null));
Assert.Throws<ArgumentException>(() => LibCryptonote.DecodeAddress(""));
}

[Fact]
public void Crytonote_DecodeIntegratedAddress()
{
var address = "4BrL51JCc9NGQ71kWhnYoDRffsDZy7m1HUU7MRU4nUMXAHNFBEJhkTZV9HdaL4gfuNBxLPc3BeMkLGaPbF5vWtANQsGwTGg55Kq4p3ENE7";
var result = LibCryptonote.DecodeIntegratedAddress(address);

Assert.Equal(19ul, result);
}
}
}
36 changes: 18 additions & 18 deletions src/MiningCore.Tests/Crypto/HashingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HashingTests : TestBase
private static readonly byte[] testValue2 = Enumerable.Repeat((byte)0x80, 80).ToArray();

[Fact]
public void Blake_Hash_Should_Match()
public void Blake_Hash()
{
var hasher = new Blake();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -34,7 +34,7 @@ public void Blake_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Blake2s_Hash_Should_Match()
public void Blake2s_Hash()
{
var hasher = new Blake2s();
var result = hasher.Digest(testValue2).ToHexString();
Expand All @@ -50,7 +50,7 @@ public void Blake2s_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Groestl_Hash_Should_Match()
public void Groestl_Hash()
{
var hasher = new Groestl();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -66,7 +66,7 @@ public void Groestl_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Kezzak_Hash_Should_Match()
public void Kezzak_Hash()
{
var hasher = new Kezzak();
var result = hasher.Digest(testValue, 0ul).ToHexString();
Expand All @@ -82,7 +82,7 @@ public void Kezzak_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Scrypt_Hash_Should_Match()
public void Scrypt_Hash()
{
var hasher = new Scrypt(1024, 1);
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -98,7 +98,7 @@ public void Scrypt_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void NeoScrypt_Hash_Should_Match()
public void NeoScrypt_Hash()
{
var hasher = new NeoScrypt(0);
var result = hasher.Digest(testValue2).ToHexString();
Expand All @@ -114,7 +114,7 @@ public void NeoScrypt_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void ScryptN_Hash_Should_Match()
public void ScryptN_Hash()
{
var clock = new MockMasterClock { CurrentTime = new DateTime(2017, 10, 16) };
var hasher = new ScryptN(clock, new []{ Tuple.Create(2048L, 1389306217L) });
Expand All @@ -132,7 +132,7 @@ public void ScryptN_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Lyra2Rev2_Hash_Should_Match()
public void Lyra2Rev2_Hash()
{
var hasher = new Lyra2Rev2();
var result = hasher.Digest(Enumerable.Repeat((byte) 5, 80).ToArray()).ToHexString();
Expand All @@ -155,7 +155,7 @@ public void Lyra2Rev2_Hash_Should_Throw_On_Short_Input()
}

[Fact]
public void Sha256D_Hash_Should_Match()
public void Sha256D_Hash()
{
var hasher = new Sha256D();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -171,7 +171,7 @@ public void Sha256D_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Sha256S_Hash_Should_Match()
public void Sha256S_Hash()
{
var hasher = new Sha256S();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -187,7 +187,7 @@ public void Sha256S_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void X11_Hash_Should_Match()
public void X11_Hash()
{
var hasher = new X11();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -203,7 +203,7 @@ public void X11_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void X17_Hash_Should_Match()
public void X17_Hash()
{
var hasher = new X17();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -219,7 +219,7 @@ public void X17_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Skein_Hash_Should_Match()
public void Skein_Hash()
{
var hasher = new Skein();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -235,7 +235,7 @@ public void Skein_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Qubit_Hash_Should_Match()
public void Qubit_Hash()
{
var hasher = new Qubit();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -251,7 +251,7 @@ public void Qubit_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void GroestlMyriad_Hash_Should_Match()
public void GroestlMyriad_Hash()
{
var hasher = new GroestlMyriad();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -267,7 +267,7 @@ public void GroestlMyriad_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void DigestReverser_Hash_Should_Match()
public void DigestReverser_Hash()
{
var hasher = new DigestReverser(new Sha256S());
var result = hasher.Digest(testValue).ToHexString();
Expand Down Expand Up @@ -317,7 +317,7 @@ public void EquihashVerifier_Should_Throw_On_Wrong_Argument_Length()
}

[Fact]
public void Sha3_256_Hash_Should_Match()
public void Sha3_256_Hash()
{
var hasher = new Sha3_256();
var result = hasher.Digest(testValue).ToHexString();
Expand All @@ -333,7 +333,7 @@ public void Sha3_256_Hash_Should_Throw_On_Null_Input()
}

[Fact]
public void Sha3_512_Hash_Should_Match()
public void Sha3_512_Hash()
{
var hasher = new Sha3_512();
var result = hasher.Digest(testValue).ToHexString();
Expand Down
71 changes: 0 additions & 71 deletions src/MiningCore.Tests/Native/LibCryptonoteTests.cs

This file was deleted.

Loading

0 comments on commit f511dd6

Please sign in to comment.