Skip to content

Commit 2e4816b

Browse files
authored
move protocol out of the consensus calss and in to the consensus factory (#128)
1 parent a7787ce commit 2e4816b

27 files changed

Lines changed: 76 additions & 57 deletions

File tree

src/Blockcore/BlockPulling/BlockPuller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public BlockPuller(IChainState chainState, NodeSettings nodeSettings, IDateTimeP
225225

226226
this.networkPeerRequirement = new NetworkPeerRequirement
227227
{
228-
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion,
228+
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
229229
RequiredServices = NetworkPeerServices.Network
230230
};
231231

src/Blockcore/Configuration/NodeSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public NodeSettings(Network network = null, string agent = "Blockcore",
135135
// Log arguments.
136136
this.Logger.LogDebug("Arguments: network='{0}', protocolVersion='{1}', agent='{2}', args='{3}'.",
137137
this.Network == null ? "(None)" : this.Network.Name,
138-
this.Network?.Consensus.ConsensusProtocol.ProtocolVersion,
138+
this.Network?.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
139139
this.Agent,
140140
args == null ? "(None)" : string.Join(" ", args));
141141

src/Blockcore/Connection/ConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public ConnectionManager(IDateTimeProvider dateTimeProvider,
134134

135135
this.Parameters.UserAgent = $"{this.ConnectionSettings.Agent}:{versionProvider.GetVersion()}";
136136

137-
this.Parameters.Version = this.NodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion;
137+
this.Parameters.Version = this.NodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion;
138138

139139
nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name, 1100);
140140
}

src/Blockcore/Controllers/NodeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public IActionResult Status()
141141
var model = new StatusModel
142142
{
143143
Version = this.fullNode.Version?.ToString() ?? "0",
144-
ProtocolVersion = (uint)(this.nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion),
144+
ProtocolVersion = (uint)(this.nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion),
145145
Difficulty = GetNetworkDifficulty(this.networkDifficulty)?.Difficulty ?? 0,
146146
Agent = this.connectionManager.ConnectionSettings.Agent,
147147
ExternalAddress = this.selfEndpointTracker.MyExternalAddress.Address.ToString(),

src/Blockcore/P2P/PeerConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected PeerConnector(
125125
this.PeerAddressManager = peerAddressManager;
126126
this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory, this.asyncProvider, this.OnPeerDisposed);
127127
this.selfEndpointTracker = selfEndpointTracker;
128-
this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion };
128+
this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion };
129129

130130
this.connectionInterval = this.CalculateConnectionInterval();
131131
}

src/External/NBitcoin/Consensus.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,8 @@ public class Consensus : IConsensus
9898
/// <inheritdoc />
9999
public List<Type> MempoolRules { get; set; }
100100

101-
/// <inheritdoc />
102-
public ConsensusProtocol ConsensusProtocol { get; }
103-
104101
public Consensus(
105102
ConsensusFactory consensusFactory,
106-
ConsensusProtocol consensusProtocol,
107103
ConsensusOptions consensusOptions,
108104
int coinType,
109105
uint256 hashGenesisBlock,
@@ -170,11 +166,6 @@ public Consensus(
170166
this.ConsensusRules = new ConsensusRules();
171167
this.MempoolRules = new List<Type>();
172168
this.ProofOfStakeTimestampMask = proofOfStakeTimestampMask;
173-
this.ConsensusProtocol = consensusProtocol;
174-
175-
// this is a small hack to allow acess to protocol verison
176-
// form serialization code.
177-
this.ConsensusFactory.Protocol = this.ConsensusProtocol;
178169
}
179170
}
180171
}

src/External/NBitcoin/ConsensusFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public virtual Transaction CreateTransaction(byte[] bytes)
131131

132132
public class ConsensusProtocol
133133
{
134-
public uint ProtocolVersion { get; set; } = Protocol.ProtocolVersion.WITNESS_VERSION;
134+
public uint ProtocolVersion { get; set; } = Protocol.ProtocolVersion.FEEFILTER_VERSION;
135135

136136
public uint MinProtocolVersion { get; set; } = Protocol.ProtocolVersion.SENDHEADERS_VERSION;
137137
}

src/External/NBitcoin/IConsensus.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,5 @@ public interface IConsensus
145145

146146
/// <summary>Group of mempool validation rules used by the given network.</summary>
147147
List<Type> MempoolRules { get; set; }
148-
149-
/// <summary>
150-
/// Information about the consensus protocol.
151-
/// </summary>
152-
ConsensusProtocol ConsensusProtocol { get; }
153148
}
154149
}

src/Features/Blockcore.Features.PoA/PoANetwork.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ public PoANetwork()
105105

106106
var bip9Deployments = new NoBIP9Deployments();
107107

108-
ConsensusProtocol consensusProtocol = new ConsensusProtocol()
108+
consensusFactory.Protocol = new ConsensusProtocol()
109109
{
110-
ProtocolVersion = (uint)ProtocolVersion.PROVEN_HEADER_VERSION,
111-
MinProtocolVersion = (uint)ProtocolVersion.POS_PROTOCOL_VERSION,
110+
ProtocolVersion = ProtocolVersion.PROVEN_HEADER_VERSION,
111+
MinProtocolVersion = ProtocolVersion.POS_PROTOCOL_VERSION,
112112
};
113113

114114
this.Consensus = new NBitcoin.Consensus(
115115
consensusFactory: consensusFactory,
116-
consensusProtocol: consensusProtocol,
117116
consensusOptions: consensusOptions,
118117
coinType: 105,
119118
hashGenesisBlock: genesisBlock.GetHash(),

src/Features/Blockcore.Features.RPC/Controllers/FullNodeController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public GetInfoModel GetInfo()
259259
var model = new GetInfoModel
260260
{
261261
Version = this.FullNode?.Version?.ToUint() ?? 0,
262-
ProtocolVersion = this.Network.Consensus.ConsensusProtocol.ProtocolVersion,
262+
ProtocolVersion = this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
263263
Blocks = this.ChainState?.ConsensusTip?.Height ?? 0,
264264
TimeOffset = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0,
265265
Connections = this.ConnectionManager?.ConnectedPeers?.Count(),
@@ -429,7 +429,7 @@ public NetworkInfoModel GetNetworkInfo()
429429
{
430430
Version = this.FullNode?.Version?.ToUint() ?? 0,
431431
SubVersion = this.Settings?.Agent,
432-
ProtocolVersion = this.Network.Consensus.ConsensusProtocol.ProtocolVersion,
432+
ProtocolVersion = this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
433433
IsLocalRelay = this.ConnectionManager?.Parameters?.IsRelay ?? false,
434434
TimeOffset = this.ConnectionManager?.ConnectedPeers?.GetMedianTimeOffset() ?? 0,
435435
Connections = this.ConnectionManager?.ConnectedPeers?.Count(),

0 commit comments

Comments
 (0)