|
1 | 1 | # beacon_chain |
2 | | -# Copyright (c) 2024 Status Research & Development GmbH |
| 2 | +# Copyright (c) 2024-2025 Status Research & Development GmbH |
3 | 3 | # Licensed and distributed under either of |
4 | 4 | # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). |
5 | 5 | # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). |
|
16 | 16 | NUM_BUCKETS = 1 shl BUCKET_BITS |
17 | 17 |
|
18 | 18 | type |
19 | | - # `newSeqUninitialized` requires its type to be SomeNumber |
20 | | - IntValidatorIndex = distinctBase ValidatorIndex |
21 | | - |
22 | 19 | BucketSortedValidators* = object |
23 | | - bucketSorted*: seq[IntValidatorIndex] |
| 20 | + bucketSorted*: seq[ValidatorIndex] |
24 | 21 | bucketUpperBounds: array[NUM_BUCKETS, uint] # avoids over/underflow checks |
25 | 22 | extraItems*: seq[ValidatorIndex] |
26 | 23 |
|
@@ -50,14 +47,14 @@ func sortValidatorBuckets*(validators: openArray[Validator]): |
50 | 47 | bucketInsertPositions[i] = accum |
51 | 48 | doAssert accum == validators.len.uint |
52 | 49 | let res = (ref BucketSortedValidators)( |
53 | | - bucketSorted: newSeqUninitialized[IntValidatorIndex](validators.len), |
| 50 | + bucketSorted: newSeqUninit[ValidatorIndex](validators.len), |
54 | 51 | bucketUpperBounds: bucketInsertPositions) |
55 | 52 |
|
56 | 53 | for i, validator in validators: |
57 | 54 | let insertPos = |
58 | 55 | addr bucketInsertPositions[getBucketNumber(validator.pubkey)] |
59 | 56 | dec insertPos[] |
60 | | - res.bucketSorted[insertPos[]] = i.IntValidatorIndex |
| 57 | + res.bucketSorted[insertPos[]] = i.ValidatorIndex |
61 | 58 |
|
62 | 59 | doAssert bucketInsertPositions[0] == 0 |
63 | 60 | for i in 1 ..< NUM_BUCKETS: |
@@ -85,6 +82,6 @@ func findValidatorIndex*( |
85 | 82 | bsv.bucketUpperBounds[bucketNumber - 1] |
86 | 83 |
|
87 | 84 | for i in lowerBounds ..< bsv.bucketUpperBounds[bucketNumber]: |
88 | | - if validators[bsv.bucketSorted[i]].pubkey == pubkey: |
89 | | - return Opt.some bsv.bucketSorted[i].ValidatorIndex |
| 85 | + if validators[bsv.bucketSorted[i].distinctBase].pubkey == pubkey: |
| 86 | + return Opt.some bsv.bucketSorted[i] |
90 | 87 | Opt.none ValidatorIndex |
0 commit comments