Skip to content

Commit 28ff37f

Browse files
authored
Remove the const PROTOCOL_VERSION and use the version per chain on the consensus factory (#130)
1 parent 2e4816b commit 28ff37f

15 files changed

Lines changed: 43 additions & 40 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.ConsensusFactory.Protocol.ProtocolVersion,
228+
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.MinProtocolVersion,
229229
RequiredServices = NetworkPeerServices.Network
230230
};
231231

src/Blockcore/P2P/Peer/NetworkPeerConnectionParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class NetworkPeerConnectionParameters
4040

4141
public NetworkPeerConnectionParameters()
4242
{
43-
this.Version = ProtocolVersion.PROTOCOL_VERSION;
43+
this.Version = ProtocolVersion.SENDHEADERS_VERSION;
4444
this.IsRelay = true;
4545
this.Services = NetworkPeerServices.Nothing;
4646
this.ConnectCancellation = default(CancellationToken);

src/Blockcore/P2P/Peer/NetworkPeerFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface INetworkPeerFactory
3838
/// <param name="cancellation">Cancallation token that allows to interrupt establishing of the connection.</param>
3939
/// <param name="networkPeerDisposer">Maintains a list of connected peers and ensures their proper disposal. Or <c>null</c> if case disposal should be handled from user code.</param>
4040
/// <returns>Network peer connected to the specified counterparty.</returns>
41-
Task<INetworkPeer> CreateConnectedNetworkPeerAsync(string endPoint, uint myVersion = ProtocolVersion.PROTOCOL_VERSION, bool isRelay = true, CancellationToken cancellation = default(CancellationToken), NetworkPeerDisposer networkPeerDisposer = null);
41+
Task<INetworkPeer> CreateConnectedNetworkPeerAsync(string endPoint, uint myVersion, bool isRelay = true, CancellationToken cancellation = default(CancellationToken), NetworkPeerDisposer networkPeerDisposer = null);
4242

4343
/// <summary>
4444
/// Creates a new network peer which is connected to a specified counterparty.
@@ -57,7 +57,7 @@ public interface INetworkPeerFactory
5757
/// <param name="externalEndPoint">IP address and port that the server is reachable from the Internet on.</param>
5858
/// <param name="version">Version of the network protocol that the server should run.</param>
5959
/// <returns>Newly created network peer server, which is ready to be started.</returns>
60-
NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version = ProtocolVersion.PROTOCOL_VERSION);
60+
NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version);
6161

6262
/// <summary>
6363
/// Creates a new representation of the network connection using TCP client object.
@@ -166,7 +166,7 @@ public INetworkPeer CreateNetworkPeer(TcpClient client, NetworkPeerConnectionPar
166166
/// <inheritdoc/>
167167
public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
168168
string endPoint,
169-
uint myVersion = ProtocolVersion.PROTOCOL_VERSION,
169+
uint myVersion,
170170
bool isRelay = true,
171171
CancellationToken cancellation = default(CancellationToken),
172172
NetworkPeerDisposer networkPeerDisposer = null)
@@ -215,7 +215,7 @@ public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
215215
}
216216

217217
/// <inheritdoc/>
218-
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version = ProtocolVersion.PROTOCOL_VERSION)
218+
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version)
219219
{
220220
Guard.NotNull(localEndPoint, nameof(localEndPoint));
221221
Guard.NotNull(externalEndPoint, nameof(externalEndPoint));

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.ConsensusFactory.Protocol.ProtocolVersion };
128+
this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.MinProtocolVersion };
129129

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

