mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-09 05:52:45 +00:00
Increase logging to track sources of balance changes.
This commit is contained in:
parent
f7c0f02129
commit
61f44afae3
@ -22,16 +22,26 @@ from ./datatypes/capella import BeaconState, ExecutionPayloadHeader, Withdrawal
|
|||||||
|
|
||||||
export extras, forks, validator, chronicles
|
export extras, forks, validator, chronicles
|
||||||
|
|
||||||
|
var debugTrackedValidator* = ValidatorIndex.high
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#increase_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#increase_balance
|
||||||
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
||||||
balance += delta
|
balance += delta
|
||||||
|
|
||||||
func increase_balance*(
|
func increase_balance(
|
||||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei,
|
||||||
|
info: typeof(instantiationInfo())) =
|
||||||
## Increase the validator balance at index ``index`` by ``delta``.
|
## Increase the validator balance at index ``index`` by ``delta``.
|
||||||
if delta != 0: # avoid dirtying the balance cache if not needed
|
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||||
|
{.noSideEffect.}:
|
||||||
|
if index == debugTrackedValidator:
|
||||||
|
debugEcho "+", $delta, " ", $info
|
||||||
increase_balance(state.balances.mitem(index), delta)
|
increase_balance(state.balances.mitem(index), delta)
|
||||||
|
|
||||||
|
template increase_balance*(
|
||||||
|
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
|
increase_balance(state, index, delta, instantiationInfo())
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#decrease_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#decrease_balance
|
||||||
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
||||||
balance =
|
balance =
|
||||||
@ -40,13 +50,21 @@ func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
|||||||
else:
|
else:
|
||||||
balance - delta
|
balance - delta
|
||||||
|
|
||||||
func decrease_balance*(
|
func decrease_balance(
|
||||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei,
|
||||||
|
info: typeof(instantiationInfo())) =
|
||||||
## Decrease the validator balance at index ``index`` by ``delta``, with
|
## Decrease the validator balance at index ``index`` by ``delta``, with
|
||||||
## underflow protection.
|
## underflow protection.
|
||||||
if delta != 0: # avoid dirtying the balance cache if not needed
|
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||||
|
{.noSideEffect.}:
|
||||||
|
if index == debugTrackedValidator:
|
||||||
|
debugEcho "-", $delta, " ", $info
|
||||||
decrease_balance(state.balances.mitem(index), delta)
|
decrease_balance(state.balances.mitem(index), delta)
|
||||||
|
|
||||||
|
template decrease_balance*(
|
||||||
|
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
|
decrease_balance(state, index, delta, instantiationInfo())
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/beacon-chain.md#deposits
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/beacon-chain.md#deposits
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#modified-apply_deposit
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/beacon-chain.md#modified-apply_deposit
|
||||||
func get_validator_from_deposit*(deposit: DepositData):
|
func get_validator_from_deposit*(deposit: DepositData):
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
|
../../beacon_chain/spec/beaconstate,
|
||||||
../../beacon_chain/spec/forks,
|
../../beacon_chain/spec/forks,
|
||||||
../../beacon_chain/spec/state_transition,
|
../../beacon_chain/spec/state_transition,
|
||||||
../../beacon_chain/validators/rewards,
|
../../beacon_chain/validators/rewards,
|
||||||
@ -68,6 +69,8 @@ proc runTest(consensusFork: static ConsensusFork,
|
|||||||
state_slot = stateSlot,
|
state_slot = stateSlot,
|
||||||
expected_balance = preStateBalance + blockValue
|
expected_balance = preStateBalance + blockValue
|
||||||
|
|
||||||
|
debugTrackedValidator = ValidatorIndex.high
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let res =
|
let res =
|
||||||
process_slots(defaultRuntimeConfig, fhPreState[],
|
process_slots(defaultRuntimeConfig, fhPreState[],
|
||||||
@ -80,6 +83,7 @@ proc runTest(consensusFork: static ConsensusFork,
|
|||||||
let advanceBalance =
|
let advanceBalance =
|
||||||
withState(fhPreState[]):
|
withState(fhPreState[]):
|
||||||
forkyState.data.balances.item(proposerIndex)
|
forkyState.data.balances.item(proposerIndex)
|
||||||
|
debugTrackedValidator = ValidatorIndex(proposerIndex)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let res =
|
let res =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user