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