Skip to content

Commit eb6e9c6

Browse files
authored
Merge pull request #1634 from Bhargavasomu/validator_registry_delta_block
Validator registry delta block
2 parents 20441a4 + 91b04cf commit eb6e9c6

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from eth_typing import (
2+
Hash32,
3+
)
4+
import rlp
5+
6+
from eth.beacon.utils.hash import (
7+
hash_eth2,
8+
)
9+
from eth.rlp.sedes import (
10+
hash32,
11+
uint24,
12+
uint64,
13+
uint384,
14+
)
15+
16+
17+
class ValidatorRegistryDeltaBlock(rlp.Serializable):
18+
"""
19+
Note: using RLP until we have standardized serialization format.
20+
"""
21+
fields = [
22+
('latest_registry_delta_root', hash32),
23+
('validator_index', uint24),
24+
('pubkey', uint384),
25+
('flag', uint64)
26+
]
27+
28+
def __init__(self,
29+
latest_registry_delta_root: Hash32,
30+
validator_index: int,
31+
pubkey: int,
32+
flag: int) -> None:
33+
super().__init__(
34+
latest_registry_delta_root=latest_registry_delta_root,
35+
validator_index=validator_index,
36+
pubkey=pubkey,
37+
flag=flag,
38+
)
39+
40+
_hash = None
41+
42+
@property
43+
def hash(self) -> Hash32:
44+
if self._hash is None:
45+
self._hash = hash_eth2(rlp.encode(self))
46+
return self._hash
47+
48+
@property
49+
def root(self) -> Hash32:
50+
# Alias of `hash`.
51+
# Using flat hash, might change to SSZ tree hash.
52+
return self.hash

eth/rlp/sedes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
uint32 = BigEndianInt(32)
1616
uint64 = BigEndianInt(64)
1717
uint256 = BigEndianInt(256)
18+
uint384 = BigEndianInt(384)
1819
trie_root = Binary.fixed_length(32, allow_empty=True)

tests/beacon/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ def sample_validator_record_params():
294294
}
295295

296296

297+
@pytest.fixture
298+
def sample_validator_registry_delta_block_params():
299+
return {
300+
'latest_registry_delta_root': b'\x01' * 32,
301+
'validator_index': 1,
302+
'pubkey': 123,
303+
'flag': 1,
304+
}
305+
306+
297307
#
298308
# Temporary default values
299309
#
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from eth.beacon.types.validator_registry_delta_block import (
2+
ValidatorRegistryDeltaBlock,
3+
)
4+
5+
6+
def test_defaults(sample_validator_registry_delta_block_params):
7+
validator_registry_delta_block = ValidatorRegistryDeltaBlock(
8+
**sample_validator_registry_delta_block_params
9+
)
10+
assert validator_registry_delta_block.latest_registry_delta_root == sample_validator_registry_delta_block_params['latest_registry_delta_root'] # noqa: E501
11+
assert validator_registry_delta_block.validator_index == sample_validator_registry_delta_block_params['validator_index'] # noqa: E501
12+
assert validator_registry_delta_block.pubkey == sample_validator_registry_delta_block_params['pubkey'] # noqa: E501
13+
assert validator_registry_delta_block.flag == sample_validator_registry_delta_block_params['flag'] # noqa: E501

0 commit comments

Comments
 (0)