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
|
||||
|
||||
var debugTrackedValidator* = ValidatorIndex.high
|
||||
|
||||
# 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) =
|
||||
balance += delta
|
||||
|
||||
func increase_balance*(
|
||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||
func increase_balance(
|
||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei,
|
||||
info: typeof(instantiationInfo())) =
|
||||
## Increase the validator balance at index ``index`` by ``delta``.
|
||||
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)
|
||||
|
||||
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
|
||||
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
||||
balance =
|
||||
|
@ -40,13 +50,21 @@ func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
|||
else:
|
||||
balance - delta
|
||||
|
||||
func decrease_balance*(
|
||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||
func decrease_balance(
|
||||
state: var ForkyBeaconState, index: ValidatorIndex, delta: Gwei,
|
||||
info: typeof(instantiationInfo())) =
|
||||
## Decrease the validator balance at index ``index`` by ``delta``, with
|
||||
## underflow protection.
|
||||
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)
|
||||
|
||||
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.3.0/specs/altair/beacon-chain.md#modified-apply_deposit
|
||||
func get_validator_from_deposit*(deposit: DepositData):
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
import
|
||||
chronicles,
|
||||
../../beacon_chain/spec/beaconstate,
|
||||
../../beacon_chain/spec/forks,
|
||||
../../beacon_chain/spec/state_transition,
|
||||
../../beacon_chain/validators/rewards,
|
||||
|
@ -68,6 +69,8 @@ proc runTest(consensusFork: static ConsensusFork,
|
|||
state_slot = stateSlot,
|
||||
expected_balance = preStateBalance + blockValue
|
||||
|
||||
debugTrackedValidator = ValidatorIndex.high
|
||||
|
||||
block:
|
||||
let res =
|
||||
process_slots(defaultRuntimeConfig, fhPreState[],
|
||||
|
@ -80,6 +83,7 @@ proc runTest(consensusFork: static ConsensusFork,
|
|||
let advanceBalance =
|
||||
withState(fhPreState[]):
|
||||
forkyState.data.balances.item(proposerIndex)
|
||||
debugTrackedValidator = ValidatorIndex(proposerIndex)
|
||||
|
||||
block:
|
||||
let res =
|
||||
|
|
Loading…
Reference in New Issue