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
4 changes: 2 additions & 2 deletions src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public partial class Trie
private readonly Cache _cache;
public Node Root => _root;

public Trie(IStoreSnapshot store, UInt256 root, bool full_state = false)
public Trie(IStoreSnapshot store, UInt256 root, bool fullState = false)
{
ArgumentNullException.ThrowIfNull(store);
_cache = new Cache(store, Prefix);
_root = root is null ? new Node() : Node.NewHash(root);
_full = full_state;
_full = fullState;
}

private static byte[] ToNibbles(ReadOnlySpan<byte> path)
Expand Down
12 changes: 6 additions & 6 deletions src/Neo/Cryptography/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,25 @@ public static byte[] AES256Decrypt(this byte[] encryptedData, byte[] key, byte[]

public static byte[] ECDHDeriveKey(KeyPair local, ECPoint remote)
{
ReadOnlySpan<byte> pubkey_local = local.PublicKey.EncodePoint(false);
ReadOnlySpan<byte> pubkey_remote = remote.EncodePoint(false);
ReadOnlySpan<byte> pubkeyLocal = local.PublicKey.EncodePoint(false);
ReadOnlySpan<byte> pubkeyRemote = remote.EncodePoint(false);
using var ecdh1 = ECDiffieHellman.Create(new ECParameters
{
Curve = ECCurve.NamedCurves.nistP256,
D = local.PrivateKey,
Q = new System.Security.Cryptography.ECPoint
{
X = pubkey_local[1..][..32].ToArray(),
Y = pubkey_local[1..][32..].ToArray()
X = pubkeyLocal[1..][..32].ToArray(),
Y = pubkeyLocal[1..][32..].ToArray()
}
});
using var ecdh2 = ECDiffieHellman.Create(new ECParameters
{
Curve = ECCurve.NamedCurves.nistP256,
Q = new System.Security.Cryptography.ECPoint
{
X = pubkey_remote[1..][..32].ToArray(),
Y = pubkey_remote[1..][32..].ToArray()
X = pubkeyRemote[1..][..32].ToArray(),
Y = pubkeyRemote[1..][32..].ToArray()
}
});
return ecdh1.DeriveKeyMaterial(ecdh2.PublicKey).Sha256();//z = r * P = r* k * G
Expand Down
20 changes: 10 additions & 10 deletions src/Neo/Extensions/Collections/ICollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ public static class ICollectionExtensions
/// <returns>The size of the array.</returns>
public static int GetVarSize<T>(this IReadOnlyCollection<T> value)
{
int value_size;
int valueSize;
var t = typeof(T);
if (typeof(ISerializable).IsAssignableFrom(t))
{
value_size = value.OfType<ISerializable>().Sum(p => p.Size);
valueSize = value.OfType<ISerializable>().Sum(p => p.Size);
}
else if (t.GetTypeInfo().IsEnum)
{
int element_size;
int elementSize;
var u = t.GetTypeInfo().GetEnumUnderlyingType();
if (u == typeof(sbyte) || u == typeof(byte))
element_size = 1;
elementSize = 1;
else if (u == typeof(short) || u == typeof(ushort))
element_size = 2;
elementSize = 2;
else if (u == typeof(int) || u == typeof(uint))
element_size = 4;
elementSize = 4;
else //if (u == typeof(long) || u == typeof(ulong))
element_size = 8;
value_size = value.Count * element_size;
elementSize = 8;
valueSize = value.Count * elementSize;
}
else
{
value_size = value.Count * Marshal.SizeOf<T>();
valueSize = value.Count * Marshal.SizeOf<T>();
}
return value.Count.GetVarSize() + value_size;
return value.Count.GetVarSize() + valueSize;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Neo/IO/Actors/PriorityMessageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

namespace Neo.IO.Actors
{
internal class PriorityMessageQueue
(Func<object, IEnumerable, bool> dropper, Func<object, bool> priority_generator) : IMessageQueue, IUnboundedMessageQueueSemantics
internal class PriorityMessageQueue(Func<object, IEnumerable, bool> dropper, Func<object, bool> priorityGenerator)
: IMessageQueue, IUnboundedMessageQueueSemantics
{
private readonly ConcurrentQueue<Envelope> _high = new();
private readonly ConcurrentQueue<Envelope> _low = new();
private readonly Func<object, IEnumerable, bool> _dropper = dropper;
private readonly Func<object, bool> _priority_generator = priority_generator;
private readonly Func<object, bool> _priorityGenerator = priorityGenerator;
private int _idle = 1;

public bool HasMessages => !_high.IsEmpty || !_low.IsEmpty;
Expand All @@ -44,7 +44,7 @@ public void Enqueue(IActorRef receiver, Envelope envelope)
if (envelope.Message is Idle) return;
if (_dropper(envelope.Message, _high.Concat(_low).Select(p => p.Message)))
return;
var queue = _priority_generator(envelope.Message) ? _high : _low;
var queue = _priorityGenerator(envelope.Message) ? _high : _low;
queue.Enqueue(envelope);
}

Expand Down
34 changes: 17 additions & 17 deletions src/Neo/Network/P2P/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public class Message : ISerializable
/// </summary>
public ISerializable Payload;

private ReadOnlyMemory<byte>
_payload_raw,
_payload_compressed;
private ReadOnlyMemory<byte> _payloadRaw;

private ReadOnlyMemory<byte> _payloadCompressed;

/// <summary>
/// True if the message is compressed
/// </summary>
public bool IsCompressed => Flags.HasFlag(MessageFlags.Compressed);

public int Size => sizeof(MessageFlags) + sizeof(MessageCommand) + _payload_compressed.GetVarSize();
public int Size => sizeof(MessageFlags) + sizeof(MessageCommand) + _payloadCompressed.GetVarSize();

/// <summary>
/// True if the message should be compressed
Expand Down Expand Up @@ -91,18 +91,18 @@ public static Message Create(MessageCommand command, ISerializable payload = nul
Flags = MessageFlags.None,
Command = command,
Payload = payload,
_payload_raw = payload?.ToArray() ?? Array.Empty<byte>()
_payloadRaw = payload?.ToArray() ?? Array.Empty<byte>()
};

message._payload_compressed = message._payload_raw;
message._payloadCompressed = message._payloadRaw;

// Try compression
if (tryCompression && message._payload_compressed.Length > CompressionMinSize)
if (tryCompression && message._payloadCompressed.Length > CompressionMinSize)
{
var compressed = message._payload_compressed.Span.CompressLz4();
if (compressed.Length < message._payload_compressed.Length - CompressionThreshold)
var compressed = message._payloadCompressed.Span.CompressLz4();
if (compressed.Length < message._payloadCompressed.Length - CompressionThreshold)
{
message._payload_compressed = compressed;
message._payloadCompressed = compressed;
message.Flags |= MessageFlags.Compressed;
}
}
Expand All @@ -112,26 +112,26 @@ public static Message Create(MessageCommand command, ISerializable payload = nul

private void DecompressPayload()
{
if (_payload_compressed.Length == 0) return;
if (_payloadCompressed.Length == 0) return;
var decompressed = Flags.HasFlag(MessageFlags.Compressed)
? _payload_compressed.Span.DecompressLz4(PayloadMaxSize)
: _payload_compressed;
? _payloadCompressed.Span.DecompressLz4(PayloadMaxSize)
: _payloadCompressed;
Payload = ReflectionCache<MessageCommand>.CreateSerializable(Command, decompressed);
}

void ISerializable.Deserialize(ref MemoryReader reader)
{
Flags = (MessageFlags)reader.ReadByte();
Command = (MessageCommand)reader.ReadByte();
_payload_compressed = reader.ReadVarMemory(PayloadMaxSize);
_payloadCompressed = reader.ReadVarMemory(PayloadMaxSize);
DecompressPayload();
}

void ISerializable.Serialize(BinaryWriter writer)
{
writer.Write((byte)Flags);
writer.Write((byte)Command);
writer.WriteVarBytes(_payload_compressed.Span);
writer.WriteVarBytes(_payloadCompressed.Span);
}

public byte[] ToArray(bool enablecompression)
Expand All @@ -149,7 +149,7 @@ public byte[] ToArray(bool enablecompression)

writer.Write((byte)(Flags & ~MessageFlags.Compressed));
writer.Write((byte)Command);
writer.WriteVarBytes(_payload_raw.Span);
writer.WriteVarBytes(_payloadRaw.Span);

writer.Flush();
return ms.ToArray();
Expand Down Expand Up @@ -193,7 +193,7 @@ internal static int TryDeserialize(ByteString data, out Message msg)
{
Flags = flags,
Command = (MessageCommand)header[1],
_payload_compressed = length <= 0 ? ReadOnlyMemory<byte>.Empty : data.Slice(payloadIndex, (int)length).ToArray()
_payloadCompressed = length <= 0 ? ReadOnlyMemory<byte>.Empty : data.Slice(payloadIndex, (int)length).ToArray()
};
msg.DecompressPayload();

Expand Down
6 changes: 3 additions & 3 deletions src/Neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class GetBlockByIndexPayload : ISerializable
/// <summary>
/// Creates a new instance of the <see cref="GetBlockByIndexPayload"/> class.
/// </summary>
/// <param name="index_start">The starting index of the blocks to request.</param>
/// <param name="indexStart">The starting index of the blocks to request.</param>
/// <param name="count">The number of blocks to request. Set this parameter to -1 to request as many blocks as possible.</param>
/// <returns>The created payload.</returns>
public static GetBlockByIndexPayload Create(uint index_start, short count = -1)
public static GetBlockByIndexPayload Create(uint indexStart, short count = -1)
{
return new GetBlockByIndexPayload
{
IndexStart = index_start,
IndexStart = indexStart,
Count = count
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/Neo/Network/P2P/Payloads/GetBlocksPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public class GetBlocksPayload : ISerializable
/// <summary>
/// Creates a new instance of the <see cref="GetBlocksPayload"/> class.
/// </summary>
/// <param name="hash_start">The starting hash of the blocks to request.</param>
/// <param name="hashStart">The starting hash of the blocks to request.</param>
/// <param name="count">The number of blocks to request. Set this parameter to -1 to request as many blocks as possible.</param>
/// <returns>The created payload.</returns>
public static GetBlocksPayload Create(UInt256 hash_start, short count = -1)
public static GetBlocksPayload Create(UInt256 hashStart, short count = -1)
{
return new GetBlocksPayload
{
HashStart = hash_start,
HashStart = hashStart,
Count = count
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Neo/Network/P2P/Payloads/NotValidBefore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public override JObject ToJson()

public override bool Verify(DataCache snapshot, Transaction tx)
{
var block_height = NativeContract.Ledger.CurrentIndex(snapshot);
return block_height >= Height;
var blockHeight = NativeContract.Ledger.CurrentIndex(snapshot);
return blockHeight >= Height;
}
}
}
Loading