Skip to content

Commit

Permalink
Merge pull request #122 from pingpongsneak/master
Browse files Browse the repository at this point in the history
Last RC release
  • Loading branch information
pingpongsneak committed Dec 18, 2022
2 parents 9057f2a + 41fa6e3 commit a9b39f5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/Ledger/Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private async Task<IReadOnlyList<Block>> FetchBlocksAsync(Peer peer, ulong skip,
{
new() { Value = iSkip.ToBytes(), ProtocolCommand = ProtocolCommand.GetBlocks },
new() { Value = chunk.ToBytes(), ProtocolCommand = ProtocolCommand.GetBlocks }
}), 500);
}));
if (blocksResponse?.Blocks is null)
{
warpTask.StopTask();
Expand Down
2 changes: 1 addition & 1 deletion core/Network/Broadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override async Task OnReceiveAsync((TopicType, byte[]) message)
if (cancellationToken.IsCancellationRequested) return ValueTask.CompletedTask;
var _ = _cypherSystemCore.P2PDeviceReq().SendAsync<EmptyMessage>(knownPeer.IpAddress,
knownPeer.TcpPort,
knownPeer.PublicKey, msg).SafeForgetAsync(_logger).ConfigureAwait(false);
knownPeer.PublicKey, msg, 250).SafeForgetAsync(_logger).ConfigureAwait(false);
}
catch (Exception)
{
Expand Down
11 changes: 7 additions & 4 deletions core/Network/P2PDeviceReq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace CypherNetwork.Network;
public interface IP2PDeviceReq
{
Task<T> SendAsync<T>(ReadOnlyMemory<byte> ipAddress, ReadOnlyMemory<byte> tcpPort, ReadOnlyMemory<byte> publicKey,
ReadOnlyMemory<byte> value, int timeMs = 200, bool deserialize = true);
ReadOnlyMemory<byte> value, int timeMs = 0, bool deserialize = true);
}

public class EmptyMessage { }
Expand Down Expand Up @@ -55,7 +55,7 @@ public P2PDeviceReq(ICypherSystemCore cypherSystemCore)
/// <returns></returns>
/// <exception cref="Exception"></exception>
public async Task<T> SendAsync<T>(ReadOnlyMemory<byte> ipAddress, ReadOnlyMemory<byte> tcpPort, ReadOnlyMemory<byte> publicKey,
ReadOnlyMemory<byte> value, int timeMs = 200, bool deserialize = true)
ReadOnlyMemory<byte> value, int timeMs = 0, bool deserialize = true)
{
var nngMsg = NngFactorySingleton.Instance.Factory.CreateMessage();
try
Expand All @@ -73,8 +73,11 @@ public P2PDeviceReq(ICypherSystemCore cypherSystemCore)
using var socket = NngFactorySingleton.Instance.Factory.RequesterOpen()
.ThenDial($"tcp://{address}:{port}", Defines.NngFlag.NNG_FLAG_NONBLOCK).Unwrap();

socket.SetOpt(Defines.NNG_OPT_RECVTIMEO, new nng_duration { TimeMs = timeMs });
socket.SetOpt(Defines.NNG_OPT_SENDTIMEO, new nng_duration { TimeMs = timeMs });
if (timeMs != 0)
{
socket.SetOpt(Defines.NNG_OPT_RECVTIMEO, new nng_duration { TimeMs = timeMs });
socket.SetOpt(Defines.NNG_OPT_SENDTIMEO, new nng_duration { TimeMs = timeMs });
}

using var ctx = socket.CreateAsyncContext(NngFactorySingleton.Instance.Factory).Unwrap();
var cipher = _cypherSystemCore.Crypto().BoxSeal(value.Span, publicKey.Span[1..33]);
Expand Down
7 changes: 4 additions & 3 deletions core/Network/PeerDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface IPeerDiscovery
/// </summary>
public sealed class PeerDiscovery : IDisposable, IPeerDiscovery
{
private const int PrunedTimeoutFromSeconds = 30;
private const int PrunedTimeoutFromSeconds = 120;
private const int SurveyorWaitTimeMilliseconds = 2500;
private const int ReceiveWaitTimeMilliseconds = 1000;
private readonly Caching<Peer> _caching = new();
Expand Down Expand Up @@ -378,7 +378,7 @@ private async Task OnReadyAsync()
}
finally
{
if (peer.Timestamp < Util.GetUtcNow().AddSeconds(-30).ToUnixTimestamp())
if (peer.Timestamp < Util.GetUtcNow().AddSeconds(-PrunedTimeoutFromSeconds).ToUnixTimestamp())
{
SetPeerCooldown(new PeerCooldown
{
Expand Down Expand Up @@ -461,7 +461,8 @@ private async Task ReceivedPeersAsync(INngMsgPart nngMsg)
if (!cachedPeer.IsDefault())
{
if (cachedPeer.Timestamp >= peer.Timestamp) continue;
UpdatePeer(peer.ClientId, peer.IpAddress, peer);
// ReSharper disable once RedundantAssignment
cachedPeer = peer;
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion core/Wallet/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,13 @@ private bool IsSpent(Output output, IWalletSession session)
Guard.Argument(m, nameof(m)).NotNull().NotEmpty();
using var pedersen = new Pedersen();
using var secp256K1 = new Secp256k1();
var (spendKey, scanKey) = Unlock();
var transactions = session.GetSafeGuardBlocks()
.SelectMany(x => x.Txs).ToArray();
if (transactions.Any() != true) return null;
transactions.Shuffle();

var (spendKey, scanKey) = Unlock();

for (var k = 0; k < nRows - 1; ++k)
for (var i = 0; i < nCols; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion core/core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
<RootNamespace>CypherNetwork</RootNamespace>
<AssemblyVersion>0.0.75.0</AssemblyVersion>
<AssemblyVersion>0.0.76.0</AssemblyVersion>
<Company>CypherNetwork</Company>
<PackageId>core</PackageId>
<AssemblyName>cyphernetworkcore</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion node/node.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<AssemblyVersion>0.0.75.0</AssemblyVersion>
<AssemblyVersion>0.0.76.0</AssemblyVersion>
<NeutralLanguage>en</NeutralLanguage>
<PackageId>node</PackageId>
</PropertyGroup>
Expand Down

0 comments on commit a9b39f5

Please sign in to comment.