Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Feb 29, 2024
1 parent 34df70e commit da60882
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
3 changes: 2 additions & 1 deletion loadtest/helpers/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions loadtest/scenarios/multiple_EOA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 12 additions & 10 deletions loadtest/scenarios/multiple_ERC20.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

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
12 changes: 11 additions & 1 deletion 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,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")
Expand Down

0 comments on commit da60882

Please sign in to comment.