Skip to content

Commit

Permalink
Merge pull request #260 from lidofinance/fix/use-actual-validator-index
Browse files Browse the repository at this point in the history
fix: get last exited validator index from the network to avoid real w…
  • Loading branch information
Ivan-Feofanov authored Oct 15, 2024
2 parents 11aab1a + c9d8552 commit 42e5f0a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
29 changes: 11 additions & 18 deletions tests/acceptance/test_veb_negative.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,12 @@ def test_handle_consensus_report_data_wrong_module_id(contract, ref_slot):


def test_handle_consensus_report_data_second_exit(contract, ref_slot):
unreachable_cl_validator_index = 100_000_000
no_global_index = (module_id, no_id) = (1, 33)
validator_id = 1
validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0]
validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0]

# set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error
last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0]
validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key)
validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key)

contract_version = contract.getContractVersion()
consensus_version = contract.getConsensusVersion()
Expand All @@ -251,10 +250,6 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot):

contract.submitReportData(report, contract_version, {"from": submitter})

last_requested_validator_index_before = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
module_id, [no_id]
)

wait_to_next_available_report_time(contracts.hash_consensus_for_validators_exit_bus_oracle)
ref_slot, _ = contracts.hash_consensus_for_validators_exit_bus_oracle.getCurrentFrame()

Expand All @@ -281,25 +276,23 @@ def test_handle_consensus_report_data_second_exit(contract, ref_slot):
(
module_id,
no_id,
last_requested_validator_index_before[0],
last_requested_validator_index_before[0],
unreachable_cl_validator_index,
unreachable_cl_validator_index,
),
)
):
contract.submitReportData(report, contract_version, {"from": submitter})


def test_handle_consensus_report_data_invalid_request_order(contract, ref_slot):
module_id = 1 # CuratedModule
no_global_index = (_, no_id) = (module_id, 33)
validator_id = 1
validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0]
validator_2_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id + 1)[0]
unreachable_cl_validator_index = 100_000_000
no_global_index = (module_id, no_id) = (1, 33) # Curated module
validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0]
validator_2_key = contracts.node_operators_registry.getSigningKey(no_id, 2)[0]

# set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error
last_requested_validator_index = contract.getLastRequestedValidatorIndices(module_id, [no_id])[0]
validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key)
validator_2 = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_2_key)
validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key)
validator_2 = LidoValidator(index=unreachable_cl_validator_index + 1, pubkey=validator_2_key)

contract_version = contract.getContractVersion()
consensus_version = contract.getConsensusVersion()
Expand Down
27 changes: 9 additions & 18 deletions tests/regression/test_validator_exit_bus_happy_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ def test_send_zero_validators_to_exit(helpers):


def test_send_validator_to_exit(helpers, web3):
unreachable_cl_validator_index = 100_000_000
no_global_index = (module_id, no_id) = (1, 33)
validator_id = 1
validator_key = contracts.node_operators_registry.getSigningKey(no_id, validator_id)[0]
validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0]

# set validator index to the next one to avoid NodeOpValidatorIndexMustIncrease error
last_requested_validator_index = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
module_id, [no_id]
)[0]
validator = LidoValidator(index=last_requested_validator_index + 1, pubkey=validator_key)
validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key)

ref_slot = _wait_for_next_ref_slot()
report, report_hash = prepare_exit_bus_report([(no_global_index, validator)], ref_slot)
Expand Down Expand Up @@ -112,15 +108,15 @@ def test_send_validator_to_exit(helpers, web3):
{
"stakingModuleId": module_id,
"nodeOperatorId": no_id,
"validatorIndex": last_requested_validator_index + 1,
"validatorIndex": unreachable_cl_validator_index,
"validatorPubkey": validator_key,
"timestamp": web3.eth.get_block(web3.eth.block_number).timestamp,
},
)

assert total_requests_after == total_requests_before + 1

assert last_requested_validator_index_after == (last_requested_validator_index + 1,)
assert last_requested_validator_index_after == (unreachable_cl_validator_index,)
assert last_processing_ref_slot_after != last_processing_ref_slot_before
assert last_processing_ref_slot_after == ref_slot

Expand All @@ -136,6 +132,7 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger):
"""
The same as test above but with multiple validators on different node operators and modules
"""
unreachable_cl_validator_index = 100_000_000
# Fill SDVT
simple_dvt_add_node_operators(
contracts.simple_dvt, stranger, [("SDVT Operator", f"0xab{'1' * 38}", f"0xcd{'1' * 38}")]
Expand All @@ -149,15 +146,9 @@ def test_send_multiple_validators_to_exit(helpers, web3, stranger):
first_validator_id = 2
second_validator_id = 3
third_validator_id = 0
first_validator_index = (
contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(first_module_id, [first_no_id])[0] + 1
)
second_validator_index = (
contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(second_module_id, [second_no_id])[0] + 1
)
third_validator_index = (
contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(third_module_id, [third_no_id])[0] + 1
)
first_validator_index = unreachable_cl_validator_index
second_validator_index = unreachable_cl_validator_index + 1
third_validator_index = unreachable_cl_validator_index + 2

first_validator_key = contracts.node_operators_registry.getSigningKey(first_no_id, first_validator_id)[0]
second_validator_key = contracts.node_operators_registry.getSigningKey(second_no_id, second_validator_id)[0]
Expand Down
7 changes: 6 additions & 1 deletion utils/test/simple_dvt_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from brownie import chain, accounts, interface
from brownie import accounts, interface, web3
from utils.config import (
contracts,
EASYTRACK_SIMPLE_DVT_TRUSTED_CALLER,
Expand Down Expand Up @@ -130,6 +130,11 @@ def simple_dvt_add_keys(simple_dvt, node_operator_id, keys_count=1):
unused_signing_keys_count_before = simple_dvt.getUnusedSigningKeyCount(node_operator_id)
node_operator_before = simple_dvt.getNodeOperator(node_operator_id, False)

reward_address = node_operator_before["rewardAddress"]
if accounts.at(reward_address, force=True).balance() == 0:
web3.provider.make_request("evm_setAccountBalance", [reward_address, "0x152D02C7E14AF6800000"])
web3.provider.make_request("hardhat_setBalance", [reward_address, "0x152D02C7E14AF6800000"])

tx = simple_dvt.addSigningKeys(
node_operator_id,
batch_size,
Expand Down

0 comments on commit 42e5f0a

Please sign in to comment.