Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[**Part-2**] Neo module/master fixes #3244

Merged
merged 43 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
40614dd
Moved `neo-modules` to `neo`
cschuchardt88 May 14, 2024
b1bad7c
Configured module projects
cschuchardt88 May 14, 2024
69c8ded
Configured Test Projects
cschuchardt88 May 14, 2024
5ffd0b1
Dotnet format
cschuchardt88 May 14, 2024
143db61
Update github workflow for tests
cschuchardt88 May 14, 2024
fc17bed
removed dupes in `.editorconfig`
cschuchardt88 May 14, 2024
c66a438
remove dupe file
cschuchardt88 May 14, 2024
d185b7a
Fixed waarning
cschuchardt88 May 14, 2024
0453f0a
fixed `macOS` workflow for leveldb
cschuchardt88 May 14, 2024
4e9f0d8
Added `EXCLUDED_TESTS` for `Neo.Plugins.Storage` on `macOS` and `Wind…
cschuchardt88 May 14, 2024
483c831
Fixed workflow tests for `windows`
cschuchardt88 May 14, 2024
3902acf
Fixed `char` ecsape for tests on `windows`
cschuchardt88 May 14, 2024
e354cbd
Fixed tests
cschuchardt88 May 14, 2024
71105dd
Fixed tests
cschuchardt88 May 14, 2024
e13b8a2
Apply suggestions from code review
shargon May 14, 2024
79fe63f
Apply suggestions from code review
shargon May 14, 2024
f80b145
Update .editorconfig
cschuchardt88 May 14, 2024
3289c9c
Update .editorconfig
cschuchardt88 May 14, 2024
9e3017b
Changed for @vncoelho request
cschuchardt88 May 16, 2024
cac59ae
Merge branch 'neo-module/master' of https://github.com/cschuchardt88/…
cschuchardt88 May 16, 2024
5871878
Merge branch 'master' into neo-module/master
cschuchardt88 May 16, 2024
d8fc1c4
Added @vncoelho changes
cschuchardt88 May 16, 2024
b728ef3
Merge branch 'neo-module/master' of https://github.com/cschuchardt88/…
cschuchardt88 May 16, 2024
cb014ff
Moved `RpcClient` to `src\plugins`
cschuchardt88 May 17, 2024
2144e0b
fixed rpc tests
cschuchardt88 May 18, 2024
19502d9
Merge branch 'master' into neo-module/master
shargon May 20, 2024
4db6165
Update .github/workflows/main.yml
cschuchardt88 May 20, 2024
81ad31a
Update .github/workflows/main.yml
cschuchardt88 May 20, 2024
68e4146
Update .github/workflows/main.yml
cschuchardt88 May 20, 2024
a50cf5a
Plugin fixes for `configuration` files
cschuchardt88 May 20, 2024
58a28f6
Merge branch 'master' into neo-module/master-fixes
vncoelho May 20, 2024
174159d
Renamed file extensions from `config` to `json`
cschuchardt88 May 20, 2024
fbc3ac9
Merge branch 'neo-module/master-fixes' of https://github.com/cschucha…
cschuchardt88 May 20, 2024
97d2f52
removed dev files
cschuchardt88 May 20, 2024
fd7cfef
Merge branch 'master' into neo-module/master-fixes
cschuchardt88 May 21, 2024
55702f6
dotnet format
cschuchardt88 May 21, 2024
14c23e0
Deleted old `config.json` files
cschuchardt88 May 22, 2024
d6b1e0b
Renamed `system` to `_system`
cschuchardt88 May 22, 2024
91ed6d4
Merge branch 'master' into neo-module/master-fixes
vncoelho May 22, 2024
4be3144
Merge branch 'master' into neo-module/master-fixes
shargon May 22, 2024
81aba7e
PreserveNewest instead of always
shargon May 22, 2024
387a3ce
Merge branch 'master' into neo-module/master-fixes
vncoelho May 22, 2024
678d459
Merge branch 'master' into neo-module/master-fixes
shargon May 22, 2024
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
5 changes: 5 additions & 0 deletions src/Plugins/ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Update="ApplicationLogs.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/Plugins/ApplicationLogs/ApplicationLogs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"PluginConfiguration": {
"Path": "ApplicationLogs_{0}",
"Network": 860833102,
"MaxStackSize": 65535,
"Debug": false
},
"Dependency": [
"RpcServer"
]
}
4 changes: 3 additions & 1 deletion src/Plugins/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LogReader : Plugin
#endregion

public override string Name => "ApplicationLogs";
public override string Description => "Synchronizes smart contract VM executions and notificatons (NotifyLog) on blockchain.";
public override string Description => "Synchronizes smart contract VM executions and notifications (NotifyLog) on blockchain.";

#region Ctor

Expand All @@ -51,6 +51,8 @@ public LogReader()

#region Override Methods

public override string ConfigFile => Combine(RootPath, "ApplicationLogs.json");

public override void Dispose()
{
Blockchain.Committing -= OnCommitting;
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/DBFTPlugin/DBFTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class DBFTPlugin : Plugin

public override string Description => "Consensus plugin with dBFT algorithm.";

public override string ConfigFile => System.IO.Path.Combine(RootPath, "DBFTPlugin.json");

public DBFTPlugin()
{
RemoteNode.MessageReceived += RemoteNode_MessageReceived;
Expand Down
6 changes: 6 additions & 0 deletions src/Plugins/DBFTPlugin/DBFTPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
<ProjectReference Include="..\..\Neo.ConsoleService\Neo.ConsoleService.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="DBFTPlugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions src/Plugins/DBFTPlugin/DBFTPlugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"PluginConfiguration": {
"RecoveryLogs": "ConsensusState",
"IgnoreRecoveryLogs": false,
"AutoStart": false,
"Network": 860833102,
"MaxBlockSize": 2097152,
"MaxBlockSystemFee": 150000000000
}
}
6 changes: 0 additions & 6 deletions src/Plugins/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@
<ProjectReference Include="..\..\Neo\Neo.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="config.json" Condition="Exists('config.json')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
36 changes: 20 additions & 16 deletions src/Plugins/OracleService/OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public class OracleService : Plugin
private OracleStatus status = OracleStatus.Unstarted;
private IWalletProvider walletProvider;
private int counter;
private NeoSystem System;
private NeoSystem system;
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved

private readonly Dictionary<string, IOracleProtocol> protocols = new Dictionary<string, IOracleProtocol>();

public override string Description => "Built-in oracle plugin";

public override string ConfigFile => System.IO.Path.Combine(RootPath, "OracleService.json");

public OracleService()
{
Blockchain.Committing += OnCommitting;
Expand All @@ -75,8 +77,8 @@ protected override void Configure()
protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Network != Settings.Default.Network) return;
System = system;
System.ServiceAdded += NeoSystem_ServiceAdded;
this.system = system;
this.system.ServiceAdded += NeoSystem_ServiceAdded;
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
}

Expand All @@ -85,7 +87,7 @@ private void NeoSystem_ServiceAdded(object sender, object service)
if (service is IWalletProvider)
{
walletProvider = service as IWalletProvider;
System.ServiceAdded -= NeoSystem_ServiceAdded;
system.ServiceAdded -= NeoSystem_ServiceAdded;
if (Settings.Default.AutoStart)
{
walletProvider.WalletChanged += WalletProvider_WalletChanged;
Expand Down Expand Up @@ -124,7 +126,8 @@ public void Start(Wallet wallet)
ConsoleHelper.Warning("Please open wallet first!");
return;
}
if (!CheckOracleAvaiblable(System.StoreView, out ECPoint[] oracles))

if (!CheckOracleAvaiblable(system.StoreView, out ECPoint[] oracles))
{
ConsoleHelper.Warning("The oracle service is unavailable");
return;
Expand Down Expand Up @@ -228,7 +231,7 @@ public JObject SubmitOracleResponse(JArray _params)

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

using (var snapshot = System.GetSnapshot())
using (var snapshot = system.GetSnapshot())
{
uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
var oracles = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.Oracle, height);
Expand Down Expand Up @@ -292,8 +295,8 @@ private async Task ProcessRequestAsync(DataCache snapshot, OracleRequest req)
}
}
var response = new OracleResponse() { Id = requestId, Code = code, Result = result };
var responseTx = CreateResponseTx(snapshot, request, response, oracleNodes, System.Settings);
var backupTx = CreateResponseTx(snapshot, request, new OracleResponse() { Code = OracleResponseCode.ConsensusUnreachable, Id = requestId, Result = Array.Empty<byte>() }, oracleNodes, System.Settings, true);
var responseTx = CreateResponseTx(snapshot, request, response, oracleNodes, system.Settings);
var backupTx = CreateResponseTx(snapshot, request, new OracleResponse() { Code = OracleResponseCode.ConsensusUnreachable, Id = requestId, Result = Array.Empty<byte>() }, oracleNodes, system.Settings, true);

Log($"[{req.OriginalTxid}]-({requestId}) Built response tx[[{responseTx.Hash}]], responseCode:{code}, result:{result.ToHexString()}, validUntilBlock:{responseTx.ValidUntilBlock}, backupTx:{backupTx.Hash}-{backupTx.ValidUntilBlock}");

Expand All @@ -304,8 +307,9 @@ private async Task ProcessRequestAsync(DataCache snapshot, OracleRequest req)
var oraclePub = account.GetKey()?.PublicKey;
if (!account.HasKey || account.Lock || !oraclePublicKeys.Contains(oraclePub)) continue;

var txSign = responseTx.Sign(account.GetKey(), System.Settings.Network);
var backTxSign = backupTx.Sign(account.GetKey(), System.Settings.Network);
var txSign = responseTx.Sign(account.GetKey(), system.Settings.Network);
var backTxSign = backupTx.Sign(account.GetKey(), system.Settings.Network);

AddResponseTxSign(snapshot, requestId, oraclePub, txSign, responseTx, backupTx, backTxSign);
tasks.Add(SendResponseSignatureAsync(requestId, txSign, account.GetKey()));

Expand All @@ -319,7 +323,7 @@ private async void ProcessRequestsAsync()
{
while (!cancelSource.IsCancellationRequested)
{
using (var snapshot = System.GetSnapshot())
using (var snapshot = system.GetSnapshot())
{
SyncPendingQueue(snapshot);
foreach (var (id, request) in NativeContract.Oracle.GetRequests(snapshot))
Expand Down Expand Up @@ -473,13 +477,13 @@ private void AddResponseTxSign(DataCache snapshot, ulong requestId, ECPoint orac
if (responseTx != null)
{
task.Tx = responseTx;
var data = task.Tx.GetSignData(System.Settings.Network);
var data = task.Tx.GetSignData(system.Settings.Network);
task.Signs.Where(p => !Crypto.VerifySignature(data, p.Value, p.Key)).ForEach(p => task.Signs.Remove(p.Key, out _));
}
if (backupTx != null)
{
task.BackupTx = backupTx;
var data = task.BackupTx.GetSignData(System.Settings.Network);
var data = task.BackupTx.GetSignData(system.Settings.Network);
task.BackupSigns.Where(p => !Crypto.VerifySignature(data, p.Value, p.Key)).ForEach(p => task.BackupSigns.Remove(p.Key, out _));
task.BackupSigns.TryAdd(oraclePub, backupSign);
}
Expand All @@ -490,9 +494,9 @@ private void AddResponseTxSign(DataCache snapshot, ulong requestId, ECPoint orac
return;
}

if (Crypto.VerifySignature(task.Tx.GetSignData(System.Settings.Network), sign, oraclePub))
if (Crypto.VerifySignature(task.Tx.GetSignData(system.Settings.Network), sign, oraclePub))
task.Signs.TryAdd(oraclePub, sign);
else if (Crypto.VerifySignature(task.BackupTx.GetSignData(System.Settings.Network), sign, oraclePub))
else if (Crypto.VerifySignature(task.BackupTx.GetSignData(system.Settings.Network), sign, oraclePub))
task.BackupSigns.TryAdd(oraclePub, sign);
else
throw new RpcException(RpcErrorFactory.InvalidSignature($"Invalid oracle response transaction signature from '{oraclePub}'."));
Expand Down Expand Up @@ -537,7 +541,7 @@ private bool CheckTxSign(DataCache snapshot, Transaction tx, ConcurrentDictionar

Log($"Send response tx: responseTx={tx.Hash}");

System.Blockchain.Tell(tx);
system.Blockchain.Tell(tx);
return true;
}
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/Plugins/OracleService/OracleService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
</ProjectReference>
</ItemGroup>

<ItemGroup>
<None Update="OracleService.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions src/Plugins/OracleService/OracleService.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"PluginConfiguration": {
"Network": 860833102,
"Nodes": [],
"MaxTaskTimeout": 432000000,
"MaxOracleTimeout": 10000,
"AllowPrivateHost": false,
"AllowedContentTypes": [ "application/json" ],
"Https": {
"Timeout": 5000
},
"NeoFS": {
"EndPoint": "http://127.0.0.1:8080",
"Timeout": 15000
},
"AutoStart": false
},
"Dependency": [
"RpcServer"
]
}
6 changes: 6 additions & 0 deletions src/Plugins/RpcServer/RpcServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<None Update="RpcServer.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/Plugins/RpcServer/RpcServer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"PluginConfiguration": {
"Servers": [
{
"Network": 860833102,
"BindAddress": "127.0.0.1",
"Port": 10332,
"SslCert": "",
"SslCertPassword": "",
"TrustedAuthorities": [],
"RpcUser": "",
"RpcPass": "",
"EnableCors": true,
"AllowOrigins": [],
"KeepAliveTimeout": 60,
"RequestHeadersTimeout": 15,
"MaxGasInvoke": 20,
"MaxFee": 0.1,
"MaxConcurrentConnections": 40,
"MaxIteratorResultItems": 100,
"MaxStackSize": 65535,
"DisabledMethods": [ "openwallet" ],
"SessionEnabled": false,
"SessionExpirationTime": 60,
"FindStoragePageSize": 50
}
]
}
}
2 changes: 2 additions & 0 deletions src/Plugins/RpcServer/RpcServerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class RpcServerPlugin : Plugin
private static readonly Dictionary<uint, RpcServer> servers = new();
private static readonly Dictionary<uint, List<object>> handlers = new();

public override string ConfigFile => System.IO.Path.Combine(RootPath, "RpcServer.json");

protected override void Configure()
{
settings = new Settings(GetConfiguration());
Expand Down
25 changes: 13 additions & 12 deletions src/Plugins/StateService/StatePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public class StatePlugin : Plugin
public const string StatePayloadCategory = "StateService";
public override string Name => "StateService";
public override string Description => "Enables MPT for the node";
public override string ConfigFile => System.IO.Path.Combine(RootPath, "StateService.json");

internal IActorRef Store;
internal IActorRef Verifier;

internal static NeoSystem System;
internal static NeoSystem system;
cschuchardt88 marked this conversation as resolved.
Show resolved Hide resolved
private IWalletProvider walletProvider;

public StatePlugin()
Expand All @@ -58,9 +59,9 @@ protected override void Configure()
protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Network != Settings.Default.Network) return;
System = system;
Store = System.ActorSystem.ActorOf(StateStore.Props(this, string.Format(Settings.Default.Path, system.Settings.Network.ToString("X8"))));
System.ServiceAdded += NeoSystem_ServiceAdded;
StatePlugin.system = system;
Store = StatePlugin.system.ActorSystem.ActorOf(StateStore.Props(this, string.Format(Settings.Default.Path, system.Settings.Network.ToString("X8"))));
StatePlugin.system.ServiceAdded += NeoSystem_ServiceAdded;
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
}

Expand All @@ -69,7 +70,7 @@ private void NeoSystem_ServiceAdded(object sender, object service)
if (service is IWalletProvider)
{
walletProvider = service as IWalletProvider;
System.ServiceAdded -= NeoSystem_ServiceAdded;
system.ServiceAdded -= NeoSystem_ServiceAdded;
if (Settings.Default.AutoVerify)
{
walletProvider.WalletChanged += WalletProvider_WalletChanged;
Expand All @@ -88,8 +89,8 @@ public override void Dispose()
base.Dispose();
Blockchain.Committing -= OnCommitting;
Blockchain.Committed -= OnCommitted;
if (Store is not null) System.EnsureStopped(Store);
if (Verifier is not null) System.EnsureStopped(Verifier);
if (Store is not null) system.EnsureStopped(Store);
if (Verifier is not null) system.EnsureStopped(Verifier);
}

private void OnCommitting(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<ApplicationExecuted> applicationExecutedList)
Expand All @@ -107,7 +108,7 @@ private void OnCommitted(NeoSystem system, Block block)
[ConsoleCommand("start states", Category = "StateService", Description = "Start as a state verifier if wallet is open")]
private void OnStartVerifyingState()
{
if (System is null || System.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
if (system is null || system.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
Start(walletProvider.GetWallet());
}

Expand All @@ -123,13 +124,13 @@ public void Start(Wallet wallet)
ConsoleHelper.Warning("Please open wallet first!");
return;
}
Verifier = System.ActorSystem.ActorOf(VerificationService.Props(wallet));
Verifier = system.ActorSystem.ActorOf(VerificationService.Props(wallet));
}

[ConsoleCommand("state root", Category = "StateService", Description = "Get state root by index")]
private void OnGetStateRoot(uint index)
{
if (System is null || System.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
if (system is null || system.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
using var snapshot = StateStore.Singleton.GetSnapshot();
StateRoot state_root = snapshot.GetStateRoot(index);
if (state_root is null)
Expand All @@ -141,7 +142,7 @@ private void OnGetStateRoot(uint index)
[ConsoleCommand("state height", Category = "StateService", Description = "Get current state root index")]
private void OnGetStateHeight()
{
if (System is null || System.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
if (system is null || system.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
ConsoleHelper.Info("LocalRootIndex: ",
$"{StateStore.Singleton.LocalRootIndex}",
" ValidatedRootIndex: ",
Expand All @@ -151,7 +152,7 @@ private void OnGetStateHeight()
[ConsoleCommand("get proof", Category = "StateService", Description = "Get proof of key and contract hash")]
private void OnGetProof(UInt256 root_hash, UInt160 script_hash, string key)
{
if (System is null || System.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
if (system is null || system.Settings.Network != Settings.Default.Network) throw new InvalidOperationException("Network doesn't match");
try
{
ConsoleHelper.Info("Proof: ", GetProof(root_hash, script_hash, Convert.FromBase64String(key)));
Expand Down
6 changes: 6 additions & 0 deletions src/Plugins/StateService/StateService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<ProjectReference Include="..\RpcServer\RpcServer.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="StateService.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading
Loading