Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed Jan 7, 2025
1 parent d34c933 commit 947ebec
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/modules/accounting/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/web3py/extensions/lido_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/accounting/test_accounting_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/web3_extentions/test_lido_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 947ebec

Please sign in to comment.