Skip to content

Commit c7bf6fb

Browse files
authored
rm debugRaiseAssert; clean up several debugComments (#6308)
* rm debugRaiseAssert; clean up several debugComments * exception linting
1 parent a7b5741 commit c7bf6fb

File tree

10 files changed

+33
-30
lines changed

10 files changed

+33
-30
lines changed

beacon_chain/consensus_object_pools/spec_cache.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import
1616
../spec/datatypes/base,
1717
./block_pools_types, blockchain_dag
1818

19-
debugComment "probably just need Electra shortLog here"
20-
import ../spec/forks # prune this, it's for electra attestation logging
19+
from ../spec/datatypes/electra import shortLog
2120

2221
export
2322
base, extras, block_pools_types, results

beacon_chain/light_client.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ proc updateGossipStatus*(
366366
lightClient: LightClient, slot: Slot, dagIsBehind = default(Option[bool])) =
367367
template cfg(): auto = lightClient.cfg
368368

369-
debugComment "when LC on electra works, add cfg.ELECTRA_FORK_EPOCH"
370-
371369
let
372370
epoch = slot.epoch
373371

beacon_chain/spec/datatypes/base.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,4 +986,3 @@ func ofLen*[T, N](ListType: type List[T, N], n: int): ListType =
986986
raise newException(SszSizeMismatchError)
987987

988988
template debugComment*(s: string) = discard
989-
template debugRaiseAssert*(s: string) = discard

beacon_chain/spec/state_transition_epoch.nim

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ func process_historical_summaries_update*(
12211221
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#new-process_pending_balance_deposits
12221222
func process_pending_balance_deposits*(
12231223
cfg: RuntimeConfig, state: var electra.BeaconState,
1224-
cache: var StateCache) =
1224+
cache: var StateCache): Result[void, cstring] =
12251225
let
12261226
available_for_processing = state.deposit_balance_to_consume +
12271227
get_activation_exit_churn_limit(cfg, state, cache)
@@ -1232,8 +1232,9 @@ func process_pending_balance_deposits*(
12321232
for deposit in state.pending_balance_deposits:
12331233
if processed_amount + deposit.amount > available_for_processing:
12341234
break
1235-
debugComment "do this validatorindex check properly (it truncates)"
1236-
increase_balance(state, deposit.index.ValidatorIndex, deposit.amount)
1235+
let deposit_validator_index = ValidatorIndex.init(deposit.index).valueOr:
1236+
return err("process_pending_balance_deposits: deposit index out of range")
1237+
increase_balance(state, deposit_validator_index, deposit.amount)
12371238
processed_amount += deposit.amount
12381239
inc next_deposit_index
12391240

@@ -1247,8 +1248,12 @@ func process_pending_balance_deposits*(
12471248
state.deposit_balance_to_consume =
12481249
available_for_processing - processed_amount
12491250

1251+
ok()
1252+
12501253
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#new-process_pending_consolidations
1251-
func process_pending_consolidations*(cfg: RuntimeConfig, state: var electra.BeaconState) =
1254+
func process_pending_consolidations*(
1255+
cfg: RuntimeConfig, state: var electra.BeaconState):
1256+
Result[void, cstring] =
12521257
var next_pending_consolidation = 0
12531258
for pending_consolidation in state.pending_consolidations:
12541259
let source_validator =
@@ -1259,25 +1264,29 @@ func process_pending_consolidations*(cfg: RuntimeConfig, state: var electra.Beac
12591264
if source_validator.withdrawable_epoch > get_current_epoch(state):
12601265
break
12611266

1267+
let
1268+
source_validator_index = ValidatorIndex.init(
1269+
pending_consolidation.source_index).valueOr:
1270+
return err("process_pending_consolidations: source index out of range")
1271+
target_validator_index = ValidatorIndex.init(
1272+
pending_consolidation.target_index).valueOr:
1273+
return err("process_pending_consolidations: target index out of range")
1274+
12621275
# Churn any target excess active balance of target and raise its max
1263-
debugComment "truncating integer conversion"
1264-
switch_to_compounding_validator(
1265-
state, pending_consolidation.target_index.ValidatorIndex)
1276+
switch_to_compounding_validator(state, target_validator_index)
12661277

12671278
# Move active balance to target. Excess balance is withdrawable.
1268-
debugComment "Truncating"
1269-
let active_balance = get_active_balance(
1270-
state, pending_consolidation.source_index.ValidatorIndex)
1271-
decrease_balance(
1272-
state, pending_consolidation.source_index.ValidatorIndex, active_balance)
1273-
increase_balance(
1274-
state, pending_consolidation.target_index.ValidatorIndex, active_balance)
1279+
let active_balance = get_active_balance(state, source_validator_index)
1280+
decrease_balance(state, source_validator_index, active_balance)
1281+
increase_balance(state, target_validator_index, active_balance)
12751282
inc next_pending_consolidation
12761283

12771284
state.pending_consolidations =
12781285
HashList[PendingConsolidation, Limit PENDING_CONSOLIDATIONS_LIMIT].init(
12791286
state.pending_consolidations.asSeq[next_pending_consolidation..^1])
12801287

1288+
ok()
1289+
12811290
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#epoch-processing
12821291
proc process_epoch*(
12831292
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
@@ -1464,8 +1473,8 @@ proc process_epoch*(
14641473
process_slashings(state, info.balances.current_epoch)
14651474

14661475
process_eth1_data_reset(state)
1467-
process_pending_balance_deposits(cfg, state, cache) # [New in Electra:EIP7251]
1468-
process_pending_consolidations(cfg, state) # [New in Electra:EIP7251]
1476+
? process_pending_balance_deposits(cfg, state, cache) # [New in Electra:EIP7251]
1477+
? process_pending_consolidations(cfg, state) # [New in Electra:EIP7251]
14691478
process_effective_balance_updates(state) # [Modified in Electra:EIP7251]
14701479
process_slashings_reset(state)
14711480
process_randao_mixes_reset(state)

tests/consensus_spec/altair/test_fixture_state_transition_epoch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import
1212
# Beacon chain internals
1313
chronicles,
14-
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
14+
../../../beacon_chain/spec/[presets, state_transition_epoch],
1515
../../../beacon_chain/spec/datatypes/altair,
1616
# Test utilities
1717
../../testutil,

tests/consensus_spec/bellatrix/test_fixture_state_transition_epoch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import
1212
# Beacon chain internals
13-
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
13+
../../../beacon_chain/spec/[presets, state_transition_epoch],
1414
../../../beacon_chain/spec/datatypes/[altair, bellatrix],
1515
# Test utilities
1616
../../testutil,

tests/consensus_spec/capella/test_fixture_state_transition_epoch.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

8+
{.push raises: [].}
89
{.used.}
910

1011
import
1112
# Status internals
1213
chronicles,
1314
# Beacon chain internals
14-
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
15+
../../../beacon_chain/spec/[presets, state_transition_epoch],
1516
../../../beacon_chain/spec/datatypes/[altair, capella],
1617
# Test utilities
1718
../../testutil,

tests/consensus_spec/deneb/test_fixture_state_transition_epoch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import
1212
# Status internals
1313
chronicles,
1414
# Beacon chain internals
15-
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
15+
../../../beacon_chain/spec/[presets, state_transition_epoch],
1616
../../../beacon_chain/spec/datatypes/[altair, deneb],
1717
# Test utilities
1818
../../testutil,

tests/consensus_spec/electra/test_fixture_state_transition_epoch.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import
1212
# Status internals
1313
chronicles,
1414
# Beacon chain internals
15-
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
15+
../../../beacon_chain/spec/[presets, state_transition_epoch],
1616
../../../beacon_chain/spec/datatypes/[altair, electra],
1717
# Test utilities
1818
../../testutil,
@@ -146,13 +146,11 @@ runSuite(ParticipationFlagDir, "Participation flag updates"):
146146
# ---------------------------------------------------------------
147147
runSuite(PendingBalanceDepositsDir, "Pending balance deposits"):
148148
process_pending_balance_deposits(cfg, state, cache)
149-
Result[void, cstring].ok()
150149

151150
# Pending consolidations
152151
# ---------------------------------------------------------------
153152
runSuite(PendingConsolidationsDir, "Pending consolidations"):
154153
process_pending_consolidations(cfg, state)
155-
Result[void, cstring].ok()
156154

157155
# Sync committee updates
158156
# ---------------------------------------------------------------

tests/test_signing_node.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ func init(
9292
of ConsensusFork.Deneb:
9393
return ForkedBeaconBlock.init(contents.denebData.signed_block.message)
9494
of ConsensusFork.Electra:
95-
debugComment "probably like the deneb case"
96-
return default(T)
95+
return ForkedBeaconBlock.init(contents.electraData.signed_block.message)
9796

9897
proc getBlock(
9998
fork: ConsensusFork,

0 commit comments

Comments
 (0)