trufflesuite / truffle

: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
14.02k stars 2.32k forks source link

Deployment crashes with ETIMEDOUT #3468

Open Bobface opened 3 years ago

Bobface commented 3 years ago

Issue

Deployment crashes because of ETIMEDOUT when requesting the latest block using Infura as provider with a stable internet connection. This deployment was to Kovan but I suspect it would also happen when deploying to mainnet.

2_deploy_timelock.js
====================

   Replacing 'DSPause'
   -------------------
   > transaction hash:    0x00e68e105052798ca01866ef6d10e3bcba07ac9b6e89ec41e7ed3e94f5259b20
   ⠼ Blocks: 4            Seconds: 23
C:\Users\User\Desktop\contracts\node_modules\request\request.js:848
          var e = new Error('ETIMEDOUT')
                  ^
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: ETIMEDOUT
    at Timeout.<anonymous> (C:\Users\User\Desktop\contracts\node_modules\request\request.js:848:19)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
    at PollingBlockTracker._performSync (C:\Users\User\Desktop\contracts\node_modules\eth-block-tracker\src\polling.js:51:24)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

The same error also appears with a different message:

   -----------------------------------
   > transaction hash:    0xfb8adea09261fae8fe28b13b2f0a1c71dff8b766905b905de37baadedea1958a
   ⠴ Blocks: 0            Seconds: 0Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } },
  stack: 'Error: ETIMEDOUT\n' +
    '    at Timeout.<anonymous> (C:\\Users\\User\\Desktop\\contracts\\node_modules\\request\\request.js:848:19)\n' +
    '    at listOnTimeout (internal/timers.js:554:17)\n' +
    '    at processTimers (internal/timers.js:497:7)'
})
    at Web3ProviderEngine.emit (events.js:303:17)
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\index.js:57:14
    at afterRequest (C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\index.js:151:21)
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\index.js:176:21
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\index.js:238:9
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\node_modules\async\internal\once.js:12:16
    at replenish (C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\node_modules\async\internal\eachOfLimit.js:61:25)
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\node_modules\async\internal\eachOfLimit.js:71:9
    at eachLimit (C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\node_modules\async\eachLimit.js:43:36)
    at C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\node_modules\async\internal\doLimit.js:9:16
    at end (C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\index.js:217:5)
    at Request._callback (C:\Users\User\Desktop\contracts\node_modules\@trufflesuite\web3-provider-engine\subproviders\rpc.js:36:21)
    at self.callback (C:\Users\User\Desktop\contracts\node_modules\request\request.js:185:22)
    at Request.emit (events.js:314:20)
    at Timeout.<anonymous> (C:\Users\User\Desktop\contracts\node_modules\request\request.js:851:16)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

Steps to Reproduce

Hard to reproduce, does not happen everytime.

Expected Behavior

Do not crash the deployment but instead retry to fetch the latest block while printing a warning.

Environment

gnidan commented 3 years ago

Hey @Bobface thanks for opening this. Is this consistently reproducible for you?

Can you try Truffle v5.1.49? We upgraded Web3.js in 5.1.50, so I'd like to rule that out as the culprit.

In any event, seems like we'll need to look into this.

Bobface commented 3 years ago

I tried with a few older versions including v5.1.49 and got the same error.

eggplantzzz commented 3 years ago

Ok, so that should confirm that this is not related to the web3 upgrade :) Thanks @Bobface!

branmcf commented 3 years ago

I've also started seeing an ETIMEDOUT error (below) when running tests against Kovan using Infura as a provider with a stable internet connection. Similarly, the error is hard to reproduce and it does not happen every time.

Uncaught Error [ERR_UNHANDLED_ERROR]: Unhandled error. 
(
    {
        code: -32603,
        message: 'read ETIMEDOUT',
        data: {
            originalError: {
                errno: 'ETIMEDOUT',
                code: 'ETIMEDOUT',
                syscall: 'read'
            }
        },
        stack: 'Error: read ETIMEDOUT\n    at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)'
    }
)

Environment: operating system: macOS Catalina truffle version: v5.1.30 node version: v10.16.3 npm version: 6.9.0

gnidan commented 3 years ago

