Commit a8839265 authored by Sergei Zubov's avatar Sergei Zubov

Merge consensus rule context and base

parent f4f13dc1
...@@ -38,7 +38,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Tests.Rules.CommonRules ...@@ -38,7 +38,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Tests.Rules.CommonRules
// Register POS consensus rules. // Register POS consensus rules.
new DeStreamFullNodeBuilderConsensusExtension.PosConsensusRulesRegistration().RegisterRules(this.network.Consensus); new DeStreamFullNodeBuilderConsensusExtension.PosConsensusRulesRegistration().RegisterRules(this.network.Consensus);
ConsensusRuleEngine consensusRuleEngine = new PosConsensusRuleEngine(this.network, this.loggerFactory.Object, DateTimeProvider.Default, ConsensusRuleEngine consensusRuleEngine = new DeStreamPosConsensusRuleEngine(this.network, this.loggerFactory.Object, DateTimeProvider.Default,
this.concurrentChain, this.nodeDeployments, this.consensusSettings, this.checkpoints.Object, this.coinView.Object, this.stakeChain.Object, this.concurrentChain, this.nodeDeployments, this.consensusSettings, this.checkpoints.Object, this.coinView.Object, this.stakeChain.Object,
this.stakeValidator.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new Mock<INodeStats>().Object, this.rewindDataIndexStore.Object) this.stakeValidator.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new Mock<INodeStats>().Object, this.rewindDataIndexStore.Object)
.Register(); .Register();
......
...@@ -36,7 +36,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -36,7 +36,7 @@ namespace Stratis.Bitcoin.Features.Consensus
services.AddSingleton<DeStreamDBreezeCoinView>(); services.AddSingleton<DeStreamDBreezeCoinView>();
services.AddSingleton<ICoinView, CachedCoinView>(); services.AddSingleton<ICoinView, CachedCoinView>();
services.AddSingleton<ConsensusController>(); services.AddSingleton<ConsensusController>();
services.AddSingleton<IConsensusRuleEngine, PowConsensusRuleEngine>(); services.AddSingleton<IConsensusRuleEngine, DeStreamPowConsensusRuleEngine>();
services.AddSingleton<IChainState, ChainState>(); services.AddSingleton<IChainState, ChainState>();
services.AddSingleton<ConsensusQuery>() services.AddSingleton<ConsensusQuery>()
.AddSingleton<INetworkDifficulty, ConsensusQuery>(provider => provider.GetService<ConsensusQuery>()) .AddSingleton<INetworkDifficulty, ConsensusQuery>(provider => provider.GetService<ConsensusQuery>())
...@@ -64,7 +64,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -64,7 +64,7 @@ namespace Stratis.Bitcoin.Features.Consensus
services.AddSingleton<IStakeValidator, StakeValidator>(); services.AddSingleton<IStakeValidator, StakeValidator>();
services.AddSingleton<ConsensusController>(); services.AddSingleton<ConsensusController>();
services.AddSingleton<IRewindDataIndexCache, RewindDataIndexCache>(); services.AddSingleton<IRewindDataIndexCache, RewindDataIndexCache>();
services.AddSingleton<IConsensusRuleEngine, PosConsensusRuleEngine>(); services.AddSingleton<IConsensusRuleEngine, DeStreamPosConsensusRuleEngine>();
services.AddSingleton<IChainState, ChainState>(); services.AddSingleton<IChainState, ChainState>();
services.AddSingleton<ConsensusQuery>() services.AddSingleton<ConsensusQuery>()
.AddSingleton<INetworkDifficulty, ConsensusQuery>(provider => provider.GetService<ConsensusQuery>()) .AddSingleton<INetworkDifficulty, ConsensusQuery>(provider => provider.GetService<ConsensusQuery>())
......
using System.Collections.Generic; using System;
using System.Collections.Generic;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Consensus;
...@@ -7,25 +8,30 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -7,25 +8,30 @@ namespace Stratis.Bitcoin.Features.Consensus
public interface IDeStreamRuleContext public interface IDeStreamRuleContext
{ {
/// <summary> /// <summary>
/// ScriptPubKeys of inputs spent in transaction /// Gets or sets scriptPubKeys of inputs spent in transaction
/// </summary> /// </summary>
IDictionary<uint256, List<Script>> InputScriptPubKeys { get; set; } IDictionary<uint256, List<Script>> InputScriptPubKeys { get; set; }
/// <summary> /// <summary>
/// Sum of inputs spent in transaction /// Gets or sets sum of inputs spent in transaction
/// </summary> /// </summary>
IDictionary<uint256, Money> TotalIn { get; set; } IDictionary<uint256, Money> TotalIn { get; set; }
} }
/// <inheritdoc cref="PosRuleContext" /> /// <inheritdoc cref="PosRuleContext" />
public class DeStreamRuleContext : PosRuleContext, IDeStreamRuleContext public class DeStreamPosRuleContext : PosRuleContext, IDeStreamRuleContext
{ {
internal DeStreamRuleContext() internal DeStreamPosRuleContext()
{ {
} }
public DeStreamRuleContext(ValidationContext validationContext, NBitcoin.Consensus consensus, public DeStreamPosRuleContext(BlockStake blockStake)
ChainedHeader consensusTip) : base(validationContext, consensus, consensusTip) : base(blockStake)
{
}
public DeStreamPosRuleContext(ValidationContext validationContext, DateTimeOffset time)
: base(validationContext,time)
{ {
} }
...@@ -44,8 +50,8 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -44,8 +50,8 @@ namespace Stratis.Bitcoin.Features.Consensus
{ {
} }
public DeStreamPowRuleContext(ValidationContext validationContext, NBitcoin.Consensus consensus, public DeStreamPowRuleContext(ValidationContext validationContext, DateTimeOffset time)
ChainedHeader consensusTip) : base(validationContext, consensus, consensusTip) : base(validationContext, time)
{ {
} }
......
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin.Base;
using Stratis.Bitcoin.Base.Deployments; using Stratis.Bitcoin.Base.Deployments;
using Stratis.Bitcoin.BlockPulling;
using Stratis.Bitcoin.Configuration.Settings; using Stratis.Bitcoin.Configuration.Settings;
using Stratis.Bitcoin.Consensus; using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Consensus.Rules; using Stratis.Bitcoin.Consensus.Rules;
using Stratis.Bitcoin.Features.Consensus.CoinViews; using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Features.Consensus.Interfaces; using Stratis.Bitcoin.Features.Consensus.Interfaces;
using Stratis.Bitcoin.Features.Consensus.ProvenBlockHeaders;
using Stratis.Bitcoin.Utilities; using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.Consensus.Rules namespace Stratis.Bitcoin.Features.Consensus.Rules
{ {
public class DeStreamPowConsensusRules : PowConsensusRules public class DeStreamPowConsensusRuleEngine : PowConsensusRuleEngine
{ {
public DeStreamPowConsensusRules(Network network, ILoggerFactory loggerFactory, public DeStreamPowConsensusRuleEngine(Network network, ILoggerFactory loggerFactory,
IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments,
ConsensusSettings consensusSettings, ICheckpoints checkpoints, CoinView utxoSet, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
ILookaheadBlockPuller puller) : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats) : base(network, loggerFactory,
consensusSettings, checkpoints, utxoSet, puller) dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState,
invalidBlockHashStore, nodeStats)
{ {
} }
public override RuleContext CreateRuleContext(ValidationContext validationContext, ChainedHeader consensusTip) public override RuleContext CreateRuleContext(ValidationContext validationContext)
{ {
return new DeStreamPowRuleContext(validationContext, this.Network.Consensus, consensusTip); return new DeStreamPowRuleContext(validationContext, DateTimeProvider.GetTimeOffset());
} }
} }
public class DeStreamPosConsensusRules : PosConsensusRules public class DeStreamPosConsensusRuleEngine : PosConsensusRuleEngine
{ {
public DeStreamPosConsensusRules(Network network, ILoggerFactory loggerFactory, public DeStreamPosConsensusRuleEngine(Network network, ILoggerFactory loggerFactory,
IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments,
ConsensusSettings consensusSettings, ICheckpoints checkpoints, CoinView utxoSet, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IStakeChain stakeChain,
ILookaheadBlockPuller puller, IStakeChain stakeChain, IStakeValidator stakeValidator) : base(network, IStakeValidator stakeValidator, IChainState chainState, IInvalidBlockHashStore invalidBlockHashStore,
loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, puller, INodeStats nodeStats, IRewindDataIndexCache rewindDataIndexCache) : base(network, loggerFactory,
stakeChain, stakeValidator) dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, stakeChain,
stakeValidator, chainState, invalidBlockHashStore, nodeStats, rewindDataIndexCache)
{ {
} }
public override RuleContext CreateRuleContext(ValidationContext validationContext, ChainedHeader consensusTip) public override RuleContext CreateRuleContext(ValidationContext validationContext)
{ {
return new DeStreamRuleContext(validationContext, this.Network.Consensus, consensusTip); return new DeStreamPosRuleContext(validationContext, DateTimeProvider.GetTimeOffset());
} }
} }
} }
\ 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