Autotask sometimes fails

Hey Team,

We have an autotask with multiple transactions that should be executed in sequence. However, sometimes defender fails with

AUTOTASK START
END RequestId: 73d62719-0563-4920-bd59-feb946167b5e
AUTOTASK COMPLETE
2022-10-03T17:21:46.204Z	ERROR	Invoke Error 	{"errorType":"Error","errorMessage":"Error while attempting request: Transaction rejected by aggregator: execution reverted","stack":["Error: Error while attempting request: Transaction rejected by aggregator: execution reverted","    at AutotaskRelayer.execute (/opt/nodejs/node_modules/defender-base-client/lib/autotask/index.js:46:19)","    at processTicksAndRejections (internal/process/task_queues.js:97:5)","    at async DefenderRelaySigner.sendTransaction (/opt/nodejs/node_modules/defender-relay-client/lib/ethers/signer.js:110:15)"]}

This is odd because there seems to be no errors on chain and when we execute them separately through the relayer it works.

Our autotask is as follows:

const ATLAS_STAKER = "0x....";
const batchSize = 20;

// Entrypoint for the Autotask
export async function handler(credentials: RelayerParams) {
  const provider = new DefenderRelayProvider(credentials);

  const signer = new DefenderRelaySigner(credentials, provider, { speed: "fast" });

  const atlasStaker = new ethers.Contract(ATLAS_STAKER, AtlasStaker.abi, signer);

  //Get current Atlas Mine position size
  const positionSize = await atlasStaker.activeAtlasPositionSize();
  const iterations = Math.ceil(positionSize.toNumber() / batchSize);

  //Start the Harvesting
  const startHarvestTx = await atlasStaker.startHarvestAndDistribute();
  const startHarvestResult = await startHarvestTx.wait();
  if (startHarvestResult.status == 0) {
    console.error("Error executing startHarvestAndDistribute()");
    process.exit(1);
  }

  //Execute the harvesting from Atlas Mine in batches
  for (let i = 0; i < iterations; i++) {
    const tx = await atlasStaker.executeHarvestAll(i * batchSize, batchSize);
    const result = await tx.wait();
    if (result.status == 0) {
      console.error("Error executing executeHarvestAll(" + i * batchSize + ", " + batchSize + ")");
      process.exit(1);
    }
  }

  //Update the emissions
  const updateEmissionsTx = await atlasStaker.executeUpdateEmissions();
  const updateEmissionsResult = await updateEmissionsTx.wait();
  if (updateEmissionsResult.status == 0) {
    console.error("Error executing executeUpdateEmissions()");
    process.exit(1);
  }

  //Execute the withdrawals from Atlas Mine in batches
  for (let i = 0; i < iterations; i++) {
    const tx = await atlasStaker.executeWithdrawAll(i * batchSize, batchSize);
    const result = await tx.wait();
    if (result.status == 0) {
      console.error("Error executing executeWithdrawAll(" + i * batchSize + ", " + batchSize + ")");
      process.exit(1);
    }
  }

  //Execute the new deposits to AtlasMine
  const executeDepositTx = await atlasStaker.executeDepositAll();
  const executeDepositResult = await executeDepositTx.wait();
  if (executeDepositResult.status == 0) {
    console.error("Error executing executeDepositAll()");
    process.exit(1);
  }

  //Finish the Harvesting
  const finishHarvestTx = await atlasStaker.finishHarvestAndDistribute();
  const finishHarvestResult = await finishHarvestTx.wait();
  if (finishHarvestResult.status == 0) {
    console.error("Error executing finishHarvestAndDistribute()");
    process.exit(1);
  }
}

Any idea on the cause?

Hi @Archethect_Archethec,

Thanks for reaching out!

Couple of questions:

  • When you say "sometimes fails" does that mean you have seen the same autotask sequence execute without any issues?
  • How many times did the autotask execute successfully compared to failing?
  • Did this start happening recently?
  • How ofter are you running this autotask?

This error is thrown when estimating the gas for transaction fails. This can happen due to various reasons, including the third party provider service failure.

Thanks

Hi @Aleksandr ,

Thanks for following up.

  • When you say "sometimes fails" does that mean you have seen the same autotask sequence execute without any issues?
    ---> Yes, sometimes it works
  • How many times did the autotask execute successfully compared to failing?
    ---> it works 80% of the time fine
  • Did this start happening recently?
    ---> It's happening since august at least.
  • How ofter are you running this autotask?
    ---> Once every day at 5.20 PM UTC