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

feat(transaction/validate): advance transaction validation when producing blocks #5582

Closed
wants to merge 4 commits into from

Conversation

halibobo1205
Copy link
Contributor

@halibobo1205 halibobo1205 commented Nov 13, 2023

close #5564.

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (df52667) 66.43% compared to head (2987803) 66.50%.

Files Patch % Lines
...rg/tron/common/validator/TransactionValidator.java 92.85% 1 Missing and 1 partial ⚠️
...mework/src/main/java/org/tron/core/db/Manager.java 50.00% 1 Missing and 1 partial ⚠️
...tron/common/validator/DupTransactionValidator.java 83.33% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #5582      +/-   ##
=============================================
+ Coverage      66.43%   66.50%   +0.07%     
- Complexity     10216    10260      +44     
=============================================
  Files            894      902       +8     
  Lines          53841    53884      +43     
  Branches        5931     5935       +4     
=============================================
+ Hits           35768    35835      +67     
+ Misses         15284    15264      -20     
+ Partials        2789     2785       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

protected Pair<GrpcAPI.Return.response_code, String> doValidate(TransactionCapsule trx) {
if (trx.getSerializedSize() > Constant.TRANSACTION_MAX_BYTE_SIZE) {
return buildResponse(GrpcAPI.Return.response_code.TOO_BIG_TRANSACTION_ERROR,
"too big transaction, the size is %d bytes", trx.getSerializedSize());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why change the logic of getting transaction size?
  2. Too big transaction previously. Is it necessary to keep all exception messages consistent in case they are useful for some Dapps?

Copy link
Contributor Author

@halibobo1205 halibobo1205 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. check size don't need to ask for new arrays.
image image
  1. in fact, it returns like that.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the modification of the return value will not have much impact, but it cannot rule out all situations, such as log filtering and other monitoring systems.
This is just a suggestion, after all, in my opinion, the amount of work required to maintain a consistent or new approach is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@Override
protected Pair<GrpcAPI.Return.response_code, String> doValidate(TransactionCapsule trx) {
byte[] transactionId = trx.getTransactionId().getBytes();
if (transactionCache.has(transactionId) && transactionStore.has(transactionId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& or || ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transaction cache uses Bloom filters, which have a false positive rate when found.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halibobo1205 halibobo1205 force-pushed the feat/advance_trans_check_for_pack branch from ac7e087 to 0b6bdca Compare November 14, 2023 07:02
int contractSize = trx.getContractSize();
if (contractSize != 1) {
return buildResponse(GrpcAPI.Return.response_code.CONTRACT_VALIDATE_ERROR,
"contract size should be exactly 1, this is extend feature ,actual :%d",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Former msg format contains: tx %s contract size should be exactly 1

protected Pair<GrpcAPI.Return.response_code, String> doValidate(TransactionCapsule trx) {
byte[] transactionId = trx.getTransactionId().getBytes();
if (transactionCache.has(transactionId) && transactionStore.has(transactionId)) {
return buildResponse(GrpcAPI.Return.response_code.DUP_TRANSACTION_ERROR, "dup trans");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Former msg is: 'dup trans : %s '

trx.validateSignature(accountStore, dynamicPropertiesStore);
return SUCCESS;
} catch (ValidateSignatureException e) {
return buildResponse(GrpcAPI.Return.response_code.SIGERROR, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Former is " %s transaction signature validate failed", txId"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trx.validateSignature(AccountStore accountStore, DynamicPropertiesStore dynamicPropertiesStore) never returns false, the following are not valid.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it

@halibobo1205 halibobo1205 force-pushed the feat/advance_trans_check_for_pack branch from 0b6bdca to 2987803 Compare November 14, 2023 09:36
import org.tron.api.GrpcAPI.Return.response_code;
import org.tron.core.capsule.TransactionCapsule;

public abstract class AbstractTransactionValidator implements Validator<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this abstract design really needed? It seems to validate some simple and fixed things only but with so many classes imported.

import org.tron.core.capsule.TransactionCapsule;

public abstract class AbstractTransactionValidator implements Validator<
Pair<response_code, String>, TransactionCapsule> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name response_code shall be changed to fit java code style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response_code is generated by proto.

@@ -1597,6 +1534,10 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) {
postponedTrxCount++;
continue; // try pack more small trx
}
// check transaction
if (!transactionValidator.silentValidate(trx)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, some checks may be skipped if that has been checked when it was pushed into pending queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary for now.

@halibobo1205 halibobo1205 self-assigned this Nov 27, 2023
@halibobo1205
Copy link
Contributor Author

There is no significant performance improvement, closed for now.

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.

Advance transaction validation when producing blocks
5 participants