Consensys / quorum

A permissioned implementation of Ethereum supporting data privacy
https://www.goquorum.com/
GNU Lesser General Public License v3.0
4.68k stars 1.29k forks source link

Transaction nonce not increasing #822

Closed vasa-develop closed 5 years ago

vasa-develop commented 5 years ago

System information

Geth version: geth version

WARN [09-13|22:33:19.148] Sanitizing cache to Go's GC limits provided=1024 updated=666 Geth Version: 1.8.18-stable Git Commit: 664c2ab20af384c5b350aabf5f6307327d8de09e Quorum Version: 2.2.5 Architecture: amd64 Protocol Versions: [63 62] Network Id: 1337 Go Version: go1.10.1 Operating System: linux GOPATH= GOROOT=/usr/local/go OS & Version: Windows/Linux/OSX

Branch, Commit Hash or Release: git status

commit 664c2ab20af384c5b350aabf5f6307327d8de09e Author: Nguyen Kien Trung trung.n.k@gmail.com Date: Tue Aug 27 15:17:59 2019 -0400

p2p/enode, p2p/discv5: fix URL parsing test for go 1.11.13 (#810)

Expected behavior

The transactions should be executed and broadcasted to all the network nodes when I send a transaction using web3.js

Actual behavior

I used the Getting Started Docs to set up a Quorum network(Istanbul BFT) on 5 nodes. Now, if I send a transaction using web3.js or web3j, the transaction for nonce=0 is executed.

q1

But, when I now query the nonce(using web3.eth.getTransactionCount()) then it's still 0. So, if I send the transaction with nonce=0 it gives "nonce too low" error. If I try increasing the nonce=1 then the transaction is sort of stuck. I think it's not broadcasted to other nodes, as I can see from the following pic.

errq

Whereas when I use remix to send the same transaction, the transaction gets executed and broadcasted to other nodes. (Basically, using remix, I don't encounter the above problem, even after sending multiple transactions)

For eg. I'm using ethereumjs-tx@^2.1.0 & web3.js@^1.2.1

var Tx = require('ethereumjs-tx').Transaction;
var privateKey = Buffer.from('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x00',
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000',
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

var tx = new Tx(rawTx);
tx.sign(privateKey);

var serializedTx = tx.serialize();

// console.log(serializedTx.toString('hex'));
// 0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);

P.S. This above approach to sign & send Transactions was working fine when I used the 7nodes example.

Steps to reproduce the behavior

Setup a 5 node network using Getting Started Docs

Try sending at least 2 transactions using single keypair. Only the first transaction gets through.

@fixanoid @jpmsam @jbhurat let me know if you need additional info.

jbhurat commented 5 years ago

Hi @vasa-develop, can you also paste your genesis config and geth startup parameters. Are these similar to the ones defined in Getting Started Docs

jbhurat commented 5 years ago

Can you also verify if the transaction has been minted in a block. From the logs, I can see QUORUM-CHECKPOINT message for transaction creation, but don't see one for block creation

vasa-develop commented 5 years ago

genesis.json

{
    "config": {
        "chainId": 10,
        "homesteadBlock": 0,
        "eip150Block": 0,
        "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "eip155Block": 0,
        "eip158Block": 0,
        "byzantiumBlock": 0,
        "constantinopleBlock": 0,
        "istanbul": {
            "epoch": 30000,
            "policy": 0
        },
        "txnSizeLimit": 64,
        "isQuorum": true
    },
    "nonce": "0x0",
    "timestamp": "0x5d836ec7",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000f8aff869942585cc1aad25ff13404b6668d2ad82adf0906f1694d64a94834f28ea49b5dbac91b2b6bdc616cdbf4394944d15bc6d3925e1627fb54071319a58da28f6e394f2a8c499c4de08093faedc461a540c573825d60894c13589647cc4033aacc300b12f52f9d5492845bdb8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0",
    "gasLimit": "0xe0000000",
    "difficulty": "0x1",
    "mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "alloc": {
        "7eb05f75b975c815e5d7e716f05836c8a085fcbc": {
            "balance": "0x446c3b15f9926687d2c40534fdb564000000000000"
        },
        "436b2528cf76634d673efa80d29eb8188076a474": {
            "balance": "0x446c3b15f9926687d2c40534fdb564000000000000"
        },
        "dc7611ab67148414c327abfab113830bb8c68c9f": {
            "balance": "0x446c3b15f9926687d2c40534fdb564000000000000"
        },
        "8024d907ffb7f19b686e48c857cbdb68313fcb6c": {
            "balance": "0x446c3b15f9926687d2c40534fdb564000000000000"
        },
        "362f547bf98d43ebb883454ea87285380c115f99": {
            "balance": "0x446c3b15f9926687d2c40534fdb564000000000000"
        }
    },
    "number": "0x0",
    "gasUsed": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

Geth startup params

#!/bin/bash
cd node0
PRIVATE_CONFIG=ignore nohup geth --datadir data --nodiscover --istanbul.blockperiod 1 --syncmode full --mine --minerthreads 1 --verbosity 5 --networkid 10 --rpc --rpcaddr 0.0.0.0 --rpcport 22000 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul --emitcheckpoints --port 30300 2>>node.log &

cd ../node1
PRIVATE_CONFIG=ignore nohup geth --datadir data --nodiscover --istanbul.blockperiod 1--syncmode full --mine --minerthreads 1 --verbosity 5 --networkid 10 --rpc --rpcaddr 0.0.0.0 --rpcport 22001 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul --emitcheckpoints --port 30301 2>>node.log &

cd ../node2
PRIVATE_CONFIG=ignore nohup geth --datadir data --nodiscover --istanbul.blockperiod 1 --syncmode full --mine --minerthreads 1 --verbosity 5 --networkid 10 --rpc --rpcaddr 0.0.0.0 --rpcport 22002 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul --emitcheckpoints --port 30302 2>>node.log &

cd ../node3
PRIVATE_CONFIG=ignore nohup geth --datadir data --nodiscover --istanbul.blockperiod 1 --syncmode full --mine --minerthreads 1 --verbosity 5 --networkid 10 --rpc --rpcaddr 0.0.0.0 --rpcport 22003 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul --emitcheckpoints --port 30303 2>>node.log &

cd ../node4
PRIVATE_CONFIG=ignore nohup geth --datadir data --nodiscover --istanbul.blockperiod 1 --syncmode full --mine --minerthreads 1 --verbosity 5 --networkid 10 --rpc --rpcaddr 0.0.0.0 --rpcport 22004 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul --emitcheckpoints --port 30304 2>>node.log &
vasa-develop commented 5 years ago

@jbhurat About the blocks, here is something that might help. The below pic says that transactions are queued.

errq1

vasa-develop commented 5 years ago

@jbhurat any thoughts?

jbhurat commented 5 years ago

@vasa-develop, I tried the above using ethereumjs-tx@^2.1.0 & web3.js@^1.2.1 and was able to reproduce the issue you are seeing and debugging it couldn't get any further. I then tried the same example using ethereumjs-tx@^1.3.4 & web3.js@1.0.0-beta.36 and it worked. Can you try the above test case and let me know whether it works for you?

jbhurat commented 5 years ago

Hi @vasa-develop, As I haven't received a response back, I am assuming this is working for you after updating versions of ethereumjs-tx and web3.js. I am going to close this ticket for now, please reopen if it still doesn't work for you

fixanoid commented 5 years ago

@vasa-develop we have updated quorum.js to support ethereumjs-tx@^2.1.0. Essentially, new version defaults to signer that may not be enabled in your config. One way to solve it is to do something like this:

var tx = new Tx(rawTx, { chain: 'mainnet', hardfork: 'constantinople' });
vasa-develop commented 5 years ago

@jbhurat @fixanoid I tried your solutions. @jbhurat's solution worked for me. So, the thing is that the ethereumjs-tx@^2.1.0 is causing the problem. As @fixanoid suggested, I was already using the additional parameter(for specifying the chain), but that didn't help.

It doesn't matter what version of web3 I use, it's the problem from ethereumjs-tx side.

The difference comes in the signed transactions. Below are the signed transactions from the 2 versions of ethereum-js

ethereumjs-tx@^2.1.0 (not working)

0xf90105038083989680947564703443b1cbae5a3c12f87006f5010bafae4380b8a40c8301528312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000008312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000a736466736464667364660000000000000000000000000000000000000000000026a0400fa11d1311c0f78b2eac1029ea278ec86ab51f331bed92af1a752a6dd1b66fa01855f079e0df73f93f2d2a89f36b353a75ce80af79dd1e0eae89bd2ba3f3799b

ethereumjs-tx@^1.3.7 (working)

0xf90105038083989680947564703443b1cbae5a3c12f87006f5010bafae4380b8a40c8301528312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000008312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000a73646673646466736466000000000000000000000000000000000000000000001ca0e9c1a998383526633e3a5842651a5f8a4eb49fa835662c108a1aa2e347f3c6afa0132b884990ca5ff4b842eabbaefe0cff31b288bc895f21d6a62ebedd88ce3cf4
fixanoid commented 5 years ago

Hey, so for signed txns with new version you should try harsfork: "homestead" or simply downgrade as suggested.

On Sun, Sep 29, 2019, 9:46 AM vasa notifications@github.com wrote:

@jbhurat https://github.com/jbhurat @fixanoid https://github.com/fixanoid I tried your solutions. @jbhurat https://github.com/jbhurat's solution worked for me. So, the thing is that the ethereumjs-tx@^2.1.0 is causing the problem. As @fixanoid https://github.com/fixanoid suggested, I was already using the additional parameter(for specifying the chain), but that didn't help.

It doesn't matter what version of web3 I use, it's the problem from ethereumjs-tx side.

The difference comes in the signed transactions. Below are the signed transactions from the 2 versions of ethereum-js

ethereumjs-tx@^2.1.0 (not working)

0xf90105038083989680947564703443b1cbae5a3c12f87006f5010bafae4380b8a40c8301528312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000008312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000a736466736464667364660000000000000000000000000000000000000000000026a0400fa11d1311c0f78b2eac1029ea278ec86ab51f331bed92af1a752a6dd1b66fa01855f079e0df73f93f2d2a89f36b353a75ce80af79dd1e0eae89bd2ba3f3799b

ethereumjs-tx@^1.3.7 (working)

0xf90105038083989680947564703443b1cbae5a3c12f87006f5010bafae4380b8a40c8301528312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000008312495f6adb4b9f76db7875d4279e27f94c23ed0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000a73646673646466736466000000000000000000000000000000000000000000001ca0e9c1a998383526633e3a5842651a5f8a4eb49fa835662c108a1aa2e347f3c6afa0132b884990ca5ff4b842eabbaefe0cff31b288bc895f21d6a62ebedd88ce3cf4

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jpmorganchase/quorum/issues/822?email_source=notifications&email_token=AADM7DFDJRE6WJPO7M5OFS3QMCWVFA5CNFSM4IYXIULKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD73VEEY#issuecomment-536302099, or mute the thread https://github.com/notifications/unsubscribe-auth/AADM7DHPR3KZSXEY66HZZNLQMCWVFANCNFSM4IYXIULA .

vasa-develop commented 5 years ago

@fixanoid I tried with ethereumjs-tx@^2.1.0 with following params:

{
            chain: 'mainnet',
            harsfork:
                "homestead"
        }

Still got the same(not working) signedTrx.

fixanoid commented 5 years ago

My apologies, it's supposed.yo say hardfork

On Sun, Sep 29, 2019, 10:10 AM vasa notifications@github.com wrote:

@fixanoid https://github.com/fixanoid I tried with ethereumjs-tx@^2.1.0 with following params:

{ chain: 'mainnet', harsfork: "homestead" }

Still got the same(not working) signedTrx.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jpmorganchase/quorum/issues/822?email_source=notifications&email_token=AADM7DH2OKOZH6YNE2VQ34TQMCZMZA5CNFSM4IYXIULKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD73VZHY#issuecomment-536304799, or mute the thread https://github.com/notifications/unsubscribe-auth/AADM7DBJILUKTRETBZRRQI3QMCZMZANCNFSM4IYXIULA .

vasa-develop commented 5 years ago

Oh, I didn't notice that! It's working now :)

sssubik commented 4 years ago

Hey @vasa-develop @fixanoid. So we get the correct nonce value when sending bulk of transactions using ethereumjs-tx@^2.1.0??

fixanoid commented 4 years ago

@sssubik Yes, you should. See example: https://github.com/jpmorganchase/quorum.js/blob/master/7nodes-test/deployContractViaHttp-externalSigningTemplate.js

sssubik commented 4 years ago

Hey @fixanoid is not the example using web3.js library for transaction count instead of ethereumjs-tx@^2.1.0? How could then ethereumjs-tx@^2.1.0 solve it?

fixanoid commented 4 years ago

@sssubik ethereumjs-tx is a package specifically for signing. web3.js is a package specifically to interact with an ethereum node. web3.js is the package that has helpers to fetch transaction counts / nonce.

If you have an issue, please open a new ticket. Thanks