PlatONnetwork / docs

9 stars 53 forks source link

Fix: gasUsed increases with account increases #189

Closed kay404 closed 2 years ago

kay404 commented 2 years ago
platon::StorageType<"balances"_n, std::map<Address, uint64_t>> balances;
platon::StorageType<"allowed"_n, std::map<Address, std::map<Address, uint64_t>>> allowed;

StorageType 会随着账户数的增加,每次用到 balances 和 allowed 时候会把所有的持有该 Token 的地址都取出来,所以随着持有地址的增加 gasUsed 也不断增加,一旦超过 gasLimit 合约就不能用了。

以下是转账测试的情况:

transfer to account 1: lat1ha87h7kdluhm0czdcjx8a65actwafz00pkunal 
gasUsed: 114593
transfer to account 2: lat1yap7jaukj5ddw3ux7e50kwkvpnamqe426guvst 
gasUsed: 109176
transfer to account 3: lat10sf7mfju570mrf4er9mlheteaws287jhvknf2c 
gasUsed: 144597
transfer to account 4: lat1fqvhtwly87tmfyg7akgtf02uwag52rvw05sx6f 
gasUsed: 159770
transfer to account 5: lat1d7daq98kuyczwjgrt5r0vmehelsqynp42rc9vx 
gasUsed: 174796
transfer to account 6: lat1kmguml7s3vtuqcm69e4999h5gzt4y2zhdkst5p 
gasUsed: 190570
transfer to account 7: lat1z6j3l9xysn97dgg73gh2g3m8txg0j2aa3r4kfp 
gasUsed: 180136
transfer to account 8: lat1k4msaqw6m0p283qkwnwsl9qllandvrhukg6nfd 
gasUsed: 215133
transfer to account 9: lat1agmnamvay36zjd8tmyax9aqj9k9hupv0vme2l6 
gasUsed: 230599
transfer to account 10: lat1q2t0vaxxzmf6cecfzdupufdpm5qn9zahascv0r 
gasUsed: 245270

同样的 approve 也是会有这种情况。