trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 680 forks source link

`eth_sendRawTransaction` end with "Transaction too old" #4268

Open benams opened 1 year ago

benams commented 1 year ago

I'm running ganache @ version 7.7.2 and trying to simulate an old transaction (tx hash is "0xb786e8dcc0257ff863b5c727090d88576758ce86be685651b9890d8e5c63c7b0") and it end with a revert for a reason I can't find. The code I use:

const providerOptions = {
    fork: { blockNumber: 16532350 },
    chain: {
        chainId: 1,
    },
};
const provider = ganache.provider(providerOptions);
return await provider.request({
    method: "eth_sendRawTransaction",
    params: [rawTransactionString],
});

My log:

eth_sendRawTransaction

Transaction: 0xb786e8dcc0257ff863b5c727090d88576758ce86be685651b9890d8e5c63c7b0 Gas usage: 24448 Block number: 16532352 Block time: Mon Feb 27 2023 13:48:59 GMT+0200 (Israel Standard Time) Runtime error: revert Revert reason: Transaction too old

I'm not sure why this error occurs and how to fix it, any ideas?

davidmurdoch commented 1 year ago

This is probably a similar problem to what is happening in https://github.com/trufflesuite/ganache/issues/4146#issuecomment-1377506906. You probably need to set --chain.time="<time of block in UTC here> UTC" and --miner.timestampIncrement=13 (13 is roughly the number of seconds between blocks) when starting ganache, (in addition to the fork block number).

We hope to change this behavior in the next major release so that when you fork from a block number ganache automatically uses the fork block's time for its internal clock (though the timestampIncrement option will be set to 1, not 13 as in my example above).

benams commented 1 year ago

Thank you again! It really solved the issue. I just need to say that for older transactions, I could simulate without this chain.time flag, and this is why I removed it in the first place. Is that expected?