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

Sync to Neov3.0.0-CI01257 #576

Merged
merged 4 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/ApplicationLogs/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList<Blockchain.Appli

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;

WriteBatch writeBatch = new WriteBatch();

Expand Down
6 changes: 3 additions & 3 deletions src/DBFTPlugin/ConsensusContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Block CreateBlock()
{
EnsureHeader();
Contract contract = Contract.CreateMultiSigContract(M, Validators);
ContractParametersContext sc = new ContractParametersContext(neoSystem.StoreView, Block.Header);
ContractParametersContext sc = new ContractParametersContext(neoSystem.StoreView, Block.Header, dbftSettings.Network);
for (int i = 0, j = 0; i < Validators.Length && j < M; i++)
{
if (GetMessage(CommitPayloads[i])?.ViewNumber != ViewNumber) continue;
Expand Down Expand Up @@ -269,7 +269,7 @@ public ExtensiblePayload MakeCommit()
{
return CommitPayloads[MyIndex] ?? (CommitPayloads[MyIndex] = MakeSignedPayload(new Commit
{
Signature = EnsureHeader().Sign(keyPair, neoSystem.Settings.Magic)
Signature = EnsureHeader().Sign(keyPair, neoSystem.Settings.Network)
}));
}

Expand All @@ -288,7 +288,7 @@ private void SignPayload(ExtensiblePayload payload)
ContractParametersContext sc;
try
{
sc = new ContractParametersContext(neoSystem.StoreView, payload);
sc = new ContractParametersContext(neoSystem.StoreView, payload, dbftSettings.Network);
wallet.Sign(sc);
}
catch (InvalidOperationException)
Expand Down
4 changes: 2 additions & 2 deletions src/DBFTPlugin/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void OnCommitReceived(ExtensiblePayload payload, Commit commit)
{
Log($"{nameof(OnCommitReceived)}: height={commit.BlockIndex} view={commit.ViewNumber} index={commit.ValidatorIndex} nc={context.CountCommitted} nf={context.CountFailed}");

byte[] hashData = context.EnsureHeader()?.GetSignData(neoSystem.Settings.Magic);
byte[] hashData = context.EnsureHeader()?.GetSignData(neoSystem.Settings.Network);
if (hashData == null)
{
existingCommitPayload = payload;
Expand Down Expand Up @@ -442,7 +442,7 @@ private void OnPrepareRequestReceived(ExtensiblePayload payload, PrepareRequest
if (!context.GetMessage<PrepareResponse>(context.PreparationPayloads[i]).PreparationHash.Equals(payload.Hash))
context.PreparationPayloads[i] = null;
context.PreparationPayloads[message.ValidatorIndex] = payload;
byte[] hashData = context.EnsureHeader().GetSignData(neoSystem.Settings.Magic);
byte[] hashData = context.EnsureHeader().GetSignData(neoSystem.Settings.Network);
for (int i = 0; i < context.CommitPayloads.Length; i++)
if (context.GetMessage(context.CommitPayloads[i])?.ViewNumber == context.ViewNumber)
if (!Crypto.VerifySignature(hashData, context.GetMessage<Commit>(context.CommitPayloads[i]).Signature, context.Validators[i]))
Expand Down
2 changes: 1 addition & 1 deletion src/DBFTPlugin/DBFTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != settings.Network) return;
if (system.Settings.Network != settings.Network) return;
neoSystem = system;
neoSystem.ServiceAdded += NeoSystem_ServiceAdded;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI01252" />
<PackageReference Include="Neo" Version="3.0.0-CI01257" />
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions src/OracleService/OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
System = system;
System.ServiceAdded += NeoSystem_ServiceAdded;
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network);
Expand Down Expand Up @@ -139,7 +139,7 @@ private void OnStop()

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
if (stopped || !started) return;
if (!CheckOracleAvaiblable(snapshot, out ECPoint[] oracles) || !CheckOracleAccount(wallet, oracles))
OnStop();
Expand Down Expand Up @@ -270,8 +270,8 @@ 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.Magic);
var backTxSign = backupTx.Sign(account.GetKey(), System.Settings.Magic);
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 Down Expand Up @@ -417,13 +417,13 @@ private void AddResponseTxSign(DataCache snapshot, ulong requestId, ECPoint orac
if (responseTx != null)
{
task.Tx = responseTx;
var data = task.Tx.GetSignData(System.Settings.Magic);
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.Magic);
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 @@ -434,9 +434,9 @@ private void AddResponseTxSign(DataCache snapshot, ulong requestId, ECPoint orac
return;
}

if (Crypto.VerifySignature(task.Tx.GetSignData(System.Settings.Magic), 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.Magic), sign, oraclePub))
else if (Crypto.VerifySignature(task.BackupTx.GetSignData(System.Settings.Network), sign, oraclePub))
task.BackupSigns.TryAdd(oraclePub, sign);
else
throw new RpcException(-100, "Invalid response transaction sign");
Expand Down
4 changes: 2 additions & 2 deletions src/RpcClient/TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private class SignItem { public Contract Contract; public HashSet<KeyPair> KeyPa
public TransactionManager(Transaction tx, RpcClient rpcClient)
{
this.tx = tx;
this.context = new ContractParametersContext(null, tx);
this.context = new ContractParametersContext(null, tx, rpcClient.protocolSettings.Network);
this.rpcClient = rpcClient;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task<Transaction> SignAsync()
{
foreach (var key in signStore[i].KeyPairs)
{
byte[] signature = Tx.Sign(key, rpcClient.protocolSettings.Magic);
byte[] signature = Tx.Sign(key, rpcClient.protocolSettings.Network);
if (!context.AddSignature(signStore[i].Contract, key.PublicKey, signature))
{
throw new Exception("AddSignature failed!");
Expand Down
8 changes: 4 additions & 4 deletions src/RpcNep17Tracker/RpcNep17Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class RpcNep17Tracker : Plugin, IPersistencePlugin

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != _network) return;
if (system.Settings.Network != _network) return;
System = system;
string path = string.Format(_dbPath, system.Settings.Magic.ToString("X8"));
string path = string.Format(_dbPath, system.Settings.Network.ToString("X8"));
_db = DB.Open(GetFullPath(path), new Options { CreateIfMissing = true });
RpcServerPlugin.RegisterMethods(this, _network);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ private void HandleNotification(DataCache snapshot, IVerifiable scriptContainer,

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
if (system.Settings.Magic != _network) return;
if (system.Settings.Network != _network) return;
// Start freshly with a new DBCache for each block.
ResetBatch();
Dictionary<Nep17BalanceKey, Nep17Balance> nep17BalancesChanged = new Dictionary<Nep17BalanceKey, Nep17Balance>();
Expand Down Expand Up @@ -211,7 +211,7 @@ void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snaps

void IPersistencePlugin.OnCommit(NeoSystem system, Block block, DataCache snapshot)
{
if (system.Settings.Magic != _network) return;
if (system.Settings.Network != _network) return;
_db.Write(WriteOptions.Default, _writeBatch);
}

Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected virtual JObject GetVersion(JArray _params)
json["wsport"] = localNode.ListenerWsPort;
json["nonce"] = LocalNode.Nonce;
json["useragent"] = LocalNode.UserAgent;
json["magic"] = system.Settings.Magic;
json["network"] = system.Settings.Network;
return json;
}

Expand Down
10 changes: 5 additions & 5 deletions src/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void ProcessInvokeWithWallet(JObject result, Signers signers = null)
result["exception"] = GetExceptionMessage(e);
return;
}
ContractParametersContext context = new(system.StoreView, tx);
ContractParametersContext context = new ContractParametersContext(system.StoreView, tx, settings.Network);
wallet.Sign(context);
if (context.Completed)
{
Expand Down Expand Up @@ -224,7 +224,7 @@ protected virtual JObject SendFrom(JArray _params)
if (tx == null)
throw new RpcException(-300, "Insufficient funds");

ContractParametersContext transContext = new ContractParametersContext(snapshot, tx);
ContractParametersContext transContext = new ContractParametersContext(snapshot, tx, settings.Network);
wallet.Sign(transContext);
if (!transContext.Completed)
return transContext.ToJson();
Expand Down Expand Up @@ -275,7 +275,7 @@ protected virtual JObject SendMany(JArray _params)
if (tx == null)
throw new RpcException(-300, "Insufficient funds");

ContractParametersContext transContext = new ContractParametersContext(snapshot, tx);
ContractParametersContext transContext = new ContractParametersContext(snapshot, tx, settings.Network);
wallet.Sign(transContext);
if (!transContext.Completed)
return transContext.ToJson();
Expand Down Expand Up @@ -314,7 +314,7 @@ protected virtual JObject SendToAddress(JArray _params)
if (tx == null)
throw new RpcException(-300, "Insufficient funds");

ContractParametersContext transContext = new ContractParametersContext(snapshot, tx);
ContractParametersContext transContext = new ContractParametersContext(snapshot, tx, settings.Network);
wallet.Sign(transContext);
if (!transContext.Completed)
return transContext.ToJson();
Expand Down Expand Up @@ -393,7 +393,7 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar

private JObject SignAndRelay(DataCache snapshot, Transaction tx)
{
ContractParametersContext context = new ContractParametersContext(snapshot, tx);
ContractParametersContext context = new ContractParametersContext(snapshot, tx, settings.Network);
wallet.Sign(context);
if (context.Completed)
{
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void Dispose()

protected override void OnSystemLoaded(NeoSystem system)
{
RpcServerSettings s = settings.Servers.FirstOrDefault(p => p.Network == system.Settings.Magic);
RpcServerSettings s = settings.Servers.FirstOrDefault(p => p.Network == system.Settings.Network);
if (s is null) return;

RpcServer server = new RpcServer(system, s);
Expand Down
14 changes: 7 additions & 7 deletions src/StateService/StatePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
System = system;
Store = System.ActorSystem.ActorOf(StateStore.Props(this, string.Format(Settings.Default.Path, system.Settings.Magic.ToString("X8"))));
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 Down Expand Up @@ -73,14 +73,14 @@ public override void Dispose()

void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<ApplicationExecuted> applicationExecutedList)
{
if (system.Settings.Magic != Settings.Default.Network) return;
if (system.Settings.Network != Settings.Default.Network) return;
StateStore.Singleton.UpdateLocalStateRoot(block.Index, snapshot.GetChangeSet().Where(p => p.State != TrackState.None).Where(p => p.Key.Id != NativeContract.Ledger.Id).ToList());
}

[ConsoleCommand("start states", Category = "StateService", Description = "Start as a state verifier if wallet is open")]
private void OnStartVerifyingState()
{
if (System is null || System.Settings.Magic != 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 @@ -102,7 +102,7 @@ public void Start(Wallet wallet)
[ConsoleCommand("state root", Category = "StateService", Description = "Get state root by index")]
private void OnGetStateRoot(uint index)
{
if (System is null || System.Settings.Magic != 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 @@ -114,14 +114,14 @@ 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.Magic != 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");
Console.WriteLine($"LocalRootIndex: {StateStore.Singleton.LocalRootIndex}, ValidatedRootIndex: {StateStore.Singleton.ValidatedRootIndex}");
}

[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.Magic != 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
{
Console.WriteLine(GetProof(root_hash, script_hash, Convert.FromBase64String(key)));
Expand Down
8 changes: 4 additions & 4 deletions src/StateService/Verification/VerificationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private ExtensiblePayload CreateVoteMessage()
if (StateRoot is null) return null;
if (!signatures.TryGetValue(myIndex, out byte[] sig))
{
sig = StateRoot.Sign(keyPair, StatePlugin.System.Settings.Magic);
sig = StateRoot.Sign(keyPair, StatePlugin.System.Settings.Network);
signatures[myIndex] = sig;
}
return CreatePayload(MessageType.Vote, new Vote
Expand All @@ -107,7 +107,7 @@ public bool AddSignature(int index, byte[] sig)
if (signatures.ContainsKey(index)) return false;
Utility.Log(nameof(VerificationContext), LogLevel.Info, $"vote received, height={rootIndex}, index={index}");
ECPoint validator = verifiers[index];
byte[] hash_data = StateRoot?.GetSignData(StatePlugin.System.Settings.Magic);
byte[] hash_data = StateRoot?.GetSignData(StatePlugin.System.Settings.Network);
if (hash_data is null || !Crypto.VerifySignature(hash_data, sig, validator))
{
Utility.Log(nameof(VerificationContext), LogLevel.Info, "incorrect vote, invalid signature");
Expand All @@ -123,7 +123,7 @@ public bool CheckSignatures()
if (StateRoot.Witness is null)
{
Contract contract = Contract.CreateMultiSigContract(M, verifiers);
ContractParametersContext sc = new(StatePlugin.System.StoreView, StateRoot);
ContractParametersContext sc = new(StatePlugin.System.StoreView, StateRoot, StatePlugin.System.Settings.Network);
for (int i = 0, j = 0; i < verifiers.Length && j < M; i++)
{
if (!signatures.TryGetValue(i, out byte[] sig)) continue;
Expand Down Expand Up @@ -157,7 +157,7 @@ private ExtensiblePayload CreatePayload(MessageType type, ISerializable payload,
Sender = Contract.CreateSignatureRedeemScript(verifiers[MyIndex]).ToScriptHash(),
Data = data,
};
ContractParametersContext sc = new ContractParametersContext(StatePlugin.System.StoreView, msg);
ContractParametersContext sc = new ContractParametersContext(StatePlugin.System.StoreView, msg, StatePlugin.System.Settings.Network);
wallet.Sign(sc);
msg.Witness = sc.GetWitnesses()[0];
return msg;
Expand Down
Loading