Skip to content

Commit 83049e4

Browse files
authored
reduce light client data store stack usage (#7067)
* reduce light client data store stack usage * copyright year linting
1 parent 2f1599e commit 83049e4

File tree

9 files changed

+27
-32
lines changed

9 files changed

+27
-32
lines changed

beacon_chain/consensus_object_pools/attestation_pool.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func candidateIdx(
213213
Opt[int] =
214214
static: doAssert pool.phase0Candidates.len == pool.electraCandidates.len
215215

216-
let poolLength = if candidateIdxtype == CandidateIdxType.electraIdx:
216+
let poolLength = if candidateIdxType == CandidateIdxType.electraIdx:
217217
pool.electraCandidates.lenu64 else: pool.phase0Candidates.lenu64
218218

219219
if slot >= pool.startingSlot and
@@ -1033,10 +1033,10 @@ proc getElectraAttestationsForBlock*(
10331033
var e2 = entry.data
10341034
e2.index = 0
10351035
e2
1036-
key = (hash_tree_root(entry2), entry.data.slot.Slot)
1036+
key = (hash_tree_root(entry2), entry.data.slot)
10371037
newAtt = entry[].toElectraAttestation(entry[].aggregates[j])
10381038

1039-
candidatesPerBlock.mGetOrPut(key, @[]).add(newAtt)
1039+
candidatesPerBlock.mgetOrPut(key, @[]).add(newAtt)
10401040

10411041
# Update cache so that the new votes are taken into account when updating
10421042
# the score below

beacon_chain/nimbus_beacon_node.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ proc checkWeakSubjectivityCheckpoint(
274274

275275
from ./spec/state_transition_block import kzg_commitment_to_versioned_hash
276276

277-
proc isSlotWithinWeakSubjectivityPeriod(dag: ChainDagRef, slot: Slot): bool =
277+
proc isSlotWithinWeakSubjectivityPeriod(dag: ChainDAGRef, slot: Slot): bool =
278278
let
279279
checkpoint = Checkpoint(
280280
epoch: epoch(getStateField(dag.headState, slot)),

beacon_chain/rpc/rest_rewards_api.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) 2018-2024 Status Research & Development GmbH
2+
# Copyright (c) 2018-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).
@@ -169,11 +169,11 @@ proc installRewardsApiHandlers*(router: var RestRouter, node: BeaconNode) =
169169

170170
let response =
171171
withState(tmpState[]):
172-
let total_active_balance =
173-
get_total_active_balance(forkyState.data, cache)
174172
var resp: seq[RestSyncCommitteeReward]
175173
when consensusFork > ConsensusFork.Phase0:
176174
let
175+
total_active_balance =
176+
get_total_active_balance(forkyState.data, cache)
177177
keys =
178178
block:
179179
var res: HashSet[ValidatorPubKey]

beacon_chain/spec/forks_light_client.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2023-2024 Status Research & Development GmbH
2+
# Copyright (c) 2023-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).
@@ -958,13 +958,13 @@ func migrateToDataFork*(
958958
discard
959959
elif newKind < x.kind:
960960
# Downgrade not supported, re-initialize
961-
x = ForkedLightClientStore(kind: newKind)
961+
x = static(ForkedLightClientStore(kind: newKind))
962962
else:
963963
# Upgrade to Altair
964964
when newKind >= LightClientDataFork.Altair:
965965
if x.kind == LightClientDataFork.None:
966-
x = ForkedLightClientStore(
967-
kind: LightClientDataFork.Altair)
966+
x = static(ForkedLightClientStore(
967+
kind: LightClientDataFork.Altair))
968968

969969
# Upgrade to Capella
970970
when newKind >= LightClientDataFork.Capella:

beacon_chain/validators/beacon_validators.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,16 @@ proc getBuilderBid[
10111011
return err unsignedBlindedBlock.error()
10121012

10131013
template execution_requests: untyped =
1014-
unsignedBlindedBlock.get.message.body.execution_requests
1014+
unsignedBlindedBlock.get.message.body.execution_requests
10151015
when SBBB is deneb_mev.SignedBlindedBeaconBlock:
1016-
return ok(BuilderBid[SBBB](
1016+
return ok(BuilderBid[SBBB](
10171017
blindedBlckPart: unsignedBlindedBlock.get,
10181018
executionRequests: default(ExecutionRequests),
10191019
executionPayloadValue: bidValue,
10201020
consensusBlockValue: consensusValue))
10211021
elif SBBB is electra_mev.SignedBlindedBeaconBlock or
10221022
SBBB is fulu_mev.SignedBlindedBeaconBlock:
1023-
return ok(BuilderBid[SBBB](
1023+
return ok(BuilderBid[SBBB](
10241024
blindedBlckPart: unsignedBlindedBlock.get,
10251025
executionRequests: execution_requests,
10261026
executionPayloadValue: bidValue,

config.nims

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# beacon_chain
2-
# Copyright (c) 2020-2024 Status Research & Development GmbH
2+
# Copyright (c) 2020-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).
@@ -114,8 +114,8 @@ elif defined(macosx) and defined(arm64):
114114
switch("passC", "-mcpu=apple-m1")
115115
switch("passL", "-mcpu=apple-m1")
116116
elif defined(riscv64):
117-
# riscv64 needs specification of ISA with extensions. 'gc' is widely supported
118-
# and seems to be the minimum extensions needed to build.
117+
# riscv64 needs specification of ISA with extensions. 'gc' is widely supported
118+
# and seems to be the minimum extensions needed to build.
119119
switch("passC", "-march=rv64gc")
120120
switch("passL", "-march=rv64gc")
121121
else:

tests/consensus_spec/test_fixture_kzg.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ proc runComputeCellsTest(suiteName, suitePath, path: string) =
217217
if p[].isErr:
218218
check output.kind == JNull
219219
else:
220-
let p_val = p[].get
220+
let p_val = newClone p[].get
221221
for i in 0..<len(p[].get):
222-
check p_val[i].bytes == fromHex[2048](output[i].getStr).get
222+
check p_val[][i].bytes == fromHex[2048](output[i].getStr).get
223223

224224
proc runComputeCellsAndKzgProofsTest(suiteName, suitePath, path: string) =
225225
let relativePathComponent = path.relativeTestPathComponent(suitePath)
@@ -240,7 +240,7 @@ proc runComputeCellsAndKzgProofsTest(suiteName, suitePath, path: string) =
240240
if p[].isErr:
241241
check output.kind == JNull
242242
else:
243-
let p_val = p[].get
243+
let p_val = newClone p[].get
244244
for i in 0..<kzg_abi.CELLS_PER_EXT_BLOB:
245245
check p_val.cells[i].bytes == fromHex[2048](output[0][i].getStr).get
246246
check p_val.proofs[i].bytes == fromHex[48](output[1][i].getStr).get

tests/test_keymanager_api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ proc addDynamicValidator(kmtest: KeymanagerToTest,
233233
pubkey: pubkey,
234234
remotes: @[
235235
RemoteSignerInfo(
236-
url: HttpHostUri(HttpHostUri(parseUri("http://127.0.0.1"))),
236+
url: HttpHostUri(parseUri("http://127.0.0.1")),
237237
pubkey: pubkey
238238
)
239239
],

tests/test_sync_committee_pool.nim

Lines changed: 6 additions & 11 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).
@@ -176,11 +176,7 @@ suite "Sync committee pool":
176176
let
177177
fork = altairFork(cfg)
178178
genesis_validators_root = eth2digest(@[5.byte, 6, 7])
179-
180-
privkey1 = MockPrivKeys[1.ValidatorIndex]
181-
privkey2 = MockPrivKeys[2.ValidatorIndex]
182-
privkey3 = MockPrivKeys[3.ValidatorIndex]
183-
privkey4 = MockPrivKeys[4.ValidatorIndex]
179+
privkey = MockPrivKeys[1.ValidatorIndex]
184180

185181
bid1 = BlockId(slot: Slot(100), root: eth2digest(@[1.byte]))
186182
bid2 = BlockId(slot: Slot(101), root: eth2digest(@[1.byte, 2]))
@@ -190,16 +186,15 @@ suite "Sync committee pool":
190186
subcommittee2 = SyncSubcommitteeIndex(1)
191187

192188
sig1 = get_sync_committee_message_signature(
193-
fork, genesis_validators_root, bid1.slot, bid1.root, privkey1)
189+
fork, genesis_validators_root, bid1.slot, bid1.root, privkey)
194190
sig2 = get_sync_committee_message_signature(
195-
fork, genesis_validators_root, bid2.slot, bid2.root, privkey1)
191+
fork, genesis_validators_root, bid2.slot, bid2.root, privkey)
196192
sig3 = get_sync_committee_message_signature(
197-
fork, genesis_validators_root, bid3.slot, bid3.root, privkey1)
193+
fork, genesis_validators_root, bid3.slot, bid3.root, privkey)
198194
sig4 = get_sync_committee_message_signature(
199-
fork, genesis_validators_root, bid3.slot, bid2.root, privkey1)
195+
fork, genesis_validators_root, bid3.slot, bid2.root, privkey)
200196

201197
# Inserting sync committee messages
202-
#
203198
pool.addSyncCommitteeMessage(
204199
bid1.slot, bid1, 1, sig1, subcommittee1, @[1'u64])
205200
pool.addSyncCommitteeMessage(

0 commit comments

Comments
 (0)