Skip to content

Commit 3285c9a

Browse files
authored
Merge branch 'master' into standardize-exception
2 parents c5719a3 + 21765dc commit 3285c9a

File tree

61 files changed

+420
-383
lines changed

Some content is hidden

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

61 files changed

+420
-383
lines changed

src/Neo.CLI/CLI/MainService.Blockchain.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void OnShowBlockCommand(string indexOrHash)
8282
ConsoleHelper.Info("", " PrevHash: ", $"{block.PrevHash}");
8383
ConsoleHelper.Info("", " NextConsensus: ", $"{block.NextConsensus}");
8484
ConsoleHelper.Info("", " PrimaryIndex: ", $"{block.PrimaryIndex}");
85-
ConsoleHelper.Info("", " PrimaryPubKey: ", $"{NativeContract.NEO.GetCommittee(NeoSystem.GetSnapshot())[block.PrimaryIndex]}");
85+
ConsoleHelper.Info("", " PrimaryPubKey: ", $"{NativeContract.NEO.GetCommittee(NeoSystem.GetSnapshotCache())[block.PrimaryIndex]}");
8686
ConsoleHelper.Info("", " Version: ", $"{block.Version}");
8787
ConsoleHelper.Info("", " Size: ", $"{block.Size} Byte(s)");
8888
ConsoleHelper.Info();

src/Neo.CLI/CLI/MainService.Network.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void OnBroadcastInvCommand(InventoryType type, UInt256[] payload)
117117
[ConsoleCommand("broadcast transaction", Category = "Network Commands")]
118118
private void OnBroadcastTransactionCommand(UInt256 hash)
119119
{
120-
if (NeoSystem.MemPool.TryGetValue(hash, out Transaction tx))
120+
if (NeoSystem.MemPool.TryGetValue(hash, out var tx))
121121
OnBroadcastCommand(MessageCommand.Transaction, tx);
122122
}
123123

src/Neo.CLI/CLI/MainService.Wallet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ private void OnCancelCommand(UInt256 txid, UInt160? sender = null, UInt160[]? si
618618
return;
619619
}
620620

621-
if (NeoSystem.MemPool.TryGetValue(txid, out Transaction conflictTx))
621+
if (NeoSystem.MemPool.TryGetValue(txid, out var conflictTx))
622622
{
623623
tx.NetworkFee = Math.Max(tx.NetworkFee, conflictTx.NetworkFee) + 1;
624624
}

src/Neo.CLI/config.fs.mainnet.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"MillisecondsPerBlock": 15000,
3434
"MaxTransactionsPerBlock": 512,
3535
"MemoryPoolMaxTransactions": 50000,
36-
"MaxTraceableBlocks": 2102400,
36+
"MaxTraceableBlocks": 17280,
3737
"InitialGasDistribution": 5200000000000000,
3838
"ValidatorsCount": 7,
3939
"Hardforks": {

src/Neo.CLI/config.fs.testnet.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"MillisecondsPerBlock": 15000,
3434
"MaxTransactionsPerBlock": 512,
3535
"MemoryPoolMaxTransactions": 50000,
36-
"MaxTraceableBlocks": 2102400,
36+
"MaxTraceableBlocks": 17280,
3737
"InitialGasDistribution": 5200000000000000,
3838
"ValidatorsCount": 7,
3939
"StandbyCommittee": [

src/Neo.Extensions/Neo.Extensions.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Akka" Version="1.5.20" />
12+
<PackageReference Include="Akka" Version="1.5.26" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/Neo/Ledger/MemoryPool.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public bool ContainsKey(UInt256 hash)
159159
/// <param name="hash">The hash of the <see cref="Transaction"/> to get.</param>
160160
/// <param name="tx">When this method returns, contains the <see cref="Transaction"/> associated with the specified hash, if the hash is found; otherwise, <see langword="null"/>.</param>
161161
/// <returns><see langword="true"/> if the <see cref="MemoryPool"/> contains a <see cref="Transaction"/> with the specified hash; otherwise, <see langword="false"/>.</returns>
162-
public bool TryGetValue(UInt256 hash, [MaybeNullWhen(false)] out Transaction? tx)
162+
public bool TryGetValue(UInt256 hash, [NotNullWhen(true)] out Transaction? tx)
163163
{
164164
_txRwLock.EnterReadLock();
165165
try

src/Neo/Neo.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Akka" Version="1.5.20" />
12+
<PackageReference Include="Akka" Version="1.5.26" />
1313
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1" />
1414
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
1515
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
1616
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
1818
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
1919
</ItemGroup>
2020

@@ -30,6 +30,7 @@
3030
<InternalsVisibleTo Include="Neo.SmartContract.Testing" />
3131
<InternalsVisibleTo Include="Neo.SmartContract.TestEngine" />
3232
<InternalsVisibleTo Include="Neo.Plugins.RpcServer.Tests" />
33+
<InternalsVisibleTo Include="Neo.Plugins.OracleService.Tests" />
3334
</ItemGroup>
3435

3536
</Project>

src/Plugins/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ public ExtensiblePayload MakePrepareResponse()
166166
});
167167
}
168168

