Skip to content

Commit

Permalink
Merge branch 'master' into dbft3.0-doublespeakers
Browse files Browse the repository at this point in the history
  • Loading branch information
vncoelho authored May 22, 2024
2 parents e84e4a0 + 12565cc commit 20d0b49
Show file tree
Hide file tree
Showing 42 changed files with 138 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</PropertyGroup>

<ItemGroup>
<None Include="../../.neo/neo.png" Pack="true" Visible="false" PackagePath=""/>
<None Include="../../.neo/README.md" Pack="true" Visible="false" PackagePath=""/>
<None Include="$(SolutionDir)/.neo/neo.png" Pack="true" Visible="false" PackagePath=""/>
<None Include="$(SolutionDir)/.neo/README.md" Pack="true" Visible="false" PackagePath=""/>
</ItemGroup>

<ItemGroup>
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 @@ -7,7 +7,7 @@
</PropertyGroup>

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

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Neo/Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.5.18" />
<PackageReference Include="Akka" Version="1.5.20" />
<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" />
Expand Down
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>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
File renamed without changes.
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>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
File renamed without changes.
10 changes: 2 additions & 8 deletions src/Plugins/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<None Include="../../../.neo/neo.png" Pack="true" Visible="false" PackagePath=""/>
<None Include="../../../.neo/README.md" Pack="true" Visible="false" PackagePath=""/>
<None Include="$(SolutionDir)/.neo/neo.png" Pack="true" Visible="false" PackagePath=""/>
<None Include="$(SolutionDir)/.neo/README.md" Pack="true" Visible="false" PackagePath=""/>
</ItemGroup>

<ItemGroup>
<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;

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;
_system = system;
_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>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
File renamed without changes.
8 changes: 7 additions & 1 deletion src/Plugins/RpcServer/RpcServer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
Expand All @@ -9,4 +9,10 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

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

</Project>
File renamed without changes.
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
2 changes: 1 addition & 1 deletion src/Plugins/SQLiteWallet/SQLiteWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

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

</Project>
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;
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;
_system = system;
Store = _system.ActorSystem.ActorOf(StateStore.Props(this, string.Format(Settings.Default.Path, system.Settings.Network.ToString("X8"))));
_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>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
File renamed without changes.
6 changes: 3 additions & 3 deletions src/Plugins/StateService/Storage/StateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public StateStore(StatePlugin system, string path)
{
if (singleton != null) throw new InvalidOperationException(nameof(StateStore));
this.system = system;
store = StatePlugin.System.LoadStore(path);
store = StatePlugin._system.LoadStore(path);
singleton = this;
StatePlugin.System.ActorSystem.EventStream.Subscribe(Self, typeof(Blockchain.RelayResult));
StatePlugin._system.ActorSystem.EventStream.Subscribe(Self, typeof(Blockchain.RelayResult));
UpdateCurrentSnapshot();
}

Expand Down Expand Up @@ -114,7 +114,7 @@ private bool OnNewStateRoot(StateRoot state_root)
using var state_snapshot = Singleton.GetSnapshot();
StateRoot local_root = state_snapshot.GetStateRoot(state_root.Index);
if (local_root is null || local_root.Witness != null) return false;
if (!state_root.Verify(StatePlugin.System.Settings, StatePlugin.System.StoreView)) return false;
if (!state_root.Verify(StatePlugin._system.Settings, StatePlugin._system.StoreView)) return false;
if (local_root.RootHash != state_root.RootHash) return false;
state_snapshot.AddValidatedStateRoot(state_root);
state_snapshot.Commit();
Expand Down
Loading

0 comments on commit 20d0b49

Please sign in to comment.