-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increasing of the block number for the confirmation workflow over HTTP is wrong. #2661
Comments
It does never resolve because ganache doesn't mine new blocks but it does fake the newHeads subscription which is the reason why it is working over WS. Did you test it with a code for example like this: function sendTx() {
return new Promise(async (resolve, reject) => {
const accounts = await web3.eth.personal.getAccounts();
web3.eth.sendTransaction({
to: accounts[1],
from: accounts[0],
value: web3.utils.toWei('0.1', 'ether')
})
.on('transactionHash', txHash => {
console.log('on transactionHash', txHash);
})
.on('receipt', resolve)
.on('confirmation', (confirmationNumber, receipt) => {
console.log('on confirmation', confirmationNumber);
})
.on('error', reject);
});
}
// OR:
async function sendTx() {
const accounts = await web3.eth.personal.getAccounts();
return web3.eth.sendTransaction({
to: accounts[1],
from: accounts[0],
value: web3.utils.toWei('0.1', 'ether')
});
} The problem you have is the combination of Promise and the EventEmitter in one call. We had an open issue because of "UnhandledPromiseRejection" errors when someone was just using the events of the PromiEvent and not the promise. This means it doesn't resolve or reject the Promise if an event listener for the error or receipt event exists. |
@szerintedmi I think it's not working due to promises. try to replace promises to the callback. It could be a temporary solution.
I tested on ganache and callback is working. I think this a problem of ganache. In Geth it works fine both with promises and callback. |
@princesinha19 I wouldn't recommend using callbacks because they will get marked as deprecated in the near future. :) |
Yes right, @nivida. That's why I stated it as a temporary solution for him. |
@nivida If callbacks are deprecated, how are you supposed to get a txhash from the API (without waiting for the receipt)? |
@nivida : Thank you for the fast response It seems there are multiple overlapping things here then:
Are there tickets for any of these or shall I create? Btw, do you have any integration tests with ganache? I'm more than happy to contribute some simple ones. |
@nivida |
So when the number arrives here: https://github.com/ethereum/web3.js/blob/1.0/packages/web3-core-method/src/observers/TransactionObserver.js#L282, it wrongly is parsed as base 16, but actually is a base 10. And after you likely to be stuck on the TransactionObserver by waiting 24 txs to be confirmed (default value I guess) to exit off the observer https://github.com/ethereum/web3.js/blob/1.0/packages/web3-core-method/src/observers/TransactionObserver.js#L166. The problem on Ganache is that ganache doesn't mine by itself rather it mines a block when receiving a tx. Ganache only mines if the user request it to mine I not sure if is a good idea to wait for 24 txs to consider the tx confirmed, it's getting stuck on the observer, maybe the user can provide a confirmation number (not checked the docs yet for it), on chains that have 1 tx per second is ok, but for mainnet is not cool. Does HTTP provider needs the confirmation like that ? |
@nivida : Also, we identified an other issue / inconsistency in this thread, wondering about that too:
|
As explained was it not thought to mixup the promise and eventemitter and we had issues with unresolved promise rejections. I will add a sentence to the docs :) I‘ve tested it with geth and parity over an websocket connection but will definitely test it with the ganache „node“ too. This will get fixed on Monday after my short vacation. Btw.: You configured the transaction module options right? |
thanks @nivida ! Ganache is a crucial part of our workflow for automated testing all our dependent modules. I think it's true for most bigger projects. So breaking ganache blocks us from upgrading web3, we are currently stuck at beta33 for long now.
enjoy it and don't check github alerts :)
You mean
|
@szerintedmi can you please change transactionConfirmationBlocks to 1, As you are using testrpc.
|
@princesinha19 : trust me I did play with a lot of different settings. Please read the whole thread and see my code example & gist where it's 1 :) |
Ya, I tested with a web3socket connection too. It's not working we will try to resolve it. |
Can confirm that I am facing the same issue. Happy to help with PR/tests if necessary, as I am blocked on a fairly mission-critical project. |
I'm using web3 1.0.0-beta.55 with the latest version of ganache-cli. Using |
@d10r do you have an event listener for 'reciept' ? When I removed that and get the reciept from the confirmation event, it doesn't hang anymore. |
Same here.
This is just WTF??? |
@einaralex no I don't. Just |
For me, neither await nor .then works. I had to resort to using .on('confirmation', (confNumber, receipt) => { ... }). Using the latest version of web3.js and Ganache. |
I'm seeing failure of promise-wrapped sendSignedTransaction to fire "confirmation" event (and "receipt") on a websocket ganache connection. Works fine on HTTP. Removing "receipt" handler makes no difference. "web3": "^2.0.0-alpha" |
Description
A tx never resolves on ganache with
WebsocketProvider
whatever I settransactionConfirmationBlocks
to.sendTransaction
,sendSignedTransaction
andconfirmation
events are NOT triggered.Only
transactionHash
event is triggered.NB:
HttpProvider
- whentransactionConfirmationBlocks
set to 1 it resolves but anything higher it still never resolves.evm_mine
manually fromtransactionHash
event or call multiple.sendTransaction
in a separate console but no effect.Expected behavior
This should work on ganache as per documentation:
Actual behavior
receipt
orconfirmation
event calledOutput from the included gist with Websocket Provider
And hanging forever...
Output from ganache (trimmed):
Steps to reproduce the behavior
run
sendTx.js
with
node ./txSend.js
(while ganache is running)Error Logs
N/A
Gists
Barebone gist to demonstrate the issue:
sendTx.js
Versions
The text was updated successfully, but these errors were encountered: