Skip to content

Commit 9fe7805

Browse files
authored
Merge branch 'master' into master
2 parents 281c76a + abeebd9 commit 9fe7805

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1978
-1569
lines changed

src/neo/Cryptography/Crypto.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public static byte[] Sign(byte[] message, byte[] prikey, byte[] pubkey)
3232
}
3333
}
3434

35-
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, byte[] pubkey)
35+
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ReadOnlySpan<byte> pubkey)
3636
{
3737
if (pubkey.Length == 33 && (pubkey[0] == 0x02 || pubkey[0] == 0x03))
3838
{
3939
try
4040
{
41-
pubkey = ECC.ECPoint.DecodePoint(pubkey, ECC.ECCurve.Secp256r1).EncodePoint(false)[1..];
41+
pubkey = ECC.ECPoint.DecodePoint(pubkey, ECC.ECCurve.Secp256r1).EncodePoint(false).AsSpan(1);
4242
}
4343
catch
4444
{
@@ -58,8 +58,8 @@ public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte
5858
Curve = ECCurve.NamedCurves.nistP256,
5959
Q = new ECPoint
6060
{
61-
X = pubkey[..32],
62-
Y = pubkey[32..]
61+
X = pubkey[..32].ToArray(),
62+
Y = pubkey[32..].ToArray()
6363
}
6464
}))
6565
{

src/neo/IO/Json/JArray.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ internal override void Write(Utf8JsonWriter writer)
114114
writer.WriteEndArray();
115115
}
116116

117+
public override JObject Clone()
118+
{
119+
var cloned = new JArray();
120+
121+
foreach (JObject item in items)
122+
{
123+
cloned.Add(item.Clone());
124+
}
125+
126+
return cloned;
127+
}
128+
117129
public static implicit operator JArray(JObject[] value)
118130
{
119131
return new JArray(value);

src/neo/IO/Json/JBoolean.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ internal override void Write(Utf8JsonWriter writer)
3636
writer.WriteBooleanValue(Value);
3737
}
3838

39+
public override JObject Clone()
40+
{
41+
return this;
42+
}
43+
3944
public static implicit operator JBoolean(bool value)
4045
{
4146
return new JBoolean(value);

src/neo/IO/Json/JNumber.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ internal override void Write(Utf8JsonWriter writer)
5858
writer.WriteNumberValue(Value);
5959
}
6060

61+
public override JObject Clone()
62+
{
63+
return this;
64+
}
65+
6166
public static implicit operator JNumber(double value)
6267
{
6368
return new JNumber(value);

src/neo/IO/Json/JObject.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ private static JObject ReadObject(ref Utf8JsonReader reader)
138138
throw new FormatException();
139139
}
140140

141-
public override string ToString()
142-
{
143-
return ToString(false);
144-
}
145-
146-
public string ToString(bool indented)
141+
public byte[] ToByteArray(bool indented)
147142
{
148143
using MemoryStream ms = new MemoryStream();
149144
using Utf8JsonWriter writer = new Utf8JsonWriter(ms, new JsonWriterOptions
@@ -153,7 +148,17 @@ public string ToString(bool indented)
153148
});
154149
Write(writer);
155150
writer.Flush();
156-
return Encoding.UTF8.GetString(ms.ToArray());
151+
return ms.ToArray();
152+
}
153+
154+
public override string ToString()
155+
{
156+
return ToString(false);
157+
}
158+
159+
public string ToString(bool indented)
160+
{
161+
return Encoding.UTF8.GetString(ToByteArray(indented));
157162
}
158163

159164
public virtual T TryGetEnum<T>(T defaultValue = default, bool ignoreCase = false) where T : Enum
@@ -199,5 +204,17 @@ public static implicit operator JObject(string value)
199204
{
200205
return (JString)value;
201206
}
207+
208+
public virtual JObject Clone()
209+
{
210+
var cloned = new JObject();
211+
212+
foreach (KeyValuePair<string, JObject> pair in Properties)
213+
{
214+
cloned[pair.Key] = pair.Value != null ? pair.Value.Clone() : Null;
215+
}
216+
217+
return cloned;
218+
}
202219
}
203220
}

src/neo/IO/Json/JString.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ internal override void Write(Utf8JsonWriter writer)
4646
writer.WriteStringValue(Value);
4747
}
4848

