I have developed a Stacking Smart contract on Polygon. It was working fine soon when deployed. But after 10-12 Days, my invest() function stops working because of (maybe) high gas value. At start the gas fee was about 712,297 and today after about 10 days, it's increased to 29,880,863. There is a huge difference which is causing invest() transaction to revert. But it does not happen always. Sometimes the transaction is successful but most of the times it reverts!
Here is my contract Address:
https://polygonscan.com/address/0xc62e1ccdefe1ecf7d7a6173b0c1a2d1fd1fc8551
Here is my invest() function code:
function invest(address referer, uint units) external {
if (!started) {
if (msg.sender == firstWallet) {
started = true;
} else revert("Not started yet");
}
processDeposit(referer, units);
payReferral(units);
payForBinate();
}
Anyone please help. Is this usual problem or is there any issue with the function?
How can I solve this problem?
Best Answer
You DoS yourself. When a number of iteration costs exceed the gas limit, the transaction fails and the contract may be blocked at some point.
I looked at your code, to be honest, it is not optimized at all, there are a lot of iterations, arrays, conditions.
payforRefferal
is really huge, contains a lot of conditions, checks.and
payForBinate()
, is even worse, it contains a lot of calculation, iterations, loops, etc.I'm afraid that your contract is almost no longer usable.
The more people will invest and the more it will be complicated to invest.