Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Blockcore/BlockPulling/BlockPuller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public BlockPuller(IChainState chainState, NodeSettings nodeSettings, IDateTimeP

this.networkPeerRequirement = new NetworkPeerRequirement
{
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.MinProtocolVersion,
RequiredServices = NetworkPeerServices.Network
};

Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/P2P/Peer/NetworkPeerConnectionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NetworkPeerConnectionParameters

public NetworkPeerConnectionParameters()
{
this.Version = ProtocolVersion.PROTOCOL_VERSION;
this.Version = ProtocolVersion.SENDHEADERS_VERSION;
this.IsRelay = true;
this.Services = NetworkPeerServices.Nothing;
this.ConnectCancellation = default(CancellationToken);
Expand Down
8 changes: 4 additions & 4 deletions src/Blockcore/P2P/Peer/NetworkPeerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface INetworkPeerFactory
/// <param name="cancellation">Cancallation token that allows to interrupt establishing of the connection.</param>
/// <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>
/// <returns>Network peer connected to the specified counterparty.</returns>
Task<INetworkPeer> CreateConnectedNetworkPeerAsync(string endPoint, uint myVersion = ProtocolVersion.PROTOCOL_VERSION, bool isRelay = true, CancellationToken cancellation = default(CancellationToken), NetworkPeerDisposer networkPeerDisposer = null);
Task<INetworkPeer> CreateConnectedNetworkPeerAsync(string endPoint, uint myVersion, bool isRelay = true, CancellationToken cancellation = default(CancellationToken), NetworkPeerDisposer networkPeerDisposer = null);

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

/// <summary>
/// Creates a new representation of the network connection using TCP client object.
Expand Down Expand Up @@ -166,7 +166,7 @@ public INetworkPeer CreateNetworkPeer(TcpClient client, NetworkPeerConnectionPar
/// <inheritdoc/>
public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
string endPoint,
uint myVersion = ProtocolVersion.PROTOCOL_VERSION,
uint myVersion,
bool isRelay = true,
CancellationToken cancellation = default(CancellationToken),
NetworkPeerDisposer networkPeerDisposer = null)
Expand Down Expand Up @@ -215,7 +215,7 @@ public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
}

/// <inheritdoc/>
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version = ProtocolVersion.PROTOCOL_VERSION)
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version)
{
Guard.NotNull(localEndPoint, nameof(localEndPoint));
Guard.NotNull(externalEndPoint, nameof(externalEndPoint));
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/P2P/PeerConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ConsensusFactory.Protocol.ProtocolVersion };
this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusFactory.Protocol.MinProtocolVersion };

