diff --git a/loadtest/helpers/init.js b/loadtest/helpers/init.js index 04ff252322..e0e68306d1 100644 --- a/loadtest/helpers/init.js +++ b/loadtest/helpers/init.js @@ -9,10 +9,11 @@ export function fundTestAccounts(client, root_address) { // fund the VUs accounts for (let i = 0; i < exec.instance.vusInitialized; i++) { - var tacc = wallet.generateKey(); + var tacc = wallet.generateKey(); accounts[i] = { private_key: tacc.private_key, address: tacc.address, + nonce: 0, }; // fund each account with some coins diff --git a/loadtest/scenarios/multiple_EOA.js b/loadtest/scenarios/multiple_EOA.js index 3062d0430e..ce83d2bbda 100644 --- a/loadtest/scenarios/multiple_EOA.js +++ b/loadtest/scenarios/multiple_EOA.js @@ -64,30 +64,32 @@ export function setup() { return { accounts: fundTestAccounts(client, root_address) }; } -var nonce = 0; -var client; +var clients = []; // VU client export default function (data) { + var client = clients[exec.vu.idInInstance - 1]; if (client == null) { client = new eth.Client({ url: rpc_url, privateKey: data.accounts[exec.vu.idInInstance - 1].private_key }); + + clients[exec.vu.idInInstance - 1] = client; } - console.log(`nonce => ${nonce}`); + const userData = data.accounts[exec.vu.idInInstance - 1] const tx = { to: "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", value: Number(0.00000001 * 1e18), gas_price: client.gasPrice(), - nonce: nonce, + nonce: userData.nonce, }; const txh = client.sendRawTransaction(tx); - console.log("tx hash => " + txh); - nonce++; + console.log("sender => " + userData.address + " tx hash => " + txh + " nonce => " + userData.nonce); + userData.nonce++; // client.waitForTransactionReceipt(txh).then((receipt) => { // console.log("tx block hash => " + receipt.block_hash); diff --git a/loadtest/scenarios/multiple_ERC20.js b/loadtest/scenarios/multiple_ERC20.js index 6f25996447..b0ec792490 100644 --- a/loadtest/scenarios/multiple_ERC20.js +++ b/loadtest/scenarios/multiple_ERC20.js @@ -73,26 +73,28 @@ export function setup() { }; } -let nonce = 0; -let client; +var clients = []; // VU client export default function (data) { - let acc = data.accounts[exec.vu.idInInstance - 1]; - + var client = clients[exec.vu.idInInstance - 1]; if (client == null) { - client = new eth.Client({ - url: rpc_url, - privateKey: acc.private_key - }); + client = new eth.Client({ + url: rpc_url, + privateKey: data.accounts[exec.vu.idInInstance - 1].private_key + }); + + clients[exec.vu.idInInstance - 1] = client; } + let acc = data.accounts[exec.vu.idInInstance - 1]; + console.log(acc.address); const con = client.newContract(data.contract_address, JSON.stringify(ZexCoin.abi)); - const res = con.txn("transfer", { gas_limit: 100000, nonce: nonce }, acc.address, 1); + const res = con.txn("transfer", { gas_limit: 100000, nonce: acc.nonce }, acc.address, 1); console.log(`txn hash => ${res}`); - nonce++; + acc.nonce++; // console.log(JSON.stringify(con.call("balanceOf", acc.address))); } diff --git a/server/server.go b/server/server.go index 5e9e9b9ff6..e464aa2a13 100644 --- a/server/server.go +++ b/server/server.go @@ -343,6 +343,7 @@ func NewServer(config *Config) (*Server, error) { PriceLimit: m.config.PriceLimit, MaxAccountEnqueued: m.config.MaxAccountEnqueued, ChainID: big.NewInt(m.config.Chain.Params.ChainID), + PeerID: m.network.AddrInfo().ID, }, ) if err != nil { diff --git a/txpool/txpool.go b/txpool/txpool.go index e1f2e5a187..10617ffad4 100644 --- a/txpool/txpool.go +++ b/txpool/txpool.go @@ -102,6 +102,7 @@ type Config struct { MaxSlots uint64 MaxAccountEnqueued uint64 ChainID *big.Int + PeerID peer.ID } /* All requests are passed to the main loop @@ -186,6 +187,9 @@ type TxPool struct { // chain id chainID *big.Int + + // localPeerID is the peer ID of the local node that is running the txpool + localPeerID peer.ID } // NewTxPool returns a new pool for processing incoming transactions. @@ -207,6 +211,7 @@ func NewTxPool( gauge: slotGauge{height: 0, max: config.MaxSlots}, priceLimit: config.PriceLimit, chainID: config.ChainID, + localPeerID: config.PeerID, // main loop channels promoteReqCh: make(chan promoteRequest), @@ -919,11 +924,16 @@ func (p *TxPool) handlePromoteRequest(req promoteRequest) { // addGossipTx handles receiving transactions // gossiped by the network. -func (p *TxPool) addGossipTx(obj interface{}, _ peer.ID) { +func (p *TxPool) addGossipTx(obj interface{}, peerID peer.ID) { if !p.sealing.Load() { return } + // ignore txs gossiped by the node itself + if p.localPeerID == peerID { + return + } + raw, ok := obj.(*proto.Txn) if !ok { p.logger.Error("failed to cast gossiped message to txn")