Skip to content

Master #546

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

Merged
merged 4 commits into from
Oct 29, 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lido-oracle"
version = "4.0.0-rc.1"
version = "4.0.1"
description = "Oracle daemon for Lido decentralized staking service. Collects and reports Ethereum 2.0 beacon chain states (the number of visible validators and their summarized balances) to the Lido dApp contract running on Ethereum 1.0 side."
authors = [
"Dmitry Chernukhin",
Expand Down
9 changes: 5 additions & 4 deletions src/modules/ejector/ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ def _get_churn_limit(self, blockstamp: ReferenceBlockStamp) -> int:
return churn_limit

def _get_total_active_validators(self, blockstamp: ReferenceBlockStamp) -> int:
total_active_validators = len([
is_active_validator(val, blockstamp.ref_epoch)
for val in self.w3.cc.get_validators(blockstamp)
])
total_active_validators = reduce(
lambda total, validator: total + int(is_active_validator(validator, blockstamp.ref_epoch)),
self.w3.cc.get_validators(blockstamp),
0,
)
logger.info({'msg': 'Calculate total active validators.', 'value': total_active_validators})
return total_active_validators

Expand Down
30 changes: 30 additions & 0 deletions tests/factory/no_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ def build_with_activation_epoch_bound(cls, max_value: int, **kwargs: Any):
validator=ValidatorStateFactory.build(activation_epoch=str(faker.pyint(max_value=max_value - 1))), **kwargs
)

@classmethod
def build_not_active_vals(cls, epoch, **kwargs: Any):
return cls.build(
validator=ValidatorStateFactory.build(
activation_epoch=str(faker.pyint(min_value=epoch + 1, max_value=FAR_FUTURE_EPOCH)),
exit_epoch=str(FAR_FUTURE_EPOCH),
),
**kwargs
)

@classmethod
def build_active_vals(cls, epoch, **kwargs: Any):
return cls.build(
validator=ValidatorStateFactory.build(
activation_epoch=str(faker.pyint(min_value=0, max_value=epoch - 1)),
exit_epoch=str(faker.pyint(min_value=epoch + 1, max_value=FAR_FUTURE_EPOCH)),
),
**kwargs
)

@classmethod
def build_exit_vals(cls, epoch, **kwargs: Any):
return cls.build(
validator=ValidatorStateFactory.build(
activation_epoch='0',
exit_epoch=str(faker.pyint(min_value=1, max_value=epoch)),
),
**kwargs
)


class NodeOperatorFactory(Web3Factory):
__model__ = NodeOperator
Expand Down
15 changes: 15 additions & 0 deletions tests/modules/ejector/test_ejector.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ def test_get_predicted_withdrawable_epoch(ejector: Ejector) -> None:
assert result == 3809, "Unexpected predicted withdrawable epoch"


@pytest.mark.unit
def test_get_total_active_validators(ejector: Ejector) -> None:
ref_blockstamp = ReferenceBlockStampFactory.build(ref_epoch=3546)
ejector.w3 = Mock()
ejector.w3.cc.get_validators = Mock(
return_value=[
*[LidoValidatorFactory.build_not_active_vals(ref_blockstamp.ref_epoch) for _ in range(150)],
*[LidoValidatorFactory.build_active_vals(ref_blockstamp.ref_epoch) for _ in range(100)],
*[LidoValidatorFactory.build_exit_vals(ref_blockstamp.ref_epoch) for _ in range(50)],
]
)

assert ejector._get_total_active_validators(ref_blockstamp) == 100


@pytest.mark.unit
@pytest.mark.usefixtures("consensus_client", "lido_validators")
def test_get_withdrawable_lido_validators(
Expand Down
Loading