|
| 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 | + validator0Secret, |
| 25 | + validator1Secret, |
| 26 | + validator2Secret, |
| 27 | + validator3Secret |
| 28 | +} from "../helper/constants"; |
| 29 | +import { makeRandomH256 } from "../helper/random"; |
| 30 | +import CodeChain from "../helper/spawn"; |
| 31 | +const { |
| 32 | + Worker, |
| 33 | + isMainThread, |
| 34 | + parentPort, |
| 35 | + workerData |
| 36 | +} = require("worker_threads"); |
| 37 | +const path = require("path"); |
| 38 | + |
| 39 | +const RLP = require("rlp"); |
| 40 | + |
| 41 | +(async () => { |
| 42 | + let nodes: CodeChain[]; |
| 43 | + |
| 44 | + const validatorAddresses = [ |
| 45 | + validator0Address, |
| 46 | + validator1Address, |
| 47 | + validator2Address, |
| 48 | + validator3Address |
| 49 | + ]; |
| 50 | + let promises = []; |
| 51 | + const validatorSecrets = [ |
| 52 | + validator0Secret, |
| 53 | + validator1Secret, |
| 54 | + validator2Secret, |
| 55 | + validator3Secret |
| 56 | + ]; |
| 57 | + |
| 58 | + for (let index = 0; index < 4; index += 1) { |
| 59 | + const worker = new Worker( |
| 60 | + path.resolve(__dirname, "./txgen_worker.js"), |
| 61 | + { |
| 62 | + workerData: { |
| 63 | + wname: `${index}`, |
| 64 | + secret: validatorSecrets[index], |
| 65 | + seqStart: 0, |
| 66 | + seqEnd: 10000, |
| 67 | + filePrefix: `${index}` |
| 68 | + } |
| 69 | + } |
| 70 | + ); |
| 71 | + |
| 72 | + let workerPromise = new Promise((resolve, reject) => { |
| 73 | + worker.on("error", reject); |
| 74 | + worker.on("exit", (code: any) => { |
| 75 | + if (code !== 0) { |
| 76 | + reject(new Error(`Worker stopped with exit code ${code}`)); |
| 77 | + } |
| 78 | + }); |
| 79 | + }); |
| 80 | + promises.push(workerPromise); |
| 81 | + } |
| 82 | + await Promise.all(promises); |
| 83 | +})().catch(console.error); |
| 84 | + |
0 commit comments