Skip to content

Commit

Permalink
Merge pull request #372 from CoiniumServ/develop
Browse files Browse the repository at this point in the history
sync 0.1.2-alpha to master
  • Loading branch information
Hüseyin Uslu committed Aug 14, 2014
2 parents ce84ab9 + f347c28 commit bdf3d28
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 30 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
##### [v0.1.2 alpha - Piri Reis](https://github.com/CoiniumServ/CoiniumServ/releases/tag/v0.1.2-alpha) - 14.08.2014

**Payments**
* Fixed a major bug in payment processor which was preventing payments to miners.
* Fixed a bug in statistics manager.

##### [v0.1.1 alpha - Piri Reis](https://github.com/CoiniumServ/CoiniumServ/releases/tag/v0.1.1-alpha) - 10.08.2014
**Mining**
* Improved SocketServiceContext and removed unnecessary overhead.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ You can send tips and furher support the project or get tips for contributing by

### Status

Expect a functioning alpha soon.
[v0.1.2 alpha](https://github.com/CoiniumServ/CoiniumServ/releases/tag/v0.1.2-alpha) released

### Features

Expand Down
17 changes: 7 additions & 10 deletions src/CoiniumServ/Blocks/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,22 @@ public Block GetBlock(string blockHash)
}
}

public TransactionDetail GetPoolOutput(Block block)
public Transaction GetGenerationTransaction(Block block)
{
try
{
var genTx = _daemonClient.GetTransaction(block.Tx.First()); // query the transaction

if (genTx == null) // make sure the generation transaction exists
return null;

// check if coin includes output address data in transaction details.
return genTx.Details.Any(x => x.Address == null)
? genTx.Details.FirstOrDefault(x => x.Account == _poolAccount) // some coins doesn't include address field in outputs, so try to determine using the associated account name.
: genTx.Details.FirstOrDefault(x => x.Address == _poolConfig.Wallet.Adress); // if coin includes address field in outputs, just use it.
return _daemonClient.GetTransaction(block.Tx.First()); // query the transaction
}
catch (RpcException e)
{
_logger.Error("Queried transaction does not exist {0:l} - {1:l}", block.Tx.First(), e.Message);
return null;
}
}

public TransactionDetail GetPoolOutput(Transaction transaction)
{
return transaction.GetPoolOutput(_poolConfig.Wallet.Adress, _poolAccount);
}
}
}
4 changes: 3 additions & 1 deletion src/CoiniumServ/Blocks/IBlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface IBlockProcessor
{
Block GetBlock(string blockHash);

TransactionDetail GetPoolOutput(Block block);
Transaction GetGenerationTransaction(Block block);

TransactionDetail GetPoolOutput(Transaction transaction);
}
}
26 changes: 24 additions & 2 deletions src/CoiniumServ/Daemon/Responses/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
#endregion

using System.Collections.Generic;
using System.Linq;

namespace CoiniumServ.Daemon.Responses
{
public class Transaction
{
public double Amount { get; set; }
public double Amount { get; set; } // seems it's set to 0 for immature transactions or generation transactions.

/// <summary>
/// As Amount may not always return the total transaction amount, TotalAmount calculates and return the value using transaction details
/// </summary>
public double TotalAmount { get { return Details.Sum(item => item.Amount); } }

public int Confirmations { get; set; }

public bool Generated { get; set; }
Expand All @@ -46,7 +53,22 @@ public class Transaction
public int TimeReceived { get; set; }

public List<TransactionDetail> Details { get; set; }



/// <summary>
/// Returns the transaction detail that contains the output for pool.
/// </summary>
/// <param name="poolAddress"></param>
/// <param name="poolAccount"></param>
/// <returns></returns>
public TransactionDetail GetPoolOutput(string poolAddress, string poolAccount)
{
// check if coin includes output address data in transaction details.
return Details.Any(x => x.Address == null)
? Details.FirstOrDefault(x => x.Account == poolAccount) // some coins doesn't include address field in outputs, so try to determine using the associated account name.
: Details.FirstOrDefault(x => x.Address == poolAddress); // if coin includes address field in outputs, just use it.
}

// not sure if fields below even exists / used
//public double Fee { get; set; }
//public string Comment { get; set; }
Expand Down
10 changes: 9 additions & 1 deletion src/CoiniumServ/Payments/PaymentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ private IList<IWorkerBalance> CalculateRewards(IEnumerable<IPaymentRound> rounds
// set previous balances
foreach(var pair in previousBalances)
{
if (pair.Value == 0) // skip zero balances
continue;

if (!workerBalances.ContainsKey(pair.Key))
workerBalances.Add(pair.Key, new WorkerBalance(pair.Key, _magnitude));

Expand Down Expand Up @@ -284,8 +287,10 @@ private void QueryBlock(ref IPersistedBlock block)
return;
}

var genTx = _blockProcessor.GetGenerationTransaction(blockInfo); // get the generation transaction.

// get the output transaction that targets pools central wallet.
var poolOutput = _blockProcessor.GetPoolOutput(blockInfo);
var poolOutput = _blockProcessor.GetPoolOutput(genTx);

// make sure we have a valid reference to poolOutput
if (poolOutput == null)
Expand All @@ -294,6 +299,8 @@ private void QueryBlock(ref IPersistedBlock block)
return;
}

block.SetReward((decimal)poolOutput.Amount); // set the reward of the block to miners.

switch (poolOutput.Category)
{
case "immature":
Expand All @@ -307,6 +314,7 @@ private void QueryBlock(ref IPersistedBlock block)
break;
}


// TODO: add back these.
// total amount of coins contained in the block.
// candidate.Amount = transaction.Details.Sum(output => (decimal)output.Amount);
Expand Down
5 changes: 3 additions & 2 deletions src/CoiniumServ/Persistance/Blocks/IPersistedBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public interface IPersistedBlock
BlockStatus Status { get; set; }
string BlockHash { get; }
string TransactionHash { get; }
decimal Reward { get; }
decimal Amount { get; }

decimal Reward { get; }
bool IsPending { get; }

void SetReward(decimal reward);
}
}
10 changes: 7 additions & 3 deletions src/CoiniumServ/Persistance/Blocks/PersistedBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ public class PersistedBlock:IPersistedBlock

