Skip to content

Commit ecabeee

Browse files
authored
switch from deprecated newSeqUninitialized to newSeqUninit (#7098)
1 parent 4879afb commit ecabeee

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

beacon_chain/era_db.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ proc getBlockSSZ*(
126126
if len > int.high.uint64:
127127
return err("Invalid uncompressed size")
128128

129-
bytes = newSeqUninitialized[byte](len)
129+
bytes = newSeqUninit[byte](len)
130130

131131
# Where it matters, we will integrity-check the data with SSZ - no
132132
# need to waste cycles on crc32
@@ -171,7 +171,7 @@ proc getStateSSZ*(
171171
min(len, partial.get().uint64 + maxUncompressedFrameDataLen - 1)
172172
else: len
173173

174-
bytes = newSeqUninitialized[byte](wanted)
174+
bytes = newSeqUninit[byte](wanted)
175175

176176
# Where it matters, we will integrity-check the data with SSZ - no
177177
# need to waste cycles on crc32

beacon_chain/networking/eth2_network.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ proc writeChunkSZ(
619619
uncompressedLenBytes = toBytes(uncompressedLen, Leb128)
620620

621621
var
622-
data = newSeqUninitialized[byte](
622+
data = newSeqUninit[byte](
623623
ord(responseCode.isSome) + contextBytes.len + uncompressedLenBytes.len +
624624
payloadSZ.len)
625625
pos = 0
@@ -638,7 +638,7 @@ proc writeChunk(conn: Connection,
638638
let
639639
uncompressedLenBytes = toBytes(payload.lenu64, Leb128)
640640
var
641-
data = newSeqUninitialized[byte](
641+
data = newSeqUninit[byte](
642642
ord(responseCode.isSome) + contextBytes.len + uncompressedLenBytes.len +
643643
snappy.maxCompressedLenFramed(payload.len).int)
644644
pos = 0
@@ -752,8 +752,8 @@ proc uncompressFramedStream(conn: Connection,
752752
doAssert maxCompressedFrameDataLen >= maxUncompressedFrameDataLen.uint64
753753

754754
var
755-
frameData = newSeqUninitialized[byte](maxCompressedFrameDataLen + 4)
756-
output = newSeqUninitialized[byte](expectedSize)
755+
frameData = newSeqUninit[byte](maxCompressedFrameDataLen + 4)
756+
output = newSeqUninit[byte](expectedSize)
757757
written = 0
758758

759759
while written < expectedSize:

beacon_chain/validator_bucket_sort.nim

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2024 Status Research & Development GmbH
2+
# Copyright (c) 2024-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -16,11 +16,8 @@ const
1616
NUM_BUCKETS = 1 shl BUCKET_BITS
1717

1818
type
19-
# `newSeqUninitialized` requires its type to be SomeNumber
20-
IntValidatorIndex = distinctBase ValidatorIndex
21-
2219
BucketSortedValidators* = object
23-
bucketSorted*: seq[IntValidatorIndex]
20+
bucketSorted*: seq[ValidatorIndex]
2421
bucketUpperBounds: array[NUM_BUCKETS, uint] # avoids over/underflow checks
2522
extraItems*: seq[ValidatorIndex]
2623

@@ -50,14 +47,14 @@ func sortValidatorBuckets*(validators: openArray[Validator]):
5047
bucketInsertPositions[i] = accum
5148
doAssert accum == validators.len.uint
5249
let res = (ref BucketSortedValidators)(
53-
bucketSorted: newSeqUninitialized[IntValidatorIndex](validators.len),
50+
bucketSorted: newSeqUninit[ValidatorIndex](validators.len),
5451
bucketUpperBounds: bucketInsertPositions)
5552

5653
for i, validator in validators:
5754
let insertPos =
5855
addr bucketInsertPositions[getBucketNumber(validator.pubkey)]
5956
dec insertPos[]
60-
res.bucketSorted[insertPos[]] = i.IntValidatorIndex
57+
res.bucketSorted[insertPos[]] = i.ValidatorIndex
6158

6259
doAssert bucketInsertPositions[0] == 0
6360
for i in 1 ..< NUM_BUCKETS:
@@ -85,6 +82,6 @@ func findValidatorIndex*(
8582
bsv.bucketUpperBounds[bucketNumber - 1]
8683

8784
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]
9087
Opt.none ValidatorIndex

ncli/e2store.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2021-2024 Status Research & Development GmbH
2+
# Copyright (c) 2021-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -95,7 +95,7 @@ proc readRecord*(f: IoHandle, data: var seq[byte]): Result[Header, string] =
9595
? f.checkBytesLeft(header.len)
9696

9797
if data.len != header.len:
98-
data = newSeqUninitialized[byte](header.len)
98+
data = newSeqUninit[byte](header.len)
9999

100100
? readFileExact(f, data)
101101

@@ -123,4 +123,3 @@ proc findIndexStartOffset*(f: IoHandle): Result[int64, string] =
123123
bytes = count.int64 * 8 + 24
124124

125125
ok(-bytes)
126-

ncli/era.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2021-2024 Status Research & Development GmbH
2+
# Copyright (c) 2021-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -113,7 +113,7 @@ proc readIndex*(f: IoHandle): Result[Index, string] =
113113
# technically not an error, but we'll throw this sanity check in here..
114114
if slot > int32.high().uint64: return err("fishy slot")
115115

116-
var offsets = newSeqUninitialized[int64](count)
116+
var offsets = newSeqUninit[int64](count)
117117
for i in 0..<count:
118118
let
119119
offset = uint64.fromBytesLE(buf.toOpenArray(pos, pos + 7))

tests/test_validator_bucket_sort.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2024 Status Research & Development GmbH
2+
# Copyright (c) 2024-2025 Status Research & Development GmbH
33
# Licensed and distributed under either of
44
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@@ -228,8 +228,8 @@ func findValidatorIndexBruteforce(
228228
if validators[validatorIndex.distinctBase].pubkey == h2:
229229
return Opt.some validatorIndex
230230
for validatorIndex in bsv.bucketSorted:
231-
if validators[validatorIndex].pubkey == h2:
232-
return Opt.some validatorIndex.ValidatorIndex
231+
if validators[validatorIndex.distinctBase].pubkey == h2:
232+
return Opt.some validatorIndex
233233
Opt.none ValidatorIndex
234234

235235
suite "ValidatorPubKey bucket sort":

0 commit comments

Comments
 (0)