Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Odd behavior when sending multiple transactions on forked node #1246

Closed
moda20 opened this issue Sep 23, 2021 · 9 comments
Closed

Odd behavior when sending multiple transactions on forked node #1246

moda20 opened this issue Sep 23, 2021 · 9 comments

Comments

@moda20
Copy link

moda20 commented Sep 23, 2021

HI, I am having huge issues when sending multiple smart contract calls (transactions), they don't all pass. when sending more than 1 transaction at the same time only one would pass. I am using the CLI to fork bsc mainnet network from getBlock.

I would like to know if there are any limitations on the fork feature on the number of requests sent. Otherwise it would be a problem with my forked provider.

EDIT : getblock has a 30call per second limitation, could my smart contract calls trigger more than 30 contract to contract calls ?

@davidmurdoch
Copy link
Member

@moda20 what version of ganache are you using?

@moda20
Copy link
Author

moda20 commented Sep 23, 2021

it's the cli version 6.12.2

@davidmurdoch
Copy link
Member

Thanks! Can you try the latest alpha at the new package name, ganache? To install:

npm uninstall ganache-cli -g
npm install ganache@alpha -g

This version actually has a built in rate limiter:

ganache --fork.url YOURURL --fork.requestsPerSecond 30 will try* to avoid hitting the limit. However, it currently limits all requests, not per rpc call, so if BSC is limiting some calls and not others this might not help too much.

Run ganache --help for more info.

  • Rate limiters are weird in that they aren't an exact science, so we can't get it perfectly right. If the limit is hit we try to respect back-off request parameters sent in the error response, but it's designed with Infura's specific back-off parameters, which are likely not going to work for BSC.

@moda20
Copy link
Author

moda20 commented Sep 24, 2021

Was trying your solution, but having issues with unlocking the default accounts on deterministic account generation. it doesn't work with an empty passphrase.

EDIT : I had to not lock accounts in order to not have that issue.

@moda20
Copy link
Author

moda20 commented Sep 25, 2021

Well i tried the new ganache@alpha forking method and it seems to take so much more time to handle and mine the transaction, and i keep getting the console logs that a transactions is not yet mined. my transaction can take up to 40 seconds to mine which is not good.

I am really confused by this issue and I'm going to post my test cases here in order to try and get more info on this :

My tests are transactions to Pancakeswap SwapExactTokensForTokens method. the method itself calls multiple other contracts and does a token Transfer via the SafeTransfer method. So i have a loop over multiple calls of the smart contract and two modes for calling, successive calls with 1 call active at a time and another where i do 2 calls at a time.

  • using the old ganache-cli (Ganache CLI v6.12.2 (ganache-core: 2.13.2)) :
    1 - when doing 1 call at a time, everything works fine the calls mostly passed
    2 - when doing the 2 or more calls at a time, there is always at least one transaction from those 2 (or more) that would fail with a "Transfer failed" error. this is odd because if I resend the same failing transactions (from the same block) one by one it will pass. the Swap transactions themselves don't have anything in common, all their internal calls are to different smart contracts each time. The following log from my tests describes the issue ( it even prevails with the cached data seen in the first couple of logs where the timing is lower)

NOTE : the timings are the durations of the requests from transactions initiation to receipt logs decoding, they are not exactly representative of the transaction time but they are not important here

T TWO => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xd071Af7B6dbF36303ed15cA66d3A6bB026C02b14 timing : 416
T ONE => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xC5e2cbaa8586D4797750B677697059a538283440 timing : 425
Returned error: VM Exception while processing transaction: revert TransferHelper: TRANSFER_FROM_FAILED
T ONE => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xdBCD8c94CE30D5eA3E312f2Da1c3932aa2F014Af timing : 346
T TWO => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xbCce4C692ce62AdED2Da8189fdca7af989D1EA78 timing : 364
Returned error: VM Exception while processing transaction: revert TransferHelper: TRANSFER_FROM_FAILED
T TWO => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xF77EFbB086E20813E3De17720204b5755e795E48 timing : 216
T ONE => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xE468004e91147bF808BeBDA6b6901bf91AcAbD6c timing : 232
Returned error: VM Exception while processing transaction: revert TransferHelper: TRANSFER_FROM_FAILED
T ONE => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xc2B234AeE89d05C48AEB6d2687F087F34dC9248E timing : 3549
T TWO => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xBf3D5083fE56A126d76Ec9b963AFfed03082A539 timing : 3565
Returned error: VM Exception while processing transaction: revert TransferHelper: TRANSFER_FROM_FAILED
T TWO => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xd0A6CDb029c2240a1e7F9352Aa1E8d2e85E81bB3 timing : 8840
T ONE => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xF3c80F567b9070358f2298BfcdC88276C257491E timing : 8852