public string TransactionHash { get; private set; }

public decimal Reward { get; private set; }

public decimal Amount { get; private set; }

public decimal Reward { get; private set; }

public bool IsPending { get { return Status != BlockStatus.Orphaned && Status != BlockStatus.Confirmed; } }

public PersistedBlock(BlockStatus status, uint height, string blockHash, string transactionHash, decimal amount, decimal reward)
public PersistedBlock(BlockStatus status, uint height, string blockHash, string transactionHash, decimal amount)
{
Status = status;
Height = height;
BlockHash = blockHash;
TransactionHash = transactionHash;
Amount = amount;
}

public void SetReward(decimal reward)
{
Reward = reward;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/CoiniumServ/Persistance/Redis/Redis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public void AddBlock(IShare share)

// add block to pending.
var pendingKey = string.Format("{0}:blocks:pending", _coin);
var entry = string.Format("{0}:{1}", share.BlockHash.ToHexString(), share.Block.Tx.First());
// entry format: blockHash:txHash:Amount
var entry = string.Format("{0}:{1}:{2}", share.BlockHash.ToHexString(), share.Block.Tx.First(), share.GenerationTransaction.TotalAmount);
_client.ZAdd(pendingKey, Tuple.Create(share.Block.Height, entry));
}

Expand Down Expand Up @@ -364,8 +365,9 @@ public IEnumerable<IPersistedBlock> GetBlocks(BlockStatus status)
var data = item.Split(':');
var blockHash = data[0];
var transactionHash = data[1];
var amount = decimal.Parse(data[2]);

blocks.Add((UInt32) score, new PersistedBlock(status, (UInt32) score, blockHash, transactionHash, 0, 0));
blocks.Add((UInt32)score, new PersistedBlock(status, (UInt32)score, blockHash, transactionHash, amount));
}
}
catch (Exception e)
Expand Down
4 changes: 3 additions & 1 deletion src/CoiniumServ/Shares/IShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public interface IShare

Block Block { get; }

Transaction GenerationTransaction { get; }

/// <summary>
/// Is the block data accepted by the coin daemon?
/// </summary>
Expand Down Expand Up @@ -89,6 +91,6 @@ public interface IShare

byte[] BlockHash { get; }

void SetFoundBlock(Block block);
void SetFoundBlock(Block block, Transaction genTx);
}
}
4 changes: 3 additions & 1 deletion src/CoiniumServ/Shares/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Share : IShare
public bool IsValid { get { return Error == ShareError.None; } }
public bool IsBlockCandidate { get; private set; }
public Block Block { get; private set; }
public Transaction GenerationTransaction { get; private set; }
public bool IsBlockAccepted { get { return Block != null; } }
public IMiner Miner { get; private set; }
public ShareError Error { get; private set; }
Expand Down Expand Up @@ -163,9 +164,10 @@ public Share(IStratumMiner miner, UInt64 jobId, IJob job, string extraNonce2, st
}
}

public void SetFoundBlock(Block block)
public void SetFoundBlock(Block block, Transaction genTx)
{
Block = block;
GenerationTransaction = genTx;
}
}
}
6 changes: 4 additions & 2 deletions src/CoiniumServ/Shares/ShareManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ private bool SubmitBlock(IShare share)
return false;
}

var poolOutput = _blockProcessor.GetPoolOutput(block); // get the output that targets pool's central address.
var genTx = _blockProcessor.GetGenerationTransaction(block); // get the generation transaction.

var poolOutput = _blockProcessor.GetPoolOutput(genTx); // get the output that targets pool's central address.

// make sure the blocks generation transaction contains our central pool wallet address
if (poolOutput == null)
Expand All @@ -211,7 +213,7 @@ private bool SubmitBlock(IShare share)
}

// if the code flows here, then it means the block was succesfully submitted and belongs to us.
share.SetFoundBlock(block); // assign the block to share.
share.SetFoundBlock(block, genTx); // assign the block to share.

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/CoiniumServ/Statistics/PerPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ private void RecacheWorkers()

foreach (var miner in _minerManager.Miners)
{
if (!miner.Authenticated)
continue;

Workers.Add(miner.Username, shares.ContainsKey(miner.Username) ? shares[miner.Username] : 0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/CoiniumServ/Utils/Versions/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class Assembly
/// <summary>
/// Main assemby version.
/// </summary>
public const string Version = "0.1.1.*";
public const string Version = "0.1.2.*";
}
}
}
6 changes: 3 additions & 3 deletions src/CoiniumServ/web/default/pool.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@
@switch (block.Status)
{
case BlockStatus.Pending:
<span class="label label-warning">@block.Status</span>
<span class="label btn-warning">@block.Status</span>
break;
case BlockStatus.Orphaned:
<span class="label label-danger">@block.Status</span>
<span class="label btn-danger">@block.Status</span>
break;
case BlockStatus.Confirmed:
<span class="label label-primary">@block.Status</span>
<span class="label btn-info">@block.Status</span>
break;
}
</td>
Expand Down

0 comments on commit bdf3d28

Please sign in to comment.