3

How does one configure either Truffle itself, or Truffle's HDWalletProvider such that the poll interval is different?

I would like my Truffle instance to be less "chatty" over JSON-RPC, when it has submitted a transaction and is waiting for a result, be decreasing the polling interval from it's default value.

I was not able to find this option in the following documentation:


In truffle-config.js, within networks:

    testnet: {
      provider: () => new HDWalletProvider(
        SEED_PHRASE,
        'https://localhost:4444/',
      ),
      gasPrice: Math.floor(GAS_PRICE),
      networkCheckTimeout: 1e3,
    },
TylerH
  • 20,799
  • 66
  • 75
  • 101
bguiz
  • 27,371
  • 47
  • 154
  • 243
  • 1
    Noticed this - but not sure how I would use it - any ideas? https://github.com/trufflesuite/truffle/blob/55c128d8032eef38dc2fa77e0b75994befada7b2/packages/hdwallet-provider/typings/web3-provider-engine/index.d.ts#L8-L9 – bguiz Nov 03 '20 at 04:02
  • It's a field of Web3Provider, which HDWalletProvider imports as a field called 'engine', so if provider is your HDWalletProvider, you would use provider.engine.pollingInterval to access the field. – Zach Nov 03 '20 at 07:23
  • hmm that's worth a shot! - `provider.engine.pollingInterval` – bguiz Nov 03 '20 at 08:59
  • Created issue: https://github.com/trufflesuite/truffle/issues/3498 – bguiz Nov 04 '20 at 05:58
  • Great work. Really impressed to see you not only following the leads on your question but being involved in fixing the problem once identified. Would you like a code review, or have the maintainers you spoke to already done that? Also, when you feel like your question is resolved here, marking an accepted answer and possibly editing your question with an addendum stating the end solution (in this case your PR) can help this question stand out to people in the same situation you were in when you posted the question. – Zach Nov 06 '20 at 01:29

2 Answers2

3

Patched @truffle/hdwallet-provider to add pollingInterval. This is now available in truffle@5.1.52.

Patched truffle to add deploymentPollingInterval. This is now available in truffle@5.1.53.

Example:

    testnet: {
      provider: () => new HDWalletProvider({
        mnemonic: {
          phrase: SEED_PHRASE,
        },
        providerOrUrl: 'http://localhost:4444',
        pollingInterval: 8000,
      }),
      gasPrice: Math.floor(GAS_PRICE),
      networkCheckTimeout: 8000,
      deploymentPollingInterval: 8000,
    },

When unspecified, the default value for pollingInterval and deploymentPollingInterval are both 4000; so the above example has the effect of making it half as "chatty" over JSON-RPC, when polling for blocks, and when running truffle migrate.

bguiz
  • 27,371
  • 47
  • 154
  • 243
1

Not sure about HDWalletProvider, and, like you, could not find any documentation regarding the polling rate for it. After browsing the source, I've come to the conclusion that HDWalletProvider doesn't include a built-in mechanism for poll-rate limiting, though I may be incorrect.

I have, however, found a wallet provider implementation that does support it, and has the usage documented.

Apologies that I couldn't find exactly what you're looking for, but hopefully this will fit your needs. I'll have more time to go over the source this weekend, and I'll update this answer if I find anything additional.

Update: After seeing your mention of the pollingInterval field for Web3ProviderEngine, you could access the corresponding engine.pollingInterval field for your instance of HDWalletProvider. If you're unclear on object instantiation and fields in TypeScript, I'd recommend opening another question on that topic, or perusing existing resources such as this question.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Zach
  • 586
  • 3
  • 12
  • 1
    That project seems to be inactive or unmaintained - last update was almost 3 years ago (jan 2018) https://github.com/DigixGlobal/truffle-lightwallet-provider/commit/9acb7f86a92deedba2d8a1d2beac95db26aa7071 ... so I'm hesitant to use it – bguiz Nov 03 '20 at 04:05
  • I can understand that; however, if the last update is stable and fits your needs, whether a package is actively maintained or not becomes a sort of moot point. It all depends on whether it suits you better to use an old package that works perfectly or a fresh and actively maintained package you have to make concessions to use. Only you can make that choice (or the senior engineer/team lead on your project if relevant). – Zach Nov 03 '20 at 07:27
  • Aha, yeah I have been burnt enough times to be really wary of situations like this! I think this is something worth patching, either within Truffle suite or within its HDWalletProvider - to ensure that it is kept maintained. – bguiz Nov 04 '20 at 01:43
  • 1
    I agree wholeheartedly. – Zach Nov 06 '20 at 01:34