this.connectionInterval = this.CalculateConnectionInterval();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/P2P/Protocol/Payloads/GetBlocksPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Blockcore.P2P.Protocol.Payloads
[Payload("getblocks")]
public class GetBlocksPayload : Payload
{
private uint version = (uint)ProtocolVersion.PROTOCOL_VERSION;
private uint version;

public uint Version
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/P2P/Protocol/Payloads/GetHeadersPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Blockcore.P2P.Protocol.Payloads
[Payload("getheaders")]
public class GetHeadersPayload : Payload
{
private uint version = (uint)ProtocolVersion.PROTOCOL_VERSION;
private uint version;

public uint Version
{
Expand Down
2 changes: 0 additions & 2 deletions src/External/NBitcoin/Protocol/Versions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
/// </summary>
public static class ProtocolVersion
{
public const uint PROTOCOL_VERSION = 70012;

/// <summary>
/// Represents th protocol version of POS chains that was used before <see cref="ProtocolVersion.PROVEN_HEADER_VERSION"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public INetworkPeer CreateNetworkPeerClient()
peerAddressManager
);

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

private IAsyncProvider GetOrCreateAsyncProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public CoreNode CreateStratisCustomPowNode(Network network, NodeConfigParameters
.UseTestChainedHeaderTree()
.MockIBD());

return CreateCustomNode(callback, network, ProtocolVersion.PROTOCOL_VERSION, configParameters: configParameters);
return CreateCustomNode(callback, network, network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, configParameters: configParameters);
}

/// <summary>
Expand Down Expand Up @@ -186,7 +186,7 @@ public CoreNode CloneStratisNode(CoreNode cloneNode, string agent = "StratisBitc
/// <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>
/// <param name="agent">A user agent string to distinguish different node versions from each other.</param>
/// <param name="configParameters">Use this to pass in any custom configuration parameters used to set up the CoreNode</param>
public CoreNode CreateCustomNode(Action<IFullNodeBuilder> callback, Network network, uint protocolVersion = ProtocolVersion.PROTOCOL_VERSION, string agent = "Custom", NodeConfigParameters configParameters = null, uint minProtocolVersion = ProtocolVersion.PROTOCOL_VERSION)
public CoreNode CreateCustomNode(Action<IFullNodeBuilder> callback, Network network, uint protocolVersion, string agent = "Custom", NodeConfigParameters configParameters = null, uint minProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION)
{
configParameters = configParameters ?? new NodeConfigParameters();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public sealed class CustomNodeRunner : NodeRunner
private readonly NodeConfigParameters configParameters;

public CustomNodeRunner(string dataDir, Action<IFullNodeBuilder> callback, Network network,
uint protocolVersion = ProtocolVersion.PROTOCOL_VERSION, NodeConfigParameters configParameters = null, string agent = "Custom",
uint minProtocolVersion = ProtocolVersion.PROTOCOL_VERSION)
uint protocolVersion, NodeConfigParameters configParameters = null, string agent = "Custom",
uint minProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION)
: base(dataDir, agent)
{
this.callback = callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void CanUnderstandUnknownParams()
.MockIBD());

var coreNode = nodeBuilder.CreateCustomNode(buildAction, this.network,
ProtocolVersion.PROTOCOL_VERSION, configParameters: extraParams);
this.network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, configParameters: extraParams);

coreNode.Start();

Expand Down Expand Up @@ -79,7 +79,7 @@ public void CanUseCustomConfigFileFromParams()
.UseNodeHost()
.MockIBD());

var coreNode = nodeBuilder.CreateCustomNode(buildAction, this.network, ProtocolVersion.PROTOCOL_VERSION, configParameters: extraParams);
var coreNode = nodeBuilder.CreateCustomNode(buildAction, this.network, this.network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, configParameters: extraParams);

coreNode.Start();

Expand All @@ -88,4 +88,4 @@ public void CanUseCustomConfigFileFromParams()
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Tests/Blockcore.IntegrationTests/ProofOfStakeSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void PremineNodeWithWalletWithOverrides()
.UseTestChainedHeaderTree()
.OverrideDateTimeProviderFor<MiningFeature>());

this.PremineNodeWithCoins = this.nodeBuilder.CreateCustomNode(callback, new StratisRegTest(), ProtocolVersion.PROTOCOL_VERSION, agent: "mint-pmnode", configParameters: configParameters);
this.PremineNodeWithCoins = this.nodeBuilder.CreateCustomNode(callback, new StratisRegTest(), this.PremineNodeWithCoins.FullNode.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion, agent: "mint-pmnode", configParameters: configParameters);
this.PremineNodeWithCoins.WithWallet().Start();
}

Expand Down Expand Up @@ -185,4 +185,4 @@ private List<TransactionData> GetTransactionsSnapshot()
return this.PremineNodeWithCoins.FullNode.WalletManager().Wallets.First().GetAllTransactions().ToList();
}
}
}
}
33 changes: 19 additions & 14 deletions src/Tests/Blockcore.Tests/Base/ConsensusManagerBehaviorTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blockcore.Consensus;
using Blockcore.P2P.Peer;
using Blockcore.P2P.Protocol.Payloads;
using Blockcore.Tests.Common;
using NBitcoin;
using NBitcoin.Protocol;
using Xunit;

