Skip to content

Commit d8276ac

Browse files
authored
Merge pull request ethereum#4044 from jtraglia/fix-random-exec-requests
2 parents 83a8042 + 1c659a9 commit d8276ac

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

tests/core/pyspec/eth2spec/test/helpers/multi_operations.py

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ def run_test_full_random_operations(spec, state, rng=Random(2080)):
260260

261261

262262
def get_random_execution_requests(spec, state, rng):
263-
deposits = get_random_deposits_requests(spec, state, rng)
264-
withdrawals = get_random_withdrawals_requests(spec, state, rng)
265-
consolidations = get_random_consolidations_requests(spec, state, rng)
263+
deposits = get_random_deposit_requests(spec, state, rng)
264+
withdrawals = get_random_withdrawal_requests(spec, state, rng)
265+
consolidations = get_random_consolidation_requests(spec, state, rng)
266266

267267
execution_requests = spec.ExecutionRequests(
268268
deposits=deposits,
@@ -273,19 +273,17 @@ def get_random_execution_requests(spec, state, rng):
273273
return execution_requests
274274

275275

276-
def get_random_deposits_requests(spec, state, rng, num_deposits=None):
276+
def get_random_deposit_requests(spec, state, rng, num_deposits=None):
277277
if num_deposits is None:
278278
num_deposits = rng.randint(0, spec.MAX_DEPOSIT_REQUESTS_PER_PAYLOAD)
279279

280280
deposit_data_leaves = [spec.DepositData() for _ in range(len(state.validators))]
281281

282-
deposits_requests = []
283-
284-
for i in range(num_deposits):
282+
deposit_requests = []
283+
for _ in range(num_deposits):
285284
index = rng.randrange(0, num_deposits)
286285
withdrawal_pubkey = pubkeys[index]
287286
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(withdrawal_pubkey)[1:]
288-
289287
deposit, _, _ = build_deposit(
290288
spec,
291289
deposit_data_leaves,
@@ -295,78 +293,60 @@ def get_random_deposits_requests(spec, state, rng, num_deposits=None):
295293
withdrawal_credentials=withdrawal_credentials,
296294
signed=True,
297295
)
298-
299-
deposit_request = spec.DepositRequest(
296+
deposit_requests.append(spec.DepositRequest(
300297
pubkey=deposit.data.pubkey,
301298
withdrawal_credentials=deposit.data.withdrawal_credentials,
302299
amount=deposit.data.amount,
303300
signature=deposit.data.signature,
304-
index=deposit.data.index,
305-
)
306-
307-
deposits_requests.append(deposit_request)
301+
index=rng.randrange(0, 2**64),
302+
))
308303

309-
return deposits_requests
304+
return deposit_requests
310305

311306

312-
def get_random_withdrawals_requests(spec, state, rng, num_withdrawals=None):
307+
def get_random_withdrawal_requests(spec, state, rng, num_withdrawals=None):
313308
if num_withdrawals is None:
314309
num_withdrawals = rng.randint(0, spec.MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD)
315310

316-
withdrawals_requests = []
317-
318-
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
319-
320311
current_epoch = spec.get_current_epoch(state)
321312
active_validator_indices = spec.get_active_validator_indices(state, current_epoch)
322313

314+
withdrawal_requests = []
323315
for _ in range(num_withdrawals):
324316
if not active_validator_indices:
325317
break
326318

327319
address = rng.getrandbits(160).to_bytes(20, 'big')
328-
329320
validator_index = rng.choice(active_validator_indices)
330321
validator = state.validators[validator_index]
331322
validator_balance = state.balances[validator_index]
332-
333-
withdrawal_request = spec.WithdrawalRequest(
323+
withdrawal_requests.append(spec.WithdrawalRequest(
334324
source_address=address,
335325
validator_pubkey=validator.pubkey,
336326
amount=rng.randint(0, validator_balance),
337-
)
338-
339-
withdrawals_requests.append(withdrawal_request)
327+
))
340328

341-
return withdrawals_requests
329+
return withdrawal_requests
342330

343331

344-
def get_random_consolidations_requests(spec, state, rng, num_consolidations=None):
332+
def get_random_consolidation_requests(spec, state, rng, num_consolidations=None):
345333
if num_consolidations is None:
346334
num_consolidations = rng.randint(0, spec.MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD)
347335

348-
consolidations_requests = []
349-
350-
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
351-
352336
current_epoch = spec.get_current_epoch(state)
353337
active_validator_indices = spec.get_active_validator_indices(state, current_epoch)
354338

339+
consolidation_requests = []
355340
for _ in range(num_consolidations):
356341
source_address = rng.getrandbits(160).to_bytes(20, 'big')
357-
358342
source_index = rng.choice(active_validator_indices)
359343
target_index = rng.choice(active_validator_indices)
360-
361344
source_validator = state.validators[source_index]
362345
target_validator = state.validators[target_index]
363-
364-
consolidation_request = spec.ConsolidationRequest(
346+
consolidation_requests.append(spec.ConsolidationRequest(
365347
source_address=source_address,
366348
source_pubkey=source_validator.pubkey,
367349
target_pubkey=target_validator.pubkey,
368-
)
369-
370-
consolidations_requests.append(consolidation_request)
350+
))
371351

372-
return consolidations_requests
352+
return consolidation_requests

0 commit comments

Comments
 (0)