Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eip6110: Queue deposit requests and apply them during epoch processing #3818

Merged
merged 72 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
fd75470
Add pending_deposits queue and queue deposit requests
mkalinin Jun 20, 2024
2a202c8
Refactor pending deposit processing
mkalinin Jun 20, 2024
0b7fef3
Limit number of pending deposits to be processed per epoch
mkalinin Jun 20, 2024
5c3a51a
Process deposit requests after Eth1 bridge deposits are applied
mkalinin Jun 25, 2024
179ee8e
Finalize deposit requests before processing
mkalinin Jun 25, 2024
43e7344
Refactor process_pending_deposits
mkalinin Jun 26, 2024
8f6b1e0
Merge remote-tracking branch 'origin/dev' into deposit-queue
mkalinin Jun 28, 2024
e1a4d8b
added some simple tests
james-prysm Jul 1, 2024
5c0a8d3
Fix off-by-one found by @james-prysm
mkalinin Jul 2, 2024
2af84d8
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 2, 2024
8099f39
merging upstream
james-prysm Jul 2, 2024
750f7a1
adding new test
james-prysm Jul 2, 2024
077edf8
Merge branch 'deposit-queue' of github.com:james-prysm/eth2.0-specs-m…
james-prysm Jul 2, 2024
b31fa63
apply pending deposit tests
james-prysm Jul 2, 2024
b2cd3ce
fixing comment
james-prysm Jul 2, 2024
03071df
preston's feedback
james-prysm Jul 3, 2024
5a2f887
Merge remote-tracking branch 'origin/dev' into deposit-queue
mkalinin Jul 3, 2024
ee4da7b
Refactor postponed deposit processing
mkalinin Jul 5, 2024
6ed15b2
Fix electra fork tests
mkalinin Jul 5, 2024
093590e
Merge remote-tracking branch 'upstream/deposit-queue' into deposit-queue
james-prysm Jul 8, 2024
1a19d82
updating tests based on mikhail changes
james-prysm Jul 9, 2024
85b752b
Fix by @pawanjay176
mkalinin Jul 9, 2024
1e9337e
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 10, 2024
577b028
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 10, 2024
8b191e6
fixing linting
james-prysm Jul 10, 2024
2c8dd39
updating tests
james-prysm Jul 11, 2024
320a692
adding test for chrun
james-prysm Jul 12, 2024
48b9928
adding out of validator range test
james-prysm Jul 12, 2024
bf03d78
fixing linting
james-prysm Jul 12, 2024
ea33eac
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 26, 2024
1feb1fb
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 26, 2024
d62559f
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 26, 2024
6903bab
Update tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_…
james-prysm Jul 26, 2024
4a4cdfc
revert beacon-chain.md changes
james-prysm Jul 26, 2024
077fd44
Merge branch 'deposit-queue' of github.com:james-prysm/eth2.0-specs-m…
james-prysm Jul 26, 2024
e80c39b
mikhail's feedback
james-prysm Jul 29, 2024
6a7bfe9
removed wrong balance
james-prysm Jul 29, 2024
824e374
applying feedback fir add validator test
james-prysm Jul 30, 2024
0a51fe0
updating tests
james-prysm Aug 2, 2024
1afa514
adding test_process_pending_deposits_limit_is_reached
james-prysm Aug 2, 2024
336c6f1
adding some more tests based on test plan
james-prysm Aug 5, 2024
3593a0c
adding 3 more tests
james-prysm Aug 5, 2024
2cf7de9
updating bridge tests
james-prysm Aug 6, 2024
337726c
adding no compounding test
james-prysm Aug 6, 2024
56fe310
adding run_process_pending_deposits to deposit request tests to prope…
james-prysm Aug 6, 2024
c5db6df
adding fork version tests
james-prysm Aug 6, 2024
698367e
Merge pull request #18 from james-prysm/deposit-queue
mkalinin Aug 7, 2024
ada5524
Use the right MaxEB to create validator from deposit
mkalinin Aug 23, 2024
a6864d4
Merge branch 'dev' into deposit-queue
mkalinin Aug 23, 2024
97e6166
Move switch to compounding to process_deposit_request
mkalinin Aug 26, 2024
990de16
Add more deposit tests
mkalinin Aug 26, 2024
c183be4
Update consolidation tests with pending deposit
mkalinin Aug 26, 2024
7afe8e0
Update eip7732 with pending_deposits
mkalinin Aug 26, 2024
ad8f54f
Update pending deposits tests
mkalinin Aug 27, 2024
22bb1de
Fix code spell
mkalinin Aug 27, 2024
0526592
Do state.pending_deposits update in a single line
mkalinin Aug 27, 2024
3ebddad
Merge branch 'dev' into deposit-queue
mkalinin Sep 4, 2024
8c726ff
Fix get_max_effective_balance call
mkalinin Sep 4, 2024
67cc3a5
Rename MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING to MAX_PENDING_DEPOS…
mkalinin Sep 5, 2024
1513492
Merge branch 'dev' into deposit-queue
mkalinin Sep 18, 2024
083402f
Remove switch_to_compounding from deposit flow
mkalinin Sep 18, 2024
5913960
Add notes on add_validator_to_registry, process_deposit modifications
mkalinin Sep 25, 2024
3330265
Apply suggestions from @jtraglia
mkalinin Sep 27, 2024
4ee4105
Merge branch 'dev' into deposit-queue
mkalinin Oct 2, 2024
a04e4c3
Fix fork logic
mkalinin Oct 2, 2024
beb2718
Apply suggestions by @ppopth
mkalinin Oct 3, 2024
358378d
Merge branch 'dev' into deposit-queue
jtraglia Oct 3, 2024
82d2bc0
Fix two tests by replacing old PendingBalanceDeposit
jtraglia Oct 3, 2024
7705984
Fix consolidation test
mkalinin Oct 4, 2024
77d2865
Rename test_apply_pending_deposit to test_process_pending_deposit
jtraglia Oct 4, 2024
3befc42
Rename test_apply_pending_deposit* to test_process_pending_deposit*
jtraglia Oct 4, 2024
ad42273
Use pending_deposits format for both test files
jtraglia Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updating tests based on mikhail changes
  • Loading branch information
