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

Fix and move test_multiple_consolidations_* tests to sanity block tests #3724

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -404,251 +404,6 @@ def test_consolidation_balance_through_two_churn_epochs(spec, state):
assert state.consolidation_balance_to_consume == expected_balance


@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
threshold_fn=default_activation_threshold,
)
@spec_test
@single_phase
def test_multiple_consolidations_below_churn(spec, state):
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
# Set the consolidation balance to consume equal to churn limit
state.consolidation_balance_to_consume = consolidation_churn_limit
current_epoch = spec.get_current_epoch(state)

yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(3):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(
spec,
state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index,
),
source_privkey,
target_privkey,
)
consolidations.append(signed_consolidation)

# Now run all the consolidations
for consolidation in consolidations:
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue

yield "post", state

expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch
assert (
state.consolidation_balance_to_consume
== consolidation_churn_limit - 3 * spec.MIN_ACTIVATION_BALANCE
)
for i in range(3):
assert state.validators[2 * i].exit_epoch == expected_exit_epoch


@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
threshold_fn=default_activation_threshold,
)
@spec_test
@single_phase
def test_multiple_consolidations_equal_churn(spec, state):
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
# Set the consolidation balance to consume equal to churn limit
state.consolidation_balance_to_consume = consolidation_churn_limit
current_epoch = spec.get_current_epoch(state)

yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(4):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(
spec,
state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index,
),
source_privkey,
target_privkey,
)
consolidations.append(signed_consolidation)

# Now run all the consolidations
for consolidation in consolidations:
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue

yield "post", state

expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch
assert state.consolidation_balance_to_consume == 0
for i in range(4):
assert state.validators[2 * i].exit_epoch == expected_exit_epoch


@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
threshold_fn=default_activation_threshold,
)
@spec_test
@single_phase
def test_multiple_consolidations_above_churn(spec, state):
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
# Set the consolidation balance to consume equal to churn limit
state.consolidation_balance_to_consume = consolidation_churn_limit
current_epoch = spec.get_current_epoch(state)

# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(4):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(
spec,
state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index,
),
source_privkey,
target_privkey,
)
consolidations.append(signed_consolidation)

# Now run all the consolidations
for consolidation in consolidations:
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue

# consolidate an additional validator
source_index = spec.get_active_validator_indices(state, current_epoch)[-2]
target_index = spec.get_active_validator_indices(state, current_epoch)[-1]
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]

# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)

signed_consolidation = sign_consolidation(
spec,
state,
spec.Consolidation(
epoch=current_epoch, source_index=source_index, target_index=target_index
),
source_privkey,
target_privkey,
)
# This is the interesting part of the test: on a pre-state with full consolidation queue,
# when processing an additional consolidation, it results in an exit in a later epoch
yield from run_consolidation_processing(spec, state, signed_consolidation)

expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch + 1
assert (
state.consolidation_balance_to_consume
== consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
)
assert state.validators[source_index].exit_epoch == expected_exit_epoch + 1
for i in range(4):
assert state.validators[2 * i].exit_epoch == expected_exit_epoch


@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
threshold_fn=default_activation_threshold,
)
@spec_test
@single_phase
def test_multiple_consolidations_equal_twice_churn(spec, state):
# This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn
consolidation_churn_limit = spec.get_consolidation_churn_limit(state)
# Set the consolidation balance to consume equal to churn limit
state.consolidation_balance_to_consume = consolidation_churn_limit
current_epoch = spec.get_current_epoch(state)

yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(8):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(
spec,
state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index,
),
source_privkey,
target_privkey,
)
consolidations.append(signed_consolidation)

# Now run all the consolidations
for consolidation in consolidations:
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue

yield "post", state

first_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.consolidation_balance_to_consume == 0
assert state.earliest_consolidation_epoch == first_exit_epoch + 1
for i in range(4):
assert state.validators[2 * i].exit_epoch == first_exit_epoch
for i in range(4, 8):
assert state.validators[2 * i].exit_epoch == first_exit_epoch + 1


# Failing tests

@with_electra_and_later
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .test_consolidation import * # noqa: F401 F403
from .test_deposit_transition import * # noqa: F401 F403
Loading
Loading