Moving this to our backlog so we can try to get to the bottom of it. Thanks for bearing with us on this issue, everyone!

tokenswapfin commented 3 years ago

May be caused by infura rate limit. I get this error everytime to migrate with infura rinkeby testnet, await deployer.deploy(SafeMath); await deployer.link(SafeMath, MyContract);

sometime, I saw there more than 40+ confirmation for SafeMath deploy,but just stay to wait SafeMath for more confirmations and don’t continue to publish my contract.

TCGV commented 3 years ago

I was also facing this issue and was able to solve it by adding both networkCheckTimeout and timeoutBlocks values to the target network configuration:

  networks: {
    kovan: {
      provider: function() {
        return new HDWalletProvider(
          mnemonic,
          "wss://kovan.infura.io/ws/v3/<ProjectID>"
        )
      },
      network_id: 42,
      networkCheckTimeout: 1000000,
      timeoutBlocks: 200
    }
  }
flcoder commented 3 years ago

Running into this here on bsc mainnet:

"truffle": "^5.1.22"

flc@DESK:~/bb/runner$ truffle test --network bsc
Using network 'bsc'.

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } },
  stack: 'Error: ETIMEDOUT\n' +
    '    at Timeout.<anonymous> (/home/flc/bb/runner/node_modules/request/request.js:848:19)\n' +
    '    at listOnTimeout (internal/timers.js:554:17)\n' +
    '    at processTimers (internal/timers.js:497:7)'
})
    at Web3ProviderEngine.emit (events.js:304:17)
    at /home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/index.js:57:14
    at afterRequest (/home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/index.js:151:21)
    at /home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/index.js:176:21
    at /home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/index.js:238:9
    at /home/flc/bb/runner/node_modules/async/internal/once.js:12:16
    at replenish (/home/flc/bb/runner/node_modules/async/internal/eachOfLimit.js:61:25)
    at /home/flc/bb/runner/node_modules/async/internal/eachOfLimit.js:71:9
    at eachLimit (/home/flc/bb/runner/node_modules/async/eachLimit.js:43:36)
    at /home/flc/bb/runner/node_modules/async/internal/doLimit.js:9:16
    at end (/home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/index.js:217:5)
    at Request._callback (/home/flc/bb/runner/node_modules/@trufflesuite/web3-provider-engine/subproviders/rpc.js:36:21)
    at self.callback (/home/flc/bb/runner/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Timeout.<anonymous> (/home/flc/bb/runner/node_modules/request/request.js:851:16)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

Truffle config:

networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    },
    testnet: {
      provider: () => new HDWalletProvider(mnemonic, `https://data-seed-prebsc-1-s1.binance.org:8545`),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: false
    },
    bsc: {
      provider: () => new HDWalletProvider(mnemonic, `https://bsc-dataseed1.binance.org`),
      network_id: 56,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true,
      gas: 3000000,
      gasPrice: 10000000000,
      networkCheckTimeout: 1000000000
    }
  }

UPDATE: Switching to a different provider endpoint worked for me.

mktcode commented 3 years ago

Just for the record: I'm trying to deploy contracts in a GitHub workflow and I am running into the same issue. Locally everything's fine.

umobiajulu commented 3 years ago

mine happend on BSC testnet, it was caused by unstable network from my end. so i used vpn on my linux machine and everything worked properly

eggplantzzz commented 3 years ago

@mktcode It may be that everything runs a lot slower in the GitHub flow

mktcode commented 3 years ago

@eggplantzzz yes, I dismissed the idea anyway. :D

pmprete commented 3 years ago

Having the same issue but with Kovan, followed this config https://github.com/trufflesuite/truffle/issues/3356#issuecomment-826310780 And it worked, using infura works better if using web sockets with truffle deploy

MananDesai54 commented 3 years ago

mine happend on BSC testnet, it was caused by unstable network from my end. so i used vpn on my linux machine and everything worked properly

this is also a point, i had same issue An unstable Internet i changed internet then it worked

sam8888888888 commented 3 years ago

i had same issue, but when i connect with VPN, its worked.

aster2709 commented 3 years ago

