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

Load tests improvement #129

Merged
merged 8 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions loadtest/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -13,22 +13,23 @@ 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,
};

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++;
}
Expand Down
24 changes: 14 additions & 10 deletions loadtest/scenarios/multiple_EOA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 18 additions & 14 deletions loadtest/scenarios/multiple_ERC20.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand All @@ -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)));
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand Down
Loading