namespace Blockcore.Tests.Base
Expand Down Expand Up @@ -50,14 +52,14 @@ public async Task ConsensusTipChanged_ConsensusTipAdvancedBuNoCachedHeadersAsync
[Fact]
public async Task ConsensusTipChanged_CachedHeadersConsumedFullyAsync()
{
var cache = new List<BlockHeader>() {this.headers[11].Header, this.headers[12].Header};
var cache = new List<BlockHeader>() { this.headers[11].Header, this.headers[12].Header };

ConsensusManagerBehavior behavior = this.helper.CreateAndAttachBehavior(this.headers[5], cache, this.headers[10], NetworkPeerState.HandShaked,
(presentedHeaders, triggerDownload) =>
{
Assert.Equal(this.headers[12].Header, presentedHeaders.Last());

return new ConnectNewHeadersResult() {Consumed = this.headers[12]};
return new ConnectNewHeadersResult() { Consumed = this.headers[12] };
});

ConnectNewHeadersResult result = await behavior.ConsensusTipChangedAsync();
Expand Down Expand Up @@ -88,7 +90,7 @@ public async Task ConsensusTipChanged_CachedHeadersConsumedPartiallyAsync()
{
Assert.Equal(this.headers[50].Header, presentedHeaders.Last());

return new ConnectNewHeadersResult() {Consumed = this.headers[40]};
return new ConnectNewHeadersResult() { Consumed = this.headers[40] };
});

ConnectNewHeadersResult result = await behavior.ConsensusTipChangedAsync();
Expand Down Expand Up @@ -221,7 +223,7 @@ public async Task ProcessGetHeadersAsync_BlockLocatorWithBogusHeadersIgnoredAsyn
this.helper.CreateAndAttachBehavior(this.headers[10]);

List<ChainedHeader> bogusHeaders = ChainedHeadersHelper.CreateConsecutiveHeaders(5);
var payload = new GetHeadersPayload(new BlockLocator() { Blocks = bogusHeaders.Select(x => x.HashBlock).ToList()});
var payload = new GetHeadersPayload(new BlockLocator() { Blocks = bogusHeaders.Select(x => x.HashBlock).ToList() });

await this.helper.ReceivePayloadAsync(payload);

Expand Down Expand Up @@ -263,14 +265,18 @@ public async Task ProcessGetHeadersAsync_SendsHeadersIfLocatorIsPartiallyOnAFork

List<ChainedHeader> chainBSuffix = ChainedHeadersHelper.CreateConsecutiveHeaders(50, this.headers[55]);

var payload = new GetHeadersPayload(new BlockLocator() { Blocks = new List<uint256>()
var payload = new GetHeadersPayload(new BlockLocator()
{
chainBSuffix.Single(x => x.Height == 90).HashBlock,
chainBSuffix.Single(x => x.Height == 60).HashBlock,
this.headers[50].HashBlock,
this.headers[30].HashBlock,
this.headers[10].HashBlock
}});
Blocks = new List<uint256>()
{
chainBSuffix.Single(x => x.Height == 90).HashBlock,
chainBSuffix.Single(x => x.Height == 60).HashBlock,
this.headers[50].HashBlock,
this.headers[30].HashBlock,
this.headers[10].HashBlock
}
})
{ Version = ProtocolVersion.SENDHEADERS_VERSION };

await this.helper.ReceivePayloadAsync(payload);

Expand Down Expand Up @@ -489,7 +495,6 @@ public async Task ProcessHeadersAsync_BanPeerThatViolatedMaxHeadersCountAsync()
this.helper.CreateAndAttachBehavior(this.headers[10], null, null, NetworkPeerState.HandShaked,
(presentedHeaders, triggerDownload) => { throw new ConsensusException(""); });


