near / nearcore

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

Tool for simulating alone tx execution in a block #5917

Open Longarithm opened 2 years ago

Longarithm commented 2 years ago

Problem Unrelated receipts / txs included into the same block may affect each other's cost. This worsens devx - while they are trying to estimate cost for some call, they may get too optimistic costs, and in reality their calls will fail. With more adoption, this will occur more frequently.

Example Example: receipts included into the block 74667247. Calls to swt07.intmainreturn00.testnet are essentially the same - args are permutation of the same vector. But the cost difference is ~100 Tgas.

Explanation TrieUpdate stores current key-value updates in the committed and prospective fields. If key is presented there, it gets value from them instead of trie lookup. This fairly saves cost for user, but makes costs less predictable - if previous tx/receipt touched all needed keys, cost will be much cheaper, and this effect is quite random.

On the first place - this optimization is good and saves both number of operations and money, we would like to save it. And additionally we would implement some tool or extra parameter to allow devs check tx/receipt cost "as it was executed alone in the block".

Idea Adjust TrieUpdate implementation - charge touched_trie_node in all cases if the "estimating" mode is enabled.

Related Zulip thread

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

bowenwang1996 commented 2 years ago

@Longarithm given the chunk cache implementation, it seems harder to estimate cost correctly now

Longarithm commented 2 years ago

The idea was that if we want to get accurate cost, we should simulate only one tx/receipt in a chunk, so the cost won't be affected by other txs/receipts. Also, it we introduce separate cost for reading cached trie nodes, we can run simulation with runtime config where cached cost and regular cost are the same.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity in the last 2 months. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.