-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepareBenchmark.js
More file actions
127 lines (106 loc) · 3.36 KB
/
Copy pathprepareBenchmark.js
File metadata and controls
127 lines (106 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const fs = require('fs')
const Tx = require('ethereumjs-tx')
const hdkey = require('ethereumjs-wallet/hdkey')
const util = require('ethereumjs-util')
const numAccounts = process.argv[2] || 1000;
const numTransactions = process.argv[3] || 10000;
const networkId = '0x42';
const nonce = "0x0000000000000000";
const difficulty = '0x40000';
const gasLimit = '0xFFFF0000';
const genesisGethTemplate = {
"nonce": nonce,
"difficulty": difficulty,
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": gasLimit,
"alloc": {}
};
const genesisParityTemplate = {
"name": "test",
"engine": {
"Ethash": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x4",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0a",
"blockReward": "0x4563918244F40000",
"registrar": "",
"frontierCompatibilityModeLimit": "0x00"
}
}
},
"params": {
"maximumExtraDataSize": "0x20",
"minGasLimit": "0xFFFF0000",
"networkID" : networkId
},
"genesis": {
"seal": {
"ethereum": {
"nonce": nonce,
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
},
"difficulty": difficulty,
"author": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": gasLimit,
},
"nodes": [ ],
"accounts": { }
}
// Generate keys
const seed = Number(new Date());
const accounts = [];
for(let i = 0; i < numAccounts; ++i) {
const key = hdkey.fromMasterSeed(seed + '_' + i)._hdkey._privateKey;
accounts.push({
key: key,
addr: util.bufferToHex(util.privateToAddress(key)),
nonce: 0
});
}
// Fill balances in genesis
const genesisGeth = Object.assign({}, genesisGethTemplate);
const genesisParity = Object.assign({}, genesisParityTemplate);
genesisGeth.alloc = genesisParity.accounts = accounts.reduce(
(val, acc) => Object.assign(val, {[acc.addr]: {balance: "654321000000000000000"}}),
{}
);
// write keys and genesis files
fs.writeFile('genesis.geth.json', JSON.stringify(genesisGeth), err =>
err || console.log('genesis.geth.json generated')
);
fs.writeFile('genesis.parity.json', JSON.stringify(genesisParity), err =>
err || console.log('genesis.parity.json generated')
);
// Generate signed transactions
const transactions = [];
for(let i = 0; i < numTransactions; ++i) {
const k = accounts[i % numAccounts];
const to = accounts[numAccounts - i % numAccounts - 1].addr;
const tx = new Tx({
from: k.addr,
nonce: k.nonce,
to: to,
gasPrice: '0x09184e72a000',
gasLimit: '0x27100',
value: '0x12300',
data: '0x0',
chainId: '0x42'
});
tx.sign(k.key);
k.nonce++;
transactions.push('0x' + tx.serialize().toString('hex'));
}
// Write transactions to file
fs.writeFile('transactions.txt', transactions.join('\n'), err =>
err || console.log(numTransactions + ' transactions written to transactions.txt')
);