all transactions are made to the same node in batch of 2.

  • using the new alpha version of ganache
    the same test cases produce the same results here, but the difference is the massive timings from 2 to 20 seconds here are the result logs (the new node returns the receipt by default instead of the error message)
Transaction has been reverted by the EVM:
{
  "transactionHash": "0xdcc91a7cf5c9e60d99cb24606ed1c3464d43d1baf8ca8edaee8c33630be23660",
  "transactionIndex": 0,
  "blockNumber": 11223284,
  "blockHash": "0xfaf0d198adb8f724029f426961bcdf9d041901d1dd93b698d656c77400d21faa",
  "from": "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1",
  "to": "0x10ed43c718714eb63d5aa57b78b54704e256024e",
  "cumulativeGasUsed": 32903,
  "gasUsed": 32903,
  "contractAddress": null,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "effectiveGasPrice": "0x6285da2",
  "type": "0x2",
  "events": {}
}
T TWO => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xd071Af7B6dbF36303ed15cA66d3A6bB026C02b14 timing : 32260
T ONE => http://localhost:5000/api/SingleSwap : swap between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xC5e2cbaa8586D4797750B677697059a538283440 timing : 32269
Transaction has been reverted by the EVM:
{
  "transactionHash": "0x3929813b3f03ad19626d93eded765aca79dcc380b2d1b5a239d5c17e1256ba4c",
  "transactionIndex": 0,
  "blockNumber": 11223287,
  "blockHash": "0xbc6801a1a72ca8fde1e2b65a110f5f8a1f555cc507627c5d39c702ab4d4c7c43",
  "from": "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1",
  "to": "0x10ed43c718714eb63d5aa57b78b54704e256024e",
  "cumulativeGasUsed": 76766,
  "gasUsed": 76766,
  "contractAddress": null,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "effectiveGasPrice": "0x4200abb",
  "type": "0x2",
  "events": {}
}
T ONE => http://localhost:5000/api/SingleSwap : ERRORRRR between 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c and token 0xdBCD8c94CE30D5eA3E312f2Da1c3932aa2F014Af timing : 17260

the same issue is present, where the timing of both transactions are very near but they never both pass.

Can somebody explain this, and maybe an idea for a workaround? right now I can't use multiple ganache nodes as that also produces other bugs probably with my provider.

@davidmurdoch
Copy link
Member

davidmurdoch commented Sep 25, 2021

I'm currently working on forking performance issues in ganache@alpha (#1339 and #1248), so those performance issues will be resolved very soon; ganache v7-alpha forking should be about 20x times faster than ganache-cli. And thank you for the note about locked accounts, I'll look into that. As far as the other issues, I won't have a chance to look into those this weekend.

@MicaiahReid
Copy link
Contributor

@moda20 We think these issues should be resolved in the next alpha version of Ganache that should be out in the next few days! Keep an eye out for that release and let us know if you are still having these issues. Thanks!

@fainashalts
Copy link

HI @moda20 can you check this with the newest version of ganache? Please let us know if that helps!

npm uninstall ganache-cli --global
npm install ganache@beta --global

The release notes for the latest release, in case it helps: https://github.com/trufflesuite/ganache/releases/tag/ganache%407.0.0-beta.1

@haltman-at
Copy link
Contributor

@moda20 Closing this for issue maintenance. Do note that Ganache 7 has now been officially released! If there's still a problem on that, please let us know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants