Skip to content

Commit

Permalink
Merge branch 'master' into standardize-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Jul 23, 2024
2 parents c5719a3 + 21765dc commit 3285c9a
Show file tree
Hide file tree
Showing 61 changed files with 420 additions and 383 deletions.
2 changes: 1 addition & 1 deletion src/Neo.CLI/CLI/MainService.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void OnShowBlockCommand(string indexOrHash)
ConsoleHelper.Info("", " PrevHash: ", $"{block.PrevHash}");
ConsoleHelper.Info("", " NextConsensus: ", $"{block.NextConsensus}");
ConsoleHelper.Info("", " PrimaryIndex: ", $"{block.PrimaryIndex}");
ConsoleHelper.Info("", " PrimaryPubKey: ", $"{NativeContract.NEO.GetCommittee(NeoSystem.GetSnapshot())[block.PrimaryIndex]}");
ConsoleHelper.Info("", " PrimaryPubKey: ", $"{NativeContract.NEO.GetCommittee(NeoSystem.GetSnapshotCache())[block.PrimaryIndex]}");
ConsoleHelper.Info("", " Version: ", $"{block.Version}");
ConsoleHelper.Info("", " Size: ", $"{block.Size} Byte(s)");
ConsoleHelper.Info();
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.CLI/CLI/MainService.Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void OnBroadcastInvCommand(InventoryType type, UInt256[] payload)
[ConsoleCommand("broadcast transaction", Category = "Network Commands")]
private void OnBroadcastTransactionCommand(UInt256 hash)
{
if (NeoSystem.MemPool.TryGetValue(hash, out Transaction tx))
if (NeoSystem.MemPool.TryGetValue(hash, out var tx))
OnBroadcastCommand(MessageCommand.Transaction, tx);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Neo.CLI/CLI/MainService.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ private void OnCancelCommand(UInt256 txid, UInt160? sender = null, UInt160[]? si
return;
}

if (NeoSystem.MemPool.TryGetValue(txid, out Transaction conflictTx))
if (NeoSystem.MemPool.TryGetValue(txid, out var conflictTx))
{
tx.NetworkFee = Math.Max(tx.NetworkFee, conflictTx.NetworkFee) + 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.CLI/config.fs.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"MillisecondsPerBlock": 15000,
"MaxTransactionsPerBlock": 512,
"MemoryPoolMaxTransactions": 50000,
"MaxTraceableBlocks": 2102400,
"MaxTraceableBlocks": 17280,
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
"Hardforks": {
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.CLI/config.fs.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"MillisecondsPerBlock": 15000,
"MaxTransactionsPerBlock": 512,
"MemoryPoolMaxTransactions": 50000,
"MaxTraceableBlocks": 2102400,
"MaxTraceableBlocks": 17280,
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
"StandbyCommittee": [
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Extensions/Neo.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.5.20" />
<PackageReference Include="Akka" Version="1.5.26" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public bool ContainsKey(UInt256 hash)
/// <param name="hash">The hash of the <see cref="Transaction"/> to get.</param>
/// <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>
/// <returns><see langword="true"/> if the <see cref="MemoryPool"/> contains a <see cref="Transaction"/> with the specified hash; otherwise, <see langword="false"/>.</returns>
public bool TryGetValue(UInt256 hash, [MaybeNullWhen(false)] out Transaction? tx)
public bool TryGetValue(UInt256 hash, [NotNullWhen(true)] out Transaction? tx)
{
_txRwLock.EnterReadLock();
try
Expand Down
5 changes: 3 additions & 2 deletions src/Neo/Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.5.20" />
<PackageReference Include="Akka" Version="1.5.26" />
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
</ItemGroup>

Expand All @@ -30,6 +30,7 @@
<InternalsVisibleTo Include="Neo.SmartContract.Testing" />
<InternalsVisibleTo Include="Neo.SmartContract.TestEngine" />
<InternalsVisibleTo Include="Neo.Plugins.RpcServer.Tests" />
<InternalsVisibleTo Include="Neo.Plugins.OracleService.Tests" />
</ItemGroup>

</Project>
13 changes: 11 additions & 2 deletions src/Plugins/DBFTPlugin/Consensus/ConsensusContext.MakePayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ public ExtensiblePayload MakePrepareResponse()
});
}

// Related to issue https://github.com/neo-project/neo/issues/3431
// Ref. https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator?view=net-8.0
//
//The System.Random class relies on a seed value that can be predictable,
//especially if the seed is based on the system clock or other low-entropy sources.
//RandomNumberGenerator, however, uses sources of entropy provided by the operating
//system, which are designed to be unpredictable.
private static ulong GetNonce()
{
Random _random = new();
Span<byte> buffer = stackalloc byte[8];
_random.NextBytes(buffer);
using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())
{
rng.GetBytes(buffer);
}
return BinaryPrimitives.ReadUInt64LittleEndian(buffer);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/OracleService/OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public JObject SubmitOracleResponse(JArray _params)

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

using (var snapshot = _system.GetSnapshot())
using (var snapshot = _system.GetSnapshotCache())
{
uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
var oracles = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.Oracle, height);
Expand Down Expand Up @@ -326,7 +326,7 @@ private async void ProcessRequestsAsync()
{
while (!cancelSource.IsCancellationRequested)
{
using (var snapshot = _system.GetSnapshot())
using (var snapshot = _system.GetSnapshotCache())
{
SyncPendingQueue(snapshot);
foreach (var (id, request) in NativeContract.Oracle.GetRequests(snapshot))
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/RocksDBStore/RocksDBStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="rocksdb" Version="8.11.3.46984" />
<PackageReference Include="rocksdb" Version="9.4.0.50294" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Plugins/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected virtual JToken GetWalletUnclaimedGas(JArray _params)
CheckWallet();
// Datoshi is the smallest unit of GAS, 1 GAS = 10^8 Datoshi
BigInteger datoshi = BigInteger.Zero;
using (var snapshot = system.GetSnapshot())
using (var snapshot = system.GetSnapshotCache())
{
uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
foreach (UInt160 account in wallet.GetAccounts().Select(p => p.ScriptHash))
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/SQLiteWallet/SQLiteWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Plugins/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public JToken GetNep11Properties(JArray _params)

using ScriptBuilder sb = new();
sb.EmitDynamicCall(nep11Hash, "properties", CallFlags.ReadOnly, tokenId);
using var snapshot = _neoSystem.GetSnapshot();
using var snapshot = _neoSystem.GetSnapshotCache();

using var engine = ApplicationEngine.Run(sb.ToArray(), snapshot, settings: _neoSystem.Settings);
JObject json = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions tests/Neo.Extensions.Tests/Neo.Extensions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions tests/Neo.Json.UnitTests/Neo.Json.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.TestKit" Version="1.5.20" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.5.20" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Akka.TestKit" Version="1.5.26" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.5.26" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions tests/Neo.Plugins.OracleService.Tests/TestBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,45 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using Akka.Actor;
using Neo.Ledger;
using Neo.Persistence;
using System;

namespace Neo.Plugins.OracleService.Tests
{
public static class TestBlockchain
{
public static readonly NeoSystem TheNeoSystem;
private static readonly NeoSystem s_theNeoSystem;
private static readonly MemoryStore s_store = new();

private class StoreProvider : IStoreProvider
{
public string Name => "TestProvider";

public IStore GetStore(string path) => s_store;
}

static TestBlockchain()
{
Console.WriteLine("initialize NeoSystem");
TheNeoSystem = new NeoSystem(ProtocolSettings.Load("config.json"), new MemoryStoreProvider());
s_theNeoSystem = new NeoSystem(ProtocolSettings.Load("config.json"), new StoreProvider());
}

public static void InitializeMockNeoSystem()
{
}

internal static DataCache GetTestSnapshot()
internal static void ResetStore()
{
s_store.Reset();
s_theNeoSystem.Blockchain.Ask(new Blockchain.Initialize()).Wait();
}

internal static SnapshotCache GetTestSnapshotCache()
{
return TheNeoSystem.GetSnapshotCache().CloneCache();
ResetStore();
return s_theNeoSystem.GetSnapshot();
}
}
}
4 changes: 2 additions & 2 deletions tests/Neo.Plugins.OracleService.Tests/UT_OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void TestFilter()
[TestMethod]
public void TestCreateOracleResponseTx()
{
var snapshot = TestBlockchain.GetTestSnapshot();
var snapshot = TestBlockchain.GetTestSnapshotCache();

var executionFactor = NativeContract.Policy.GetExecFeeFactor(snapshot);
Assert.AreEqual(executionFactor, (uint)30);
Expand All @@ -85,7 +85,7 @@ public void TestCreateOracleResponseTx()
Filter = "",
CallbackContract = UInt160.Zero,
CallbackMethod = "callback",
UserData = System.Array.Empty<byte>()
UserData = []
};
byte Prefix_Transaction = 11;
snapshot.Add(NativeContract.Ledger.CreateStorageKey(Prefix_Transaction, request.OriginalTxid), new StorageItem(new TransactionState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions tests/Neo.Plugins.RpcServer.Tests/UT_RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void TestGetCandidates()
var json = new JArray();
var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, _neoSystem.Settings.ValidatorsCount);
snapshot.Commit();
var candidates = NativeContract.NEO.GetCandidates(_neoSystem.GetSnapshot());
var candidates = NativeContract.NEO.GetCandidates(_neoSystem.GetSnapshotCache());

foreach (var candidate in candidates)
{
Expand All @@ -266,7 +266,7 @@ public void TestGetCommittee()
public void TestGetNativeContracts()
{
var result = _rpcServer.GetNativeContracts(new JArray());
var contracts = new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(_neoSystem.GetSnapshot(), p.Hash).ToJson()));
var contracts = new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(_neoSystem.GetSnapshotCache(), p.Hash).ToJson()));
Assert.AreEqual(contracts.ToString(), result.ToString());
}

Expand Down
Loading

0 comments on commit 3285c9a

Please sign in to comment.