Skip to content

Commit 9044f99

Browse files
committed
Fix get_new_validator_registry_delta_chain_tip
1 parent e0e23c2 commit 9044f99

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

eth/beacon/helpers.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
clamp,
2828
)
2929

30-
from eth.beacon.block_committees_info import (
31-
BlockCommitteesInfo,
32-
)
33-
from eth.beacon.types.shard_committees import (
34-
ShardCommittee,
35-
)
30+
from eth.beacon.block_committees_info import BlockCommitteesInfo
31+
from eth.beacon.types.shard_committees import ShardCommittee
32+
from eth.beacon.types.validator_registry_delta_block import ValidatorRegistryDeltaBlock
3633
from eth.beacon._utils.random import (
3734
shuffle,
3835
split,
@@ -364,19 +361,19 @@ def get_effective_balance(validator: 'ValidatorRecord', max_deposit: int) -> int
364361

365362

366363
def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_chain_tip: Hash32,
367-
index: int,
364+
validator_index: int,
368365
pubkey: int,
369366
flag: int) -> Hash32:
370367
"""
371368
Compute the next hash in the validator registry delta hash chain.
372369
"""
373-
return hash_eth2(
374-
current_validator_registry_delta_chain_tip +
375-
flag.to_bytes(1, 'big') +
376-
index.to_bytes(3, 'big') +
377-
# TODO: currently, we use 256-bit pubkey which is different form the spec
378-
pubkey.to_bytes(32, 'big')
379-
)
370+
# TODO: switch to SSZ tree hashing
371+
return ValidatorRegistryDeltaBlock(
372+
latest_registry_delta_root=current_validator_registry_delta_chain_tip,
373+
validator_index=validator_index,
374+
pubkey=pubkey,
375+
flag=flag,
376+
).root
380377

381378

382379
def get_fork_version(fork_data: 'ForkData',

eth/beacon/types/deposit_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
hash32,
1515
uint384,
1616
)
17-
from eth.beacon.utils.hash import hash_eth2
17+
from eth.beacon._utils.hash import hash_eth2
1818

1919

2020
class DepositInput(rlp.Serializable):

tests/beacon/test_helpers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,12 @@ def mock_get_shard_committees_at_slot(state,
467467

468468

469469
def test_get_active_validator_indices(sample_validator_record_params):
470-
# 3 validators are ACTIVE by default.
470+
# 3 validators are ACTIVE
471471
validators = [
472472
ValidatorRecord(
473473
**sample_validator_record_params,
474+
).copy(
475+
status=ValidatorStatusCode.ACTIVE,
474476
)
475477
for i in range(3)
476478
]
@@ -613,7 +615,7 @@ def test_get_effective_balance(balance, max_deposit, expected, sample_validator_
613615

614616
@pytest.mark.parametrize(
615617
(
616-
'index,'
618+
'validator_index,'
617619
'pubkey,'
618620
'flag,'
619621
'expected'
@@ -623,17 +625,17 @@ def test_get_effective_balance(balance, max_deposit, expected, sample_validator_
623625
1,
624626
2 * 256 - 1,
625627
1,
626-
b'\xe8\xaaH\x14\xa3\xban\x8f^rn1\xdf\xfd\xe1\xed\xe9S*\x80\xf5\xe3\x03\x983\x15\xd1\x91t\xcc\xb4h' # noqa: E501
628+
b'\xb8K\xad[zDE\xef\x00Z\x9c\x04\xdc\x95\xff\x9c\xeaP\x15\xf5\xfb\xdd\x0f\x1c:\xd7U+\x81\x92:\xee' # noqa: E501
627629
),
628630
]
629631
)
630-
def test_get_new_validator_registry_delta_chain_tip(index,
632+
def test_get_new_validator_registry_delta_chain_tip(validator_index,
631633
pubkey,
632634
flag,
633635
expected):
634636
result = get_new_validator_registry_delta_chain_tip(
635637
current_validator_registry_delta_chain_tip=ZERO_HASH32,
636-
index=index,
638+
validator_index=validator_index,
637639
pubkey=pubkey,
638640
flag=flag,
639641
)

0 commit comments

Comments
 (0)