Skip to content

Commit d7d7470

Browse files
committed
Add a script blocking transaction relay
Without transaction propagation, higher tps can be reached.
1 parent 1f56e74 commit d7d7470

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright 2018-2019 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
import {
18+
faucetAddress,
19+
faucetSecret,
20+
validator0Address,
21+
validator1Address,
22+
validator2Address,
23+
validator3Address
24+
} from "../helper/constants";
25+
import { wait } from "../helper/promise";
26+
import { makeRandomH256 } from "../helper/random";
27+
import CodeChain from "../helper/spawn";
28+
29+
(async () => {
30+
let nodes: CodeChain[];
31+
32+
const validatorAddresses = [
33+
validator0Address,
34+
validator1Address,
35+
validator2Address,
36+
validator3Address
37+
];
38+
nodes = validatorAddresses.map(address => {
39+
return new CodeChain({
40+
chain: `${__dirname}/../scheme/tendermint-tps.json`,
41+
argv: [
42+
"--engine-signer",
43+
address.toString(),
44+
"--password-path",
45+
"test/tendermint/password.json",
46+
"--force-sealing",
47+
"--no-discovery",
48+
"--no-tx-relay",
49+
"--enable-devel-api"
50+
],
51+
additionalKeysPath: "tendermint/keys"
52+
});
53+
});
54+
await Promise.all(nodes.map(node => node.start()));
55+
56+
await Promise.all([
57+
nodes[0].connect(nodes[1]),
58+
nodes[0].connect(nodes[2]),
59+
nodes[0].connect(nodes[3]),
60+
nodes[1].connect(nodes[2]),
61+
nodes[1].connect(nodes[3]),
62+
nodes[2].connect(nodes[3])
63+
]);
64+
await Promise.all([
65+
nodes[0].waitPeers(4 - 1),
66+
nodes[1].waitPeers(4 - 1),
67+
nodes[2].waitPeers(4 - 1),
68+
nodes[3].waitPeers(4 - 1)
69+
]);
70+
71+
const transactions = [];
72+
const numTransactions = parseInt(process.env.TEST_NUM_TXS || "10000", 10);
73+
const baseSeq = 0;
74+
75+
for (let i = 0; i < numTransactions; i++) {
76+
const value = makeRandomH256();
77+
const accountId = nodes[0].sdk.util.getAccountIdFromPrivate(value);
78+
const recipient = nodes[0].sdk.core.classes.PlatformAddress.fromAccountId(
79+
accountId,
80+
{ networkId: "tc" }
81+
);
82+
const transaction = nodes[0].sdk.core
83+
.createPayTransaction({
84+
recipient,
85+
quantity: 1
86+
})
87+
.sign({
88+
secret: faucetSecret,
89+
seq: baseSeq + i,
90+
fee: 10
91+
});
92+
transactions.push(transaction);
93+
}
94+
95+
for (let i = numTransactions - 1; i > 0; i--) {
96+
await nodes[0].sdk.rpc.chain.sendSignedTransaction(transactions[i]);
97+
}
98+
const startTime = new Date();
99+
console.log(`Start at: ${startTime}`);
100+
await nodes[0].sdk.rpc.chain.sendSignedTransaction(transactions[0]);
101+
102+
while (true) {
103+
let flag = true;
104+
for (let i = 0; i < 4; i++) {
105+
const hash = transactions[numTransactions - 1].hash();
106+
const result = await nodes[i].sdk.rpc.chain.containsTransaction(
107+
hash
108+
);
109+
110+
console.log(`Node ${i} result: ${result}`);
111+
if (!result) {
112+
flag = false;
113+
break;
114+
}
115+
}
116+
if (flag) {
117+
break;
118+
}
119+
120+
await wait(300);
121+
}
122+
const endTime = new Date();
123+
console.log(`End at: ${endTime}`);
124+
const tps =
125+
(numTransactions * 1000.0) / (endTime.getTime() - startTime.getTime());
126+
console.log(
127+
`Elapsed time (ms): ${endTime.getTime() - startTime.getTime()}`
128+
);
129+
console.log(`TPS: ${tps}`);
130+
131+
await Promise.all(nodes.map(node => node.clean()));
132+
})().catch(console.error);

0 commit comments

Comments
 (0)