ETH-Pantheon / Aion

A system for Scheduling transactions with arbitrary bytecode on the Ethereum Network
https://www.aion.ethpantheon.com
MIT License
26 stars 13 forks source link

Trouble running locally #21

Closed ArinCantCode closed 3 years ago

ArinCantCode commented 3 years ago

Hi i'm trying to run aion locally for testing my contract.

I'm deploying the Aion contract to network i run with ganache-cli, which ends up being a success. Then i run mongodb and executor in separate terminal after setting all the environment variables.

I'm trying to now test whether everything works as expected but when i try to make a ScheduleCall call i get:


     Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"id\":51,\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"VM Exception while processing transaction: revert\",\"code\":-32000,\"data\":{\"stack\":\"c: VM Exception while processing transaction: revert\\n    at Function.c.fromResults (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\\n    at e.exports (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2089395)\",\"name\":\"c\"}}}","error":{"code":-32000,"data":{"stack":"c: VM Exception while processing transaction: revert\n    at Function.c.fromResults (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n    at e.exports (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2089395)","name":"c"}},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"gasPrice\":\"0x4a817c800\",\"from\":\"0x6849a4071e381d8930befac117b5fa35198fc824\",\"to\":\"0x9d97acc768b9c485d425a92c34977b63a26cc5c8\",\"data\":\"0xdea8dc4f0000000000000000000000000000000000000000000000000000000060b77d4a0000000000000000000000006849a4071e381d8930befac117b5fa35198fc82400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000\"}],\"id\":51,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://127.0.0.1:8545"}, tx={"data":"0xdea8dc4f0000000000000000000000000000000000000000000000000000000060b77d4a0000000000000000000000006849a4071e381d8930befac117b5fa35198fc82400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030d40000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000","to":{},"from":"0x6849A4071E381D8930bEfaC117b5fA35198Fc824","gasPrice":{},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.2.0)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:213:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:225:20)
      at /home/arin/SourceCode/blockchain/SmartSub/node_modules/@ethersproject/abstract-signer/src.ts/index.ts:213:31
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Promise.all (index 5)

I can call serviceFee successfully which returns me: 500000000000000

I have tried both calling the ScheduleCall from within my test contract that looks like this:

// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.0;

//  Aion interface
abstract contract Aion {
    uint256 public serviceFee;
    function ScheduleCall(uint256 blocknumber, address to, uint256 value, uint256 gaslimit, uint256 gasprice, bytes calldata, bool schedType) virtual public payable returns (uint,address);

}

// Main contract
contract Scheduler{
    Aion aion;

    address public owner;
    uint256 public count;

    constructor() public payable {
        owner = msg.sender;
    }

    function scheduleMyfucntion() public {
        aion = Aion(0x9D97Acc768B9c485D425a92c34977B63A26cC5C8);
        bytes memory data = abi.encodeWithSelector(bytes4(keccak256('myfucntion()')));
        uint callCost = 200000*1e9 + aion.serviceFee();
        aion.ScheduleCall{value: callCost}( block.timestamp + 1 days, address(this), 0, 200000, 1e9, data, true);
    }

    function myfucntion() public {
        // do your task here and call again the function to schedule
        scheduleMyfucntion();
    }
}

and simply using ethers js in my test:

await aion.ScheduleCall(1622637898, "0x9D97Acc768B9c485D425a92c34977B63A26cC5C8", 0, 200000,1e9, "0x", true)

here is my test:

// We import Chai to use its asserting functions here.
const ABI = require("./SCHEDULER_ABI.json")
const AION_ABI = require("./AION_ABI.json")
const { ethers } = require("hardhat");
// `describe` is a Mocha function that allows you to organize your tests. It's
// not actually needed, but having your tests organized makes debugging them
// easier. All Mocha functions are available in the global scope.

// `describe` receives the name of a section of your test suite, and a callback.
// The callback must define the tests of that section. This callback can't be
// an async function.
describe("Test", () => {
  let aion
  let scheduler

  beforeEach(async () => {
    // AionFactory = await ethers.getContractFactory("Aion");
    // AionContract = await AionFactory.deploy();

    const SchedulerFactory = await ethers.getContractFactory("Scheduler");
    const SchedulerContract = await SchedulerFactory.deploy();
    const privateKey = '0xf9141d59fa5e07973d76b7c76fba1f18e4358c4fde97dc36bd969f36b6878434';
    const provider = ethers.providers.getDefaultProvider('http://127.0.0.1:8545');
    const wallet = new ethers.Wallet(privateKey, provider);
    const aionContract = new ethers.Contract("0x9D97Acc768B9c485D425a92c34977B63A26cC5C8", AION_ABI, wallet)
    const schedulerContract = new ethers.Contract(SchedulerContract.address, ABI, wallet)
    scheduler = await schedulerContract.deployed()
    aion = await  aionContract.deployed()
  });

  // You can nest describe calls to create subsections.
  // describe("Deployment", () => {
    // it("Should set the right owner", async () => {
      // expect(await SchedulerContract.owner()).to.equal(owner.address);
  //   });
  // });

  describe("Scheduler", () => {
    it("Should schedule call", async () => {
      console.log(await scheduler.scheduleMyfucntion())
      console.log(await aion.ScheduleCall(1622637898, "0x9D97Acc768B9c485D425a92c34977B63A26cC5C8", 0, 200000,1e9, "0x", true))
    })
  })
});
jfdelgad commented 3 years ago

Hello Arin

Is the error coming from the executor code? it is not clear from your question of there is one error or many and what part of the system is generating the error.

As per your text, I am assuming that the estimageGas function is not working. This may be due to your web3 provider. If your environment does not allow estimating gas, then you will need to modify the code and set the gas manually.

The best test will be to run this in a public network and use (for instance) infura as your web3 provider.

Hope this helps

ArinCantCode commented 3 years ago

Thanks for response,

Is the error coming from the executor code? it is not clear from your question of there is one error or many and what part of the system is generating the error.

There is one error that i specified in the post, it happens when calling the ScheduleCall. I have tried to call this function in different ways, one was directly through my tests as noted above:

await aion.ScheduleCall(1622637898, "0x9D97Acc768B9c485D425a92c34977B63A26cC5C8", 0, 200000,1e9, "0x", true)

As this doesn't work i also tried to do it like in the example from the README you guys provide, and that is the await scheduler.scheduleMyfucntion() where scheduler is my contract that uses Aion contract to call ScheduleCall.

Both ways give me the same error, when calling ScheduleCall.

As per your text, I am assuming that the estimageGas function is not working

I'm not an expert with blockchain in general, what makes you think this is the case? When i googled this part of the error: UNPREDICTABLE_GAS_LIMIT people mention it's more likely due to contract issues as the error also states this: VM Exception while processing transaction: revert

EDIT:

I think i have found the boogeyman, this line in the Aion contract is causing the issue:

require(msg.value == value.add(gaslimit.mul(gasprice)).add(serviceFee));

ArinCantCode commented 3 years ago

Issue solved i didn't realize i need to send ether to my contract in order to send it later to the aion contract...

Thanks for your time 👍