-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bug in @trufflesuite/web3-provider-engine 14.0.6 (dependency of @truffle/hdwallet-provider 1.0.36 where getBlockByNumber function of the blockTracker event listener sometimes returns a null block object and crashes applications with error TypeError: Cannot read property 'number' of null
#3130
Bug in @trufflesuite/web3-provider-engine 14.0.6 (dependency of @truffle/hdwallet-provider 1.0.36 where getBlockByNumber function of the blockTracker event listener sometimes returns a null block object and crashes applications with error TypeError: Cannot read property 'number' of null
#3130
Comments
Nice sleuthing @ltfschoen ! Glad to hear this was a known issue MM resolved in a later version of |
Until this goes out in our official weekly release, the fix for this is out at Please give it a shot and let us know if this particular error has been resolved! 🙏 |
Testing out dependency change: trufflesuite/truffle#3130 (comment)
just to confirm this works :) |
* fix: npm install && npm audit fix Seems like there is some dependency trouble. Try blindly solving it with npm audit fix. * chore: CI node version to 10.20 * chore: lock truffle version * test: tmp diable CI cache * chore: add debug on http request * chore: revive cache...seems unrelated * artifect logs * chore: bump truffle version * debug: is it HDwallet issue? * debug: back to function hd wallet provider * test: does deploy still work? * debug: use cache var to delay wallet provider initiation * test * revert truffle-config.js * provider back to a function * chore: use @truffle/hdwallet-provider@next Testing out dependency change: trufflesuite/truffle#3130 (comment) * chore: re-enable master branch filter on rinkeby deploy * docs: remove unrelevant comment Co-authored-by: Kevin Sullivan <4653170+kevsul@users.noreply.github.com>
Is there something I can do to work around this? I tried to update my package.json file to use a different version of "@truffle/hdwallet-provider": "^1.0.36". Is there something I can do while this is down? |
Oh I saw you can do |
Ah now my script is just hanging instead of breaking. I'm using It's freezing at Not sure if that is enough information. Sounds like we may have to update the script or the box |
Hey @PatrickAlphaC , does the script consistently fail on that line? I assume you're referring to the official box here. I'm wondering if the issue you're seeing is related to #3133. Will take a look and try to reproduce! |
@PatrickAlphaC following up, the issue you're seeing isn't #3133. Looking at the script I believe you're referring to here... You'll need to set the provider on const MyContract = artifacts.require('MyContract')
const { LinkToken } = require('@chainlink/contracts/truffle/v0.4/LinkToken')
module.exports = async callback => {
const mc = await MyContract.deployed()
const tokenAddress = await mc.getChainlinkToken()
LinkToken.setProvider(process.env.RPC_URL) // <-------------------- ropsten infura api url
const token = await LinkToken.at(tokenAddress)
console.log('Funding contract:', mc.address)
const tx = await token.transfer(mc.address, payment)
callback(tx.tx)
} We also expose The other hiccup is that you'll need to specify the sender in the ie. const tx = await token.transfer(mc.address, payment, {
from: web3.currentProvider.addresses[0],
}); In migration & testing contexts, And finally... because the script is attempting to interact with contracts already live on the network, I don't believe you'll be able to successfully transfer tokens unless the loaded account/sender already has tokens assigned to it on the live contract. |
@CruzMolina thank you so much for this detailed response. With your suggestions it now hangs at the part that you said wouldn't work:
I guess I don't understand why this isn't working.
|
@PatrickAlphaC You should be able to see the rpc error bubble up by wrapping the exec script in a const MyContract = artifacts.require("MyContract");
const { LinkToken } = require("@chainlink/contracts/truffle/v0.4/LinkToken");
module.exports = async (callback) => {
try {
const mc = await MyContract.deployed();
const tokenAddress = await mc.getChainlinkToken();
LinkToken.setProvider(process.env.RPC_URL);
const token = await LinkToken.at(tokenAddress);
console.log("Funding contract:", mc.address);
const tx = await token.transfer(mc.address, payment, {
from: web3.currentProvider.addresses[0],
});
callback(tx.tx);
} catch (error) {
callback(error);
}
}; |
Very helpful, thank you! |
Issue
Truffle's fork of the Metamask web3-provider-engine doesn't include changes such as adding a
_getBlockByNumberWithRetry
and catering for when the block tracker event listener occasionally returns a block object that has anull
value. As a result, when you use the dependency "@truffle/hdwallet-provider": "^1.0.36" (which depends on "@trufflesuite/web3-provider-engine" "14.0.6") in your project, it will eventually crash.Steps to Reproduce
It requires patience to reproduce because you have to wait until
_getBlockByNumber
eventually returns anull
value, which could take over an hour.To reproduce, clone my faucet project https://github.com/DataHighway-DHX/faucet, set it up by following the instructions in the README, which include installing Node.js 14.4.0 and Yarn.
Then modify the dependencies to add some console.logs for debugging by editing DataHighway-DHX/faucet-mining/node_modules/@trufflesuite/web3-provider-engine/index.js, and modifying the code by adding the section shown below between
// MODIFICATIONS START HERE
and// MODIFICATIONS END HERE
:Then run the code:
And watch the terminal logs until the output becomes
Then you've got evidence of where and why it crashed.
Expected Behavior
I expected it not to crash. But now that I know that it crashes because the block object sometimes returns a
null
object, I know that to fix it we just need to make the same changes that MetaMask's web3-provider-engine did. They previously fixed that bug by exiting early from that getBlockByNumber function here https://github.com/MetaMask/web3-provider-engine/blob/master/index.js#L57, and more recently they just replaced the _getBlockByNumber function with a _getBlockByNumberWithRetry function in this commit MetaMask/web3-provider-engine@caaf92bActual Results
Refer to actual results in the above "Steps to Reproduce" section
Environment
truffle version
): N/A ("@truffle/hdwallet-provider": "^1.0.36")node --version
): v14.4.0npm --version
): 6.14.5The text was updated successfully, but these errors were encountered: