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

Commit

Permalink
Dev (#410)
Browse files Browse the repository at this point in the history
* Refactored TLS certificate loading

* Disable TLS 1.0

* Mini refactor

* WIP

* GC optimization for outgoing stratum traffic

* Prevent memory leak

* Re-enable proxy header spoofing protection and add support for IPv4 on IPv6

* Connection logging

* Refactor

* Cleanup

* Connection logging for unsecure connections rephrased

* WIP

* Logging cleanup

* Code cleanup

* WIP

* Added ignored linux socket error

* Bitcoin Diamond (BCD)

* BCD

* Reduced log noise

* WIP

* Coherent connection logging

* WIP

* Fixed Makefile

* Cryptonight Variant test

* WIP LibCryptonight

* WIP

* libcryptonight working

* Ignore certain exceptions during shutdown

* More tests

* Fixed blockrewardMultiplier getting initialized to zero

* Makefile warnings

* Makefile

* Makefile

* Improved SendAsync of StratumClient

* Bitcoin Gold Address decode fix

* WIP

* More BTG fixes

* And another BTG fix

* Trimming

* Comments

* Compile error fix

* WIP

* Revert BTG network diff

* Code cleanup

* Crash fix

* Fix async exceptions

* WIP

* Re-introduce sendQueue for StratumClient

* ProcessSendQueueAsync cleanup

* Replace NetMQ with clrzmq4

* Fix compile warnings

* WIP

* WIP

* ShareReceiver endianess fix

* Temporary disable telemetry

* TMP fix

* WIP

* Makefile consolidation

* disable optimizations for now on libcryptonight/Makefile

* Fix ZeroMQ message memory leaks

* More leak fixes

* O2

* Update README.md
Fixes #260

* BOM stripping

* Revert libcryptnight

* Revert "BOM stripping"

This reverts commit 8f7b73e.

* JSON trimming

* Revert "Revert libcryptnight"

This reverts commit 6f52717.

* ThreadLocal context-state for Cryptonight

* Fixed windows builds (Fixes #399).

* WIP

* GC optimizations Part 1

* GC optimizations Part 2

* GC optimizations Part 3

* WIP

* Code cleanup

* WIP

* WIP

* Remove unnecessary unsafe statements

* WIP

* WIP

* Eliminate shared ThreadLocal for cryptonight state

* Revert "Eliminate shared ThreadLocal for cryptonight state"

This reverts commit 75ce96a.

* Pre-allocate one context per CPU

* WIP

* Remove logspam

* Comments

* Per cryptonight family context leasing

* WIP

* Lazy alloc

* WIP

* Bittube

* WIP

* WIP

* Address prefix

* API fields cleanup

* WIP

* WIP

* Optimize Deserialize

* WIP

* AddMemoryPressure

* WIP

* WIP

* WIP

* Stratum reliability

* Cleanup

* Mini refactor

* Bullet-proofing StratumClient disposal

* WIP

* Cancellation support

* Prefer live network stats for pool api

* Update network stats even if internal stratum is disabled

* WIP

* WIP

* Formatting

* Refactor

* Cleanup

* Plural

* WIP

* Fix

* Cleanup

* Who needs a send queue

* Socket send-timeout

* Streamlined stratum error-handling

* WIP

* Error logging

* Additional safety net

* Streamlined build process for Windows and Linux

* WIP

* appveyor.yml

* appveyor.yml

* WIP

* WIP

* WIP

* WIP

* typo

* Guard against configuration errors

* build artifact test

* WIP

* WIP

* 7z

* Archive names

* Test

* WIP

* Typo

* .gitignore

* Statically link native libs on linux to reduce dependencies

* Revert "Statically link native libs on linux to reduce dependencies"

This reverts commit 5c78978.

* Revert "Who needs a send queue"

* WIP

* Fix makefile clean failure

* Disable Deserialize fastpath

* Always include id property in JSON RPC responses even if unused. Should fix #375

* README.md

* Simplified built scripts

* Dispose all CancellationTokenSources

* comments

* ZMQ Curve Security for Share Relay send/recv

* Refactor

* ZMQ Curve encapsulation, refactor and cleanup

* Enable socket-keepalive

* Docs

* WIP

* Logging

* WIP

* Validate poolid on ShareReceiver

* Websocket logging

* Parity backup polling
WebsocketSubscribe receive timeout -> reconnect

* DaemonClient logging scoped to pool now

* Fix release build error

* ETH logging

* Revert polling

* http2 implies SSL

* Change hash algorithm for PKBDF

* Revert

* WIP

* Fixed key mismatch
  • Loading branch information
Oliver Weichhold authored Oct 2, 2018
1 parent f6c5c78 commit 0f31c6a
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 255 deletions.
Binary file modified libs/ZeroMQ.dll
Binary file not shown.
32 changes: 16 additions & 16 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected virtual void SetupJobUpdates()
{
logger.Info(() => $"Subscribing to ZMQ push-updates from {string.Join(", ", zmq.Values)}");

var blockNotify = daemon.ZmqSubscribe(zmq, 2)
var blockNotify = daemon.ZmqSubscribe(logger, zmq, 2)
.Select(msg =>
{
using (msg)
Expand Down Expand Up @@ -228,7 +228,7 @@ protected virtual async Task<DaemonResponse<TBlockTemplate>> GetBlockTemplateAsy
{
logger.LogInvoke();

var result = await daemon.ExecuteCmdAnyAsync<TBlockTemplate>(
var result = await daemon.ExecuteCmdAnyAsync<TBlockTemplate>(logger,
BitcoinCommands.GetBlockTemplate, getBlockTemplateParams);

return result;
Expand All @@ -254,7 +254,7 @@ protected virtual async Task ShowDaemonSyncProgressAsync()
return;
}

var infos = await daemon.ExecuteCmdAllAsync<BlockchainInfo>(BitcoinCommands.GetBlockchainInfo);
var infos = await daemon.ExecuteCmdAllAsync<BlockchainInfo>(logger, BitcoinCommands.GetBlockchainInfo);

if (infos.Length > 0)
{
Expand All @@ -264,7 +264,7 @@ protected virtual async Task ShowDaemonSyncProgressAsync()
if (blockCount.HasValue)
{
// get list of peers and their highest block height to compare to ours
var peerInfo = await daemon.ExecuteCmdAnyAsync<PeerInfo[]>(BitcoinCommands.GetPeerInfo);
var peerInfo = await daemon.ExecuteCmdAnyAsync<PeerInfo[]>(logger, BitcoinCommands.GetPeerInfo);
var peers = peerInfo.Response;

if (peers != null && peers.Length > 0)
Expand All @@ -283,7 +283,7 @@ private async Task UpdateNetworkStatsAsync()

try
{
var results = await daemon.ExecuteBatchAnyAsync(
var results = await daemon.ExecuteBatchAnyAsync(logger,
new DaemonCmd(BitcoinCommands.GetMiningInfo),
new DaemonCmd(BitcoinCommands.GetNetworkInfo)
);
Expand Down Expand Up @@ -312,7 +312,7 @@ private async Task UpdateNetworkStatsAsync()
protected virtual async Task<(bool Accepted, string CoinbaseTransaction)> SubmitBlockAsync(Share share, string blockHex)
{
// execute command batch
var results = await daemon.ExecuteBatchAnyAsync(
var results = await daemon.ExecuteBatchAnyAsync(logger,
hasSubmitBlockMethod
? new DaemonCmd(BitcoinCommands.SubmitBlock, new[] { blockHex })
: new DaemonCmd(BitcoinCommands.GetBlockTemplate, new { mode = "submit", data = blockHex }),
Expand Down Expand Up @@ -360,7 +360,7 @@ protected virtual void SetupCrypto()

protected virtual async Task<bool> AreDaemonsHealthyLegacyAsync()
{
var responses = await daemon.ExecuteCmdAllAsync<DaemonInfo>(BitcoinCommands.GetInfo);
var responses = await daemon.ExecuteCmdAllAsync<DaemonInfo>(logger, BitcoinCommands.GetInfo);

if (responses.Where(x => x.Error?.InnerException?.GetType() == typeof(DaemonClientException))
.Select(x => (DaemonClientException) x.Error.InnerException)
Expand All @@ -372,14 +372,14 @@ protected virtual async Task<bool> AreDaemonsHealthyLegacyAsync()

protected virtual async Task<bool> AreDaemonsConnectedLegacyAsync()
{
var response = await daemon.ExecuteCmdAnyAsync<DaemonInfo>(BitcoinCommands.GetInfo);
var response = await daemon.ExecuteCmdAnyAsync<DaemonInfo>(logger, BitcoinCommands.GetInfo);

return response.Error == null && response.Response.Connections > 0;
}

protected virtual async Task ShowDaemonSyncProgressLegacyAsync()
{
var infos = await daemon.ExecuteCmdAllAsync<DaemonInfo>(BitcoinCommands.GetInfo);
var infos = await daemon.ExecuteCmdAllAsync<DaemonInfo>(logger, BitcoinCommands.GetInfo);

if (infos.Length > 0)
{
Expand All @@ -389,7 +389,7 @@ protected virtual async Task ShowDaemonSyncProgressLegacyAsync()
if (blockCount.HasValue)
{
// get list of peers and their highest block height to compare to ours
var peerInfo = await daemon.ExecuteCmdAnyAsync<PeerInfo[]>(BitcoinCommands.GetPeerInfo);
var peerInfo = await daemon.ExecuteCmdAnyAsync<PeerInfo[]>(logger, BitcoinCommands.GetPeerInfo);
var peers = peerInfo.Response;

if (peers != null && peers.Length > 0)
Expand All @@ -408,7 +408,7 @@ private async Task UpdateNetworkStatsLegacyAsync()

try
{
var results = await daemon.ExecuteBatchAnyAsync(
var results = await daemon.ExecuteBatchAnyAsync(logger,
new DaemonCmd(BitcoinCommands.GetConnectionCount)
);

Expand Down Expand Up @@ -442,7 +442,7 @@ public virtual async Task<bool> ValidateAddressAsync(string address, Cancellatio
{
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(address), $"{nameof(address)} must not be empty");

var result = await daemon.ExecuteCmdAnyAsync<ValidateAddressResponse>(ct,
var result = await daemon.ExecuteCmdAnyAsync<ValidateAddressResponse>(logger, ct,
BitcoinCommands.ValidateAddress, new[] { address });

return result.Response != null && result.Response.IsValid;
Expand Down Expand Up @@ -609,7 +609,7 @@ protected override async Task<bool> AreDaemonsHealthyAsync()
if (hasLegacyDaemon)
return await AreDaemonsHealthyLegacyAsync();

var responses = await daemon.ExecuteCmdAllAsync<BlockchainInfo>(BitcoinCommands.GetBlockchainInfo);
var responses = await daemon.ExecuteCmdAllAsync<BlockchainInfo>(logger, BitcoinCommands.GetBlockchainInfo);

if (responses.Where(x => x.Error?.InnerException?.GetType() == typeof(DaemonClientException))
.Select(x => (DaemonClientException) x.Error.InnerException)
Expand All @@ -624,7 +624,7 @@ protected override async Task<bool> AreDaemonsConnectedAsync()
if (hasLegacyDaemon)
return await AreDaemonsConnectedLegacyAsync();

var response = await daemon.ExecuteCmdAnyAsync<NetworkInfo>(BitcoinCommands.GetNetworkInfo);
var response = await daemon.ExecuteCmdAnyAsync<NetworkInfo>(logger, BitcoinCommands.GetNetworkInfo);

return response.Error == null && response.Response?.Connections > 0;
}
Expand All @@ -635,7 +635,7 @@ protected override async Task EnsureDaemonsSynchedAsync(CancellationToken ct)

while(true)
{
var responses = await daemon.ExecuteCmdAllAsync<BlockTemplate>(
var responses = await daemon.ExecuteCmdAllAsync<BlockTemplate>(logger,
BitcoinCommands.GetBlockTemplate, getBlockTemplateParams);

var isSynched = responses.All(x => x.Error == null);
Expand Down Expand Up @@ -669,7 +669,7 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
new DaemonCmd(BitcoinCommands.GetDifficulty),
};

var results = await daemon.ExecuteBatchAnyAsync(commands);
var results = await daemon.ExecuteBatchAnyAsync(logger, commands);

if (results.Any(x => x.Error != null))
{
Expand Down
8 changes: 4 additions & 4 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public virtual async Task<Block[]> ClassifyBlocksAsync(Block[] blocks)
new[] { block.TransactionConfirmationData })).ToArray();

// execute batch
var results = await daemon.ExecuteBatchAnyAsync(batch);
var results = await daemon.ExecuteBatchAnyAsync(logger, batch);

for(var j = 0; j < results.Length; j++)
{
Expand Down Expand Up @@ -267,15 +267,15 @@ public virtual async Task PayoutAsync(Balance[] balances)

// send command
tryTransfer:
var result = await daemon.ExecuteCmdSingleAsync<string>(BitcoinCommands.SendMany, args, new JsonSerializerSettings());
var result = await daemon.ExecuteCmdSingleAsync<string>(logger, BitcoinCommands.SendMany, args, new JsonSerializerSettings());

if (result.Error == null)
{
if (didUnlockWallet)
{
// lock wallet
logger.Info(() => $"[{LogCategory}] Locking wallet");
await daemon.ExecuteCmdSingleAsync<JToken>(BitcoinCommands.WalletLock);
await daemon.ExecuteCmdSingleAsync<JToken>(logger, BitcoinCommands.WalletLock);
}

// check result
Expand All @@ -299,7 +299,7 @@ public virtual async Task PayoutAsync(Balance[] balances)
{
logger.Info(() => $"[{LogCategory}] Unlocking wallet");

var unlockResult = await daemon.ExecuteCmdSingleAsync<JToken>(BitcoinCommands.WalletPassphrase, new[]
var unlockResult = await daemon.ExecuteCmdSingleAsync<JToken>(logger, BitcoinCommands.WalletPassphrase, new[]
{
(object) extraPoolPaymentProcessingConfig.WalletPassword,
(object) 5 // unlock for N seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BitcoinGoldJobManager(IComponentContext ctx,

protected override async Task<DaemonResponse<ZCashBlockTemplate>> GetBlockTemplateAsync()
{
var result = await daemon.ExecuteCmdAnyAsync<ZCashBlockTemplate>(
var result = await daemon.ExecuteCmdAnyAsync<ZCashBlockTemplate>(logger,
BitcoinCommands.GetBlockTemplate, getBlockTemplateParams);

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/MiningCore/Blockchain/Dash/DashPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public override async Task PayoutAsync(Balance[] balances)

// send command
tryTransfer:
var result = await daemon.ExecuteCmdSingleAsync<string>(BitcoinCommands.SendMany, args, new JsonSerializerSettings());
var result = await daemon.ExecuteCmdSingleAsync<string>(logger, BitcoinCommands.SendMany, args, new JsonSerializerSettings());

if (result.Error == null)
{
if (didUnlockWallet)
{
// lock wallet
logger.Info(() => $"[{LogCategory}] Locking wallet");
await daemon.ExecuteCmdSingleAsync<JToken>(BitcoinCommands.WalletLock);
await daemon.ExecuteCmdSingleAsync<JToken>(logger, BitcoinCommands.WalletLock);
}

// check result
Expand All @@ -137,7 +137,7 @@ public override async Task PayoutAsync(Balance[] balances)
{
logger.Info(() => $"[{LogCategory}] Unlocking wallet");

var unlockResult = await daemon.ExecuteCmdSingleAsync<JToken>(BitcoinCommands.WalletPassphrase, new[]
var unlockResult = await daemon.ExecuteCmdSingleAsync<JToken>(logger, BitcoinCommands.WalletPassphrase, new[]
{
(object) extraPoolPaymentProcessingConfig.WalletPassword,
(object) 5 // unlock for N seconds
Expand Down
26 changes: 15 additions & 11 deletions src/MiningCore/Blockchain/Ethereum/EthereumJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ protected bool UpdateJob(EthereumBlockTemplate blockTemplate)
if (blockTemplate == null || blockTemplate.Header?.Length == 0)
return false;

logger.Info(() => $"Blocktemplate {blockTemplate.Height}-{blockTemplate.Header}");

var job = currentJob;
var isNew = currentJob == null || job.BlockTemplate.Header != blockTemplate.Header;
var isNew = currentJob == null ||
job.BlockTemplate.Height < blockTemplate.Height ||
job.BlockTemplate.Header != blockTemplate.Header;

if (isNew)
{
Expand Down Expand Up @@ -159,7 +163,7 @@ private async Task<EthereumBlockTemplate> GetBlockTemplateAsync()
{
logger.LogInvoke();

var response = await daemon.ExecuteCmdAnyAsync<JToken>(EC.GetWork);
var response = await daemon.ExecuteCmdAnyAsync<JToken>(logger, EC.GetWork);

if (response.Error != null)
{
Expand Down Expand Up @@ -208,7 +212,7 @@ private EthereumBlockTemplate AssembleBlockTemplate(string[] work)

private async Task ShowDaemonSyncProgressAsync()
{
var responses = await daemon.ExecuteCmdAllAsync<object>(EC.GetSyncState);
var responses = await daemon.ExecuteCmdAllAsync<object>(logger, EC.GetSyncState);
var firstValidResponse = responses.FirstOrDefault(x => x.Error == null && x.Response != null)?.Response;

if (firstValidResponse != null)
Expand All @@ -224,7 +228,7 @@ private async Task ShowDaemonSyncProgressAsync()
if (syncStates.Any())
{
// get peer count
var response = await daemon.ExecuteCmdAllAsync<string>(EC.GetPeerCount);
var response = await daemon.ExecuteCmdAllAsync<string>(logger, EC.GetPeerCount);
var validResponses = response.Where(x => x.Error == null && x.Response != null).ToArray();
var peerCount = validResponses.Any() ? validResponses.Max(x => x.Response.IntegralFromHex<uint>()) : 0;

Expand Down Expand Up @@ -260,7 +264,7 @@ private async Task UpdateNetworkStatsAsync()
new DaemonCmd(EC.GetPeerCount),
};

var results = await daemon.ExecuteBatchAnyAsync(commands);
var results = await daemon.ExecuteBatchAnyAsync(logger, commands);

if (results.Any(x => x.Error != null))
{
Expand All @@ -287,7 +291,7 @@ private async Task UpdateNetworkStatsAsync()
private async Task<bool> SubmitBlockAsync(Share share, string fullNonceHex, string headerHash, string mixHash)
{
// submit work
var response = await daemon.ExecuteCmdAnyAsync<object>(EC.SubmitWork, new[]
var response = await daemon.ExecuteCmdAnyAsync<object>(logger, EC.SubmitWork, new[]
{
fullNonceHex,
headerHash,
Expand Down Expand Up @@ -446,7 +450,7 @@ protected override void ConfigureDaemons()

protected override async Task<bool> AreDaemonsHealthyAsync()
{
var responses = await daemon.ExecuteCmdAllAsync<Block>(EC.GetBlockByNumber, new[] { (object) "pending", true });
var responses = await daemon.ExecuteCmdAllAsync<Block>(logger, EC.GetBlockByNumber, new[] { (object) "pending", true });

if (responses.Where(x => x.Error?.InnerException?.GetType() == typeof(DaemonClientException))
.Select(x => (DaemonClientException) x.Error.InnerException)
Expand All @@ -458,7 +462,7 @@ protected override async Task<bool> AreDaemonsHealthyAsync()

protected override async Task<bool> AreDaemonsConnectedAsync()
{
var response = await daemon.ExecuteCmdAnyAsync<string>(EC.GetPeerCount);
var response = await daemon.ExecuteCmdAnyAsync<string>(logger, EC.GetPeerCount);

return response.Error == null && response.Response.IntegralFromHex<uint>() > 0;
}
Expand All @@ -469,7 +473,7 @@ protected override async Task EnsureDaemonsSynchedAsync(CancellationToken ct)

while(true)
{
var responses = await daemon.ExecuteCmdAllAsync<object>(EC.GetSyncState);
var responses = await daemon.ExecuteCmdAllAsync<object>(logger, EC.GetSyncState);

var isSynched = responses.All(x => x.Error == null &&
x.Response is bool && (bool) x.Response == false);
Expand Down Expand Up @@ -504,7 +508,7 @@ protected override async Task PostStartInitAsync(CancellationToken ct)
new DaemonCmd(EC.ParityChain),
};

var results = await daemon.ExecuteBatchAnyAsync(commands);
var results = await daemon.ExecuteBatchAnyAsync(logger, commands);

if (results.Any(x => x.Error != null))
{
Expand Down Expand Up @@ -625,7 +629,7 @@ protected virtual void SetupJobUpdates()
logger.Info(() => $"Subscribing to WebSocket push-updates from {string.Join(", ", wsDaemons.Keys.Select(x => x.Host).Distinct())}");

// stream work updates
var getWorkObs = daemon.WebsocketSubscribe(wsDaemons, EC.ParitySubscribe, new[] { (object) EC.GetWork })
var getWorkObs = daemon.WebsocketSubscribe(logger, wsDaemons, EC.ParitySubscribe, new[] { (object) EC.GetWork })
.Select(data =>
{
try
Expand Down
Loading

0 comments on commit 0f31c6a

Please sign in to comment.