diff --git a/loadtest/helpers/init.js b/loadtest/helpers/init.js index 04ff252322..cc12ed2947 100644 --- a/loadtest/helpers/init.js +++ b/loadtest/helpers/init.js @@ -2,7 +2,7 @@ import eth from 'k6/x/ethereum'; import exec from 'k6/execution'; import wallet from 'k6/x/ethereum/wallet'; -export function fundTestAccounts(client, root_address) { +export async function fundTestAccounts(client, root_address) { var accounts = []; var nonce = client.getNonce(root_address); console.log(`nonce => ${nonce}`); @@ -13,12 +13,13 @@ export function fundTestAccounts(client, root_address) { accounts[i] = { private_key: tacc.private_key, address: tacc.address, + nonce: 0, }; // fund each account with some coins var tx = { to: tacc.address, - value: Number(0.05 * 1e18), + value: Number(10 * 1e18), gas_price: client.gasPrice(), nonce: nonce, }; @@ -26,9 +27,9 @@ export function fundTestAccounts(client, root_address) { console.log(JSON.stringify(tx)); var txh = client.sendRawTransaction(tx) console.log(`txn hash => ${txh}`); - client.waitForTransactionReceipt(txh).then((receipt) => { - console.log(`account funded => ${JSON.stringify(receipt)}`); - }); + + var receipt = await client.waitForTransactionReceipt(txh); + console.log(`account funded => ${JSON.stringify(receipt)}`); nonce++; } diff --git a/loadtest/scenarios/multiple_EOA.js b/loadtest/scenarios/multiple_EOA.js index 3062d0430e..60ee16bd3e 100644 --- a/loadtest/scenarios/multiple_EOA.js +++ b/loadtest/scenarios/multiple_EOA.js @@ -5,7 +5,7 @@ import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js'; let setupTimeout = __ENV.SETUP_TIMEOUT; if (setupTimeout == undefined) { - setupTimeout = "220s" + setupTimeout = "1800s" } let rate = __ENV.RATE; @@ -55,39 +55,43 @@ if (rpc_url == undefined) { rpc_url = "http://localhost:10002" } -export function setup() { +export async function setup() { const client = new eth.Client({ url: rpc_url, mnemonic: mnemonic, }); - return { accounts: fundTestAccounts(client, root_address) }; + var accounts = await fundTestAccounts(client, root_address); + + return { accounts: accounts }; } -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, + gas_price: client.gasPrice()*1.2, + 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..4db5d0763a 100644 --- a/loadtest/scenarios/multiple_ERC20.js +++ b/loadtest/scenarios/multiple_ERC20.js @@ -5,7 +5,7 @@ import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js'; let setupTimeout = __ENV.SETUP_TIMEOUT; if (setupTimeout == undefined) { - setupTimeout = "220s" + setupTimeout = "1800s" } let rate = __ENV.RATE; @@ -57,7 +57,7 @@ if (rpc_url == undefined) { const ZexCoin = JSON.parse(open("../contracts/ZexCoinERC20.json")); -export function setup() { +export async function setup() { let data = {}; const client = new eth.Client({ @@ -67,32 +67,36 @@ export function setup() { const receipt = client.deployContract(JSON.stringify(ZexCoin.abi), ZexCoin.bytecode.substring(2), 500000000000, "ZexCoin", "ZEX") + var accounts = await fundTestAccounts(client, root_address); + return { - accounts: fundTestAccounts(client, root_address), + accounts: accounts, contract_address: data.contract_address }; } -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); - console.log(`txn hash => ${res}`); + const res = con.txn("transfer", { gas_limit: 100000, nonce: acc.nonce, gas_price: client.gasPrice()*1.3 }, acc.address, 1); + console.log("sender => " + acc.address + " tx hash => " + res + " nonce => " + acc.nonce); - nonce++; + acc.nonce++; // console.log(JSON.stringify(con.call("balanceOf", acc.address))); } diff --git a/scripts/cluster b/scripts/cluster index 585d6f89c2..27eacef977 100755 --- a/scripts/cluster +++ b/scripts/cluster @@ -60,7 +60,7 @@ function initPolybftConsensus() { function createGenesis() { ./blade genesis $genesis_params \ --block-gas-limit 10000000 \ - --premine 0x85da99c8a7c2c95964c8efd687e95e632fc533d6:1000000000000000000000 \ + --premine 0x85da99c8a7c2c95964c8efd687e95e632fc533d6 \ --premine 0x0000000000000000000000000000000000000000 \ --epoch-size 10 \ --reward-wallet 0xDEADBEEF:1000000 \ 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..f09a6f07bb 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,8 +924,8 @@ func (p *TxPool) handlePromoteRequest(req promoteRequest) { // addGossipTx handles receiving transactions // gossiped by the network. -func (p *TxPool) addGossipTx(obj interface{}, _ peer.ID) { - if !p.sealing.Load() { +func (p *TxPool) addGossipTx(obj interface{}, peerID peer.ID) { + if !p.sealing.Load() || p.localPeerID == peerID { return } diff --git a/txpool/txpool_test.go b/txpool/txpool_test.go index b55c45760e..cb07d05f94 100644 --- a/txpool/txpool_test.go +++ b/txpool/txpool_test.go @@ -14,6 +14,7 @@ import ( "github.com/golang/protobuf/ptypes/any" "github.com/hashicorp/go-hclog" + "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -600,6 +601,7 @@ func TestAddGossipTx(t *testing.T) { t.Parallel() pool, err := newTestPool() + pool.localPeerID = peer.ID("test") assert.NoError(t, err) pool.SetSigner(signer)