near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.3k stars 600 forks source link

Unify transaction validation in chunk producer and chunk validator code paths #11707

Open bowenwang1996 opened 2 days ago

bowenwang1996 commented 2 days ago

Currently a chunk producer validates transactions before applying a chunk by calling validate_chunk_transactions, which does not validate individual transactions. On the other hand, a chunk validator validates each individual transaction before applying the chunk by calling validate_prepared_transactions. The problem is not only that these two code paths are not consistent, but also that chunk validators call verify_and_charge_transaction twice during the validation of a chunk, once in validate_prepared_transactions and once in apply_new_chunk. The call to verify_and_charge_transaction can be expensive because it involves signature verification. We should fix it so that chunk validators follow the same transaction validation path and avoid calling verify_and_charge_transaction twice during chunk validation.