49+
public override JObject Clone()
50+
{
51+
return this;
52+
}
53+
4954
public static implicit operator JString(Enum value)
5055
{
5156
return new JString(value.ToString());

src/neo/Ledger/Blockchain.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private class ParallelVerified { public Transaction Transaction; public bool Sho
4545
Witness = new Witness
4646
{
4747
InvocationScript = Array.Empty<byte>(),
48-
VerificationScript = new[] { (byte)OpCode.PUSHT }
48+
VerificationScript = new[] { (byte)OpCode.PUSH1 }
4949
},
5050
ConsensusData = new ConsensusData
5151
{
@@ -157,14 +157,14 @@ private static Transaction DeployNativeContracts()
157157
byte[] script;
158158
using (ScriptBuilder sb = new ScriptBuilder())
159159
{
160-
sb.EmitSysCall(InteropService.Neo_Native_Deploy);
160+
sb.EmitSysCall(InteropService.Native.Deploy);
161161
script = sb.ToArray();
162162
}
163163
return new Transaction
164164
{
165165
Version = 0,
166166
Script = script,
167-
Sender = (new[] { (byte)OpCode.PUSHT }).ToScriptHash(),
167+
Sender = (new[] { (byte)OpCode.PUSH1 }).ToScriptHash(),
168168
SystemFee = 0,
169169
Attributes = new TransactionAttribute[0],
170170
Cosigners = new Cosigner[0],
@@ -173,7 +173,7 @@ private static Transaction DeployNativeContracts()
173173
new Witness
174174
{
175175
InvocationScript = Array.Empty<byte>(),
176-
VerificationScript = new[] { (byte)OpCode.PUSHT }
176+
VerificationScript = new[] { (byte)OpCode.PUSH1 }
177177
}
178178
}
179179
};

src/neo/Network/P2P/LocalNode.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Net.Sockets;
1111
using System.Reflection;
1212
using System.Threading;
13+
using System.Threading.Tasks;
1314

1415
namespace Neo.Network.P2P
1516
{
@@ -21,6 +22,7 @@ internal class SendDirectly { public IInventory Inventory; }
2122

2223
public const uint ProtocolVersion = 0;
2324
private const int MaxCountFromSeedList = 5;
25+
private readonly IPEndPoint[] SeedList = new IPEndPoint[ProtocolSettings.Default.SeedList.Length];
2426

2527
private static readonly object lockObj = new object();
2628
private readonly NeoSystem system;
@@ -56,6 +58,14 @@ public LocalNode(NeoSystem system)
5658
throw new InvalidOperationException();
5759
this.system = system;
5860
singleton = this;
61+
62+
// Start dns resolution in parallel
63+
64+
for (int i = 0; i < ProtocolSettings.Default.SeedList.Length; i++)
65+
{
66+
int index = i;
67+
Task.Run(() => SeedList[index] = GetIpEndPoint(ProtocolSettings.Default.SeedList[index]));
68+
}
5969
}
6070
}
6171

@@ -97,33 +107,18 @@ private static IPEndPoint GetIPEndpointFromHostPort(string hostNameOrAddress, in
97107
return new IPEndPoint(ipAddress, port);
98108
}
99109

100-
/// <summary>
101-
/// Return an amount of random seeds nodes from the default SeedList file defined on <see cref="ProtocolSettings"/>.
102-
/// </summary>
103-
/// <param name="seedsToTake">Limit of random seed nodes to be obtained, also limited by the available seeds from file.</param>
104-
private static IEnumerable<IPEndPoint> GetIPEndPointsFromSeedList(int seedsToTake)
110+
internal static IPEndPoint GetIpEndPoint(string hostAndPort)
105111
{
106-
if (seedsToTake > 0)
112+
if (string.IsNullOrEmpty(hostAndPort)) return null;
113+
114+
try
107115
{
108-
Random rand = new Random();
109-
foreach (string hostAndPort in ProtocolSettings.Default.SeedList.OrderBy(p => rand.Next()))
110-
{
111-
if (seedsToTake == 0) break;
112-
string[] p = hostAndPort.Split(':');
113-
IPEndPoint seed;
114-
try
115-
{
116-
seed = GetIPEndpointFromHostPort(p[0], int.Parse(p[1]));
117-
}
118-
catch (AggregateException)
119-
{
120-
continue;
121-
}
122-
if (seed == null) continue;
123-
seedsToTake--;
124-
yield return seed;
125-
}
116+
string[] p = hostAndPort.Split(':');
117+
return GetIPEndpointFromHostPort(p[0], int.Parse(p[1]));
126118
}
119+
catch { }
120+
121+
return null;
127122
}
128123

129124
public IEnumerable<RemoteNode> GetRemoteNodes()
@@ -153,7 +148,9 @@ protected override void NeedMorePeers(int count)
153148
{
154149
// Will call AddPeers with default SeedList set cached on <see cref="ProtocolSettings"/>.
155150
// It will try to add those, sequentially, to the list of currently uncconected ones.
156-
AddPeers(GetIPEndPointsFromSeedList(count));
151+
152+
Random rand = new Random();
153+
AddPeers(SeedList.Where(u => u != null).OrderBy(p => rand.Next()).Take(count));
157154
}
158155
}
159156

src/neo/Network/P2P/Payloads/Witness.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ void ISerializable.Deserialize(BinaryReader reader)
3030
{
3131
// This is designed to allow a MultiSig 10/10 (around 1003 bytes) ~1024 bytes
3232
// Invocation = 10 * 64 + 10 = 650 ~ 664 (exact is 653)
33-
InvocationScript = reader.ReadVarBytes(664);
33+
InvocationScript = reader.ReadVarBytes(663);
3434
// Verification = 10 * 33 + 10 = 340 ~ 360 (exact is 351)
35-
VerificationScript = reader.ReadVarBytes(360);
35+
VerificationScript = reader.ReadVarBytes(361);
3636
}
3737

3838
void ISerializable.Serialize(BinaryWriter writer)

src/neo/Plugins/Plugin.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,23 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
8585
if (args.Name.Contains(".resources"))
8686
return null;
8787

88+
AssemblyName an = new AssemblyName(args.Name);
89+
8890
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == args.Name);
89-
if (assembly != null)
90-
return assembly;
91+
if (assembly is null)
92+
assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == an.Name);
93+
if (assembly != null) return assembly;
9194

92-
AssemblyName an = new AssemblyName(args.Name);
9395
string filename = an.Name + ".dll";
96+
string path = filename;
97+
if (!File.Exists(path)) path = Combine(GetDirectoryName(Assembly.GetEntryAssembly().Location), filename);
98+
if (!File.Exists(path)) path = Combine(PluginsDirectory, filename);
99+
if (!File.Exists(path)) path = Combine(PluginsDirectory, args.RequestingAssembly.GetName().Name, filename);
100+
if (!File.Exists(path)) return null;
94101

95102
try
96103
{
97-
return Assembly.Load(File.ReadAllBytes(filename));
104+
return Assembly.Load(File.ReadAllBytes(path));
98105
}
99106
catch (Exception ex)
100107
{

0 commit comments

Comments
 (0)