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.ProtocolVersion,
MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion,
RequiredServices = NetworkPeerServices.Network
};

Expand Down
19 changes: 6 additions & 13 deletions src/Blockcore/Configuration/NodeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public static string NormalizeDirectorySeparator(this string path)
/// </summary>
public class NodeSettings : IDisposable
{
/// <summary>The version of the protocol supported by the current implementation of the Full Node.</summary>
public const ProtocolVersion SupportedProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION;

/// <summary>A factory responsible for creating a Full Node logger instance.</summary>
public ILoggerFactory LoggerFactory { get; private set; }

Expand Down Expand Up @@ -76,11 +73,8 @@ public class NodeSettings : IDisposable
/// </summary>
public TextFileConfiguration ConfigReader { get; private set; }

/// <summary>The version of the protocol supported by the Full Node.</summary>
public ProtocolVersion ProtocolVersion { get; private set; }

/// <summary>The lowest version of the protocol which the Full Node supports.</summary>
public ProtocolVersion? MinProtocolVersion { get; set; }
public uint? MinProtocolVersion { get; set; }

/// <summary>The network which the node is configured to run on. The network can be a "mainnet", "testnet",
/// or "regtest" network. All three network configurations can be defined, and one is selected at the command
Expand Down Expand Up @@ -126,23 +120,22 @@ public class NodeSettings : IDisposable
/// - Alternatively, if the file name is not supplied then a network-specific file
/// name would be determined. In this case we first need to determine the network.
/// </remarks>
public NodeSettings(Network network = null, ProtocolVersion protocolVersion = SupportedProtocolVersion,
string agent = "Blockcore", string[] args = null, NetworksSelector networksSelector = null)
public NodeSettings(Network network = null, string agent = "Blockcore",
Comment thread
dangershony marked this conversation as resolved.
string[] args = null, NetworksSelector networksSelector = null)
{
// Create the default logger factory and logger.
var loggerFactory = ExtendedLoggerFactory.Create();
this.Logger = loggerFactory.CreateLogger(typeof(NodeSettings).FullName);

// Record arguments.
this.Network = network;
this.ProtocolVersion = protocolVersion;
this.Agent = agent;
this.ConfigReader = new TextFileConfiguration(args ?? new string[] { });

// Log arguments.
this.Logger.LogDebug("Arguments: network='{0}', protocolVersion='{1}', agent='{2}', args='{3}'.",
this.Network == null ? "(None)" : this.Network.Name,
this.ProtocolVersion,
this.Network?.Consensus.ConsensusProtocol.ProtocolVersion,
this.Agent,
args == null ? "(None)" : string.Join(" ", args));

Expand Down Expand Up @@ -251,9 +244,9 @@ public bool PrintHelpAndExit
/// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
/// <param name="protocolVersion">Supported protocol version for which to create the configuration.</param>
/// <returns>Default node configuration.</returns>
public static NodeSettings Default(Network network, ProtocolVersion protocolVersion = SupportedProtocolVersion)
public static NodeSettings Default(Network network)
{
return new NodeSettings(network, protocolVersion);
return new NodeSettings(network);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ConnectionManager(IDateTimeProvider dateTimeProvider,

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

this.Parameters.Version = this.NodeSettings.ProtocolVersion;
this.Parameters.Version = this.NodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion;

nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name, 1100);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/Controllers/NodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public IActionResult Status()
var model = new StatusModel
{
Version = this.fullNode.Version?.ToString() ?? "0",
ProtocolVersion = (uint)(this.nodeSettings.ProtocolVersion),
ProtocolVersion = (uint)(this.nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion),
Difficulty = GetNetworkDifficulty(this.networkDifficulty)?.Difficulty ?? 0,
Agent = this.connectionManager.ConnectionSettings.Agent,
ExternalAddress = this.selfEndpointTracker.MyExternalAddress.Address.ToString(),
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore/P2P/Peer/INetworkPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface INetworkPeer : IDisposable
/// <summary>
/// The negotiated protocol version (minimum of supported version between <see cref="MyVersion"/> and the <see cref="PeerVersion"/>).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"See ref" in documentation is now wrong.

/// </summary>
ProtocolVersion Version { get; }
uint Version { get; }

/// <summary><c>true</c> if the connection to the peer is considered active, <c>false</c> otherwise, including any case of error.</summary>
bool IsConnected { get; }
Expand Down
10 changes: 5 additions & 5 deletions src/Blockcore/P2P/Peer/NetworkPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class NetworkPeerDisconnectReason
public class NetworkPeerRequirement
{
/// <summary>Minimal protocol version that the peer must support or <c>null</c> if there is no requirement for minimal protocol version.</summary>
public ProtocolVersion? MinVersion { get; set; }
public uint? MinVersion { get; set; }

/// <summary>Specification of network services that the peer must provide.</summary>
public NetworkPeerServices RequiredServices { get; set; }
Expand Down Expand Up @@ -179,14 +179,14 @@ public PerformanceCounter Counter
}

/// <inheritdoc/>
public ProtocolVersion Version
public uint Version
{
get
{
ProtocolVersion peerVersion = this.PeerVersion == null ? this.MyVersion.Version : this.PeerVersion.Version;
ProtocolVersion myVersion = this.MyVersion.Version;
uint peerVersion = this.PeerVersion == null ? this.MyVersion.Version : this.PeerVersion.Version;
uint myVersion = this.MyVersion.Version;
uint min = Math.Min((uint)peerVersion, (uint)myVersion);
return (ProtocolVersion)min;
return min;
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/Blockcore/P2P/Peer/NetworkPeerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ public async Task ConnectAsync(IPEndPoint endPoint, CancellationToken cancellati

using (var ms = new MemoryStream())
{
message.ReadWrite(new BitcoinStream(ms, true)
message.ReadWrite(new BitcoinStream(ms, true, this.network.Consensus.ConsensusFactory, this.peer.Version)
{
ProtocolVersion = this.peer.Version,
TransactionOptions = this.peer.SupportedTransactionOptions,
ConsensusFactory = this.network.Consensus.ConsensusFactory
});

byte[] bytes = ms.ToArray();
Expand Down Expand Up @@ -337,13 +335,13 @@ public async Task ConnectAsync(IPEndPoint endPoint, CancellationToken cancellati
/// <returns>Binary message received from the connected counterparty.</returns>
/// <exception cref="OperationCanceledException">Thrown if the operation was cancelled or the end of the stream was reached.</exception>
/// <exception cref="ProtocolViolationException">Thrown if the incoming message is too big.</exception>
private async Task<byte[]> ReadMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation = default(CancellationToken))
private async Task<byte[]> ReadMessageAsync(uint protocolVersion, CancellationToken cancellation = default(CancellationToken))
{
// First find and read the magic.
await this.ReadMagicAsync(this.network.MagicBytes, cancellation).ConfigureAwait(false);

// Then read the header, which is formed of command, length, and possibly also a checksum.
int checksumSize = protocolVersion >= ProtocolVersion.MEMPOOL_GD_VERSION ? Message.ChecksumSize : 0;
int checksumSize = Message.ChecksumSize;
int headerSize = Message.CommandSize + Message.LengthSize + checksumSize;

var messageHeader = new byte[headerSize];
Expand Down Expand Up @@ -455,7 +453,7 @@ private async Task ReadMagicAsync(byte[] magic, CancellationToken cancellation)
/// for parsing the message from binary data. That method need stream to read from, so to achieve that we create a memory stream from our data,
/// which is not efficient. This should be improved.
/// </remarks>
private async Task<(Message Message, int RawMessageSize)> ReadAndParseMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation)
private async Task<(Message Message, int RawMessageSize)> ReadAndParseMessageAsync(uint protocolVersion, CancellationToken cancellation)
{
Message message = null;

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 @@ -15,7 +15,7 @@ public class NetworkPeerConnectionParameters
/// <summary>Send addr unsollicited message of the AddressFrom peer when passing to Handshaked state.</summary>
public bool Advertize { get; set; }

public ProtocolVersion Version { get; set; }
public uint Version { get; set; }

/// <summary>If true, the node will receive all incoming transactions if no bloomfilter are set.</summary>
public bool IsRelay { get; set; }
Expand Down
9 changes: 5 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, ProtocolVersion myVersion = ProtocolVersion.PROTOCOL_VERSION, bool isRelay = true, CancellationToken cancellation = default(CancellationToken), NetworkPeerDisposer networkPeerDisposer = null);
Task<INetworkPeer> CreateConnectedNetworkPeerAsync(string endPoint, uint myVersion = ProtocolVersion.PROTOCOL_VERSION, 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, ProtocolVersion version = ProtocolVersion.PROTOCOL_VERSION);
NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version = ProtocolVersion.PROTOCOL_VERSION);

/// <summary>
/// Creates a new representation of the network connection using TCP client object.
Expand Down Expand Up @@ -102,6 +102,7 @@ public class NetworkPeerFactory : INetworkPeerFactory

/// <summary>Configuration related to incoming and outgoing connections.</summary>
private readonly ConnectionManagerSettings connectionManagerSettings;

private readonly IAsyncProvider asyncProvider;

/// <summary>Callback that is invoked just before a message is to be sent to a peer, or <c>null</c> when nothing needs to be called.</summary>
Expand Down Expand Up @@ -165,7 +166,7 @@ public INetworkPeer CreateNetworkPeer(TcpClient client, NetworkPeerConnectionPar
/// <inheritdoc/>
public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
string endPoint,
ProtocolVersion myVersion = ProtocolVersion.PROTOCOL_VERSION,
uint myVersion = ProtocolVersion.PROTOCOL_VERSION,
bool isRelay = true,
CancellationToken cancellation = default(CancellationToken),
NetworkPeerDisposer networkPeerDisposer = null)
Expand Down Expand Up @@ -214,7 +215,7 @@ public async Task<INetworkPeer> CreateConnectedNetworkPeerAsync(
}

/// <inheritdoc/>
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, ProtocolVersion version = ProtocolVersion.PROTOCOL_VERSION)
public NetworkPeerServer CreateNetworkPeerServer(IPEndPoint localEndPoint, IPEndPoint externalEndPoint, uint version = ProtocolVersion.PROTOCOL_VERSION)
{
Guard.NotNull(localEndPoint, nameof(localEndPoint));
Guard.NotNull(externalEndPoint, nameof(externalEndPoint));
Expand Down
4 changes: 2 additions & 2 deletions src/Blockcore/P2P/Peer/NetworkPeerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NetworkPeerServer : IDisposable
public Network Network { get; private set; }

/// <summary>Version of the protocol that the server is running.</summary>
public ProtocolVersion Version { get; private set; }
public uint Version { get; private set; }

/// <summary>The parameters that will be cloned and applied for each peer connecting to <see cref="NetworkPeerServer"/>.</summary>
public NetworkPeerConnectionParameters InboundNetworkPeerConnectionParameters { get; set; }
Expand Down Expand Up @@ -82,7 +82,7 @@ public class NetworkPeerServer : IDisposable
public NetworkPeerServer(Network network,
IPEndPoint localEndPoint,
IPEndPoint externalEndPoint,
ProtocolVersion version,
uint version,
ILoggerFactory loggerFactory,
INetworkPeerFactory networkPeerFactory,
IInitialBlockDownloadState initialBlockDownloadState,
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.ProtocolVersion };
this.Requirements = new NetworkPeerRequirement { MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.Network.Consensus.ConsensusProtocol.ProtocolVersion };

this.connectionInterval = this.CalculateConnectionInterval();
}
Expand Down
Loading