First, thank you for all your wonderful contributions!
I have been running a keep3r against the YearnV1EarnKeep3r job. It was quiet for a while (no work), but then last night I started getting transaction errors calling the work() function every minute or so. Each failed with an out of gas error (999,181 gas used from 1,000,000 gas limit) and they cost me roughly $10 each for gas fees. It drained my wallet before I was able to stop it. Not a huge amount of money, but not the best outcome either.
I want to find out what I did wrong, if anything, and how to avoid this in future, as I want to fully embrace the zero maintenance philosophy of Keep3r.
In the Eth virtual machine, you need to allocate a high enough gas limit to run a tx. Because of the concept of gas refunds, sometimes the required gas limit to finish a tx without an out-of-gas error is much higher than the gas that will actually be used. In your gas, your gas limit was too low.
Also, I recommend adding some backstops to your code so that if you fail a tx, you don’t try again for some time. That way you don’t get drained like that.
I suggest upping your gas limit. You can manually pass a higher gas limit or adjust the algorithm used to calculate a proper one.