guys, where can I find the entire configuration object for a network, as in the docs I cant find networkCheckTimeout and timeoutBlocks and helpful properties like these (I may have missed it), anyone kind enough to drop a link? thanks

eggplantzzz commented 3 years ago

Hey @aster2709, you can find those here.

frankdev7 commented 2 years ago

Use instead of: https://ropsten.infura.io/v3/PROJECTID

this wss://ropsten.infura.io/ws/v3/PROJECTID

it works.

dgamma3 commented 2 years ago

Use instead of: https://ropsten.infura.io/v3/PROJECTID

this wss://ropsten.infura.io/ws/v3/PROJECTID

it works.

worked for me :) thanks!

Francodiner commented 2 years ago

Try this! Worked for me

testnet: { provider: () => new HDWalletProvider(mnemonic, https://data-seed-prebsc-1-s1.binance.org:8545), network_id: 97, gas: 5000000, gasPrice: 40000000000, confirmations: 1, timeoutBlocks: 400, skipDryRun: false, websocket: true, timeoutBlocks: 90000, networkCheckTimeout: 9000000 },

gorojou commented 2 years ago

I have the same error code: -32603, message: 'ETIMEDOUT', data: { originalError: { code: 'ETIMEDOUT', connect: true } }, stack: 'Error: ETIMEDOUT\n' + ' at Timeout. (/home/usuario/Escritorio/csd-bridge/node_modules/request/request.js:848:19)\n' + ' at listOnTimeout (node:internal/timers:557:17)\n' + ' at processTimers (node:internal/timers:500:7)'

This is my env Truffle v5.4.27 (core: 5.4.27) Solidity - 0.8.0 (solc-js) Node v16.13.1 Web3.js v1.5.3

My truffle.config ethTestnet: { provider: () => new HDWalletProvider( mnemonic, 'https://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', 0, 1 ), network_id: 4, //rinkeby gas: 5000000, gasPrice: 40000000000, confirmations: 1, timeoutBlocks: 400, skipDryRun: false, websocket: true, timeoutBlocks: 90000, networkCheckTimeout: 9000000 }

cmooninfotech commented 2 years ago

it's not truffle issue, you have to changed network provider too

SolidityDevSK commented 2 years ago

it's not truffle issue, you have to changed network provider too

This answer is so ridiculous. I never get this error when compiling in remix. Truffle developers may not have a problem. But fighting for a solution will increase the use of truffles. Changing the provider in the bsc network may be a solution, but there is no provider option in ethereum test servers.

eggplantzzz commented 2 years ago

@SolidityDevSK this is not an error related to compilation. This error usually occurs when either the user has a bad/slow connection, when they have the provider incorrectly configured, or when a node is especially flaky. Make sure that your url is correct.

kosty4 commented 2 years ago

-32000 for me was resolved with rpc change to 'https://bscrpc.com', however, new error -32603 'ETIMEDOUT' was arised after it. the contract is a dead simple hello world contract. I'm getting tired of trying to find a solution, as I came here from trying to deploy to polygon mainnet which has absolute as when you deploy to bsc mainnet.. help. deployment on testnets works just fine!

barhouum7 commented 2 years ago

I've started seeing the exact same ETIMEDOUT error when deploying my Smart Contract on Goerli Testnet, and using Alchemy as my node provider.

image

And I was able to fix it by simply replacing https in my node provider URL with wss For example:

https://eth-goerli.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY} // Url to an Ethereum Node

To >>>

wss://eth-goerli.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY} // Url to an Ethereum Node

goerli: {
      provider: function () {
        return new HDWalletProvider(
          privateKeys.split(','), // Array of account private keys
          `wss://eth-goerli.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`// Url to an Ethereum Node
        )
      },
      gas: 5000000,
      gasPrice: 25000000000,
      network_id: 5,
      skipDryRun: true,
      confirmations: 10,
      networkCheckTimeout: 1000000,
      websocket: true,
      timeoutBlocks: 90000
    }
miladnikad commented 2 years ago

When I used other endpoints, The issue was fixed. You can try the below endpoints.

BSC RPC Endpoints:

https://data-seed-prebsc-1-s1.binance.org:8545/
https://data-seed-prebsc-2-s1.binance.org:8545/
https://data-seed-prebsc-1-s2.binance.org:8545/
https://data-seed-prebsc-2-s2.binance.org:8545/
https://data-seed-prebsc-1-s3.binance.org:8545/
https://data-seed-prebsc-2-s3.binance.org:8545/
dav1app commented 1 year ago

Polygon testnet is failing on the same circumstances and unfortunately infura doesn't provide a WSS connection to Polygon.

I've decided to debug node_modules/request/request.js and it seams that Truffle is attempting to make multiple requests at once, despite of NodeJS well-known concurrency request issues.

Editing pollingInterval has no effect, since the requests are not for the pooling itself.

ID was removed on purpose. It is present on the request.

REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551440969,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551440980,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551440997,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551441009,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551441020,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1665551441031,"jsonrpc":"2.0","params":[],"method":"eth_chainId"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST {
  uri: 'https://polygon-mumbai.infura.io/v3/',
  method: 'POST',
  headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
  body: '{"id":1,"jsonrpc":"2.0","params":[],"method":"eth_blockNumber"}',
  rejectUnauthorized: false,
  timeout: 20000,
  callback: [Function (anonymous)]
}
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/
REQUEST make request https://polygon-mumbai.infura.io/v3/

Right after that, we receive an unhandled rejection

Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: ETIMEDOUT
    at Timeout.<anonymous> (/home/dav1app/Projects/Rafa/Repos/token/node_modules/request/request.js:848:19)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
    at PollingBlockTracker._performSync (/home/dav1app/Projects/Rafa/Repos/token/node_modules/eth-block-tracker/src/polling.js:51:24)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
UnhandledRejections detected
Promise {
  <rejected> {
    code: -32603,
    message: 'ETIMEDOUT',
    data: { originalError: [Object] },
    stack: 'Error: ETIMEDOUT\n' +
      '    at Timeout.<anonymous> (/home/dav1app/Projects/Rafa/Repos/token/node_modules/request/request.js:848:19)\n' +
      '    at listOnTimeout (node:internal/timers:559:17)\n' +
      '    at processTimers (node:internal/timers:502:7)'
  }
} {
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } },
  stack: 'Error: ETIMEDOUT\n' +
    '    at Timeout.<anonymous> (/home/dav1app/Projects/Rafa/Repos/token/node_modules/request/request.js:848:19)\n' +
    '    at listOnTimeout (node:internal/timers:559:17)\n' +
    '    at processTimers (node:internal/timers:502:7)'
}
Promise {
  <rejected> {
    code: -32603,
    message: 'ETIMEDOUT',
    data: { originalError: [Object] },
    stack: 'Error: ETIMEDOUT\n' +
      '    at Timeout.<anonymous> (/home/dav1app/Projects/Rafa/Repos/token/node_modules/request/request.js:848:19)\n' +
      '    at listOnTimeout (node:internal/timers:559:17)\n' +
      '    at processTimers (node:internal/timers:502:7)'
  }
} {
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } },
  stack: 'Error: ETIMEDOUT\n' +
    '    at Timeout.<anonymous> (/home/dav1app/Projects/Rafa/Repos/token/node_modules/request/request.js:848:19)\n' +
    '    at listOnTimeout (node:internal/timers:559:17)\n' +
    '    at processTimers (node:internal/timers:502:7)'
}

