-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize VerifyWitness and tx.verify #2054
Optimize VerifyWitness and tx.verify #2054
Conversation
Plese wait for #2052 |
What does this optimize? |
We'll add adjustable opcode pricing later and also want to keep Therefore, we want to separate signature verification from cost verification. |
MemoryPool contents is always valid (verified) against some snapshot. This snapshot is only changed when new block is added. Between blocks we only have one valid chain state that can be read by multiple threads without any issues, thus we can execute concurrently not only state-independent, but also state-dependent parts of transaction verification. To simplify execution flow (minimize single-threaded Blockchain message handling and eliminate duplicate DB accesses for ContainsTransaction) TransactionRouter is an independent entity now, though of course we can also attach the same actor functionality to MemoryPool itself. TransactionVerificationContext balance checking is moved to MemoryPool from Transaction with this, Transaction shouldn't care (it can check overall GAS balance though). This is directly related to neo-project#2045 work (it solves state access problem there) and in some sense is an alternative to neo-project#2054 (makes fee calculation easier, though IsStandardContract() trick to optimize out these contracts during reverification is still relevant and can be added here). At this stage it's just a prototype, some additional optimizations and simplifications are possible of course, but this prototype shows the direction and the main question for now is whether this direction is interesting for us.
Conflicts. |
Attached is TPS comparison between this PR and newest master branch code. Env: 1 consensus node with 6 i7 cores and 16 GB rams Besides, a TPS comparison between the newest master branch code and commit 6fc4161: It seems that TPS has dropped since then. |
Looks like a revert from #1507 |
Some partes is reverted. |
if (witnesses[i].VerificationScript.IsSignatureContract()) | ||
net_fee -= (ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] * 2 + ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + ApplicationEngine.OpCodePrices[OpCode.SYSCALL] + ApplicationEngine.ECDsaVerifyPrice); | ||
else if (witnesses[i].VerificationScript.IsMultiSigContract(out int m, out int n)) | ||
net_fee -= (ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] * (m + n) + ApplicationEngine.OpCodePrices[OpCode.PUSHINT8] * 2 + ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + ApplicationEngine.OpCodePrices[OpCode.SYSCALL] + ApplicationEngine.ECDsaVerifyPrice * n); |
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.
It could be any kind of push, same price but just to take care..
UInt160[] hashes = GetScriptHashesForVerifying(null); | ||
if (hashes.Length != witnesses.Length) return VerifyResult.Invalid; | ||
for (int i = 0; i < hashes.Length; i++) | ||
if (witnesses[i].VerificationScript.IsStandardContract()) |
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.
Maybe we can cache if it's standar inside the witness, otherwise we check it at least twice.
Co-authored-by: Shargon <[email protected]>
Co-authored-by: Shargon <[email protected]>
return true; | ||
} | ||
|
||
internal static bool VerifyWitness(this IVerifiable verifiable, StoreView snapshot, UInt160 hash, Witness witness, long gas, out long fee) |
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.
fee
it's only computed if it return true
, it works for our current model, but we should take care.
Merge? |
No description provided.