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 35 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
)
from eth2spec.test.helpers.state import next_epoch_via_block
from eth2spec.test.helpers.withdrawals import set_validator_fully_withdrawable
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with


def run_process_pending_deposits(spec, state):
yield from run_epoch_processing_with(
spec, state, 'process_pending_deposits')


@with_electra_and_later
Expand All @@ -18,6 +24,7 @@ def test_new_deposit_under_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -30,6 +37,7 @@ def test_new_deposit_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -42,6 +50,7 @@ def test_new_deposit_over_max(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, signed=True)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -64,6 +73,7 @@ def test_new_deposit_eth1_withdrawal_credentials(spec, state):
)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -85,6 +95,7 @@ def test_new_deposit_non_versioned_withdrawal_credentials(spec, state):
)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand Down Expand Up @@ -177,6 +188,7 @@ def test_incorrect_sig_top_up(spec, state):

# invalid signatures, in top-ups, are allowed!
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -194,6 +206,7 @@ def test_incorrect_withdrawal_credentials_top_up(spec, state):

# inconsistent withdrawal credentials, in top-ups, are allowed!
yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -208,6 +221,7 @@ def test_key_validate_invalid_subgroup(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, pubkey=pubkey, signed=True)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand All @@ -224,6 +238,7 @@ def test_key_validate_invalid_decompression(spec, state):
deposit_request = prepare_deposit_request(spec, validator_index, amount, pubkey=pubkey, signed=True)

yield from run_deposit_request_processing(spec, state, deposit_request, validator_index)
yield from run_process_pending_deposits(spec, state)


@with_electra_and_later
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
from eth2spec.test.context import (
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
spec_state_test,
with_electra_and_later,
)
from eth2spec.test.helpers.keys import privkeys, pubkeys
from tests.core.pyspec.eth2spec.test.helpers.deposits import build_deposit_data
from eth2spec.test.helpers.state import next_epoch_via_block


def run_process_pending_deposits(spec, state):
yield from run_epoch_processing_with(
spec, state, 'process_pending_deposits')


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

# select validator set outside of the mainnet preset of 256
index = len(state.validators)
withdrawal_credentials = (
spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkeys[index])[1:]
)
deposit_data = build_deposit_data(spec,
pubkeys[index],
privkeys[index],
amount,
withdrawal_credentials,
signed=True)
deposit = spec.PendingDeposit(
pubkey=pubkeys[index],
withdrawal_credentials=withdrawal_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
old_validator_count = len(state.validators)
state.pending_deposits.append(deposit)
yield from run_process_pending_deposits(spec, state)
# validator count should increase by 1
assert len(state.validators) == old_validator_count + 1


@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_increases_balance(spec, state):
amount = 100
# 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,
amount=amount,
slot=spec.GENESIS_SLOT
)
# 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_switch_to_compounding(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:]
)
# advance the state
next_epoch_via_block(spec, state)
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=pubkeys[index],
withdrawal_credentials=compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[index] = 0
# run test
spec.apply_pending_deposit(state, deposit)
# validator balance should increase
assert state.balances[index] == amount
current_credentials = state.validators[0].withdrawal_credentials
assert current_credentials == compounding_credentials


@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_switch_to_compounding_no_compounding(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:]
)
# wrong compounding
compounding_credentials = (
spec.hash(b"wrong compounding address")[:]
)
# advance the state
next_epoch_via_block(spec, state)
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=pubkeys[index],
withdrawal_credentials=compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[index] = 0
# run test
spec.apply_pending_deposit(state, deposit)
# validator balance should increase
assert state.balances[index] == amount
current_credentials = state.validators[0].withdrawal_credentials
assert current_credentials == withdrawal_credentials


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

# choose a value public key that's in the validator set
index = 0
compounding_credentials = (
spec.COMPOUNDING_WITHDRAWAL_PREFIX +
spec.hash(pubkeys[index])[1:]
)
# advance the state
next_epoch_via_block(spec, state)
bls_credentials = state.validators[index].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=pubkeys[index],
withdrawal_credentials=compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[index] = 0
# run test
spec.apply_pending_deposit(state, deposit)
# validator balance should increase
assert state.balances[index] == amount
current_credentials = state.validators[index].withdrawal_credentials
# does not switch to compounding
assert current_credentials == bls_credentials


@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_switch_to_compounding_invalid_sig(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:]
)
# advance the state
next_epoch_via_block(spec, state)
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
# creates wrong signature
deposit_data = build_deposit_data(spec,
pubkeys[index],
privkeys[index],
amount,
withdrawal_credentials,
signed=True)
deposit = spec.PendingDeposit(
pubkey=pubkeys[index],
withdrawal_credentials=compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[index] = 0
# run test
spec.apply_pending_deposit(state, deposit)
# validator balance should increase
assert state.balances[index] == amount
current_credentials = state.validators[0].withdrawal_credentials
assert current_credentials == withdrawal_credentials


@with_electra_and_later
@spec_state_test
def test_apply_pending_deposit_switch_to_compounding_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
deposit_data = build_deposit_data(spec,
pubkeys[index],
privkeys[index],
amount,
compounding_credentials,
signed=True)
deposit = spec.PendingDeposit(
pubkey=pubkeys[index],
withdrawal_credentials=compounding_credentials,
amount=amount,
slot=spec.GENESIS_SLOT,
signature=deposit_data.signature,
)
state.balances[index] = 0
# run test
spec.apply_pending_deposit(state, deposit)
# validator balance should increase
assert state.balances[index] == amount
# make sure validator did not switch to compounding if not exited
current_credentials = state.validators[0].withdrawal_credentials
assert current_credentials == withdrawal_credentials
# postpone pending_deposit
assert len(state.pending_deposits) == 0
Loading
Loading