james-prysm committed Jul 9, 2024
commit 1a19d82bbcc74c59a55336a5a03a7e1f3bf48765
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,10 @@ def test_apply_pending_deposit_add_validator_to_registry(spec, state):

@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_not_withdrawable_epoch_while_exiting(spec, state):
def test_apply_pending_deposit_increases_balance(spec, state):
amount = 100
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = spec.FAR_FUTURE_EPOCH

deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
)
assert spec.apply_pending_deposit(state,deposit) == False

@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_not_withdrawable_epoch_at_current_epoch_while_exiting(spec, state):
amount = 100
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = spec.get_current_epoch(state)

deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
)
assert spec.apply_pending_deposit(state,deposit) == False

@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_withdrawable_epoch_while_exiting(spec, state):
amount = 100
state.slot = spec.SLOTS_PER_EPOCH * 2
# validator exit epoch must be less than far future
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1
state.validators[0].withdrawable_epoch = 0

state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH
# signature doesn't matter here as it's interpreted as a top-up
deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
Expand All @@ -80,38 +45,55 @@ def test_apply_pending_deposit_withdrawable_epoch_while_exiting(spec, state):
)
# reset the balance
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
# run test
spec.apply_pending_deposit(state,deposit)
assert state.balances[0] == amount


@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_withdrawable_epoch_while_exited(spec, state):
def test_apply_pending_deposit_switch_to_compounding(spec, state):
amount = 100
state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH
# signature doesn't matter here as it's interpreted as a top-up

# choose a value public key that's in the validator set
index = 0
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
compounding_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[index].withdrawal_credentials = withdrawal_credentials
# set validator to be exited by current epoch
state.validators[index].exit_epoch = spec.get_current_epoch(state) - 1
deposit_data = build_deposit_data(spec,
pubkeys[index],
privkeys[index],
amount,
compounding_credentials,
signed=True)
deposit = spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials= state.validators[0].withdrawal_credentials,
pubkey=pubkeys[index],
withdrawal_credentials= compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
# reset the balance
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
# run test
spec.apply_pending_deposit(state,deposit)
# validator balance should increase
assert state.balances[0] == amount

