diff --git a/src/constants.py b/src/constants.py index 51c9ce6c7..bd5dd9601 100644 --- a/src/constants.py +++ b/src/constants.py @@ -13,7 +13,7 @@ # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#gwei-values EFFECTIVE_BALANCE_INCREMENT = 2 ** 0 * 10 ** 9 MAX_EFFECTIVE_BALANCE = Gwei(32 * 10 ** 9) -MIN_ACTIVATION_BALANCE = Gwei(32 * 10 ** 9) +LIDO_DEPOSIT_AMOUNT = Gwei(32 * 10 ** 9) # https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#execution MAX_WITHDRAWALS_PER_PAYLOAD = 2 ** 4 # https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#withdrawal-prefixes diff --git a/src/modules/accounting/accounting.py b/src/modules/accounting/accounting.py index 4cda508a3..d5c6b5af1 100644 --- a/src/modules/accounting/accounting.py +++ b/src/modules/accounting/accounting.py @@ -216,12 +216,13 @@ def get_updated_modules_stats( def _get_consensus_lido_state(self, blockstamp: ReferenceBlockStamp) -> tuple[ValidatorsCount, ValidatorsBalance]: lido_validators = self.w3.lido_validators.get_lido_validators(blockstamp) - count = len(lido_validators) - pending_deposits_sum = self.w3.lido_validators.calculate_pending_deposits_sum(lido_validators) - total_balance = Gwei(sum(int(validator.balance) for validator in lido_validators) + pending_deposits_sum) + validators_count = len(lido_validators) + active_balance = sum(int(validator.balance) for validator in lido_validators) + pending_deposits = self.w3.lido_validators.calculate_pending_deposits_sum(lido_validators) + total_balance = Gwei(active_balance + pending_deposits) - logger.info({'msg': 'Calculate lido state on CL. (Validators count, Total balance in gwei)', 'value': (count, total_balance)}) - return ValidatorsCount(count), ValidatorsBalance(total_balance) + logger.info({'msg': f'Calculate Lido state on CL. {validators_count=}, {active_balance=}, {pending_deposits=}, {total_balance=} (Gwei)'}) + return ValidatorsCount(validators_count), ValidatorsBalance(total_balance) def _get_finalization_data(self, blockstamp: ReferenceBlockStamp) -> tuple[FinalizationShareRate, FinalizationBatches]: simulation = self.simulate_full_rebase(blockstamp) diff --git a/src/web3py/extensions/lido_validators.py b/src/web3py/extensions/lido_validators.py index 90758e1ef..b1fddc23a 100644 --- a/src/web3py/extensions/lido_validators.py +++ b/src/web3py/extensions/lido_validators.py @@ -6,7 +6,7 @@ from eth_typing import ChecksumAddress from web3.module import Module -from src.constants import FAR_FUTURE_EPOCH, MIN_ACTIVATION_BALANCE +from src.constants import FAR_FUTURE_EPOCH, LIDO_DEPOSIT_AMOUNT from src.providers.consensus.types import Validator from src.providers.keys.types import LidoKey from src.types import BlockStamp, StakingModuleId, NodeOperatorId, NodeOperatorGlobalIndex, StakingModuleAddress @@ -178,7 +178,7 @@ def calculate_pending_deposits_sum(lido_validators: list[LidoValidator]) -> int: # NOTE: Using 32 ETH as a default validator pending balance is OK for the current protocol implementation. # It must be changed in case of validators consolidation feature implementation. return sum( - MIN_ACTIVATION_BALANCE + LIDO_DEPOSIT_AMOUNT for validator in lido_validators if int(validator.balance) == 0 and int(validator.validator.activation_epoch) == FAR_FUTURE_EPOCH ) diff --git a/tests/modules/accounting/test_accounting_module.py b/tests/modules/accounting/test_accounting_module.py index cf357bb25..a69effa17 100644 --- a/tests/modules/accounting/test_accounting_module.py +++ b/tests/modules/accounting/test_accounting_module.py @@ -6,7 +6,7 @@ from web3.types import Wei from src import variables -from src.constants import MIN_ACTIVATION_BALANCE +from src.constants import LIDO_DEPOSIT_AMOUNT from src.modules.accounting import accounting as accounting_module from src.modules.accounting.accounting import Accounting from src.modules.accounting.accounting import logger as accounting_logger @@ -112,7 +112,7 @@ def test_get_consensus_lido_state(accounting: Accounting): count, balance = accounting._get_consensus_lido_state(bs) assert count == 10 - assert balance == sum((int(val.balance) for val in validators)) + 3 * MIN_ACTIVATION_BALANCE + assert balance == sum((int(val.balance) for val in validators)) + 3 * LIDO_DEPOSIT_AMOUNT @pytest.mark.unit diff --git a/tests/web3_extentions/test_lido_validators.py b/tests/web3_extentions/test_lido_validators.py index bd26579b1..fb393f2e5 100644 --- a/tests/web3_extentions/test_lido_validators.py +++ b/tests/web3_extentions/test_lido_validators.py @@ -2,7 +2,7 @@ import pytest -from src.constants import MIN_ACTIVATION_BALANCE +from src.constants import LIDO_DEPOSIT_AMOUNT from src.modules.accounting.types import BeaconStat from src.web3py.extensions.lido_validators import CountOfKeysDiffersException from tests.factory.blockstamp import ReferenceBlockStampFactory @@ -54,7 +54,7 @@ def test_calc_pending_deposits_sum(web3, lido_validators, contracts): lido_validators = web3.lido_validators.get_lido_validators(blockstamp) pending_deposits_sum = web3.lido_validators.calculate_pending_deposits_sum(lido_validators) - assert pending_deposits_sum == 5 * MIN_ACTIVATION_BALANCE + assert pending_deposits_sum == 5 * LIDO_DEPOSIT_AMOUNT @pytest.mark.unit