Skip to content

Commit

Permalink
use intsets in block transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Jan 26, 2021
1 parent 45508b0 commit 91d9e5f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2020 Status Research & Development GmbH
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand All @@ -20,7 +20,7 @@
{.push raises: [Defect].}

import
std/[algorithm, collections/sets, options, sequtils, sets],
std/[algorithm, intsets, options, sequtils],
chronicles,
../extras, ../ssz/merkleization, metrics,
./beaconstate, ./crypto, ./datatypes, ./digest, ./helpers, ./validator,
Expand All @@ -29,7 +29,8 @@ import

# Generics visibility issue with toSeq(items(intersection(HashSet, HashSet)))
# https://github.com/nim-lang/Nim/issues/11225
export sets
when false:

This comment has been minimized.

Copy link
@arnetheduck

arnetheduck Jan 26, 2021

Member

test code?

This comment has been minimized.

Copy link
@tersec

tersec Jan 26, 2021

Author Contributor

It's a marker/documentation of a bug workaround that's not useful anymore, since IntSet isn't a generic type, unlike HashSet[ValidatorIndex], and therefore doesn't doesn't suffer from the generic sandwich situation. So it's potentially useful to keep a code-memory of regardless.

That whole section could just be removed now, too.

This comment has been minimized.

Copy link
@mratsim

mratsim Jan 26, 2021

Contributor

I think everyone is aware of the generic sandwich now and the compiler will be prompt to remind you so this can go.

This comment has been minimized.

Copy link
@mratsim

mratsim Jan 26, 2021

Contributor

And tagging the issue because of how annoying it is: nim-lang/Nim#11225

export sets

# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/beacon-chain.md#block-header
func process_block_header*(
Expand Down Expand Up @@ -215,8 +216,8 @@ proc check_attester_slashing*(
var slashed_indices: seq[ValidatorIndex]

for index in sorted(toSeq(intersection(
toHashSet(attestation_1.attesting_indices.asSeq),
toHashSet(attestation_2.attesting_indices.asSeq)).items), system.cmp):
toIntSet(attestation_1.attesting_indices.asSeq),
toIntSet(attestation_2.attesting_indices.asSeq)).items), system.cmp):
if is_slashable_validator(
state.validators.asSeq()[index], get_current_epoch(state)):
slashed_indices.add index.ValidatorIndex
Expand Down

0 comments on commit 91d9e5f

Please sign in to comment.