Right after seeing this, I've tried to run all the requests manually, all of them seems to be working fine.

Some of you might not see an issue with this because the APIs are fast enough to answer your requests.

This behavior should change. I'm in favor of including a throttle option to allow requests to be handled individually.

cliffoo commented 1 year ago

Hey all, is anyone still getting timeout errors with the latest release of Truffle (5.7.5)? Using whatever endpoints polygon and bnb chain are recommending?

cc @Bobface

ltfschoen commented 1 year ago

i'm using Truffle 5.10.0 / Node.js v18.16.0 and still encountering these errors.

I tried running truffle test --verbose-rpc --debug --network moonbase and troubleshooting in different ways listed below:

i was recommended to switch to Hardhat instead of Truffle, which is not surprising given this issues has been open for almost 3 years, but i'd still like to persevere since i've always used Truffle... hopefully someone creates an ecosystem bounty since so many tutorials use Truffle and so many users probably encounter this issue and don't report it in this thread. i agreed with @dav1app and support trying to include a throttle operation. if there were such an option i think i could have a long timeout and many retries and without getting an error like [ProviderError: Too Many Requests] { code: -32603, data: [Object] }

if anyone wants to reproduce the issue, just checkout this commit https://github.com/ltfschoen/InkTemplate/pull/16/commits/2f663661968b4e848740b15255b1722cb927678b

