From 0e35f5245a912d6acc7d342921e46e8e44b78904 Mon Sep 17 00:00:00 2001 From: dangershony Date: Sun, 24 May 2020 02:19:58 +0100 Subject: [PATCH] move protocol out of the consensus calss and in to the consensus factory --- src/Blockcore/BlockPulling/BlockPuller.cs | 2 +- src/Blockcore/Configuration/NodeSettings.cs | 2 +- src/Blockcore/Connection/ConnectionManager.cs | 2 +- src/Blockcore/Controllers/NodeController.cs | 2 +- src/Blockcore/P2P/PeerConnector.cs | 2 +- src/External/NBitcoin/Consensus.cs | 9 --------- src/External/NBitcoin/ConsensusFactory.cs | 2 +- src/External/NBitcoin/IConsensus.cs | 5 ----- src/Features/Blockcore.Features.PoA/PoANetwork.cs | 7 +++---- .../Controllers/FullNodeController.cs | 4 ++-- .../Bitcoin/Blockcore.Networks.Bitcoin/BitcoinMain.cs | 3 +-- .../Bitcoin/Blockcore.Networks.Bitcoin/BitcoinRegTest.cs | 7 ++++++- .../Bitcoin/Blockcore.Networks.Bitcoin/BitcoinTest.cs | 7 ++++++- src/Networks/City/City/Networks/CityMain.cs | 5 ++--- src/Networks/City/City/Networks/CityRegTest.cs | 8 +++++++- src/Networks/City/City/Networks/CityTest.cs | 8 +++++++- .../Stratis/Blockcore.Networks.Stratis/StratisMain.cs | 5 ++--- .../Stratis/Blockcore.Networks.Stratis/StratisRegTest.cs | 7 ++++++- .../Stratis/Blockcore.Networks.Stratis/StratisTest.cs | 7 ++++++- src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs | 7 +++---- src/Networks/x42/x42/Networks/Consensus/x42Consensus.cs | 5 ----- src/Networks/x42/x42/Networks/x42Main.cs | 5 ++--- src/Networks/x42/x42/Networks/x42RegTest.cs | 8 +++++++- src/Networks/x42/x42/Networks/x42Test.cs | 8 +++++++- .../Controller/FullNodeControllerTest.cs | 2 +- src/Tests/Blockcore.IntegrationTests/API/ApiSteps.cs | 2 +- .../Blockcore.IntegrationTests/RPC/GetInfoActionTests.cs | 2 +- 27 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/Blockcore/BlockPulling/BlockPuller.cs b/src/Blockcore/BlockPulling/BlockPuller.cs index 6881be18f..4ed33e1ab 100644 --- a/src/Blockcore/BlockPulling/BlockPuller.cs +++ b/src/Blockcore/BlockPulling/BlockPuller.cs @@ -225,7 +225,7 @@ public BlockPuller(IChainState chainState, NodeSettings nodeSettings, IDateTimeP this.networkPeerRequirement = new NetworkPeerRequirement { - MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion, + MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, RequiredServices = NetworkPeerServices.Network }; diff --git a/src/Blockcore/Configuration/NodeSettings.cs b/src/Blockcore/Configuration/NodeSettings.cs index bb8af8bb6..93a06dc95 100644 --- a/src/Blockcore/Configuration/NodeSettings.cs +++ b/src/Blockcore/Configuration/NodeSettings.cs @@ -135,7 +135,7 @@ public NodeSettings(Network network = null, string agent = "Blockcore", // Log arguments. this.Logger.LogDebug("Arguments: network='{0}', protocolVersion='{1}', agent='{2}', args='{3}'.", this.Network == null ? "(None)" : this.Network.Name, - this.Network?.Consensus.ConsensusProtocol.ProtocolVersion, + this.Network?.Consensus.ConsensusFactory.Protocol.ProtocolVersion, this.Agent, args == null ? "(None)" : string.Join(" ", args)); diff --git a/src/Blockcore/Connection/ConnectionManager.cs b/src/Blockcore/Connection/ConnectionManager.cs index 8b6e85031..4ced7ab4c 100644 --- a/src/Blockcore/Connection/ConnectionManager.cs +++ b/src/Blockcore/Connection/ConnectionManager.cs @@ -134,7 +134,7 @@ public ConnectionManager(IDateTimeProvider dateTimeProvider, this.Parameters.UserAgent = $"{this.ConnectionSettings.Agent}:{versionProvider.GetVersion()}"; - this.Parameters.Version = this.NodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion; + this.Parameters.Version = this.NodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion; nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name, 1100); } diff --git a/src/Blockcore/Controllers/NodeController.cs b/src/Blockcore/Controllers/NodeController.cs index 7499825dc..2da71aaab 100644 --- a/src/Blockcore/Controllers/NodeController.cs +++ b/src/Blockcore/Controllers/NodeController.cs @@ -141,7 +141,7 @@ public IActionResult Status() var model = new StatusModel { Version = this.fullNode.Version?.ToString() ?? "0", - ProtocolVersion = (uint)(this.nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion), + ProtocolVersion = (uint)(this.nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion), Difficulty = GetNetworkDifficulty(this.networkDifficulty)?.Difficulty ?? 0, Agent = this.connectionManager.ConnectionSettings.Agent, ExternalAddress = this.selfEndpointTracker.MyExternalAddress.Address.ToString(), diff --git a/src/Blockcore/P2P/PeerConnector.cs b/src/Blockcore/P2P/PeerConnector.cs index 849b87dc5..0710b1dab 100644 --- a/src/Blockcore/P2P/PeerConnector.cs +++ b/src/Blockcore/P2P/PeerConnector.cs @@ -125,7 +125,7 @@ protected PeerConnector( this.PeerAddressManager = peerAddressManager; this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory, this.asyncProvider, this.OnPeerDisposed); this.selfEndpointTracker = selfEndpointTracker; - this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion }; + this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion }; this.connectionInterval = this.CalculateConnectionInterval(); } diff --git a/src/External/NBitcoin/Consensus.cs b/src/External/NBitcoin/Consensus.cs index b0d9aa41e..547aa91d7 100644 --- a/src/External/NBitcoin/Consensus.cs +++ b/src/External/NBitcoin/Consensus.cs @@ -98,12 +98,8 @@ public class Consensus : IConsensus /// public List MempoolRules { get; set; } - /// - public ConsensusProtocol ConsensusProtocol { get; } - public Consensus( ConsensusFactory consensusFactory, - ConsensusProtocol consensusProtocol, ConsensusOptions consensusOptions, int coinType, uint256 hashGenesisBlock, @@ -170,11 +166,6 @@ public Consensus( this.ConsensusRules = new ConsensusRules(); this.MempoolRules = new List(); this.ProofOfStakeTimestampMask = proofOfStakeTimestampMask; - this.ConsensusProtocol = consensusProtocol; - - // this is a small hack to allow acess to protocol verison - // form serialization code. - this.ConsensusFactory.Protocol = this.ConsensusProtocol; } } } \ No newline at end of file diff --git a/src/External/NBitcoin/ConsensusFactory.cs b/src/External/NBitcoin/ConsensusFactory.cs index 9c61889d7..6d5bfc354 100644 --- a/src/External/NBitcoin/ConsensusFactory.cs +++ b/src/External/NBitcoin/ConsensusFactory.cs @@ -131,7 +131,7 @@ public virtual Transaction CreateTransaction(byte[] bytes) public class ConsensusProtocol { - public uint ProtocolVersion { get; set; } = Protocol.ProtocolVersion.WITNESS_VERSION; + public uint ProtocolVersion { get; set; } = Protocol.ProtocolVersion.FEEFILTER_VERSION; public uint MinProtocolVersion { get; set; } = Protocol.ProtocolVersion.SENDHEADERS_VERSION; } diff --git a/src/External/NBitcoin/IConsensus.cs b/src/External/NBitcoin/IConsensus.cs index ceb05de81..718cfed19 100644 --- a/src/External/NBitcoin/IConsensus.cs +++ b/src/External/NBitcoin/IConsensus.cs @@ -145,10 +145,5 @@ public interface IConsensus /// Group of mempool validation rules used by the given network. List MempoolRules { get; set; } - - /// - /// Information about the consensus protocol. - /// - ConsensusProtocol ConsensusProtocol { get; } } } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.PoA/PoANetwork.cs b/src/Features/Blockcore.Features.PoA/PoANetwork.cs index c086e8b09..f3bdc04e5 100644 --- a/src/Features/Blockcore.Features.PoA/PoANetwork.cs +++ b/src/Features/Blockcore.Features.PoA/PoANetwork.cs @@ -105,15 +105,14 @@ public PoANetwork() var bip9Deployments = new NoBIP9Deployments(); - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { - ProtocolVersion = (uint)ProtocolVersion.PROVEN_HEADER_VERSION, - MinProtocolVersion = (uint)ProtocolVersion.POS_PROTOCOL_VERSION, + ProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, }; this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: consensusOptions, coinType: 105, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Features/Blockcore.Features.RPC/Controllers/FullNodeController.cs b/src/Features/Blockcore.Features.RPC/Controllers/FullNodeController.cs index 8670adb25..d238b8d36 100644 --- a/src/Features/Blockcore.Features.RPC/Controllers/FullNodeController.cs +++ b/src/Features/Blockcore.Features.RPC/Controllers/FullNodeController.cs @@ -259,7 +259,7 @@ public GetInfoModel GetInfo() var model = new GetInfoModel { Version = this.FullNode?.Version?.ToUint() ?? 0, - ProtocolVersion = this.Network.Consensus.ConsensusProtocol.ProtocolVersion, + ProtocolVersion = this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, Blocks = this.ChainState?.ConsensusTip?.Height ?? 0, TimeOffset = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0, Connections = this.ConnectionManager?.ConnectedPeers?.Count(), @@ -429,7 +429,7 @@ public NetworkInfoModel GetNetworkInfo() { Version = this.FullNode?.Version?.ToUint() ?? 0, SubVersion = this.Settings?.Agent, - ProtocolVersion = this.Network.Consensus.ConsensusProtocol.ProtocolVersion, + ProtocolVersion = this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, IsLocalRelay = this.ConnectionManager?.Parameters?.IsRelay ?? false, TimeOffset = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0, Connections = this.ConnectionManager?.ConnectedPeers?.Count(), diff --git a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinMain.cs b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinMain.cs index ccd93a657..b020db6b6 100644 --- a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinMain.cs +++ b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinMain.cs @@ -67,7 +67,7 @@ public BitcoinMain() [BitcoinBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, 1479168000, 1510704000, BIP9DeploymentsParameters.DefaultMainnetThreshold) }; - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, MinProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION, @@ -75,7 +75,6 @@ public BitcoinMain() this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: new ConsensusOptions(), // Default - set to Bitcoin params. coinType: 0, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinRegTest.cs b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinRegTest.cs index 4d6015d2e..c52886d2e 100644 --- a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinRegTest.cs +++ b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinRegTest.cs @@ -50,9 +50,14 @@ public BitcoinRegTest() [BitcoinBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.AlwaysActive) }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION, + }; + this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: new ConsensusOptions(), // Default - set to Bitcoin params. coinType: 0, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinTest.cs b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinTest.cs index c71bede63..d62b067e3 100644 --- a/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinTest.cs +++ b/src/Networks/Bitcoin/Blockcore.Networks.Bitcoin/BitcoinTest.cs @@ -51,9 +51,14 @@ public BitcoinTest() [BitcoinBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, 1462060800, 1493596800, BIP9DeploymentsParameters.DefaultTestnetThreshold) }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION, + }; + this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: new ConsensusOptions(), // Default - set to Bitcoin params. coinType: 1, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/City/City/Networks/CityMain.cs b/src/Networks/City/City/Networks/CityMain.cs index 8181c7c99..7db9ed445 100644 --- a/src/Networks/City/City/Networks/CityMain.cs +++ b/src/Networks/City/City/Networks/CityMain.cs @@ -82,15 +82,14 @@ public CityMain() [BuriedDeployments.BIP66] = 0 }; - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { - ProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION, + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, }; Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/City/City/Networks/CityRegTest.cs b/src/Networks/City/City/Networks/CityRegTest.cs index 0c8d1de17..464a731fe 100644 --- a/src/Networks/City/City/Networks/CityRegTest.cs +++ b/src/Networks/City/City/Networks/CityRegTest.cs @@ -7,6 +7,7 @@ using NBitcoin; using NBitcoin.BouncyCastle.Math; using NBitcoin.DataEncoders; +using NBitcoin.Protocol; namespace City.Networks { @@ -64,9 +65,14 @@ public CityRegTest() [BuriedDeployments.BIP66] = 0 }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/City/City/Networks/CityTest.cs b/src/Networks/City/City/Networks/CityTest.cs index 4cc9f2829..c839c2cd8 100644 --- a/src/Networks/City/City/Networks/CityTest.cs +++ b/src/Networks/City/City/Networks/CityTest.cs @@ -7,6 +7,7 @@ using NBitcoin; using NBitcoin.BouncyCastle.Math; using NBitcoin.DataEncoders; +using NBitcoin.Protocol; namespace City.Networks { @@ -64,9 +65,14 @@ public CityTest() [BuriedDeployments.BIP66] = 0 }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisMain.cs b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisMain.cs index 7ed7925cd..a84d72d10 100644 --- a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisMain.cs +++ b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisMain.cs @@ -112,15 +112,14 @@ public StratisMain() BIP9DeploymentsParameters.DefaultMainnetThreshold) }; - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { - ProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION, + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, }; this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: consensusOptions, coinType: 105, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisRegTest.cs b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisRegTest.cs index df27f13f0..551c8d85e 100644 --- a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisRegTest.cs +++ b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisRegTest.cs @@ -76,9 +76,14 @@ public StratisRegTest() [StratisBIP9Deployments.ColdStaking] = new BIP9DeploymentsParameters("ColdStaking", 2, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.AlwaysActive), }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: 105, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisTest.cs b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisTest.cs index d7cf3c2c0..b060a11b5 100644 --- a/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisTest.cs +++ b/src/Networks/Stratis/Blockcore.Networks.Stratis/StratisTest.cs @@ -94,9 +94,14 @@ public StratisTest() BIP9DeploymentsParameters.DefaultTestnetThreshold) }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: 105, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs b/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs index f28401e52..7962df267 100644 --- a/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs +++ b/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs @@ -79,15 +79,14 @@ public XdsMain() [XdsBIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, BIP9DeploymentsParameters.AlwaysActive, 999999999, BIP9DeploymentsParameters.AlwaysActive) }; - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { - ProtocolVersion = (uint)ProtocolVersion.PROVEN_HEADER_VERSION, - MinProtocolVersion = (uint)ProtocolVersion.POS_PROTOCOL_VERSION, + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, }; this.Consensus = new NBitcoin.Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: consensusOptions, coinType: (int)this.GenesisNonce, hashGenesisBlock: this.Genesis.GetHash(), diff --git a/src/Networks/x42/x42/Networks/Consensus/x42Consensus.cs b/src/Networks/x42/x42/Networks/Consensus/x42Consensus.cs index d1e132298..969a6164a 100644 --- a/src/Networks/x42/x42/Networks/Consensus/x42Consensus.cs +++ b/src/Networks/x42/x42/Networks/Consensus/x42Consensus.cs @@ -154,12 +154,8 @@ public class x42Consensus : IConsensus /// public Money LastProofOfStakeRewardHeight { get; } - /// - public ConsensusProtocol ConsensusProtocol { get; } - public x42Consensus( ConsensusFactory consensusFactory, - ConsensusProtocol consensusProtocol, ConsensusOptions consensusOptions, int coinType, uint256 hashGenesisBlock, @@ -233,7 +229,6 @@ uint proofOfStakeTimestampMask this.MempoolRules = new List(); this.PosEmptyCoinbase = posEmptyCoinbase; this.ProofOfStakeTimestampMask = proofOfStakeTimestampMask; - this.ConsensusProtocol = consensusProtocol; } } } \ No newline at end of file diff --git a/src/Networks/x42/x42/Networks/x42Main.cs b/src/Networks/x42/x42/Networks/x42Main.cs index f2ae72aef..42d8ec133 100644 --- a/src/Networks/x42/x42/Networks/x42Main.cs +++ b/src/Networks/x42/x42/Networks/x42Main.cs @@ -88,15 +88,14 @@ public x42Main() [x42BIP9Deployments.Segwit] = new BIP9DeploymentsParameters("Segwit", 1, new DateTime(2020, 3, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(2021, 3, 1, 0, 0, 0, DateTimeKind.Utc), BIP9DeploymentsParameters.DefaultMainnetThreshold) }; - ConsensusProtocol consensusProtocol = new ConsensusProtocol() + consensusFactory.Protocol = new ConsensusProtocol() { - ProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION, + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, }; this.Consensus = new x42Consensus( consensusFactory: consensusFactory, - consensusProtocol: consensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/x42/x42/Networks/x42RegTest.cs b/src/Networks/x42/x42/Networks/x42RegTest.cs index e2d51a3f2..350425995 100644 --- a/src/Networks/x42/x42/Networks/x42RegTest.cs +++ b/src/Networks/x42/x42/Networks/x42RegTest.cs @@ -7,6 +7,7 @@ using NBitcoin; using NBitcoin.BouncyCastle.Math; using NBitcoin.DataEncoders; +using NBitcoin.Protocol; namespace x42.Networks { @@ -64,9 +65,14 @@ public x42RegTest() [BuriedDeployments.BIP66] = 0 }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + this.Consensus = new x42Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Networks/x42/x42/Networks/x42Test.cs b/src/Networks/x42/x42/Networks/x42Test.cs index ff30c4949..edd0b5bd1 100644 --- a/src/Networks/x42/x42/Networks/x42Test.cs +++ b/src/Networks/x42/x42/Networks/x42Test.cs @@ -7,6 +7,7 @@ using NBitcoin; using NBitcoin.BouncyCastle.Math; using NBitcoin.DataEncoders; +using NBitcoin.Protocol; namespace x42.Networks { @@ -72,9 +73,14 @@ public x42Test() [BuriedDeployments.BIP66] = 0 }; + consensusFactory.Protocol = new ConsensusProtocol() + { + ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION, + MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION, + }; + this.Consensus = new x42Consensus( consensusFactory: consensusFactory, - consensusProtocol: this.Consensus.ConsensusProtocol, consensusOptions: consensusOptions, coinType: setup.CoinType, hashGenesisBlock: genesisBlock.GetHash(), diff --git a/src/Tests/Blockcore.Features.RPC.Tests/Controller/FullNodeControllerTest.cs b/src/Tests/Blockcore.Features.RPC.Tests/Controller/FullNodeControllerTest.cs index 0ddbe15a8..d7d53ce2f 100644 --- a/src/Tests/Blockcore.Features.RPC.Tests/Controller/FullNodeControllerTest.cs +++ b/src/Tests/Blockcore.Features.RPC.Tests/Controller/FullNodeControllerTest.cs @@ -493,7 +493,7 @@ public void GetInfo_NoSettings_ReturnsModel() this.fullNode.Object, this.nodeSettings, this.network, this.chain, this.chainState.Object, this.connectionManager.Object); GetInfoModel model = this.controller.GetInfo(); - Assert.Equal(this.Network.Consensus.ConsensusProtocol.ProtocolVersion, model.ProtocolVersion); + Assert.Equal(this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, model.ProtocolVersion); Assert.Equal(0, model.RelayFee); } diff --git a/src/Tests/Blockcore.IntegrationTests/API/ApiSteps.cs b/src/Tests/Blockcore.IntegrationTests/API/ApiSteps.cs index 3e9b98a6e..e1c47cd58 100644 --- a/src/Tests/Blockcore.IntegrationTests/API/ApiSteps.cs +++ b/src/Tests/Blockcore.IntegrationTests/API/ApiSteps.cs @@ -482,7 +482,7 @@ private void status_information_is_returned() statusResponse.Network.Should().Be(statusNode.Network.Name); statusResponse.ConsensusHeight.Should().Be(0); statusResponse.BlockStoreHeight.Should().Be(0); - statusResponse.ProtocolVersion.Should().Be((uint)(statusNode.Settings.Network.Consensus.ConsensusProtocol.ProtocolVersion)); + statusResponse.ProtocolVersion.Should().Be((uint)(statusNode.Settings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion)); statusResponse.RelayFee.Should().Be(statusNode.Settings.MinRelayTxFeeRate.FeePerK.ToUnit(MoneyUnit.BTC)); statusResponse.DataDirectoryPath.Should().Be(statusNode.Settings.DataDir); diff --git a/src/Tests/Blockcore.IntegrationTests/RPC/GetInfoActionTests.cs b/src/Tests/Blockcore.IntegrationTests/RPC/GetInfoActionTests.cs index 1addd05ce..1262eb96b 100644 --- a/src/Tests/Blockcore.IntegrationTests/RPC/GetInfoActionTests.cs +++ b/src/Tests/Blockcore.IntegrationTests/RPC/GetInfoActionTests.cs @@ -22,7 +22,7 @@ public void CallWithDependencies() GetInfoModel info = controller.GetInfo(); NodeSettings nodeSettings = NodeSettings.Default(fullNode.Network); - uint expectedProtocolVersion = fullNode.Network.Consensus.ConsensusProtocol.ProtocolVersion; + uint expectedProtocolVersion = fullNode.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion; decimal expectedRelayFee = nodeSettings.MinRelayTxFeeRate.FeePerK.ToUnit(NBitcoin.MoneyUnit.BTC); Assert.NotNull(info); Assert.Equal(0, info.Blocks);