tip: 268
title: SmartContract ABI optimization
author: yanghang8612 <[email protected]>
status: Final
type: Standards Track
category: VM
created: 2021-05-19
Move ABI out of SmartContract and store it in a new ABI store.
The ABI field is totally indeed when the TVM executing SmartContract. Moving out ABI can reduce execution time of some opcodes such as EXTCODEHASH
SLOAD
SSTORE
ISCONTRACT
CREATE
and CREATE2
.
Add a new store called ABI Store. The data stored in it is like below.
message ABI {
message Entry {
enum EntryType {
UnknownEntryType = 0;
Constructor = 1;
Function = 2;
Event = 3;
Fallback = 4;
Receive = 5;
}
message Param {
bool indexed = 1;
string name = 2;
string type = 3;
}
enum StateMutabilityType {
UnknownMutabilityType = 0;
Pure = 1;
View = 2;
Nonpayable = 3;
Payable = 4;
}
bool anonymous = 1;
bool constant = 2;
string name = 3;
repeated Param inputs = 4;
repeated Param outputs = 5;
EntryType type = 6;
bool payable = 7;
StateMutabilityType stateMutability = 8;
}
repeated Entry entrys = 1;
}
While committing contract cache, save ABI of the deployed contract to the ABI store, clear the ABI field of contract and save it to the Contract store.
Get the ABI of contract in ABI store.
When tron clients start, traverse all contracts in store and save every contract`s ABI to the ABI store. While doing this operation, clear the ABI field of contract and update the contract to store.
class MoveAbiHelper
def do_traverse_work() -> None:
for contract in contract_store:
if !abi_store.has(contract.address):
abi_store.save(contract.getABI())
contract.clear(field.ABI)
contract_store.save(contract)
assert contract_store.total() == abi_store.total()
No known backward compatibility issues.