169+
// Related to issue https://github.com/neo-project/neo/issues/3431
170+
// Ref. https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator?view=net-8.0
171+
//
172+
//The System.Random class relies on a seed value that can be predictable,
173+
//especially if the seed is based on the system clock or other low-entropy sources.
174+
//RandomNumberGenerator, however, uses sources of entropy provided by the operating
175+
//system, which are designed to be unpredictable.
169176
private static ulong GetNonce()
170177
{
171-
Random _random = new();
172178
Span<byte> buffer = stackalloc byte[8];
173-
_random.NextBytes(buffer);
179+
using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())
180+
{
181+
rng.GetBytes(buffer);
182+
}
174183
return BinaryPrimitives.ReadUInt64LittleEndian(buffer);
175184
}
176185
}

src/Plugins/OracleService/OracleService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public JObject SubmitOracleResponse(JArray _params)
234234

235235
finishedCache.ContainsKey(requestId).False_Or(RpcError.OracleRequestFinished);
236236

237-
using (var snapshot = _system.GetSnapshot())
237+
using (var snapshot = _system.GetSnapshotCache())
238238
{
239239
uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
240240
var oracles = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.Oracle, height);
@@ -326,7 +326,7 @@ private async void ProcessRequestsAsync()
326326
{
327327
while (!cancelSource.IsCancellationRequested)
328328
{
329-
using (var snapshot = _system.GetSnapshot())
329+
using (var snapshot = _system.GetSnapshotCache())
330330
{
331331
SyncPendingQueue(snapshot);
332332
foreach (var (id, request) in NativeContract.Oracle.GetRequests(snapshot))

src/Plugins/RocksDBStore/RocksDBStore.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="rocksdb" Version="8.11.3.46984" />
11+
<PackageReference Include="rocksdb" Version="9.4.0.50294" />
1212
</ItemGroup>
1313

1414
</Project>

src/Plugins/RpcServer/RpcServer.Wallet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected virtual JToken GetWalletUnclaimedGas(JArray _params)
9797
CheckWallet();
9898
// Datoshi is the smallest unit of GAS, 1 GAS = 10^8 Datoshi
9999
BigInteger datoshi = BigInteger.Zero;
100-
using (var snapshot = system.GetSnapshot())
100+
using (var snapshot = system.GetSnapshotCache())
101101
{
102102
uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
103103
foreach (UInt160 account in wallet.GetAccounts().Select(p => p.ScriptHash))

src/Plugins/SQLiteWallet/SQLiteWallet.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
1313
</ItemGroup>
1414

1515
</Project>

src/Plugins/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public JToken GetNep11Properties(JArray _params)
283283

284284
using ScriptBuilder sb = new();
285285
sb.EmitDynamicCall(nep11Hash, "properties", CallFlags.ReadOnly, tokenId);
286-
using var snapshot = _neoSystem.GetSnapshot();
286+
using var snapshot = _neoSystem.GetSnapshotCache();
287287

288288
using var engine = ApplicationEngine.Run(sb.ToArray(), snapshot, settings: _neoSystem.Settings);
289289
JObject json = new();

tests/Neo.ConsoleService.Tests/Neo.ConsoleService.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
15-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
15+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1616
</ItemGroup>
1717

1818
</Project>

tests/Neo.Cryptography.BLS12_381.Tests/Neo.Cryptography.BLS12_381.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
15-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
16-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1717
</ItemGroup>
1818

1919
</Project>

tests/Neo.Cryptography.MPTTrie.Tests/Neo.Cryptography.MPTTrie.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
10-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
11-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
10+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
11+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

tests/Neo.Extensions.Tests/Neo.Extensions.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
10-
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
11-
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
10+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
11+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
15-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
15+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1616
</ItemGroup>
1717

1818
</Project>

tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
<ItemGroup>
99
<PackageReference Include="Moq" Version="4.20.70" />
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
12-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
12+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

tests/Neo.Plugins.OracleService.Tests/Neo.Plugins.OracleService.Tests.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Akka.TestKit" Version="1.5.20" />
11-
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.5.20" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
13-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
14-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
10+
<PackageReference Include="Akka.TestKit" Version="1.5.26" />
11+
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.5.26" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
13+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
14+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,45 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12+
using Akka.Actor;
13+
using Neo.Ledger;
1214
using Neo.Persistence;
1315
using System;
1416

1517
namespace Neo.Plugins.OracleService.Tests
1618
{
1719
public static class TestBlockchain
1820
{
19-
public static readonly NeoSystem TheNeoSystem;
21+
private static readonly NeoSystem s_theNeoSystem;
22+
private static readonly MemoryStore s_store = new();
23+
24+
private class StoreProvider : IStoreProvider
25+
{
26+
public string Name => "TestProvider";
27+
28+
public IStore GetStore(string path) => s_store;
29+
}
2030

2131
static TestBlockchain()
2232
{
2333
Console.WriteLine("initialize NeoSystem");
24-
TheNeoSystem = new NeoSystem(ProtocolSettings.Load("config.json"), new MemoryStoreProvider());
34+
s_theNeoSystem = new NeoSystem(ProtocolSettings.Load("config.json"), new StoreProvider());
2535
}
2636

2737
public static void InitializeMockNeoSystem()
2838
{
2939
}
3040

31-
internal static DataCache GetTestSnapshot()
41+
internal static void ResetStore()
42+
{
43+
s_store.Reset();
44+
s_theNeoSystem.Blockchain.Ask(new Blockchain.Initialize()).Wait();
45+
}
46+
47+
internal static SnapshotCache GetTestSnapshotCache()
3248
{
33-
return TheNeoSystem.GetSnapshotCache().CloneCache();
49+
ResetStore();
50+
return s_theNeoSystem.GetSnapshot();
3451
}
3552
}
3653
}

tests/Neo.Plugins.OracleService.Tests/UT_OracleService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void TestFilter()
7070
[TestMethod]
7171
public void TestCreateOracleResponseTx()
7272
{
73-
var snapshot = TestBlockchain.GetTestSnapshot();
73+
var snapshot = TestBlockchain.GetTestSnapshotCache();
7474

7575
var executionFactor = NativeContract.Policy.GetExecFeeFactor(snapshot);
7676
Assert.AreEqual(executionFactor, (uint)30);
@@ -85,7 +85,7 @@ public void TestCreateOracleResponseTx()
8585
Filter = "",
8686
CallbackContract = UInt160.Zero,
8787
CallbackMethod = "callback",
88-
UserData = System.Array.Empty<byte>()
88+
UserData = []
8989
};
9090
byte Prefix_Transaction = 11;
9191
snapshot.Add(NativeContract.Ledger.CreateStorageKey(Prefix_Transaction, request.OriginalTxid), new StorageItem(new TransactionState()

tests/Neo.Plugins.RpcServer.Tests/Neo.Plugins.RpcServer.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
1212
<PackageReference Include="Moq" Version="4.20.70" />
13-
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
14-
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
13+
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
14+
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void TestGetCandidates()
239239
var json = new JArray();
240240
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, _neoSystem.Settings.ValidatorsCount);
241241
snapshot.Commit();
242-
var candidates = NativeContract.NEO.GetCandidates(_neoSystem.GetSnapshot());
242+
var candidates = NativeContract.NEO.GetCandidates(_neoSystem.GetSnapshotCache());
243243

244244
foreach (var candidate in candidates)
245245
{
@@ -266,7 +266,7 @@ public void TestGetCommittee()
266266
public void TestGetNativeContracts()
267267
{
268268
var result = _rpcServer.GetNativeContracts(new JArray());
269-
var contracts = new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(_neoSystem.GetSnapshot(), p.Hash).ToJson()));
269+
var contracts = new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(_neoSystem.GetSnapshotCache(), p.Hash).ToJson()));
270270
Assert.AreEqual(contracts.ToString(), result.ToString());
271271
}
272272

0 commit comments

Comments
 (0)