Commit 73ee2662 authored by Sergei Zubov's avatar Sergei Zubov

Merge pos minting

parent eacb32ab
...@@ -4,13 +4,14 @@ using Stratis.Bitcoin.Configuration.Logging; ...@@ -4,13 +4,14 @@ using Stratis.Bitcoin.Configuration.Logging;
using Stratis.Bitcoin.Features.MemoryPool; using Stratis.Bitcoin.Features.MemoryPool;
using Stratis.Bitcoin.Features.Miner.Controllers; using Stratis.Bitcoin.Features.Miner.Controllers;
using Stratis.Bitcoin.Features.Miner.Interfaces; using Stratis.Bitcoin.Features.Miner.Interfaces;
using Stratis.Bitcoin.Features.Miner.Staking;
using Stratis.Bitcoin.Features.RPC; using Stratis.Bitcoin.Features.RPC;
using Stratis.Bitcoin.Features.Wallet; using Stratis.Bitcoin.Features.Wallet;
using Stratis.Bitcoin.Mining; using Stratis.Bitcoin.Mining;
namespace Stratis.Bitcoin.Features.Miner namespace Stratis.Bitcoin.Features.Miner
{ {
public static class DeStreamFullNodeBuilderMinerExtension public static class DeStreamFullNodeBuilderMiningExtension
{ {
public static IFullNodeBuilder AddDeStreamPowMining(this IFullNodeBuilder fullNodeBuilder) public static IFullNodeBuilder AddDeStreamPowMining(this IFullNodeBuilder fullNodeBuilder)
{ {
...@@ -28,8 +29,8 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -28,8 +29,8 @@ namespace Stratis.Bitcoin.Features.Miner
services.AddSingleton<IPowMining, PowMining>(); services.AddSingleton<IPowMining, PowMining>();
services.AddSingleton<IBlockProvider, BlockProvider>(); services.AddSingleton<IBlockProvider, BlockProvider>();
services.AddSingleton<BlockDefinition, DeStreamPowBlockDefinition>(); services.AddSingleton<BlockDefinition, DeStreamPowBlockDefinition>();
services.AddSingleton<MinerController>(); services.AddSingleton<MiningRpcController>();
services.AddSingleton<MiningRPCController>(); services.AddSingleton<MiningController>();
services.AddSingleton<MinerSettings>(); services.AddSingleton<MinerSettings>();
}); });
}); });
...@@ -57,8 +58,8 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -57,8 +58,8 @@ namespace Stratis.Bitcoin.Features.Miner
services.AddSingleton<BlockDefinition, DeStreamPowBlockDefinition>(); services.AddSingleton<BlockDefinition, DeStreamPowBlockDefinition>();
services.AddSingleton<BlockDefinition, DeStreamPosPowBlockDefinition>(); services.AddSingleton<BlockDefinition, DeStreamPosPowBlockDefinition>();
services.AddSingleton<BlockDefinition, PosBlockDefinition>(); services.AddSingleton<BlockDefinition, PosBlockDefinition>();
services.AddSingleton<MinerController>(); services.AddSingleton<MiningRpcController>();
services.AddSingleton<MiningRPCController>(); services.AddSingleton<MiningController>();
services.AddSingleton<MinerSettings>(); services.AddSingleton<MinerSettings>();
}); });
}); });
......
...@@ -98,16 +98,16 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -98,16 +98,16 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
/// <summary>Number of UTXO descriptions that a single worker's task will process.</summary> /// <summary>Number of UTXO descriptions that a single worker's task will process.</summary>
/// <remarks>To achieve a good level of parallelism, this should be low enough so that CPU threads are used, /// <remarks>To achieve a good level of parallelism, this should be low enough so that CPU threads are used,
/// but high enough to compensate for tasks' overhead.</remarks> /// but high enough to compensate for tasks' overhead.</remarks>
private const int UtxoStakeDescriptionsPerCoinstakeWorker = 25; protected const int UtxoStakeDescriptionsPerCoinstakeWorker = 25;
/// <summary>Consumes manager class.</summary> /// <summary>Consumes manager class.</summary>
private readonly IConsensusManager consensusManager; protected readonly IConsensusManager consensusManager;
/// <summary>Thread safe access to the best chain of block headers (that the node is aware of) from genesis.</summary> /// <summary>Thread safe access to the best chain of block headers (that the node is aware of) from genesis.</summary>
private readonly ConcurrentChain chain; private readonly ConcurrentChain chain;
/// <summary>Specification of the network the node runs on - regtest/testnet/mainnet.</summary> /// <summary>Specification of the network the node runs on - regtest/testnet/mainnet.</summary>
private readonly Network network; protected readonly Network network;
/// <summary>Provides date time functionality.</summary> /// <summary>Provides date time functionality.</summary>
private readonly IDateTimeProvider dateTimeProvider; private readonly IDateTimeProvider dateTimeProvider;
...@@ -128,13 +128,13 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -128,13 +128,13 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
private readonly IAsyncLoopFactory asyncLoopFactory; private readonly IAsyncLoopFactory asyncLoopFactory;
/// <summary>A manager providing operations on wallets.</summary> /// <summary>A manager providing operations on wallets.</summary>
private readonly IWalletManager walletManager; protected readonly IWalletManager walletManager;
/// <summary>Factory for creating loggers.</summary> /// <summary>Factory for creating loggers.</summary>
private readonly ILoggerFactory loggerFactory; protected readonly ILoggerFactory loggerFactory;
/// <summary>Instance logger.</summary> /// <summary>Instance logger.</summary>
private readonly ILogger logger; protected readonly ILogger logger;
/// <summary>Loop in which the node attempts to generate new POS blocks by staking coins from its wallet.</summary> /// <summary>Loop in which the node attempts to generate new POS blocks by staking coins from its wallet.</summary>
private IAsyncLoop stakingLoop; private IAsyncLoop stakingLoop;
...@@ -159,7 +159,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -159,7 +159,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
/// Target reserved balance that will not participate in staking. /// Target reserved balance that will not participate in staking.
/// It is possible that less than this amount will be reserved. /// It is possible that less than this amount will be reserved.
/// </summary> /// </summary>
private Money targetReserveBalance; protected Money targetReserveBalance;
/// <summary>Time in milliseconds between attempts to generate PoS blocks.</summary> /// <summary>Time in milliseconds between attempts to generate PoS blocks.</summary>
private readonly int minerSleep; private readonly int minerSleep;
...@@ -179,10 +179,10 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -179,10 +179,10 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
/// <summary>Information about node's staking for RPC "getstakinginfo" command.</summary> /// <summary>Information about node's staking for RPC "getstakinginfo" command.</summary>
/// <remarks>This object does not need a synchronized access because there is no execution logic /// <remarks>This object does not need a synchronized access because there is no execution logic
/// that depends on the reported information.</remarks> /// that depends on the reported information.</remarks>
private Models.GetStakingInfoModel rpcGetStakingInfoModel; protected Models.GetStakingInfoModel rpcGetStakingInfoModel;
/// <summary>Estimation of the total staking weight of all nodes on the network.</summary> /// <summary>Estimation of the total staking weight of all nodes on the network.</summary>
private long networkWeight; protected long networkWeight;
/// <summary> /// <summary>
/// Timestamp of the last attempt to search for POS solution. /// Timestamp of the last attempt to search for POS solution.
...@@ -576,7 +576,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -576,7 +576,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
} }
/// <inheritdoc/> /// <inheritdoc/>
public async Task<bool> CreateCoinstakeAsync(List<UtxoStakeDescription> utxoStakeDescriptions, Block block, ChainedHeader chainTip, long searchInterval, long fees, CoinstakeContext coinstakeContext) public virtual async Task<bool> CreateCoinstakeAsync(List<UtxoStakeDescription> utxoStakeDescriptions, Block block, ChainedHeader chainTip, long searchInterval, long fees, CoinstakeContext coinstakeContext)
{ {
coinstakeContext.CoinstakeTx.Inputs.Clear(); coinstakeContext.CoinstakeTx.Inputs.Clear();
coinstakeContext.CoinstakeTx.Outputs.Clear(); coinstakeContext.CoinstakeTx.Outputs.Clear();
...@@ -700,7 +700,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -700,7 +700,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
return true; return true;
} }
internal Transaction PrepareCoinStakeTransactions(int currentChainHeight, CoinstakeContext coinstakeContext, long coinstakeOutputValue, int utxosCount, long amountStaked) internal virtual Transaction PrepareCoinStakeTransactions(int currentChainHeight, CoinstakeContext coinstakeContext, long coinstakeOutputValue, int utxosCount, long amountStaked)
{ {
// Split stake into SplitFactor utxos if above threshold. // Split stake into SplitFactor utxos if above threshold.
bool shouldSplitStake = this.ShouldSplitStake(utxosCount, amountStaked, coinstakeOutputValue, currentChainHeight); bool shouldSplitStake = this.ShouldSplitStake(utxosCount, amountStaked, coinstakeOutputValue, currentChainHeight);
...@@ -742,7 +742,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -742,7 +742,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
/// <param name="block">Template of the block that we are trying to mine.</param> /// <param name="block">Template of the block that we are trying to mine.</param>
/// <param name="minimalAllowedTime">Minimal valid timestamp for new coinstake transaction.</param> /// <param name="minimalAllowedTime">Minimal valid timestamp for new coinstake transaction.</param>
/// <param name="searchInterval">Length of an unexplored block time space in seconds. It only makes sense to look for a solution within this interval.</param> /// <param name="searchInterval">Length of an unexplored block time space in seconds. It only makes sense to look for a solution within this interval.</param>
private void CoinstakeWorker(CoinstakeWorkerContext context, ChainedHeader chainTip, Block block, long minimalAllowedTime, long searchInterval) protected virtual void CoinstakeWorker(CoinstakeWorkerContext context, ChainedHeader chainTip, Block block, long minimalAllowedTime, long searchInterval)
{ {
context.Logger.LogTrace("Going to process {0} UTXOs.", context.utxoStakeDescriptions.Count); context.Logger.LogTrace("Going to process {0} UTXOs.", context.utxoStakeDescriptions.Count);
...@@ -867,7 +867,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking ...@@ -867,7 +867,7 @@ namespace Stratis.Bitcoin.Features.Miner.Staking
/// <param name="input">Transaction input.</param> /// <param name="input">Transaction input.</param>
/// <param name="transaction">Transaction being built.</param> /// <param name="transaction">Transaction being built.</param>
/// <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns>
private bool SignTransactionInput(UtxoStakeDescription input, Transaction transaction) protected virtual bool SignTransactionInput(UtxoStakeDescription input, Transaction transaction)
{ {
bool res = false; bool res = false;
try try
......
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Description>Stratis Bitcoin Features Miner</Description> <Description>Stratis Bitcoin Features Miner</Description>
<AssemblyTitle>Stratis.Bitcoin.Features.Miner</AssemblyTitle> <AssemblyTitle>Stratis.Bitcoin.Features.Miner</AssemblyTitle>
...@@ -16,21 +15,18 @@ ...@@ -16,21 +15,18 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>3.0.0.0</Version> <Version>3.0.0.0</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<CodeAnalysisRuleSet>..\None.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>..\None.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Stratis.Bitcoin.Features.Miner\**" /> <Compile Remove="Stratis.Bitcoin.Features.Miner\**" />
<EmbeddedResource Remove="Stratis.Bitcoin.Features.Miner\**" /> <EmbeddedResource Remove="Stratis.Bitcoin.Features.Miner\**" />
<None Remove="Stratis.Bitcoin.Features.Miner\**" /> <None Remove="Stratis.Bitcoin.Features.Miner\**" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Tracer.Fody" Version="2.2.0" /> <PackageReference Include="Tracer.Fody" Version="2.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" /> <ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.MemoryPool\Stratis.Bitcoin.Features.MemoryPool.csproj" /> <ProjectReference Include="..\Stratis.Bitcoin.Features.MemoryPool\Stratis.Bitcoin.Features.MemoryPool.csproj" />
...@@ -38,14 +34,12 @@ ...@@ -38,14 +34,12 @@
<ProjectReference Include="..\Stratis.Bitcoin.Features.Wallet\Stratis.Bitcoin.Features.Wallet.csproj" /> <ProjectReference Include="..\Stratis.Bitcoin.Features.Wallet\Stratis.Bitcoin.Features.Wallet.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" /> <ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' "> <PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants> <DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn> <NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile></DocumentationFile> <DocumentationFile>
</DocumentationFile>
</PropertyGroup> </PropertyGroup>
</Project>
</Project> \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment