stellar_core_commander 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CONTRIBUTING.md +60 -0
- data/bin/scc +70 -11
- data/examples/cross_host_simple_payment.rb +5 -5
- data/examples/history_generate_and_catchup.rb +26 -0
- data/examples/history_testnet_catchup.rb +15 -0
- data/examples/inflation.rb +8 -0
- data/examples/load_generation.rb +15 -0
- data/examples/load_generation_auto.rb +15 -0
- data/examples/multi_host_simple_payment.rb +12 -5
- data/examples/set_options.rb +23 -0
- data/examples/simple_payment.rb +3 -1
- data/examples/version_mix_consensus.rb +46 -0
- data/lib/stellar_core_commander.rb +1 -0
- data/lib/stellar_core_commander/commander.rb +50 -16
- data/lib/stellar_core_commander/convert.rb +1 -5
- data/lib/stellar_core_commander/docker_process.rb +220 -44
- data/lib/stellar_core_commander/local_process.rb +82 -41
- data/lib/stellar_core_commander/operation_builder.rb +128 -59
- data/lib/stellar_core_commander/process.rb +478 -49
- data/lib/stellar_core_commander/transactor.rb +222 -85
- data/lib/stellar_core_commander/version.rb +1 -1
- data/stellar_core_commander.gemspec +1 -1
- metadata +14 -6
@@ -21,17 +21,27 @@ module StellarCoreCommander
|
|
21
21
|
@operation_builder = OperationBuilder.new(self)
|
22
22
|
@manual_close = false
|
23
23
|
|
24
|
-
|
24
|
+
network_passphrase = @commander.process_options[:network_passphrase]
|
25
|
+
Stellar.on_network network_passphrase do
|
26
|
+
account :master, Stellar::KeyPair.master
|
27
|
+
end
|
25
28
|
end
|
26
29
|
|
27
30
|
def require_process_running
|
28
|
-
if @process
|
31
|
+
if @process.nil?
|
29
32
|
@process = @commander.get_root_process self
|
33
|
+
|
30
34
|
if not @named.has_key? @process.name
|
31
35
|
add_named @process.name, @process
|
32
36
|
end
|
33
37
|
end
|
38
|
+
|
34
39
|
@commander.start_all_processes
|
40
|
+
@commander.require_processes_in_sync
|
41
|
+
end
|
42
|
+
|
43
|
+
def shutdown(*args)
|
44
|
+
@process.shutdown *args
|
35
45
|
end
|
36
46
|
|
37
47
|
Contract String => Any
|
@@ -42,7 +52,12 @@ module StellarCoreCommander
|
|
42
52
|
#
|
43
53
|
def run_recipe(recipe_path)
|
44
54
|
recipe_content = IO.read(recipe_path)
|
45
|
-
|
55
|
+
network_passphrase = @commander.process_options[:network_passphrase]
|
56
|
+
Stellar.on_network network_passphrase do
|
57
|
+
instance_eval recipe_content, recipe_path, 1
|
58
|
+
end
|
59
|
+
rescue => e
|
60
|
+
crash_recipe e
|
46
61
|
end
|
47
62
|
|
48
63
|
|
@@ -58,114 +73,92 @@ module StellarCoreCommander
|
|
58
73
|
add_named name, keypair
|
59
74
|
end
|
60
75
|
|
76
|
+
Contract Symbol => Any
|
77
|
+
# recipe_step is a helper method to define
|
78
|
+
# a method that follows the common procedure of executing a recipe step:
|
79
|
+
#
|
80
|
+
# 1. ensure all processes are running
|
81
|
+
# 2. build the envelope by forwarding to the operation builder
|
82
|
+
# 3. submit the envelope to the process
|
83
|
+
#
|
84
|
+
# @param name [Symbol] the method to be defined and delegated to @operation_builder
|
85
|
+
def self.recipe_step(name)
|
86
|
+
define_method name do |*args|
|
87
|
+
require_process_running
|
88
|
+
envelope = @operation_builder.send(name, *args)
|
89
|
+
submit_transaction envelope
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
61
93
|
|
62
94
|
#
|
63
95
|
# @see StellarCoreCommander::OperationBuilder#payment
|
64
96
|
def payment(*args)
|
65
97
|
require_process_running
|
66
98
|
envelope = @operation_builder.payment(*args)
|
99
|
+
|
67
100
|
submit_transaction envelope do |result|
|
68
101
|
payment_result = result.result.results!.first.tr!.value
|
69
102
|
raise FailedTransaction unless payment_result.code.value >= 0
|
70
103
|
end
|
71
104
|
end
|
72
105
|
|
73
|
-
#
|
74
106
|
# @see StellarCoreCommander::OperationBuilder#create_account
|
75
|
-
|
76
|
-
require_process_running
|
77
|
-
envelope = @operation_builder.create_account(*args)
|
78
|
-
submit_transaction envelope
|
79
|
-
end
|
107
|
+
recipe_step :create_account
|
80
108
|
|
81
|
-
#
|
82
109
|
# @see StellarCoreCommander::OperationBuilder#trust
|
83
|
-
|
84
|
-
require_process_running
|
85
|
-
envelope = @operation_builder.trust(*args)
|
86
|
-
submit_transaction envelope
|
87
|
-
end
|
110
|
+
recipe_step :trust
|
88
111
|
|
89
|
-
#
|
90
112
|
# @see StellarCoreCommander::OperationBuilder#change_trust
|
91
|
-
|
92
|
-
require_process_running
|
93
|
-
envelope = @operation_builder.change_trust(*args)
|
94
|
-
submit_transaction envelope
|
95
|
-
end
|
113
|
+
recipe_step :change_trust
|
96
114
|
|
97
|
-
#
|
98
115
|
# @see StellarCoreCommander::OperationBuilder#offer
|
99
|
-
|
100
|
-
require_process_running
|
101
|
-
envelope = @operation_builder.offer(*args)
|
102
|
-
submit_transaction envelope
|
103
|
-
end
|
116
|
+
recipe_step :offer
|
104
117
|
|
105
|
-
#
|
106
118
|
# @see StellarCoreCommander::OperationBuilder#passive_offer
|
107
|
-
|
108
|
-
require_process_running
|
109
|
-
envelope = @operation_builder.passive_offer(*args)
|
110
|
-
submit_transaction envelope
|
111
|
-
end
|
119
|
+
recipe_step :passive_offer
|
112
120
|
|
113
|
-
#
|
114
|
-
|
115
|
-
def require_trust_auth(*args)
|
116
|
-
require_process_running
|
117
|
-
envelope = @operation_builder.require_trust_auth(*args)
|
118
|
-
submit_transaction envelope
|
119
|
-
end
|
121
|
+
# @see StellarCoreCommander::OperationBuilder#set_options
|
122
|
+
recipe_step :set_options
|
120
123
|
|
121
|
-
#
|
122
124
|
# @see StellarCoreCommander::OperationBuilder#set_flags
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
recipe_step :set_flags
|
126
|
+
|
127
|
+
# @see StellarCoreCommander::OperationBuilder#clear_flags
|
128
|
+
recipe_step :clear_flags
|
129
|
+
|
130
|
+
# @see StellarCoreCommander::OperationBuilder#require_trust_auth
|
131
|
+
recipe_step :require_trust_auth
|
128
132
|
|
129
|
-
#
|
130
133
|
# @see StellarCoreCommander::OperationBuilder#add_signer
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
recipe_step :add_signer
|
135
|
+
|
136
|
+
# @see StellarCoreCommander::OperationBuilder#set_master_signer_weight
|
137
|
+
recipe_step :set_master_signer_weight
|
138
|
+
|
139
|
+
# @see StellarCoreCommander::OperationBuilder#remove_signer
|
140
|
+
recipe_step :remove_signer
|
136
141
|
|
137
|
-
#
|
138
142
|
# @see StellarCoreCommander::OperationBuilder#set_thresholds
|
139
|
-
|
140
|
-
require_process_running
|
141
|
-
envelope = @operation_builder.set_thresholds(*args)
|
142
|
-
submit_transaction envelope
|
143
|
-
end
|
143
|
+
recipe_step :set_thresholds
|
144
144
|
|
145
|
-
#
|
146
|
-
|
147
|
-
def allow_trust(*args)
|
148
|
-
require_process_running
|
149
|
-
envelope = @operation_builder.allow_trust(*args)
|
150
|
-
submit_transaction envelope
|
151
|
-
end
|
145
|
+
# @see StellarCoreCommander::OperationBuilder#set_inflation_dest
|
146
|
+
recipe_step :set_inflation_dest
|
152
147
|
|
148
|
+
# @see StellarCoreCommander::OperationBuilder#set_home_domain
|
149
|
+
recipe_step :set_home_domain
|
150
|
+
|
151
|
+
# @see StellarCoreCommander::OperationBuilder#allow_trust
|
152
|
+
recipe_step :allow_trust
|
153
153
|
|
154
|
-
#
|
155
154
|
# @see StellarCoreCommander::OperationBuilder#revoke_trust
|
156
|
-
|
157
|
-
require_process_running
|
158
|
-
envelope = @operation_builder.revoke_trust(*args)
|
159
|
-
submit_transaction envelope
|
160
|
-
end
|
155
|
+
recipe_step :revoke_trust
|
161
156
|
|
162
|
-
#
|
163
157
|
# @see StellarCoreCommander::OperationBuilder#merge_account
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
158
|
+
recipe_step :merge_account
|
159
|
+
|
160
|
+
# @see StellarCoreCommander::OperationBuilder#inflation
|
161
|
+
recipe_step :inflation
|
169
162
|
|
170
163
|
Contract None => Any
|
171
164
|
#
|
@@ -186,7 +179,7 @@ module StellarCoreCommander
|
|
186
179
|
$stderr.puts "could not be found in txhistory table on process #{@process.name}"
|
187
180
|
rescue FailedTransaction
|
188
181
|
$stderr.puts "Failed to validate tx: #{Convert.to_hex envelope.tx.hash}"
|
189
|
-
$stderr.puts "failed result: #{result.to_xdr(:
|
182
|
+
$stderr.puts "failed result: #{result.to_xdr(:base64)}"
|
190
183
|
exit 1
|
191
184
|
end
|
192
185
|
end
|
@@ -194,6 +187,23 @@ module StellarCoreCommander
|
|
194
187
|
@process.unverified.clear
|
195
188
|
end
|
196
189
|
|
190
|
+
Contract None => Num
|
191
|
+
def ledger_num
|
192
|
+
require_process_running
|
193
|
+
@process.ledger_num
|
194
|
+
end
|
195
|
+
|
196
|
+
Contract Num, Symbol => Any
|
197
|
+
def catchup(ledger, mode=:minimal)
|
198
|
+
require_process_running
|
199
|
+
@process.catchup ledger, mode
|
200
|
+
end
|
201
|
+
|
202
|
+
Contract None => Any
|
203
|
+
def crash
|
204
|
+
@process.crash
|
205
|
+
end
|
206
|
+
|
197
207
|
Contract Symbol => Stellar::KeyPair
|
198
208
|
def get_account(name)
|
199
209
|
require_process_running
|
@@ -213,15 +223,45 @@ module StellarCoreCommander
|
|
213
223
|
end
|
214
224
|
end
|
215
225
|
|
216
|
-
Contract
|
217
|
-
def
|
226
|
+
Contract Num, Num, Or[Symbol, Num] => Any
|
227
|
+
def start_load_generation(accounts=10000000, txs=10000000, txrate=500)
|
228
|
+
$stderr.puts "starting load generation: #{accounts} accounts, #{txs} txs, #{txrate} tx/s"
|
229
|
+
@process.start_load_generation accounts, txs, txrate
|
230
|
+
end
|
231
|
+
|
232
|
+
Contract None => Bool
|
233
|
+
def load_generation_complete
|
234
|
+
@process.load_generation_complete
|
235
|
+
end
|
218
236
|
|
219
|
-
|
220
|
-
|
237
|
+
Contract Num, Num, Or[Symbol, Num] => Any
|
238
|
+
def generate_load_and_await_completion(accounts, txs, txrate)
|
239
|
+
runs = @process.load_generation_runs
|
240
|
+
start_load_generation accounts, txs, txrate
|
241
|
+
retry_until_true retries: accounts + txs do
|
242
|
+
txs = @process.transactions_applied
|
243
|
+
r = @process.load_generation_runs
|
244
|
+
tps = @process.transactions_per_second
|
245
|
+
ops = @process.operations_per_second
|
246
|
+
$stderr.puts "loadgen runs: #{r}, ledger: #{ledger_num}, txs: #{txs}, actual tx/s: #{tps} op/s: #{ops}"
|
247
|
+
r != runs
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
Contract None => Hash
|
252
|
+
def metrics
|
253
|
+
@process.metrics
|
254
|
+
end
|
255
|
+
|
256
|
+
Contract Symbol, ArrayOf[Symbol], Hash => Process
|
257
|
+
def process(name, quorum=[name], options={})
|
258
|
+
|
259
|
+
if @manual_close and quorum.size != 1
|
260
|
+
raise "Cannot use `process` with multi-node quorum, this recipe has previously declared `use_manual_close`."
|
221
261
|
end
|
222
262
|
|
223
263
|
$stderr.puts "creating process #{name}"
|
224
|
-
p = @commander.make_process self, name, quorum,
|
264
|
+
p = @commander.make_process self, name, quorum, options
|
225
265
|
$stderr.puts "process #{name} is #{p.idname}"
|
226
266
|
add_named name, p
|
227
267
|
end
|
@@ -238,6 +278,21 @@ module StellarCoreCommander
|
|
238
278
|
@process = tmp
|
239
279
|
end
|
240
280
|
|
281
|
+
def retry_until_true(**opts, &block)
|
282
|
+
retries = opts[:retries] || 20
|
283
|
+
timeout = opts[:timeout] || 3
|
284
|
+
while retries > 0
|
285
|
+
b = begin yield block end
|
286
|
+
if b
|
287
|
+
return b
|
288
|
+
end
|
289
|
+
retries -= 1
|
290
|
+
$stderr.puts "sleeping #{timeout} secs, #{retries} retries left"
|
291
|
+
sleep timeout
|
292
|
+
end
|
293
|
+
raise "Ran out of retries while waiting for success"
|
294
|
+
end
|
295
|
+
|
241
296
|
Contract Stellar::KeyPair => Num
|
242
297
|
def next_sequence(account)
|
243
298
|
require_process_running
|
@@ -247,12 +302,81 @@ module StellarCoreCommander
|
|
247
302
|
base_sequence + inflight_count + 1
|
248
303
|
end
|
249
304
|
|
305
|
+
Contract Or[Symbol, Stellar::KeyPair] => Bool
|
306
|
+
def account_created(account)
|
307
|
+
require_process_running
|
308
|
+
if account.is_a?(Symbol)
|
309
|
+
account = get_account(account)
|
310
|
+
end
|
311
|
+
begin
|
312
|
+
@process.account_row(account)
|
313
|
+
return true
|
314
|
+
rescue
|
315
|
+
return false
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
Contract Or[Symbol, Stellar::KeyPair] => Num
|
320
|
+
def balance(account)
|
321
|
+
require_process_running
|
322
|
+
if account.is_a?(Symbol)
|
323
|
+
account = get_account(account)
|
324
|
+
end
|
325
|
+
raise "no process!" unless @process
|
326
|
+
@process.balance_for(account)
|
327
|
+
end
|
328
|
+
|
250
329
|
Contract None => Any
|
251
330
|
def use_manual_close()
|
252
331
|
$stderr.puts "using manual_close mode"
|
253
332
|
@manual_close = true
|
254
333
|
end
|
255
334
|
|
335
|
+
Contract None => Bool
|
336
|
+
def check_no_error_metrics
|
337
|
+
@commander.check_no_process_error_metrics
|
338
|
+
end
|
339
|
+
|
340
|
+
Contract ArrayOf[Or[Symbol, Process]] => Bool
|
341
|
+
def check_equal_ledger_objects(processes)
|
342
|
+
raise "no process!" unless @process
|
343
|
+
for p in processes
|
344
|
+
if p.is_a?(Symbol)
|
345
|
+
p = get_process(p)
|
346
|
+
end
|
347
|
+
@process.check_equal_ledger_objects(p)
|
348
|
+
end
|
349
|
+
true
|
350
|
+
end
|
351
|
+
|
352
|
+
Contract Or[Symbol, Process] => Any
|
353
|
+
def check_ledger_sequence_is_prefix_of(other)
|
354
|
+
raise "no process!" unless @process
|
355
|
+
if other.is_a?(Symbol)
|
356
|
+
other = get_process(other)
|
357
|
+
end
|
358
|
+
@process.check_ledger_sequence_is_prefix_of(other)
|
359
|
+
end
|
360
|
+
|
361
|
+
Contract None => Bool
|
362
|
+
def check_database_against_ledger_buckets
|
363
|
+
runs = @process.checkdb_runs
|
364
|
+
@process.start_checkdb
|
365
|
+
retry_until_true do
|
366
|
+
r = @process.checkdb_runs
|
367
|
+
$stderr.puts "checkdb runs: #{r}, checked: #{@process.objects_checked}"
|
368
|
+
r != runs
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
Contract Or[Symbol, Process] => Any
|
373
|
+
def check_integrity_against(other)
|
374
|
+
check_no_error_metrics
|
375
|
+
check_database_against_ledger_buckets
|
376
|
+
check_equal_ledger_objects [other]
|
377
|
+
check_ledger_sequence_is_prefix_of other
|
378
|
+
end
|
379
|
+
|
256
380
|
private
|
257
381
|
Contract Symbol, Any => Any
|
258
382
|
def add_named(name, object)
|
@@ -266,8 +390,8 @@ module StellarCoreCommander
|
|
266
390
|
Contract Stellar::TransactionEnvelope, Or[nil, Proc] => Any
|
267
391
|
def submit_transaction(envelope, &after_confirmation)
|
268
392
|
require_process_running
|
269
|
-
|
270
|
-
@process.submit_transaction
|
393
|
+
b64 = envelope.to_xdr(:base64)
|
394
|
+
@process.submit_transaction b64
|
271
395
|
|
272
396
|
# submit to process
|
273
397
|
@process.unverified << [envelope, after_confirmation]
|
@@ -295,5 +419,18 @@ module StellarCoreCommander
|
|
295
419
|
result
|
296
420
|
end
|
297
421
|
|
422
|
+
Contract Exception => Any
|
423
|
+
def crash_recipe(e)
|
424
|
+
puts
|
425
|
+
puts "Error! (#{e.class.name}): #{e.message}"
|
426
|
+
puts
|
427
|
+
puts e.backtrace.
|
428
|
+
reject{|l| l =~ %r{gems/contracts-.+?/} }. # filter contract frames
|
429
|
+
join("\n")
|
430
|
+
puts
|
431
|
+
|
432
|
+
exit 1
|
433
|
+
end
|
434
|
+
|
298
435
|
end
|
299
436
|
end
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "stellar-base", "
|
20
|
+
spec.add_dependency "stellar-base", ">= 0.6.1"
|
21
21
|
spec.add_dependency "slop", "~> 3.6.0"
|
22
22
|
spec.add_dependency "faraday", "~> 0.9.1"
|
23
23
|
spec.add_dependency "faraday_middleware", "~> 0.9.1"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stellar_core_commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Fleckenstein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stellar-base
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.6.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.6.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: slop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,6 +173,7 @@ extensions: []
|
|
173
173
|
extra_rdoc_files: []
|
174
174
|
files:
|
175
175
|
- ".gitignore"
|
176
|
+
- CONTRIBUTING.md
|
176
177
|
- Gemfile
|
177
178
|
- LICENSE.txt
|
178
179
|
- README.md
|
@@ -180,13 +181,20 @@ files:
|
|
180
181
|
- bin/scc
|
181
182
|
- examples/allow_trust.rb
|
182
183
|
- examples/cross_host_simple_payment.rb
|
184
|
+
- examples/history_generate_and_catchup.rb
|
185
|
+
- examples/history_testnet_catchup.rb
|
186
|
+
- examples/inflation.rb
|
187
|
+
- examples/load_generation.rb
|
188
|
+
- examples/load_generation_auto.rb
|
183
189
|
- examples/merge_account.rb
|
184
190
|
- examples/multi_host_simple_payment.rb
|
185
191
|
- examples/non_native_payment.rb
|
186
192
|
- examples/passive_offer.rb
|
187
193
|
- examples/pathed_payment.rb
|
194
|
+
- examples/set_options.rb
|
188
195
|
- examples/simple_payment.rb
|
189
196
|
- examples/trade.rb
|
197
|
+
- examples/version_mix_consensus.rb
|
190
198
|
- lib/stellar_core_commander.rb
|
191
199
|
- lib/stellar_core_commander/commander.rb
|
192
200
|
- lib/stellar_core_commander/convert.rb
|