mangrovedao / mangrove-bots

🌴 Bots for the Mangrove ecosystem
4 stars 3 forks source link

Greedy Taker bot should gracefully handle slow mining of tx's #14

Open espendk opened 2 years ago

espendk commented 2 years ago

Is your feature request related to a problem? Please describe. July 12, 2022, the Greedy Taker bot was stopped as it was using too much resources.

Investigations showed that some of its tx's were 43 hours to be mined:

billede

We think the ultra-slow mining caused the issue:

Describe the solution you'd like The bot should gracefully handle when tx's are slow to be mined.

A possible solution could be, that if the previous tx for a market has not been mined when the bot's recurring job runs again, the bot should send a replacement tx (with a higher gas price) instead of a new one.

Describe alternatives you've considered An easier solution would be to just wait for the tx to be mined, before running again. Some downsides of that solution:

Additional context The configuration in the MARKETS env var at the time were:

[
    {
      "baseToken": "WETH",
      "quoteToken": "USDC",
      "takerConfig": {
        "sleepTimeMilliseconds": 60000,
        "offerCountCap": 5
      }
    },
    {
      "baseToken": "WETH",
      "quoteToken": "DAI",
      "takerConfig": {
        "sleepTimeMilliseconds": 60000,
        "offerCountCap": 5
      }
    },
    {
      "baseToken": "DAI",
      "quoteToken": "USDC",
      "takerConfig": {
        "sleepTimeMilliseconds": 60000,
        "offerCountCap": 5
      }
    }
]
adhusson commented 2 years ago

Dropping a link to https://docs.ethers.io/v5/api/experimental/#experimental-noncemanager which may provide an easy access to nonce management if we decide to replace old txs.

edit: nevermind, @espendk notified me that we already use this -- and it's part of the issue.

peterMangrove commented 1 year ago

@espendk Is there an easy way to recreate this? Maybe creating a test for it?

espendk commented 1 year ago

@espendk Is there an easy way to recreate this? Maybe creating a test for it?

Not sure. It would require that the local test chain doesn't mine tx's immediately - maybe that can be controlled in anvil?

It would of course be best if we could test this in an automated manner. But if it's impossible or big task, then implementing logic that tracks the state of previous tx's should be sufficient. This is a test bot after all, not production code.

lnist commented 8 months ago

@espendk is greedy taker bot still relevant now that we have arbitrage bot and real markets? I would suggest we close this.

espendk commented 8 months ago

@espendk is greedy taker bot still relevant now that we have arbitrage bot and real markets? I would suggest we close this.

I believe greedy taker bot is still needed (and used) on testnets where arbitrage is impractical since testnet markets are often in a weird state.