Skip to content

Commit

Permalink
Implemented block-processor to query blocks.
Browse files Browse the repository at this point in the history
renamed blocks.cs in statistics as blockcount.cs.
removed 'kicked' block concept completely.
cleaned persisted block structures, we just have ipersistblock.cs now.
removed hash candicate structure.
also improved submitblock logic within sharemanager.
  • Loading branch information
bonesoul committed Aug 7, 2014
1 parent cc8c5a6 commit 2671f95
Show file tree
Hide file tree
Showing 30 changed files with 310 additions and 663 deletions.
98 changes: 98 additions & 0 deletions src/CoiniumServ/Blocks/BlockProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#region License
//
// CoiniumServ - Crypto Currency Mining Pool Server Software
// Copyright (C) 2013 - 2014, CoiniumServ Project - http://www.coinium.org
// http://www.coiniumserv.com - https://github.com/CoiniumServ/CoiniumServ
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For the terms of this license, see licenses/gpl_v3.txt.
//
// Alternatively, you can license this software under a commercial
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion

using System;
using System.Linq;
using CoiniumServ.Daemon;
using CoiniumServ.Daemon.Exceptions;
using CoiniumServ.Daemon.Responses;
using CoiniumServ.Pools.Config;
using Serilog;

namespace CoiniumServ.Blocks
{
public class BlockProcessor:IBlockProcessor
{
private readonly IDaemonClient _daemonClient;

private readonly IPoolConfig _poolConfig;

private readonly ILogger _logger;

public BlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient)
{
_poolConfig = poolConfig;
_daemonClient = daemonClient;
_logger = Log.ForContext<BlockProcessor>().ForContext("Component", poolConfig.Coin.Name);
}

public bool GetBlockDetails(string blockHash, out Block block, out Transaction generationTransaction)
{
block = null;
generationTransaction = null;

try
{
// query the block.
block = _daemonClient.GetBlock(blockHash);

// read the very first (generation transaction) of the block
var generationTx = block.Tx.First();

// also make sure the transaction includes our pool wallet address.
generationTransaction = _daemonClient.GetTransaction(generationTx);

return true;
}
catch (RpcException e)
{
_logger.Error("Queried block does not exist {0:l}, {1:l}", blockHash, e.Message);
return false;
}
}

public bool CheckGenTxHash(Block block, string expectedTxHash)
{
// get the generation transaction for the block.
var genTx = block.Tx.First();

if (expectedTxHash == genTx)
return true;

Log.Debug("Queried block {0:l} doesn't seem to belong us as reported generation transaction hash [{1:l}] doesn't match our expected one [{2:l}]", block.Hash, genTx, expectedTxHash);
return false;
}

public bool ContainsPoolOutput(Transaction transaction)
{
// check if the transaction includes output for the configured central pool wallet address.
var gotPoolOutput = transaction.Details.Any(x => x.Address == _poolConfig.Wallet.Adress);

if (gotPoolOutput) // if we got the correct pool output
return true; // then the block seems to belong us.

Log.Debug("Queried block doesn't seem to belong us as generation transaction doesn't contain an output for pool's central wallet address: {0:}", _poolConfig.Wallet.Adress);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@
//
#endregion

using System.Collections.Generic;
using CoiniumServ.Daemon.Responses;

namespace CoiniumServ.Persistance.Blocks
namespace CoiniumServ.Blocks
{
public interface IPendingBlock: IPersistedBlock
public interface IBlockProcessor
{
bool IsFinalized { get; }
bool GetBlockDetails(string blockHash, out Block block, out Transaction generationTransaction);

IFinalizedBlock Finalized { get; }
bool CheckGenTxHash(Block block, string expectedTxHash);

List<IHashCandidate> Candidates { get; }

void AddHashCandidate(IHashCandidate hash);

void Check();
bool ContainsPoolOutput(Transaction transaction);
}
}
18 changes: 5 additions & 13 deletions src/CoiniumServ/CoiniumServ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Blocks\BlockProcessor.cs" />
<Compile Include="Blocks\IBlockProcessor.cs" />
<Compile Include="Coin\Helpers\Hashrate.cs" />
<Compile Include="Configuration\IJsonConfigReader.cs" />
<Compile Include="Configuration\IStackConfig.cs" />
Expand Down Expand Up @@ -143,6 +145,7 @@
<Compile Include="Payments\IRewardsConfig.cs" />
<Compile Include="Jobs\Manager\JobConfig.cs" />
<Compile Include="Miners\MinerConfig.cs" />
<Compile Include="Persistance\Blocks\PersistedBlock.cs" />
<Compile Include="Persistance\IStorageConfig.cs" />
<Compile Include="Payments\IWalletConfig.cs" />
<Compile Include="Payments\RewardsConfig.cs" />
Expand All @@ -153,8 +156,8 @@
<Compile Include="Server\Web\Modules\Donate.cs" />
<Compile Include="Server\Web\Models\IndexModel.cs" />
<Compile Include="Server\Web\Models\PoolModel.cs" />
<Compile Include="Statistics\Blocks.cs" />
<Compile Include="Statistics\IBlocks.cs" />
<Compile Include="Statistics\BlocksCount.cs" />
<Compile Include="Statistics\IBlocksCount.cs" />
<Compile Include="Statistics\IJsonResponse.cs" />
<Compile Include="Statistics\ILatestBlocks.cs" />
<Compile Include="Statistics\IStatisticsConfig.cs" />
Expand Down Expand Up @@ -200,18 +203,7 @@
<Compile Include="Payments\PaymentProcessor.cs" />
<Compile Include="Payments\WorkerBalance.cs" />
<Compile Include="Persistance\Blocks\BlockStatus.cs" />
<Compile Include="Persistance\Blocks\IConfirmedBlock.cs" />
<Compile Include="Persistance\Blocks\IFinalizedBlock.cs" />
<Compile Include="Persistance\Blocks\IKickedBlock.cs" />
<Compile Include="Persistance\Blocks\IOrphanedBlock.cs" />
<Compile Include="Persistance\Blocks\IPendingBlock.cs" />
<Compile Include="Persistance\Blocks\IPersistedBlock.cs" />
<Compile Include="Persistance\Blocks\IHashCandidate.cs" />
<Compile Include="Persistance\Blocks\PendingBlock.cs" />
<Compile Include="Persistance\Blocks\HashCandidate.cs" />
<Compile Include="Persistance\Blocks\ConfirmedBlock.cs" />
<Compile Include="Persistance\Blocks\KickedBlock.cs" />
<Compile Include="Persistance\Blocks\OrphanedBlock.cs" />
<Compile Include="Persistance\Redis\IRedisConfig.cs" />
<Compile Include="Persistance\Redis\RedisConfig.cs" />
<Compile Include="Repository\Registries\AlgorithmRegistry.cs" />
Expand Down
11 changes: 7 additions & 4 deletions src/CoiniumServ/Factories/IObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endregion

using CoiniumServ.Banning;
using CoiniumServ.Blocks;
using CoiniumServ.Cryptology.Algorithms;
using CoiniumServ.Daemon;
using CoiniumServ.Jobs.Manager;
Expand Down Expand Up @@ -78,9 +79,11 @@ IJobManager GetJobManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJ

IJobTracker GetJobTracker();

IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage);
IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage, IBlockProcessor blockProcessor);

IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage);
IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage, IBlockProcessor blockProcessor);

IBlockProcessor GetBlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient);

IBanManager GetBanManager(IPoolConfig poolConfig, IShareManager shareManager);

Expand All @@ -98,9 +101,9 @@ IJobManager GetJobManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJ

IPools GetPoolStats();

IPerPool GetPerPoolStats(IPoolConfig poolConfig, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocks blockStatistics, IStorage storage);
IPerPool GetPerPoolStats(IPoolConfig poolConfig, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocksCount blockStatistics, IStorage storage);

IBlocks GetBlockStats(ILatestBlocks latestBlocks, IStorage storage);
IBlocksCount GetBlockStats(ILatestBlocks latestBlocks, IStorage storage);

ILatestBlocks GetLatestBlocks(IStorage storage);

Expand Down
26 changes: 20 additions & 6 deletions src/CoiniumServ/Factories/ObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endregion

using CoiniumServ.Banning;
using CoiniumServ.Blocks;
using CoiniumServ.Cryptology.Algorithms;
using CoiniumServ.Daemon;
using CoiniumServ.Jobs.Manager;
Expand Down Expand Up @@ -145,31 +146,44 @@ public IJobTracker GetJobTracker()
return _applicationContext.Container.Resolve<IJobTracker>();
}

public IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage)
public IShareManager GetShareManager(IPoolConfig poolConfig, IDaemonClient daemonClient, IJobTracker jobTracker, IStorage storage, IBlockProcessor blockProcessor)
{
var @params = new NamedParameterOverloads
{
{"poolConfig", poolConfig},
{"daemonClient", daemonClient},
{"jobTracker", jobTracker},
{"storage", storage},
{"blockProcessor", blockProcessor}
};

return _applicationContext.Container.Resolve<IShareManager>(@params);
}

public IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage)
public IPaymentProcessor GetPaymentProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient, IStorage storage, IBlockProcessor blockProcessor)
{
var @params = new NamedParameterOverloads
{
{"poolConfig", poolConfig},
{"daemonClient", daemonClient},
{"storage", storage},
{"storage", storage},
{"blockProcessor", blockProcessor},
};

return _applicationContext.Container.Resolve<IPaymentProcessor>(@params);
}

public IBlockProcessor GetBlockProcessor(IPoolConfig poolConfig, IDaemonClient daemonClient)
{
var @params = new NamedParameterOverloads
{
{"poolConfig", poolConfig},
{"daemonClient", daemonClient},
};

return _applicationContext.Container.Resolve<IBlockProcessor>(@params);
}

public IBanManager GetBanManager(IPoolConfig poolConfig, IShareManager shareManager)
{
var @params = new NamedParameterOverloads
Expand Down Expand Up @@ -216,7 +230,7 @@ public IPools GetPoolStats()
return _applicationContext.Container.Resolve<IPools>();
}

public IPerPool GetPerPoolStats(IPoolConfig poolConfig, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocks blockStatistics, IStorage storage)
public IPerPool GetPerPoolStats(IPoolConfig poolConfig, IDaemonClient daemonClient, IMinerManager minerManager, IHashAlgorithm hashAlgorithm, IBlocksCount blockStatistics, IStorage storage)
{
var @params = new NamedParameterOverloads
{
Expand All @@ -241,15 +255,15 @@ public ILatestBlocks GetLatestBlocks(IStorage storage)
return _applicationContext.Container.Resolve<ILatestBlocks>(@params);
}

public IBlocks GetBlockStats(ILatestBlocks latestBlocks, IStorage storage)
public IBlocksCount GetBlockStats(ILatestBlocks latestBlocks, IStorage storage)
{
var @params = new NamedParameterOverloads
{
{"latestBlocks", latestBlocks},
{"storage", storage},
};

return _applicationContext.Container.Resolve<IBlocks>(@params);
return _applicationContext.Container.Resolve<IBlocksCount>(@params);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Payments/IPaymentRound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace CoiniumServ.Payments
{
public interface IPaymentRound
{
IFinalizedBlock Block { get; }
IPersistedBlock Block { get; }

Dictionary<string, double> Shares { get; }

Expand Down
Loading

0 comments on commit 2671f95

Please sign in to comment.