# truffle test --network moonbase
Using network 'moonbase'.

Compiling your contracts...
===========================
✓ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./contracts/Flipper.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/lib/RandomNumber.sol
> Artifacts written to /tmp/test--18663-seNy7rBUyL0E
> Compiled successfully using:
   - solc: 0.8.20+commit.a1b79de6.Emscripten.clang
accounts:  [ '0x1dd907ABb024E17d196de0D7Fe8EB507b6cCaae7' ]

  Contract: Flipper
randomnessInstance.address: 0x0000000000000000000000000000000000000809
randomNumberInstance.address: 0x7ae29716433406B30FB252790716a7471c1B1bBD
flipperInstance.address: 0x4a204dD4a648fbE859a509dd7535e94Fa35c464c
    1) "before each" hook for "checks stored value"

  0 passing (3s)
  1 failing

  1) Contract: Flipper
       "before each" hook for "checks stored value":
     Uncaught Error: Unhandled error. ({
  code: -32603,
  message: 'Too Many Requests',
  data: { originalError: {} }
})
      at new NodeError (node:internal/errors:399:5)
      at Web3ProviderEngine.emit (node:events:502:17)
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/index.js:54:14
      at afterRequest (node_modules/web3-provider-engine/index.js:148:21)
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/index.js:174:21
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/index.js:232:9
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/node_modules/async/internal/once.js:12:16
      at replenish (node_modules/web3-provider-engine/node_modules/async/internal/eachOfLimit.js:61:25)
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/node_modules/async/internal/eachOfLimit.js:71:9
      at eachLimit (node_modules/web3-provider-engine/node_modules/async/eachLimit.js:43:36)
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/node_modules/async/internal/doLimit.js:9:16
      at end (node_modules/web3-provider-engine/index.js:211:5)
      at /app/dapps/evm2/flipper/node_modules/web3-provider-engine/subproviders/rpc.js:52:18
      at Request._callback (node_modules/web3-provider-engine/subproviders/rpc.js:53:11)
      at Request.self.callback (node_modules/request/request.js:185:22)
      at Request.emit (node:events:513:28)
      at Request.<anonymous> (node_modules/request/request.js:1154:10)
      at Request.emit (node:events:513:28)
      at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)
      at Object.onceWrapper (node:events:627:28)
      at IncomingMessage.emit (node:events:525:35)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21)
ltfschoen commented 1 year ago

so i had a look into that error i was getting. i'm using the latest @truffle/hdwallet-provider v2.1.12, which uses web3-provider-engine v16.0.3, and the problem with using that dependency is they say at https://www.npmjs.com/package/web3-provider-engine:

⚠️ PLEASE READ ⚠️vThis package was originally created for MetaMask and is being phased out in favor of json-rpc-engine and eth-json-rpc-middleware. As such, we will no longer be accepting changes to this package except those which address security issues.

the error that i'm getting is because of that dependency, which hasn't been phased out by the latest version of @truffle/hdwallet-provider yet.

if i find the line number that generated my error here, it's caused by the response from Web3ProviderEngine.prototype._getBlockByNumberWithRetry = function(blockNumber, cb) here, which just hard-codes doing 5x retries here, and also hard-codes 1 second as the interval between each retry here.

also in web3-provider-engine/subproviders/rpc.js they use a hard-coded timeout of 20 seconds here, and that's where it returns Too Many Requests if rate limiting response is provided.

with those changes it gets through most of my tests but still gives the Too Many Requests error when it gets up to the "should flip the value" test.

so it would be interesting to see if the issue occurred in the Truffle version that used web3-provider-engine version prior to this commit https://github.com/MetaMask/web3-provider-engine/commit/caaf92bd472c8738d508181d7fd5445df8da432f