src/Blockcore/P2P/Protocol/Payloads/GetBlocksPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Blockcore.P2P.Protocol.Payloads
99
[Payload("getblocks")]
1010
public class GetBlocksPayload : Payload
1111
{
12-
private uint version = (uint)ProtocolVersion.PROTOCOL_VERSION;
12+
private uint version;
1313

1414
public uint Version
1515
{

src/Blockcore/P2P/Protocol/Payloads/GetHeadersPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Blockcore.P2P.Protocol.Payloads
99
[Payload("getheaders")]
1010
public class GetHeadersPayload : Payload
1111
{
12-
private uint version = (uint)ProtocolVersion.PROTOCOL_VERSION;
12+
private uint version;
1313

1414
public uint Version
1515
{

src/External/NBitcoin/Protocol/Versions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
/// </summary>
66
public static class ProtocolVersion
77
{
8-
public const uint PROTOCOL_VERSION = 70012;
9-
108
/// <summary>
119
/// Represents th protocol version of POS chains that was used before <see cref="ProtocolVersion.PROVEN_HEADER_VERSION"/>
1210
/// </summary>

src/Tests/Blockcore.IntegrationTests.Common/EnvironmentMockUpHelpers/CoreNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public INetworkPeer CreateNetworkPeerClient()
276276
peerAddressManager
277277
);
278278

279-
return networkPeerFactory.CreateConnectedNetworkPeerAsync("127.0.0.1:" + this.ProtocolPort).ConfigureAwait(false).GetAwaiter().GetResult();
279+
return networkPeerFactory.CreateConnectedNetworkPeerAsync("127.0.0.1:" + this.ProtocolPort, this.runner.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion).ConfigureAwait(false).GetAwaiter().GetResult();
280280
}
281281

282282
private IAsyncProvider GetOrCreateAsyncProvider()

src/Tests/Blockcore.IntegrationTests.Common/EnvironmentMockUpHelpers/NodeBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public CoreNode CreateStratisCustomPowNode(Network network, NodeConfigParameters
153153
.UseTestChainedHeaderTree()
154154
.MockIBD());
155155

156-
return CreateCustomNode(callback, network, ProtocolVersion.PROTOCOL_VERSION, configParameters: configParameters);
156+
return CreateCustomNode(callback, network, network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, configParameters: configParameters);
157157
}
158158

159159
/// <summary>
@@ -186,7 +186,7 @@ public CoreNode CloneStratisNode(CoreNode cloneNode, string agent = "StratisBitc
186186
/// <param name="protocolVersion">Use <see cref="ProtocolVersion.PROTOCOL_VERSION"/> for BTC PoW-like networks and <see cref="ProtocolVersion.POS_PROTOCOL_VERSION"/> for Stratis PoS-like networks.</param>
187187
/// <param name="agent">A user agent string to distinguish different node versions from each other.</param>
188188
/// <param name="configParameters">Use this to pass in any custom configuration parameters used to set up the CoreNode</param>
189-
public CoreNode CreateCustomNode(Action<IFullNodeBuilder> callback, Network network, uint protocolVersion = ProtocolVersion.PROTOCOL_VERSION, string agent = "Custom", NodeConfigParameters configParameters = null, uint minProtocolVersion = ProtocolVersion.PROTOCOL_VERSION)
189+
public CoreNode CreateCustomNode(Action<IFullNodeBuilder> callback, Network network, uint protocolVersion, string agent = "Custom", NodeConfigParameters configParameters = null, uint minProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION)
190190
{
191191
configParameters = configParameters ?? new NodeConfigParameters();
192192

src/Tests/Blockcore.IntegrationTests.Common/Runners/CustomRunner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public sealed class CustomNodeRunner : NodeRunner
1818
private readonly NodeConfigParameters configParameters;
1919

2020
public CustomNodeRunner(string dataDir, Action<IFullNodeBuilder> callback, Network network,
21-
uint protocolVersion = ProtocolVersion.PROTOCOL_VERSION, NodeConfigParameters configParameters = null, string agent = "Custom",
22-
uint minProtocolVersion = ProtocolVersion.PROTOCOL_VERSION)
21+
uint protocolVersion, NodeConfigParameters configParameters = null, string agent = "Custom",
22+
uint minProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION)
2323
: base(dataDir, agent)
2424
{
2525
this.callback = callback;

0 commit comments

Comments
 (0)