int maxHeaders = typeof(ConsensusManagerBehavior).GetPrivateConstantValue<int>("MaxItemsPerHeadersMessage");

List<ChainedHeader> headersToPresent = ChainedHeadersHelper.CreateConsecutiveHeaders(maxHeaders + 500, null, true);
Expand Down Expand Up @@ -683,4 +688,4 @@ public void UpdateBestSentHeader_ChangedIfHeaderIsOnFork()
Assert.Equal(headerOnChainB, behavior.BestSentHeader);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tests/Blockcore.Tests/P2P/NetworkPeerServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Validate_AllowClientConnection_State(bool inIBD, bool isWhiteListed,
var networkPeerServer = new NetworkPeerServer(this.Network,
endpointAddNode,
endpointAddNode,
ProtocolVersion.PROTOCOL_VERSION,
this.Network.Consensus.ConsensusFactory.Protocol.ProtocolVersion,
this.extendedLoggerFactory,
networkPeerFactory.Object,
initialBlockDownloadState.Object,
Expand Down
8 changes: 4 additions & 4 deletions src/Tests/Blockcore.Tests/P2P/NetworkPeerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void NetworkPeerRequirementCheckForOutboundWithValidVersionAndInvalidServ
public void NetworkPeerRequirementCheckForOutboundWithInvalidVersionAndValidServiceReturnsFalse()
{
NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();
networkPeerRequirement.MinVersion = ProtocolVersion.PROTOCOL_VERSION;
networkPeerRequirement.MinVersion = ProtocolVersion.SENDHEADERS_VERSION;
networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
Assert.False(networkPeerRequirement.Check(new VersionPayload() { Services = NetworkPeerServices.Network, Version = ProtocolVersion.POS_PROTOCOL_VERSION }, false, out string reason));
}
Expand All @@ -42,7 +42,7 @@ public void NetworkPeerRequirementCheckForOutboundWithInvalidVersionAndValidServ
public void NetworkPeerRequirementCheckForOutboundWithInvalidVersionAndInvalidServiceReturnsFalse()
{
NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();
networkPeerRequirement.MinVersion = ProtocolVersion.PROTOCOL_VERSION;
networkPeerRequirement.MinVersion = ProtocolVersion.SENDHEADERS_VERSION;
networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
Assert.False(networkPeerRequirement.Check(new VersionPayload() { Services = NetworkPeerServices.Nothing, Version = ProtocolVersion.POS_PROTOCOL_VERSION }, false, out string reason));
}
Expand All @@ -69,7 +69,7 @@ public void NetworkPeerRequirementCheckForInboundWithValidVersionAndInvalidServi
public void NetworkPeerRequirementCheckForInboundWithInvalidVersionAndValidServiceReturnsFalse()
{
NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();
networkPeerRequirement.MinVersion = ProtocolVersion.PROTOCOL_VERSION;
networkPeerRequirement.MinVersion = ProtocolVersion.SENDHEADERS_VERSION;
networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
Assert.False(networkPeerRequirement.Check(new VersionPayload() { Services = NetworkPeerServices.Network, Version = ProtocolVersion.POS_PROTOCOL_VERSION }, true, out string reason));
}
Expand All @@ -78,7 +78,7 @@ public void NetworkPeerRequirementCheckForInboundWithInvalidVersionAndValidServi
public void NetworkPeerRequirementCheckForInboundWithInvalidVersionAndInvalidServiceReturnsFalse()
{
NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();
networkPeerRequirement.MinVersion = ProtocolVersion.PROTOCOL_VERSION;
networkPeerRequirement.MinVersion = ProtocolVersion.SENDHEADERS_VERSION;
networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
Assert.False(networkPeerRequirement.Check(new VersionPayload() { Services = NetworkPeerServices.Nothing, Version = ProtocolVersion.POS_PROTOCOL_VERSION }, true, out string reason));
}
Expand Down