Skip to content
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

session_nonces increment issue #9

Open
milyInzhoop opened this issue Feb 24, 2016 · 2 comments
Open

session_nonces increment issue #9

milyInzhoop opened this issue Feb 24, 2016 · 2 comments

Comments

@milyInzhoop
Copy link

I saw that session_nonce and global nonce for a Sender X was incremented even if you enter a wrong password or if you cancel the transaction. This causes that your next transaction will be always queued.

I MOVED the row:

 // Update caches.
 session_nonces[sender] = final_nonce + 1;
 _this3.global_nonces[sender] = final_nonce + 1;

AFTER (row 169):

_this3.transaction_signer.signTransaction(tx_params, function (err, raw_tx) {
              if (err != null) {
                return next(err);
 }

and it solves for me.

Look at our version on github for complete file:
https://github.com/inzhoop-co/LETH/blob/master/www/lib/thirdparty/hooked-web3-provider.js

@gaiazov
Copy link

gaiazov commented Apr 11, 2016

I was able to just override sendTransaction implementation to always get the nonce as transaction count from the node

var originalSignFn = keystore.signTransaction.bind(keystore);
keystore.signTransaction = function(txParams, callback) {
    web3.eth.getTransactionCount(txParams.from, 'pending', function(err, result) {
        txParams.nonce = Web3.prototype.toHex(result);
        originalSignFn(txParams, callback);
    });
};

@rangelife
Copy link

rangelife commented Sep 27, 2016

The problem with always getting the pending transaction count is that you might send multiple transactions in quick succession- the first tx gets signed and sent, but before it's queued the second tx is signed, at which point the pending tx count is the same as before, meaning you send multiple different transactions with the same nonce (which, i've observed, on geth at least, raises no error from sendTransaction, and only one of the transactions actually ends up getting mined, the other completely disappears with no error).

Incrementing the nonce anywhere in the signing hook is a problem, because it doesn't take into account the possibility that the node will reject the transaction before queueing it, even if the signing hook has completed successfully (in which case the next transaction must have the same nonce as before, or it'll cause a nonce gap and a jammed account).

The only safe way I can see to do this is to:

  • make the signing hook always use the pending tx count as the nonce value
  • ensure that all sendTransaction calls are serialised. This queueing is a burden on the client code- so I think there's a good case for trying to add it to web3 itself.

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

No branches or pull requests

3 participants