Skip to content

Commit

Permalink
use block ID vs full block in LC data caching (#3741)
Browse files Browse the repository at this point in the history
`cacheLightClientData` does not need full block data, pass just ID.
  • Loading branch information
etan-status authored Jun 14, 2022
1 parent 0c00b85 commit 81ff20b
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ proc getLightClientData(
try: dag.lightClientCache.data[bid]
except KeyError: raiseAssert "Unreachable"

proc cacheLightClientData*(
dag: ChainDAGRef,
state: HashedBeaconStateWithSyncCommittee,
blck: TrustedSignedBeaconBlockWithSyncAggregate) =
proc cacheLightClientData(
dag: ChainDAGRef, state: HashedBeaconStateWithSyncCommittee, bid: BlockId) =
## Cache data for a given block and its post-state to speed up creating future
## `LightClientUpdate` and `LightClientBootstrap` instances that refer to this
## block and state.
let bid = BlockId(root: blck.root, slot: blck.message.slot)
var cachedData {.noinit.}: CachedLightClientData
state.data.build_proof(
altair.CURRENT_SYNC_COMMITTEE_INDEX,
Expand Down Expand Up @@ -352,10 +349,10 @@ proc processNewBlockForLightClient*(
return

when signedBlock is bellatrix.TrustedSignedBeaconBlock:
dag.cacheLightClientData(state.bellatrixData, signedBlock)
dag.cacheLightClientData(state.bellatrixData, signedBlock.toBlockId())
dag.createLightClientUpdates(state.bellatrixData, signedBlock, parentBid)
elif signedBlock is altair.TrustedSignedBeaconBlock:
dag.cacheLightClientData(state.altairData, signedBlock)
dag.cacheLightClientData(state.altairData, signedBlock.toBlockId())
dag.createLightClientUpdates(state.altairData, signedBlock, parentBid)
elif signedBlock is phase0.TrustedSignedBeaconBlock:
raiseAssert "Unreachable" # `earliestSlot` cannot be before Altair
Expand Down Expand Up @@ -720,7 +717,7 @@ proc initLightClientCache*(dag: ChainDAGRef) =
withStateAndBlck(state, bdata):
when stateFork >= BeaconStateFork.Altair:
# Cache light client data (non-finalized blocks may refer to this)
dag.cacheLightClientData(state, blck)
dag.cacheLightClientData(state, blck.toBlockId())

# Create `LightClientUpdate` instances
if bid.slot != lowSlot:
Expand Down

0 comments on commit 81ff20b

Please sign in to comment.