assert state.validators[0].withdrawal_credentials == compounding_credentials

@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_switch_to_compounding(spec, state):
def test_apply_pending_deposit_switch_to_compounding_while_validator_not_exited(spec, state):
amount = 100

# choose a value public key that's in the validator set
index = 0
withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
compounding_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
state.validators[index].withdrawal_credentials = withdrawal_credentials
# set validator to not be exited
state.validators[index].exit_epoch = spec.FAR_FUTURE_EPOCH
deposit_data = build_deposit_data(spec,
pubkeys[index],
Expand All @@ -127,8 +109,10 @@ def test_apply_pending_deposit_switch_to_compounding(spec, state):
signature=deposit_data.signature,
)
state.balances[0] = 0
assert spec.apply_pending_deposit(state,deposit) == True
# validator count should increase by 1
# run test
spec.apply_pending_deposit(state,deposit)
# validator balance should increase
assert state.balances[0] == amount
assert state.validators[0].withdrawal_credentials == compounding_credentials
# make sure validator did not switch to compounding if not exited
assert state.validators[0].withdrawal_credentials == withdrawal_credentials

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_pending_deposit_eth1_bridge_not_applied(spec, state):

@with_electra_and_later
@spec_state_test
def test_pending_deposit_deposit_not_finalized(spec, state):
def test_pending_deposit_not_finalized(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE
# set slot to something not finalized
slot=spec.compute_start_slot_at_epoch(state.finalized_checkpoint.epoch+1)
Expand All @@ -75,6 +75,65 @@ def test_pending_deposit_deposit_not_finalized(spec, state):
# deposit was postponed and not processed
assert len(state.pending_deposits) == 1

@with_electra_and_later
@spec_state_test
def test_pending_deposit_validator_withdrawn(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE

withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(state.validators[0].pubkey)[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[0].withdrawal_credentials = withdrawal_credentials
# set validator to be withdrawable by current epoch
state.validators[0].withdrawable_epoch = spec.get_current_epoch(state) - 1
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials=state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
))
# set deposit_requests_start_index to something low so that we skip the bridge validation
state.deposit_requests_start_index = 0
print("deposit indexes",state.eth1_deposit_index,state.deposit_requests_start_index)
# set deposit_balance_to_consume to some initial amount to see its removal later on in the test
state.deposit_balance_to_consume = amount
# reset balance for assert
state.balances[0] = 0
yield from run_process_pending_deposits(spec, state)
# deposit_balance_to_consume was reset to 0
assert state.deposit_balance_to_consume == 0
# deposit was processed
assert state.pending_deposits == []
# balance increases because of withdraw
assert state.balances[0] == amount

@with_electra_and_later
@spec_state_test
def test_pending_deposit_validator_exiting_but_not_withdrawn(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE

withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + spec.hash(state.validators[0].pubkey)[1:]
state.slot = spec.SLOTS_PER_EPOCH * 2
state.validators[0].withdrawal_credentials = withdrawal_credentials
# set validator to be withdrawable by current epoch
state.validators[0].exit_epoch = spec.get_current_epoch(state) - 1
state.validators[0].withdrawable_epoch = spec.FAR_FUTURE_EPOCH
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials=state.validators[0].withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
))
# set deposit_requests_start_index to something low so that we skip the bridge validation
state.deposit_requests_start_index = 0
print("deposit indexes",state.eth1_deposit_index,state.deposit_requests_start_index)
# set deposit_balance_to_consume to some initial amount to see its removal later on in the test
state.deposit_balance_to_consume = amount

yield from run_process_pending_deposits(spec, state)
# deposit_balance_to_consume was reset to 0
assert state.deposit_balance_to_consume == 0
# deposit was postponed and not processed
assert len(state.pending_deposits) == 1


@with_electra_and_later
Expand Down