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

Optimize VerifyWitness and tx.verify #2054

Merged
merged 24 commits into from
Dec 7, 2020

Conversation

Tommo-L
Copy link
Contributor

@Tommo-L Tommo-L commented Nov 10, 2020

No description provided.

@shargon
Copy link
Member

shargon commented Nov 10, 2020

Plese wait for #2052

@Qiao-Jin Qiao-Jin mentioned this pull request Nov 11, 2020
@erikzhang
Copy link
Member

What does this optimize?

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Nov 25, 2020

What does this optimize?

We'll add adjustable opcode pricing later and also want to keep VerifyStateIndependent method for tps enhancement, #2045 (comment)

Therefore, we want to separate signature verification from cost verification.

roman-khimov added a commit to roman-khimov/neo that referenced this pull request Nov 26, 2020
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.
@Tommo-L
Copy link
Contributor Author

Tommo-L commented Nov 30, 2020

Let's move on, then we have a chance to merge #2045 #2063

@erikzhang
Copy link
Member

Conflicts.

@Qiao-Jin
Copy link
Contributor

Qiao-Jin commented Dec 2, 2020

Attached is TPS comparison between this PR and newest master branch code.

Env: 1 consensus node with 6 i7 cores and 16 GB rams

image

Besides, a TPS comparison between the newest master branch code and commit 6fc4161:

image

It seems that TPS has dropped since then.

@shargon
Copy link
Member

shargon commented Dec 2, 2020

Looks like a revert from #1507

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Dec 2, 2020

Looks like a revert from #1507

Some partes is reverted.

Tommo-L added 2 commits December 2, 2020 20:10
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);
Copy link
Member

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())
Copy link
Member

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.

return true;
}

internal static bool VerifyWitness(this IVerifiable verifiable, StoreView snapshot, UInt160 hash, Witness witness, long gas, out long fee)
Copy link
Member

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.

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Dec 7, 2020

Merge?
Two PRs were blocked by this PR.

@erikzhang erikzhang merged commit 5b48ee8 into neo-project:master Dec 7, 2020
ShawnYun pushed a commit to ShawnYun/neo that referenced this pull request Jan 8, 2021
cloud8little pushed a commit to cloud8little/neo that referenced this pull request Jan 24, 2021
ixje added a commit to CityOfZion/neo-mamba that referenced this pull request Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants