-
Notifications
You must be signed in to change notification settings - Fork 100
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
[StateService] Verification #470
[StateService] Verification #470
Conversation
using Akka.Actor; | ||
using Neo.Cryptography; | ||
using Neo.Cryptography.ECC; | ||
using Neo.IO; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Persistence; | ||
using Neo.Plugins.StateService.Storage; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using Neo.Wallets; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Neo.Plugins.StateService.Verification | ||
{ | ||
public class VerificationContext | ||
{ | ||
private const uint MaxValidUntilBlockIncrement = 100; | ||
private StateRoot root; | ||
private ExtensiblePayload payload; | ||
private readonly Wallet wallet; | ||
private readonly KeyPair keyPair; | ||
private readonly int myIndex; | ||
private readonly uint rootIndex; | ||
private readonly ECPoint[] verifiers; | ||
private int M => verifiers.Length - (verifiers.Length - 1) / 3; | ||
private readonly Dictionary<int, byte[]> signatures = new Dictionary<int, byte[]>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using Akka.Actor; | |
using Neo.Cryptography; | |
using Neo.Cryptography.ECC; | |
using Neo.IO; | |
using Neo.Ledger; | |
using Neo.Network.P2P; | |
using Neo.Network.P2P.Payloads; | |
using Neo.Persistence; | |
using Neo.Plugins.StateService.Storage; | |
using Neo.SmartContract; | |
using Neo.SmartContract.Native; | |
using Neo.Wallets; | |
using System; | |
using System.Collections.Generic; | |
namespace Neo.Plugins.StateService.Verification | |
{ | |
public class VerificationContext | |
{ | |
private const uint MaxValidUntilBlockIncrement = 100; | |
private StateRoot root; | |
private ExtensiblePayload payload; | |
private readonly Wallet wallet; | |
private readonly KeyPair keyPair; | |
private readonly int myIndex; | |
private readonly uint rootIndex; | |
private readonly ECPoint[] verifiers; | |
private int M => verifiers.Length - (verifiers.Length - 1) / 3; | |
private readonly Dictionary<int, byte[]> signatures = new Dictionary<int, byte[]>(); | |
using Akka.Actor; | |
using Neo.Cryptography; | |
using Neo.Cryptography.ECC; | |
using Neo.IO; | |
using Neo.Ledger; | |
using Neo.Network.P2P; | |
using Neo.Network.P2P.Payloads; | |
using Neo.Persistence; | |
using Neo.Plugins.StateService.Storage; | |
using Neo.SmartContract; | |
using Neo.SmartContract.Native; | |
using Neo.Wallets; | |
using System; | |
using System.Collections.Concurrent; | |
namespace Neo.Plugins.StateService.Verification | |
{ | |
public class VerificationContext | |
{ | |
private const uint MaxValidUntilBlockIncrement = 100; | |
private StateRoot root; | |
private ExtensiblePayload payload; | |
private readonly Wallet wallet; | |
private readonly KeyPair keyPair; | |
private readonly int myIndex; | |
private readonly uint rootIndex; | |
private readonly ECPoint[] verifiers; | |
private int M => verifiers.Length - (verifiers.Length - 1) / 3; | |
private readonly ConcurrentDictionary<int, byte[]> signatures = new ConcurrentDictionary<int, byte[]>(); |
Use concurrent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use concurrent, it is only in one actor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VerificationService
use Concurrent for his dictionary and it use this class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need concurrent in VerificationService
, how do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
signatures.Add(index, sig); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signatures.Add(index, sig); | |
return true; | |
return signatures.TryAdd(index, sig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@erikzhang @shargon Please review again. |
Merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something strange,
Once I activate this plugin the screen do not allow to be stopped on linux server with ctrl+c
.
Multiple nodes are running together and the ones with this plugin activated suffers this.
Did you install oracle plugin? As @ProDog tested #494, orcale plugin will cause this can't exit problem. |
{ | ||
if (MaxCachedVerificationProcessCount <= contexts.Count) | ||
{ | ||
var indexes = contexts.Keys.OrderBy(i => i).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ReadOnlySpan<T>
is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
ReadOnlySpan<T>
is better.
Use this var indexes = new ReadOnlySpan<uint>(contexts.Keys.OrderBy(i => i).ToArray());
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (MaxCachedVerificationProcessCount <= contexts.Count)
{
contexts.Keys.OrderBy(p => p).Take(contexts.Count - MaxCachedVerificationProcessCount + 1).ForEach(p =>
{
if (contexts.TryRemove(p, out var value))
{
value.Timer.CancelIfNotNull();
}
});
}
@erikzhang How about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the code it's ok
hi @ZhangTao1596, you are correct, I forgot to delete the |
{ | ||
Timeout = TimeSpan.FromMilliseconds(TimeoutMilliseconds), | ||
}; | ||
var client = new RpcClient(http_client, url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use ExtensiblePayload
with p2p, but it could be done in a different PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Using p2p, We won't need url and avoid inconsistence between urls and public keys.
I have code here https:/ZhangTao1596/neo-modules/tree/state-service-p2p.
@Tommo-L worries that use p2p will put more pressure on p2p. And he proposes add service discovery function.
Once we make agreement, I will create another pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use service discovery, will it expose the IP address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this for now. I will make p2p improvement pr later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use p2p will put more pressure on p2p.
Yes
will it expose the IP address?
Maybe we can encrypt part of the service information so that only the relevant node can decrypt it, like:
service type + service information
state: xxxxxxx
oracle: yyyyyyy
rpc: 192.168.1.1
...
We can consider it later, after this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tommo-L Can you create a issue of your idea. We can discuss there. Since oracle and state both need that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oracle can't use p2p message for siging!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can discuss here #493
Merge? |
Step 2/3 StateService
Since there are too many changes in StateService, I will split it into 3 parts to commit pull request, and this is the 2nd.
Changes: