forked from doubiliu/eosforce-web-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeos.py
340 lines (278 loc) · 12.8 KB
/
nodeos.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/python3
import argparse
import json
import os
import subprocess
import sys
import time
args = None
logFile = None
datas = {
'initAccounts':[],
'initProducers':[],
'initProducerSigKeys':[],
'initAccountsKeys':[],
'maxClients':0
}
unlockTimeout = 999999999
def jsonArg(a):
return " '" + json.dumps(a) + "' "
def run(args):
print('nodeos.py:', args)
logFile.write(args + '\n')
if subprocess.call(args, shell=True):
print('nodeos.py: exiting because of error')
sys.exit(1)
def retry(args):
while True:
print('nodeos.py:', args)
logFile.write(args + '\n')
if subprocess.call(args, shell=True):
print('*** Retry')
else:
break
def background(args):
print('nodeos.py:', args)
logFile.write(args + '\n')
return subprocess.Popen(args, shell=True)
def sleep(t):
print('sleep', t, '...')
time.sleep(t)
print('resume')
def importKeys():
keys = {}
for a in datas["initAccountsKeys"]:
key = a[1]
if not key in keys:
keys[key] = True
run(args.cleos + 'wallet import --private-key ' + key)
def createNodeDir(nodeIndex, bpaccount, key):
dir = args.nodes_dir + ('%02d-' % nodeIndex) + bpaccount['name'] + '/'
run('rm -rf ' + dir)
run('mkdir -p ' + dir)
# data dir
run('mkdir -p ' + dir + 'datas/')
run('cp -r ' + args.config_dir + ' ' + dir)
config_opts = ''.join(list(map(lambda i: ('p2p-peer-address = 127.0.0.1:%d\n' % (9001 + (nodeIndex + i) % 23 )), range(6))))
config_opts += (
('\n\nhttp-server-address = 0.0.0.0:%d\n' % (8887 + nodeIndex)) +
('p2p-listen-endpoint = 0.0.0.0:%d\n\n\n' % (9000 + nodeIndex)) +
('producer-name = %s\n' % (bpaccount['name'])) +
('signature-provider = %s=KEY:%s\n' % ( bpaccount['bpkey'], key[1] )) +
('bp-mapping = %s=KEY:%sa\n\n\n' % ( bpaccount['name'], bpaccount['name'] )) +
'plugin = eosio::chain_api_plugin\n' +
'plugin = eosio::history_plugin\n' +
'plugin = eosio::history_api_plugin\n' +
'plugin = eosio::producer_plugin\n' +
'plugin = eosio::http_plugin\n\n\n' +
'contracts-console = true\n' +
('agent-name = "TestBPNode%2d"\n' % (nodeIndex)) +
'http-validate-host=false\n' +
('max-clients = %d\n' % (datas["maxClients"])) +
'chain-state-db-size-mb = 16384\n' +
'https-client-validate-peers = false\n' +
'access-control-allow-origin = *\n' +
'access-control-allow-headers = Content-Type\n' +
'p2p-max-nodes-per-host = 10\n' +
'allowed-connection = any\n' +
'max-transaction-time = 16000\n' +
'max-irreversible-block-age = 36000\n' +
'enable-stale-production = true\n' +
'filter-on=*\n\n\n'
)
# config files
with open(dir + 'config/config.ini', mode='w') as f:
f.write(config_opts)
def createNodeDirs(inits, keys):
for i in range(0, len(inits)):
createNodeDir(i + 1, datas["initProducers"][i], keys[i])
def startNode(nodeIndex, bpaccount, key):
dir = args.nodes_dir + ('%02d-' % nodeIndex) + bpaccount['name'] + '/'
print('bpaccount ', bpaccount)
print('key ', key, ' ', key[1])
cmd = (
args.nodeos +
' --config-dir ' + os.path.abspath(dir) + '/config'
' --data-dir ' + os.path.abspath(dir) + '/datas'
)
with open(dir + '../' + bpaccount['name'] + '.log', mode='w') as f:
f.write(cmd + '\n\n')
background(cmd + ' 2>>' + dir + '../' + bpaccount['name'] + '.log')
def startProducers(inits, keys):
for i in range(0, len(inits)):
startNode(i + 1, datas["initProducers"][i], keys[i])
def listProducers():
run(args.cleos + 'get table eosio eosio bps')
def stepKillAll():
run('killall -2 keosd nodeos || true')
sleep(1)
def stepStartWallet():
run('rm -rf ' + os.path.abspath(args.wallet_dir))
run('mkdir -p ' + os.path.abspath(args.wallet_dir))
background(args.keosd + ' --unlock-timeout %d --wallet-dir %s' % (unlockTimeout, os.path.abspath(args.wallet_dir)))
sleep(.4)
def stepCreateWallet():
run('mkdir -p ' + os.path.abspath(args.wallet_dir))
run(args.cleos + 'wallet create --file ./data/pw')
def stepStartProducers():
startProducers(datas["initProducers"], datas["initProducerSigKeys"])
sleep(20)
stepSetFuncs()
def stepCreateNodeDirs():
createNodeDirs(datas["initProducers"], datas["initProducerSigKeys"])
sleep(0.5)
def stepLog():
#run('tail -n 100 ' + args.nodes_dir + 'biosbpa.log')
listProducers()
run(args.cleos + ' get info')
print('you can use \"alias cleost=\'%s\'\" to call cleos to testnet' % args.cleos)
run('tail -f -n 100 ' + args.nodes_dir + 'biosbpa.log')
def stepMkConfig():
with open(os.path.abspath(args.config_dir) + '/genesis.json') as f:
a = json.load(f)
datas["initAccounts"] = a['initial_account_list']
datas["initProducers"] = a['initial_producer_list']
with open(os.path.abspath(args.config_dir) + '/keys/sigkey.json') as f:
a = json.load(f)
datas["initProducerSigKeys"] = a['keymap']
with open(os.path.abspath(args.config_dir) + '/keys/key.json') as f:
a = json.load(f)
datas["initAccountsKeys"] = a['keymap']
datas["maxClients"] = len(datas["initProducers"]) + 10
def stepMakeGenesis():
run('rm -rf ' + os.path.abspath(args.config_dir))
run('mkdir -p ' + os.path.abspath(args.config_dir))
run('mkdir -p ' + os.path.abspath(args.config_dir) + '/keys/' )
run('cp ' + args.contracts_dir + '/eosio.token.abi ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/eosio.token.wasm ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/System02.abi ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/System02.wasm ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/eosio.msig.abi ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/eosio.msig.wasm ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/eosio.lock.abi ' + os.path.abspath(args.config_dir))
run('cp ' + args.contracts_dir + '/eosio.lock.wasm ' + os.path.abspath(args.config_dir))
# testnet will use new System contract from start
run('cp ' + args.contracts_dir + '/System02.abi ' + os.path.abspath(args.config_dir) + "/System01.abi")
run('cp ' + args.contracts_dir + '/System02.wasm ' + os.path.abspath(args.config_dir) + "/System01.wasm")
# testnet will use new System contract from start
run('cp ' + args.contracts_dir + '/System02.abi ' + os.path.abspath(args.config_dir) + "/System.abi")
run('cp ' + args.contracts_dir + '/System02.wasm ' + os.path.abspath(args.config_dir) + "/System.wasm")
run('~/eosforce/programs/genesis/genesis')
run('mv ./genesis.json ' + os.path.abspath(args.config_dir))
run('mv ./key.json ' + os.path.abspath(args.config_dir) + '/keys/')
run('mv ./sigkey.json ' + os.path.abspath(args.config_dir) + '/keys/')
run('echo "[]" >> ' + os.path.abspath(args.config_dir) + '/activeacc.json')
def cleos(cmd):
run(args.cleos + cmd)
sleep(.5)
def pushAction(account, action, permission, data_str):
data_str = data_str.replace('\'', '\"')
cleos( 'push action %s %s \'%s\' -p %s' % (account, action, data_str, permission) )
def setNumConfig(func_typ, num):
pushAction( 'eosio', 'setconfig', 'force.config',
('{"typ":"%s","num":%s,"key":"","fee":"0.0000 EOS"}' % (func_typ, num)) )
def setAssetConfig(func_typ, asset):
pushAction( 'eosio', 'setconfig', 'force.config',
('{"typ":"%s","num":0,"key":"","fee":"%s"}' % (func_typ, asset)) )
def setFuncStartBlock(func_typ, num):
setNumConfig(func_typ, num)
def setFee(account, act, fee, cpu, net, ram):
cleos( 'set setfee ' +
('%s %s ' % (account, act)) +
('"%s EOS" %d %d %d' % (fee, cpu, net, ram)))
def stepSetFuncs():
# we need set some func start block num
setFee('eosio', 'setconfig', '0.0100', 100000, 1000000, 1000)
setFuncStartBlock('f.system1', 10)
setFuncStartBlock('f.msig', 11)
setFuncStartBlock('f.prods', 12)
setFuncStartBlock('f.eosio', 13)
setFuncStartBlock('f.feelimit', 14)
setFuncStartBlock('f.ram4vote', 15)
setFuncStartBlock('f.onfeeact', 16)
setFuncStartBlock('f.cprod', 17)
setNumConfig('res.trxsize', 10240000) # should add trx size limit in new version
setFee('eosio', 'votefix', '0.2500', 5000, 512, 128)
setFee('eosio', 'revotefix', '0.5000', 10000, 1024, 128)
setFee('eosio', 'outfixvote', '0.0500', 1000, 512, 128)
def clearData():
stepKillAll()
run('rm -rf ' + os.path.abspath(args.config_dir))
run('rm -rf ' + os.path.abspath(args.nodes_dir))
run('rm -rf ' + os.path.abspath(args.wallet_dir))
run('rm -rf ' + os.path.abspath(args.log_path))
run('rm -rf ' + os.path.abspath('./pw'))
run('rm -rf ' + os.path.abspath('./config.ini'))
def restart():
stepKillAll()
stepMkConfig()
background(args.keosd + ' --unlock-timeout %d --wallet-dir %s' % (unlockTimeout, os.path.abspath(args.wallet_dir)))
sleep(.4)
with open('./data/pw', mode='r') as f:
pwd = f.read()
run(args.cleos + 'wallet open ')
run(args.cleos + 'wallet unlock --password ' + pwd)
#stepStartProducers()
startProducers(datas["initProducers"], datas["initProducerSigKeys"])
sleep(15)
stepLog()
def init():
stepMakeGenesis()
stepMkConfig()
stepStartWallet()
stepCreateWallet()
importKeys()
stepCreateNodeDirs()
stepStartProducers()
stepLog()
# =======================================================================================================================
# Command Line Arguments
parser = argparse.ArgumentParser()
commands = [
('s', 'stop', stepKillAll, False, "Kill all nodeos and keosd processes"),
('c', 'clearData', clearData, False, "Clear all Data, del ./nodes and ./wallet"),
('r', 'restart', restart, False, "Restart all nodeos and keosd processes"),
('g', 'mkGenesis', stepMakeGenesis, True, "Make Genesis"),
('m', 'mkConfig', stepMkConfig, True, "Make Configs"),
('w', 'wallet', stepStartWallet, True, "Start keosd, create wallet, fill with keys"),
('W', 'createWallet', stepCreateWallet, True, "Create wallet"),
('i', 'importKeys', importKeys, True, "importKeys"),
('D', 'createDirs', stepCreateNodeDirs, True, "create dirs for node and log"),
('P', 'start-prod', stepStartProducers, True, "Start producers"),
('l', 'log', stepLog, True, "Show tail of node's log"),
]
parser.add_argument('--root', metavar='', help="Eosforce root dir from git", default='/workspace/eosforce-web-ide/data/')
parser.add_argument('--contracts-dir', metavar='', help="Path to contracts directory", default='~/eosforce/tutorials/genesis-contracts/')
parser.add_argument('--cleos', metavar='', help="Cleos command", default='cleos ')
parser.add_argument('--nodeos', metavar='', help="Path to nodeos binary", default='nodeos')
parser.add_argument('--nodes-dir', metavar='', help="Path to nodes directory", default='./data/nodes/')
parser.add_argument('--keosd', metavar='', help="Path to keosd binary", default='keosd')
parser.add_argument('--log-path', metavar='', help="Path to log file", default='./data/output.log')
parser.add_argument('--wallet-dir', metavar='', help="Path to wallet directory", default='./data/wallet/')
parser.add_argument('--config-dir', metavar='', help="Path to config directory", default='./data/config')
# parser.add_argument('-a', '--all', action='store_true', help="Do everything marked with (*)")
for (flag, command, function, inAll, help) in commands:
prefix = ''
if inAll: prefix += '*'
if prefix: help = '(' + prefix + ') ' + help
if flag:
parser.add_argument('-' + flag, '--' + command, action='store_true', help=help, dest=command)
else:
parser.add_argument('--' + command, action='store_true', help=help, dest=command)
args = parser.parse_args()
if not os.path.isdir(os.path.abspath(args.root)):
subprocess.call('mkdir data ', shell=True)
logFile = open(args.log_path, 'a')
logFile.write('\n\n' + '*' * 80 + '\n\n\n')
haveCommand = False
for (flag, command, function, inAll, help) in commands:
if getattr(args, command):
if function:
haveCommand = True
function()
if not haveCommand:
# print('nodeos.py: Tell me what to do. -a does almost everything. -h shows options.')
if os.path.isdir(os.path.abspath(args.config_dir)):
restart()
else:
init()